-
Notifications
You must be signed in to change notification settings - Fork 43
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
Custom errors or require? #30
Comments
I personally prefer |
If I remember correctly, the main downside of requires was bytecode side. That won't be a problem here |
Custom errors allow to have debug variables (also useful in production): error Unauthorized(uint256 var); |
Agree, but we never used it yet, and it would be replaced by offchain tool as well (tenderly, phalcon, etc.) |
New poll haha? |
Except @Rubilmax's point, which I think is fair but not mandatory, there is nothing in favor of custom errors. Except if new points arise we can conclude in favor of requires. |
I think custom errors are useful for other reasons as well. They allow us to standardize the errors and reuse them throughout the code, rather than having to synchronize the same error messages across different contexts. This makes writing and maintaining tests throughout code changes easier. Also, bytecode size does impact the gas cost of calling the contract. In particular, 3 extra gas is used per byte to call the contract. |
You could do the same using constants no?
Really? Do you have the source please? |
I don't think so (https://www.evm.codes/#f1?fork=shanghai) |
If you dive into the footnotes of call, there is an additional dynamic cost. |
It's about the memory size no? |
When calling a contract, the code must be copied. (Otherwise, how can you run the code?) |
I'm pretty sure that the code of the called contract is not copied in the EVM memory (otherwise you would not even need a contract size limit). So the cost of calling a big contract is the same than calling a small contract. |
Agree with @MathisGD |
Nice ! As a side note, this is a good use case for morpho-sandbox, where I can reproduce and tweak your code by just doing |
Good point, I'll open a PR (but FYI I checked that the long contract's bytecode is longer) https://github.com/morpho-labs/morpho-sandbox/pull/10 |
Okay, yes I see I'm wrong on the gas cost point. I guess do whatever you like then, though I still think it's strange that we would choose to use string errors over a solidity feature that is becoming widely used and integrated across many tools. Using strings means that every contract that wants to handle the error has to adapt to matching the string rather than using the error hash if they want to catch the error. And the error would not appear in the ABI. |
That's a good point actually |
The best thing would be require with custom error ? PR in solidity 0.8.21 ? |
Not me 🙈 |
Ok so it comes down to:
|
There's also a gas discussion. Custom errors being cheaper than requires. |
1., 2., and gas diff are not important to me.
On this topic (4.), try/catching in solidity does not support custom errors for now: it only supports string/bytes. It's a syntax thing only, but it counts to me. I also don't want the decision we're taking now influence the choice of dependencies (such as I'm ok to move on with |
When I wrote point 3 I had in mind that it prevents typos, so I don't see how it's related to making it easier for integrators to have error messages. You are talking about point 4 right ?
Thanks I'll edit my message so that it is exhaustive |
This is indeed a nice benefit of having errors extracted to a single place. Let's forget about my point because indeed, integrators debugging an integration would either have the reason string or the custom error, each being enough to debug. |
I think the difference it that custom errors are added to the ABI |
The problem is that the
That's why etherscan is always displaying "execution error" on morpho optimizers errors |
@julien-devatom we're going toward the require for your information |
No description provided.
The text was updated successfully, but these errors were encountered: