-
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 #55
Comments
1 L 4 r 7 nc [G-1] Improving storage efficiency through Struct Packing [G-2] Replacing booleans with uint256(1)/uint256(2) for gas optimization [G-3] Multiple address/ID mappings can be combined into a single mapping of an address/ID to a struct, where appropriate [G-4] totalDepositedAmountPerUser[_l1Token][_depositor] should be cached [G-5] Efficient event consolidation for Glogtopic Gas Savings [G-6] Optimize gas usage by avoiding variable declarations inside loops [G-7] Use dot notation method for struct assignment [G-8] !_checkBit(processedLogs, uint8(logKey) this check is redundant when processedLogs is 0 [G-9] The claimFailedDeposit() function can be refactored for greater gas efficiency [G-10] Optimize the fallback() function for better gas efficiency [G-11] Optimize the commitBatches() function for better gas efficiency [G-12] Optimize the requestL2Transaction() function for better gas efficiency [G-13] Optimize code to avoid to spend unnecessary GAS [G-14] Not initializing variables to their default values incurs extra gas, So leaving them with their default values is more gas-efficient [G-15] Don't cache immutable variable incurs extra Gas [G-16] Bytes constants are more efficient than string constants [G-17] Don't cache variable only used once [G-18] First perform less expensive checks and then proceed to more costly ones |
141345 marked the issue as sufficient quality report |
GalloDaSballo marked the issue as grade-b |
Struct packing traditionally marked as LOW for Previous contests . I also confirmed this issue with sponsor he accepted this. The protocol versions can be uint96 . This findings alone saves 4000 GAS . Even no other wardens reported this issue [G-1] Improving storage efficiency through Struct Packing[G-1.1] protocolVersion and l2SystemContractsUpgradeBatchNumber can be uint96 instead of uint256 : Saves 4000 GAS , 2 SLOT Also saving mapping cache traditionally comes under LOW categorytotalDepositedAmountPerUser[_l1Token][_depositor] should be cached : Saves 100 GAS , 1 SLOD The claimFailedDeposit() function can be refactored for greater gas efficiencyThis saves 1 external call if any failures in Regarding issue #996 there is OOS findings are marked as LOW . These instances are already found in bot reports. 4 Findings marked as LOW . Please check this . [G-8] totalBatchesCommitted is read twice from storage in Executor::commitBatches() Thank you |
[G-18] This is invalid, in both cases we're reading from struct. [G-15] and [G-17] are dups, Both issues are referring to caching local variable and should be counted once [G-16] This is invalid [G-13] This is not refactoring issue, it's just changing the order of [G-08] This seems to be invalid, this is required to make sure that log hasn't been processed multiple of times [G-07] This is not refactoring issue, it should be NC [G-05] Events There are two emergency cases - someone is trying to change the governor (then In case of contract's critical changes, each event should be linked to the action. Current implementation provides that. [G-1.2] |
Hi @lsaudit Thank you for your suggestions. I think all your understanding and assumptions are wrong. [G-18] regarding this require(!diamondStorage.isFrozen || !facet.isFreezable, "q1"); !diamondStorage.isFrozen is a state variable, while !facet.isFreezable is a memory variable. According to best practices for gas optimization, it's more efficient to first check the memory variable !facet.isFreezable. If this check returns true, then it's not necessary to access the state variable !diamondStorage.isFrozen, as memory operations are less costly in terms of gas than state variable accesses. This approach helps in reducing gas consumption and optimizing smart contract performance [G-15] Its about immutable cache [G-17] its about state variables cache. This is the standard way followed for all findings. [G-16] I reported about constants not normal variables. Constant values in a Solidity contract are fixed and do not change anywhere in the contract once they are assigned. These values always remain the same, as all instances are constants. Once a constant value is assigned, it cannot be changed [G-9] regarding this issue if any failures this will save 1 external calls. Yes ,refactoring because the structure of the code is aligned . Any changes in existing code always comes refactoring category [G-13],[G-12], [G-11], [G-10], [G-9] yes still the code structure is changed. All this suggestions saves gas in particular scenarios. [G-8] !_checkBit(processedLogs, uint8(logKey) this check is redundant when processedLogs is 0. Suggestion indicates that the check becomes redundant during the first iteration, as the processedLogs value is initially 0. In this scenario, the condition will always be true for the first iteration, rendering the check unnecessary at that stage [G-05] Suggestion about combining events in Solidity smart contracts is indeed a recognized gas optimization technique. In scenarios where functions like acceptGovernor() and acceptAdmin() are called, and both trigger separate events, combining these two events into a single event can result in significant gas savings. By emitting a single event instead of two separate ones, you save on the gas costs associated with each event. Specifically, you conserve 375 gas for each Glogtopic (the cost for a topic in an event log) and an additional 700 gas for the two instances combined. This optimization is beneficial because it reduces the amount of data stored on the blockchain and the computational work needed to process and log these events. This approach has been accepted in many previous contests, demonstrating its effectiveness in optimizing smart contracts for better gas efficiency [G-1.2] This struct optimization alone saves Regarding your suggestion, the sponsor has confirmed that the increment within the contract is always sequential, as per their response. I don't know disclosing sponsor name is right or wrong. so i just hide his name |
I want to add some additional points here [G-10] Optimize the fallback() function for better gas efficiency I don't understand why this is marked as disputed. Any failures in require(msg.data.length >= 4 || msg.data.length == 0, "Ut") mean that creating the storage variable Diamond.DiamondStorage storage diamondStorage = Diamond.getDiamondStorage() and making an external call is a waste of gas. This finding has already been proven and accepted in many old contests. [G-11] Optimize the commitBatches() function for better gas efficiency According to Solidity coding standards and for better gas efficiency, parameters should be checked first, followed by function calls and state variable checks [G-12] Optimize the requestL2Transaction() function for better gas efficiency If there are any failures in this check _l2GasPerPubdataByteLimit == REQUIRED_L2_GAS_PRICE_PER_PUBDATA, then checking and assigning sender values becomes a waste of gas. I also want to mention that all my findings include the I also sent 'many unique findings' and Struct packing is a prime example of this. This technique alone saves 6000 gas and uses only 3 slots, which no other wardens have reported. This mitigation accepted by sponsor. "My report is currently the second best. It has
If the grades based on Example Thank you for this chance to express my thoughts. |
There is an inconsistency in the severity assessment. Different opinions exist between the judge and the presorter. One report marks the same findings as ignored, while another report marks the same findings as NC and L. Based on this, the grades assigned are affected. It seems that my reports have mistakenly marked some of my findings as 'Ignored', I believe. From issue #624 these findings are accepted in other reports as valid but in my reports those are marked as ignoring findings. My findingsFrom Issue #924 My findingsI request to reassess my findings. Regards, |
Have reviewed and believe B is acceptable, ultimately I believe the report to be sufficient, but not A, would recommend less findings but higher impact |
See the markdown file with the details of this report here.
The text was updated successfully, but these errors were encountered: