Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaceasserts with require #149

Open
Tracked by #46
emizzle opened this issue Aug 12, 2024 · 3 comments · May be fixed by #216
Open
Tracked by #46

Replaceasserts with require #149

emizzle opened this issue Aug 12, 2024 · 3 comments · May be fixed by #216
Assignees
Labels
Marketplace See https://miro.com/app/board/uXjVNZ03E-c=/ for details

Comments

@emizzle
Copy link
Collaborator

emizzle commented Aug 12, 2024

See comment #144 (comment).

@markspanbroek
Copy link
Member

There is a semantic difference between require() and assert(). Preconditions such as requirements on a function's input are handled by require(), Things that a programmer thinks should never happen are handled by assert().
This semantic difference is for example used by echidna for fuzzing. They use require() to ensure that fuzzed input values match expected ranges, and then check that assertions don't happen.

Also I expect there to be a good reason why asserts eat up all the gas; maybe to ensure that exceptions are not caught and then handled elsewhere. It could be a security property that ensures that execution really stops.

@0x-r4bbit
Copy link
Collaborator

@markspanbroek you're not wrong, and we're probably entering the space of bike shedding here.
I'd extend the definition of where/when to use require to "use for conditions that depend on external factors the code doesn't control", which is user inputs as you've described, but also external calls like transferring tokens.
This also allows for providing proper custom errors (which asserts don't allow for).

Assertions are more appropriate for internal checks and typically used for cases when there's a serious internal error to your code.

Ultimately it's your decision, but I at least wanted to bring it up.

@markspanbroek
Copy link
Member

Ah, good point @0x-r4bbit, the call to the ERC20 contract can indeed be seen as an external call which the code doesn't control. Using require() does make sense there. I read the description of this issue as "we're going to replace all asserts with requires".

@2-towns 2-towns self-assigned this Jan 17, 2025
@2-towns 2-towns linked a pull request Jan 17, 2025 that will close this issue
@2-towns 2-towns added the Marketplace See https://miro.com/app/board/uXjVNZ03E-c=/ for details label Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Marketplace See https://miro.com/app/board/uXjVNZ03E-c=/ for details
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants