The function withdraw of Vault.sol calculates _toWithdraw, _after and _diff
if _diff < _toWithdraw then:
_amount = _balance + _diff, which is the same as:
_amount = _balance + _after - _balance, which is the same as:
_amount = _after
Changing this makes the code easier to read and save a bit of gas.
Handle
gpersoon
Vulnerability details
Impact
The function withdraw of Vault.sol calculates _toWithdraw, _after and _diff if _diff < _toWithdraw then: _amount = _balance + _diff, which is the same as: _amount = _balance + _after - _balance, which is the same as: _amount = _after
Changing this makes the code easier to read and save a bit of gas.
Proof of Concept
https://github.com/code-423n4/2021-09-yaxis/blob/main/contracts/v3/Vault.sol#L226
Tools Used
Recommended Mitigation Steps
replace _amount = _balance.add(_diff);
with _amount = _after;