You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Starting from Solidity v0.8.4, there is a convenient and gas-efficient way to explain to users why an operation failed through the use of custom errors. Until now, you could already use strings to give more information about failures (e.g., revert("Insufficient funds.");), but they are rather expensive, especially when it comes to deploy cost, and it is difficult to use dynamic information in them.
Source: https://blog.soliditylang.org/2021/04/21/custom-errors/
Mitigation
Consider using custom errors instead if the contract uses solidity version 0.8.4 or above.
As the fact that EVM is a 256-bits stack machine, contract storage will be read and written in a 256 bits stack. All stacks will be read and written on utilizing for the struct variable that used multiple stacks (total size > 256 bits). Therefore, if a contract want to update certain variables which located in the same storage slot or less than the total slot, it is better to read/write only the particular variables rather than the entire struct.
Custom Error Should Be Used For Gas-optimization
Permalinks
Description
Mitigation
Consider using custom errors instead if the contract uses solidity version 0.8.4 or above.
Local Variable Used Only Once
Permalinks
https://github.com/code-423n4/2022-05-cally/blob/1849f9ee12434038aa80753266ce6a2f2b082c59/contracts/src/Cally.sol#L227-L228
Description
It is assumed that
auctionStartTimestamp
is a locally cached variable in order to reduce gas cost, however, it is only used once after being defined.Mitigation
auctionStartTimestamp
can be replaced at this line to save more gas.Update Only Certain Variable in Struct Can Save More Gas
Permalinks
https://github.com/code-423n4/2022-05-cally/blob/1849f9ee12434038aa80753266ce6a2f2b082c59/contracts/src/Cally.sol#L241
Description
As the fact that EVM is a 256-bits stack machine, contract storage will be read and written in a 256 bits stack. All stacks will be read and written on utilizing for the struct variable that used multiple stacks (total size > 256 bits). Therefore, if a contract want to update certain variables which located in the same storage slot or less than the total slot, it is better to read/write only the particular variables rather than the entire struct.
Mitigation
The LoC 231-241 can be replaced as following:
The LoC 278-279 can be replaced as following:
The gas report test from Foundry:
│ Function Name ┆ min ┆ avg ┆ median ┆ max ┆ # calls │
│ buyOption ┆ 1788 ┆ 75271 ┆ 79045 ┆ 99845 ┆ 41 │
│ buyOption (optimized) ┆ 1788 ┆ 74517 ┆ 78186 ┆ 98986 ┆ 41 |
│ exercise ┆ 470 ┆ 50035 ┆ 64223 ┆ 87933 ┆ 18 │
│ exercise (optimized) ┆ 470 ┆ 49258 ┆ 63163 ┆ 86873 ┆ 18 │
The text was updated successfully, but these errors were encountered: