-
Notifications
You must be signed in to change notification settings - Fork 20
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
Standardize on Custom errors #143
Conversation
There will be many opinions on this, it is important to not bikeshed so not going to die on a hill over this but I do think there is value in common error types like I also prefer to have a |
One thing to note is that providing the contract name in the error means it's immediately obvious where an error was thrown.
Yep totally down with this, easier to read. |
I will pushback against common errors solely because it is nice to not have to run everything with |
Ok your arguments against common errors are good and I am on board with this standard |
|
||
# Proposed Solution - Revert and Custom Errors | ||
|
||
All errors returned from Optimism Smart Contracts should use `revert` with custom errors for both efficiency and safety. In the case of scripts and tests which currently use `require` frequently, they should be instead replaced with `assertEq` or similar `assert*` where appropriate, including a string as a revert message. This will allow for semgrep rules to more easily enforce the no `require` constraint. Custom errors should also include the contract name as a prefix, followed by an underscore, and `Error` as a suffix for clarity and consistency. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have we verified there are no forge issues with assertEq
when used in setUp()
or constructors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked through open foundry issues and didn't see anything? Are there anything specific concerns you had in mind?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the original issue where assertions didn't work in setUp
and I think in constructors too: foundry-rs/foundry#1291
That was a long time ago, but I'd suggest setting up a quick test to verify that the assertEq
methods still cause failures when hit in both setUp
and constructors, just to be safe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-ran your POC test
Ran 1 test suite in 124.97ms (414.42µs CPU time): 0 tests passed, 1 failed, 0 skipped (1 total tests)
Failing tests:
Encountered 1 failing test in test/Counter.t.sol:SetUpFailureTest
[FAIL. Reason: setup failed: assertion failed] setUp() (gas: 0)
Test now fails in the setUp process which is as expect and doesn't run the other tests, LGTM?
Discussed in meeting #150 , consensus is approved but PR's should be done file by file with prior discussion with the protocol team |
Description
Set a clear standard on how to handle errors for OP Smart Contracts, using only custom errors and reverts.
Tests
No tests needed
Additional context
Carried over from discord, but the idea is to stop bikeshedding around using both require with error strings and custom errors and just standardized on custom errors, which I lay out in the doc. There was some concern around using require in scripts + tests, but after some discussion on discord we agreed
assertEq
should be able to cover that in most casesMetadata
optimism issue #12478