-
Notifications
You must be signed in to change notification settings - Fork 0
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
Gas Optimizations #1058
Comments
3 r 4 nc Defer writing to state variables(Save 2 SSTORE - 4400 Gas) Defer 1 SSTORE to later (Save 2200 Gas in case of reverts) Avoid making an sstore if we might revert in the execution(Save 1 SSTORE: 2200 Gas if we revert) Avoid an sstore in case of a revert(Save 2200 Gas) Optimize function _addFunctions Optimize function deposit(): Avoid making an external call in case of a revert Function deposit() can be optimized by reordering the order of executions(avoid making external calls if we can make early reverts) Making use of the modifier in this function increases gas cost due to the external call that can be avoided in case we revert on parameter validation Reorder the checks to have cheaper checks first(Save 1 SLOAD in case of a revert - 2100 Gas) Save an entire SLOAD by optimizing the order of execution(saves gas if we revert - 2100 Gas) The fallback function Should validate msg.data.length first which could help avoid making a state load Avoid reading state variables earlier on if we might revert on a different cheaper check(Save 1 SLOAD in case of a revert - 2100 Gas) Cache totalDepositedAmountPerUser[_l1Token][_depositor] to a local variable The whole thing should be done in assembly Don't cache if using once No need to cache deriveL2GasPrice(_gasPrice, _l2GasPerPubdataByteLimit); Evaluate the simple arithmetic offline Unnecessary casting Caching calldata length increases gas |
141345 marked the issue as sufficient quality report |
GalloDaSballo marked the issue as grade-b |
The whole thing should be done in assemblyI've run this test in Remix-IDE:
Don't cache if using once, No need to cache deriveL2GasPrice(_gasPrice, _l2GasPerPubdataByteLimit);There are multiple of instances related to this issue. E.g., in my report I've identified about 40 variables which shoudn't be cached when they are used only once: #338 Honestly, it would be extremely unfair, if my report with more than 40 redundant variables was classified as 1 x NC, and this report - with 2 redundant variables only - the same, as 1 x NC. This issue does not describe even 10% of the instances with above problem. There are multiple of other instances (please check my linked report) which should be also mentioned here. I do not think that this issue classifies as NC, since it's too cursory. A lot of instances are missing. Caching calldata length increases gasI created a simple PoC in Remix-IDE:
IMHO, it's invalid, but I'd like to ask anyone to take another look into it |
I think this was judge fine wrt assembly you must test in context and with optimizer on Because with assembly you can skip fixing the fmp you should save gas + some unchecked math Also your test is messing up the dispatcher Recommend you use foundry Not changing the score here |
See the markdown file with the details of this report here.
The text was updated successfully, but these errors were encountered: