code-423n4 / 2021-09-yaxis-findings

0 stars 0 forks source link

Gas: Loop in `StablesConverter.expected` can be avoided #124

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Handle

cmichel

Vulnerability details

The two loops in StablesConverter.expected can be avoided by using the indices mapping.

Recommended Mitigation Steps

Instead of the for loop, simply get the index i by doing:

if (_output == address(token3CRV)) {
  uint256 i = indices[_input];
  amounts[i] = _inputAmount;
} else if (_input == address(token3CRV)) {
  uint256 i = indices[_output];
  return stableSwap3Pool.calc_withdraw_one_coin(_inputAmount, i);
}

This replaces all the tokens[i] sloads with a single one.

GalloDaSballo commented 2 years ago

Similarly to #123 , sponsor mitigated, LG