code-423n4 / 2021-06-pooltogether-findings

0 stars 0 forks source link

Gas optimization on `BadgerYieldSource` #108

Closed code423n4 closed 3 years ago

code423n4 commented 3 years ago

Handle

shw

Vulnerability details

Impact

The redeemToken function in BadgerYieldSource can be designed as more gas-efficient by reusing local variables.

Proof of Concept

Variables badgerSett and badger in the BadgerYieldSource are currently declared private. However, a similar implementation, SushiYieldSource, declares sushiBar and sushiAddr public. Suppose the badgerSett and badger in BadgerYieldSource are needed to be declared public. In that case, the redeemToken function can be more gas-efficient by reading these two state variables into local variables first and then reusing them, as written in the redeemToken function of SushiYieldSource contract.

Referenced code: BadgerYieldSource.sol#L15-L16 BadgerYieldSource.sol#L57-L81 SushiYieldSource.sol#L17-L18 SushiYieldSource.sol#L66-L92

Recommended Mitigation Steps

Let badgerSett and badger be public and re-write the redeemToken function in the BadgerYieldSource contract.

asselstine commented 3 years ago

See https://github.com/code-423n4/2021-06-pooltogether-findings/issues/38