code-423n4 / 2021-05-yield-findings

0 stars 0 forks source link

Inefficient Witch buy #25

Open code423n4 opened 3 years ago

code423n4 commented 3 years ago

Handle

cmichel

Vulnerability details

In Witch.buy there's the possibility to do one multiplication instead of two divisions: Instead of computing the ink price as 1 / artPrice and then dividing by it to get the ink amount as ink = art / price, just keep the art price and multiply it by the art amount. These lines need to be changed:

price = term1.wmul(term2); // this is the art price in terms of ink now, instead of ink price
ink = uint256(art).wmulup(price); // can just multiply by art price

Impact

One saves gas by doing one multiplication instead of two divisions which seems to be an important goal of Yield v2.

alcueca commented 3 years ago

I need to confirm the math is right, before I confirm.