Comments (30)
I personally prefer require
because with them you write invariants whereas with if () revert
you write what you don't want to see, which is a little bit less natural to me.
from morpho-blue.
If I remember correctly, the main downside of requires was bytecode side. That won't be a problem here
from morpho-blue.
It's about the memory size no?
When calling a contract, the code must be copied. (Otherwise, how can you run the code?)
from morpho-blue.
The best thing would be require with custom error ? PR in solidity 0.8.21 ?
from morpho-blue.
1., 2., and gas diff are not important to me.
3. can have an impact on integrators: if it's easy for them to have error messages, it's easier for them to integrate us (debug their txs).
- is the most important one 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 Ownable
, Owned
, EIP712
, etc): I don't think we should select a dependency based on whether they throw custom errors or reason strings (because I don't value this debate much, nor its impact).
I'm ok to move on with require
strings or custom errors, as I don't have a strong opinion either.
from morpho-blue.
Custom errors allow to have debug variables (also useful in production):
error Unauthorized(uint256 var);
from morpho-blue.
Agree, but we never used it yet, and it would be replaced by offchain tool as well (tenderly, phalcon, etc.)
from morpho-blue.
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.
You could do the same using constants no?
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.
Really? Do you have the source please?
from morpho-blue.
It's about the memory size no?
from morpho-blue.
quick proof:
- https://gist.github.com/MathisGD/eee8c4c2e8783b3a49bf4daf99c19b46
- https://gist.github.com/MathisGD/af514c4d707117c4e6df0ee1f632d90b
from morpho-blue.
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
from morpho-blue.
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.
from morpho-blue.
That's a good point actually
from morpho-blue.
Ok so it comes down to:
require
condition feeling more natural thanrevert
condition. Do we want to write the happy case of the revert case ?
Happy case for me.- bytecode size.
It should not matter for blue. - ensuring that revert messages are consistent at compilation.
It's a nice benefit but not extremely important IMO - using the one that is getting the most support.
I don't know enough to say, but it seems like an important point - custom errors cost less gas than requires
If I remember well it was not by much
from morpho-blue.
There's also a gas discussion. Custom errors being cheaper than requires.
from morpho-blue.
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 ?
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.
Also, 3. can be achieved with reason strings as well as custom errors (it's only about defining them in a single place)?
from morpho-blue.
I think the difference it that custom errors are added to the ABI
from morpho-blue.
The problem is that the revert
adds nothing to the transaction payload and fills the error message with "execution reverted". We have to go through the whole call trace to retrieve the error.
require
uses the error message and fills it with the message written in the code. The error is therefore raised to the highest level and simplifies the reading of the transaction.
That's why etherscan is always displaying "execution error" on morpho optimizers errors
from morpho-blue.
@julien-devatom we're going toward the require for your information
from morpho-blue.
New poll haha?
from morpho-blue.
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.
from morpho-blue.
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.
from morpho-blue.
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.
I don't think so (https://www.evm.codes/#f1?fork=shanghai)
from morpho-blue.
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.
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.
from morpho-blue.
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.
from morpho-blue.
Agree with @MathisGD
from morpho-blue.
quick proof:
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 git checkout
. For example, I might want to check the contracts size here
from morpho-blue.
Not me 🙈
from morpho-blue.
- can have an impact on integrators: if it's easy for them to have error messages, it's easier for them to integrate us (debug their txs).
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 ?
There's also a gas discussion. Custom errors being cheaper than requires.
Thanks I'll edit my message so that it is exhaustive
from morpho-blue.
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.
Just for that I think I'd go for the require with strings as @Rubilmax proposed in #126 unless solc 0.8.21 fixes that
from morpho-blue.
Related Issues (20)
- Unnecessary cast HOT 1
- Contango integration feedback HOT 4
- Revert silent invariant tests HOT 1
- Add return bytes to callbacks
- Restore invariants in CI
- The Cantina security review has a "draft" overlay HOT 1
- Test living vertigo mutations HOT 5
- `MorphoBalancesLib.expectedBorrowAssets` may return a value greater than `totalBorrowAssets` HOT 4
- IRM zero
- `changePrank` is deprecated HOT 2
- re-add the certora rule removed in #642
- remove the test tree
- Should `expectedAssets` precise the rounding HOT 2
- Cantina Managed report is still draft HOT 1
- Fix NPMjs deployment
- Update whitepaper with correct market naming HOT 1
- are you deploy to Sepolia Testnet yet? HOT 1
- Morpho pinned to solc 0.8.19 make it incompatible with latest OpenZeppelin HOT 6
- boundUnhealthyPosition does not use amountCollateral at all
- `forge t` failing on `main`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from morpho-blue.