Closed code423n4 closed 2 years ago
Disagree with the finding, we are reading from calldata which means cost of reading is 3 gas per read, cost of storing on storage is 3 as well, it would give is no savings to apply this improvemnet
Agree with sponsor, making finding invalid.
Handle
pants
Vulnerability details
At IbbtcVaultZap.deposit you read _amounts[i] twice.
Vulnerability details
There are many places in the code (especially in for-each loops) that loads the same array element more than once. In such cases, only one array boundaries check should take place, and the rest are unnecessary. Therefore, this array element should be cached in a local variable and then be loaded again using this local variable, skipping the redundent second array boundaries check.
Impact
Unnecessary array boundaries checks are taken place and increase gas costs.
Tool Used
Manual code review.
Recommended Mitigation Steps
Load the array elements once, cache them in local variables and then read them again using the local variables. For example: