When the _finalize
function is executed through the withdraw
function, it calls the _handleReturn
function with the actual withdrawal amount and the positionClosed
status as parameters.
The issue arises when positionClosed
is false. The logic above allows the user to withdraw more tokens than intended.
Let’s illustrate with an example.
Assume the ratio of tokens to shares is 1:1, and the total amount of tokens is 120.
The attacker deposits 20 tokens to open a position. (Total tokens: 140, Attackers’ shares: 20)
The attacker closes 19 tokens of the position. (withdrawn
= 19)
—> amount = 19 (withdrawn
) + (140 - 19) (balanceBeforeWithdrawal
) * 20 (shares
) / 140 (totalShares
)
—> amount = 19 + 17.28 ⇒ 36.28
—> The withdrawal amount is 36 tokens, which is more than the 20 tokens originally deposited.
Now, let's assume the attacker closes all positions.
The attacker deposits 20 tokens to open a position. (Total tokens: 140, Attackers’ shares: 20)
The attacker closes all positions. 140 (total tokens) * 20 (shares) / 140 (totalShares) ⇒ 20
The attacker receives the same 20 tokens they initially deposited.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.