Platform: Code4rena
Start Date: 14/11/2021
Pot Size: $30,000 USDC
Total HM: 7
Participants: 13
Period: 3 days
Judge: leastwood
Total Solo HM: 4
Id: 57
League: ETH
Rank: 10/13
Findings: 2
Award: $241.56
🌟 Selected for report: 3
🚀 Solo Findings: 0
🌟 Selected for report: pants
pants
At Zap.sol init function you have the for loop pattern:
for (uint256 i = 0; i < array.length; i++) {
// do something with array[i]
}
In such for loops, the `array.length` is read on every iteration, instead of caching it once in a local variable and read it again using the local variable. ## Impact Storage reads are much more expensive than reading local variables. Memory and calldata reads are a bit more expensive than reading local variables. ## Tool Used Manual code review. ## Recommended Mitigation Steps Read these values from storage / memory / calldata once, cache them in local variables and then read them again using the local variables. For example:
uint256 length = array.length;
for (uint256 i = 0; i < length; i++) {
// do something with array[i]
}
#0 - GalloDaSballo
2021-11-17T15:46:48Z
Agree we should have cached the length value
🌟 Selected for report: pants
pants
The function deposit(uint256[4] calldata _amounts) public whenNotPaused could be set external instead of public. (in IbbtcVaultZap)
#0 - GalloDaSballo
2021-11-17T15:44:51Z
Agree with the finding
🌟 Selected for report: pants
pants
uint initial value is 0. Therefore the assignment uint i = 0 is unnecessary (Zap.sol line 70)
#0 - GalloDaSballo
2021-11-17T15:45:18Z
Agree but probably wontfix for readability