code-423n4 / 2022-06-badger-findings

0 stars 0 forks source link

Gas Optimizations #114

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

[GAS - 01] In claimBribesFromHiddenHand, token could be reused

The same external call is made twice:

https://github.com/Badger-Finance/vested-aura/blob/d504684e4f9b56660a9e6c6dfb839dcebac3c174/contracts/MyStrategy.sol#L318 https://github.com/Badger-Finance/vested-aura/blob/d504684e4f9b56660a9e6c6dfb839dcebac3c174/contracts/MyStrategy.sol#L301

Therefore gas could saved using a memory array to avoid doing the same external call twice.

GalloDaSballo commented 2 years ago

token is the address of the token we got from the claim identifier, disagree that it can be reused

Picodes commented 2 years ago

@GalloDaSballo to clarify, my suggestion would be to store all the token results of line 301 in an array to reuse this array on line 318

GalloDaSballo commented 2 years ago

That is correct and would save 100 + 100 gas (give or take) per token as each time we are STATIC_CALLing (100 gas) to get the token back and the SLOAD would be from hot slot (100 gas)