57271 sc medium incorrect penalty calculation on emergency withdrawals redemption s
Description
The Problematic code
//@audit: penalty incorrectly applied even when the token has already been unlocked. Should only be applied to tokens that are still locked.
function _emergencyWithdraw(address by, address to, address _owner, uint256 assets, uint256 shares) internal {
require(shares > 0, SharesEqZero());
uint256 penalty = FixedPointMathLib.fullMulDiv(assets, penaltyPercentage, SCALING_FACTOR);
uint256 payout;
unchecked {
payout = assets - penalty; //@audit-issue: penalty is only for locked tokens. It does not check the amount of locked/unlocked tokens before applying
}
if (by != _owner) _spendAllowance(_owner, by, shares); //@audit-info: protects against other users stealing funds
_removeAnySharesFor(_owner, shares);
_burn(_owner, shares);
LONG.safeTransfer(to, payout);
LONG.safeTransfer(treasury, penalty);
emit EmergencyWithdraw(by, to, _owner, assets, shares); //@audit-low: emits the wring data. should emit payout: for both assets and shares. shouldnt count input -> incorrect information
// also emit standard ERC4626 Withdraw for indexers/analytics
emit Withdraw(by, to, _owner, assets, shares);
}Code Flow
Impact
Mitigation
Link to Proof of Concept
Proof of Concept
Previous57485 sc medium emergencywithdraw cost more penalty than expectedNext57716 sc critical erc4626 inflation bug in staking contract
Was this helpful?