code-423n4 / 2021-11-badgerzaps-findings

0 stars 0 forks source link

SLOAD pools.length for Every Loop is Waste of Gas #28

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Handle

Meta0xNull

Vulnerability details

Impact

The Pool size is known which is 0 to 3. Thus, SLOAD pools.length for Every Loop is Waste of Gas

Proof of Concept

https://github.com/Badger-Finance/ibbtc/blob/d8b95e8d145eb196ba20033267a9ba43a17be02c/contracts/Zap.sol#L70

Tools Used

Manual Review

Recommended Mitigation Steps

Before: for (uint i = 0; i < pools.length; i++)

After: for (uint i = 0; i < 4; i++)

GalloDaSballo commented 2 years ago

Agree with finding