Platform: Code4rena
Start Date: 24/10/2023
Pot Size: $149,725 USDC
Total HM: 7
Participants: 52
Period: 21 days
Judge: ronnyx2017
Total Solo HM: 2
Id: 300
League: ETH
Rank: 38/52
Findings: 1
Award: $21.02
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: DavidGiladi
Also found by: 0xhex, 0xta, Collinsoden, JCK, Madalad, SAQ, SY_S, Sathish9098, cheatc0d3, codeslide, hihen, hunter_w3b, jamshed, lsaudit, mgf15, nonseodion, oualidpro, petrichor, sivanesh_808, tala7985, unique, ybansal2403, zabihullahazadzoi
21.0214 USDC - $21.02
Rearranging the structure of the MoveTokensParams
struct can lead to significant gas savings in smart contracts. Each slot saved in the struct can potentially avoid an extra SSTORE operation, which costs around 20,000 gas for the first setting of the struct.
Before Rearrangement:
struct MoveTokensParams { address user; uint256 collSharesChange; uint256 collAddUnderlying; // ONLY for isCollIncrease=true bool isCollIncrease; uint256 netDebtChange; bool isDebtIncrease; }
After Rearrangement:
struct MoveTokensParams { uint256 collSharesChange; uint256 collAddUnderlying; uint256 netDebtChange; address user; bool isCollIncrease; bool isDebtIncrease; // potentially more bools or small fields here }
Before Rearrangement:
struct ChainlinkResponse { uint80 roundEthBtcId; uint80 roundStEthEthId; uint256 answer; uint256 timestampEthBtc; uint256 timestampStEthEth; bool success; }
After Rearrangement:
struct ChainlinkResponse { uint80 roundEthBtcId; uint80 roundStEthEthId; bool success; uint256 answer; uint256 timestampEthBtc; uint256 timestampStEthEth; }
In the current FallbackResponse struct, the timestamp variable is declared as uint256, which occupies a complete storage slot of 256 bits. Given that timestamps generally represent time in seconds since the Unix epoch, the range provided by a uint240 is excessively large, covering a period significantly longer than 100 years. This over-allocation of storage is inefficient in terms of gas usage and contract storage.
struct FallbackResponse { uint256 answer; - uint256 timestamp; + uint248 timestamp; // Downcasted from uint256 bool success; }
uint240
for the timestamp
instead of uint256
.In the IPriceFeed
contract, the minuteDecayFactor
variable is declared as uint256
. However, this size may be larger than necessary for its intended use. A smaller data type, such as uint248
, could be sufficient depending on the maximum value minuteDecayFactor
is expected to hold. This change would allow for more efficient use of storage space.
uint256 public constant SECONDS_IN_ONE_MINUTE = 60; uint256 public constant MIN_REDEMPTION_FEE_FLOOR = (DECIMAL_PRECISION * 5) / 1000; // 0.5% uint256 public redemptionFeeFloor = MIN_REDEMPTION_FEE_FLOOR; bool public redemptionsPaused; // Suggested Change: Downcast minuteDecayFactor to uint248 + uint248 public minuteDecayFactor = 999037758833783000; - uint256 public minuteDecayFactor = 999037758833783000; uint256 public constant MIN_MINUTE_DECAY_FACTOR = 1; // Non-zero uint256 public constant MAX_MINUTE_DECAY_FACTOR = 999999999999999999; // Very fast decay rate uint256 internal immutable deploymentStartTime;
30. EnumerableSet.Bytes32Set internal enabledFunctionSigsPublic;
17. bytes32 NO_ROLES = bytes32(0);
#0 - c4-pre-sort
2023-11-17T14:43:28Z
bytes032 marked the issue as sufficient quality report
#1 - c4-judge
2023-11-28T03:05:53Z
jhsagd76 marked the issue as grade-c
#2 - jhsagd76
2023-12-06T17:11:26Z
4 * 4
16
#3 - c4-judge
2023-12-06T20:55:20Z
jhsagd76 marked the issue as grade-b