Open code423n4 opened 2 years ago
cmichel
The two loops in StablesConverter.convert can be avoided by using the indices mapping.
StablesConverter.convert
indices
Instead of the for loop, simply get the index i by doing:
for
i
if (_output == address(token3CRV)) { uint256 i = indices[_input]; amounts[i] = _inputAmount; } else if (_input == address(token3CRV)) { uint256 i = indices[_output]; remove_liquidity_one_coin(_, i); }
This replaces all the tokens[i] sloads with a single one.
tokens[i]
Using indices instead of looping will save gas, Sponsor mitigated, LG
Handle
cmichel
Vulnerability details
The two loops in
StablesConverter.convert
can be avoided by using theindices
mapping.Recommended Mitigation Steps
Instead of the
for
loop, simply get the indexi
by doing:This replaces all the
tokens[i]
sloads with a single one.