yearn / yearn-vaults

Yearn Vault smart contracts
https://yearn.finance/
GNU Affero General Public License v3.0
518 stars 317 forks source link

Withdraw more than expected causes underflow #82

Closed banteg closed 3 years ago

banteg commented 3 years ago

If liquidatePosition(uint256 _amountNeeded)(uint256 _amountFreed) frees more than expected, it causes underflow down the line. This should be handled at BaseStrategy level and not cause an error.

Use this Strategy fix for now https://github.com/banteg/strategy-uni-lp-pickle/commit/fc8da9e0133b59dc19e26f5df79f6e2d836a7f78

Macarse commented 3 years ago

yHegic strategies are also doing that same fix: https://github.com/Macarse/yhegic/blob/master/contracts/strategies/StrategyHegic.sol#L102-L103

banteg commented 3 years ago

A better fix suggested by Sam https://github.com/banteg/strategy-uni-lp-pickle/commit/08f849a5639086b34c9dca248662ac4330a8bedb

fubuloubu commented 3 years ago

It is intended that the implementer be aware of the amount freed, and that it should exceed neither the amount needed nor the amount the strategy currently has available to it locally. It is only intended to use this function in withdraw but we can discuss further of how it could be used in other functions to reduce duplicated code in strategies.

https://github.com/iearn-finance/yearn-vaults/blob/cff924f1894cca1820a588b14d341c4fa4f384c0/contracts/BaseStrategy.sol#L373-L379