curve admin can drain pool via reentrancy (equal to execute emergency withdraw and rug tokenmak fund by third party)
The report claims that a Curve pool admin can drain the pool by setting a malicious fee receiver and reentering the withdraw_admin_fees function, which could harm Tokemak's funds if it uses that pool. The attacker could repeatedly reenter to withdraw more than the admin balance.
Source: https://github.com/sherlock-audit/2023-06-tokemak-judging/issues/862
Found by
ctf_sec
curve admin can drain pool via reentrancy (equal to execute emergency withdraw and rug tokenmak fund)
Vulnerability Detail
A few curve liquidity is pool is well in-scope:
Curve Pools
Curve stETH/ETH: 0x06325440D014e39736583c165C2963BA99fAf14E
Curve stETH/ETH ng: 0x21E27a5E5513D6e65C4f830167390997aA84843a
Curve stETH/ETH concentrated: 0x828b154032950C8ff7CF8085D841723Db2696056
Curve stETH/frxETH: 0x4d9f9D15101EEC665F77210cB999639f760F831E
Curve rETH/ETH: 0x6c38cE8984a890F5e46e6dF6117C26b3F1EcfC9C
Curve rETH/wstETH: 0x447Ddd4960d9fdBF6af9a790560d0AF76795CB08
Curve rETH/frxETH: 0xbA6c373992AD8ec1f7520E5878E5540Eb36DeBf1
Curve cbETH/ETH: 0x5b6C539b224014A09B3388e51CaAA8e354c959C8
Curve cbETH/frxETH: 0x548E063CE6F3BaC31457E4f5b4e2345286274257
Curve frxETH/ETH: 0xf43211935C781D5ca1a41d2041F397B8A7366C7A
Curve swETH/frxETH: 0xe49AdDc2D1A131c6b8145F0EBa1C946B7198e0BA
one of the pool is 0x21E27a5E5513D6e65C4f830167390997aA84843a
https://etherscan.io/address/0x21E27a5E5513D6e65C4f830167390997aA84843a#code#L1121
Admin of curve pools can easily drain curve pools via reentrancy or via the withdraw_admin_fees function.
@external
def withdraw_admin_fees():
receiver: address = Factory(self.factory).get_fee_receiver(self)
amount: uint256 = self.admin_balances[0]
if amount != 0:
raw_call(receiver, b"", value=amount)
amount = self.admin_balances[1]
if amount != 0:
assert ERC20(self.coins[1]).transfer(receiver, amount, default_return_value=True)
self.admin_balances = empty(uint256[N_COINS])
if admin of the curve can set a receiver to a malicious smart contract and reenter withdraw_admin_fees a 1000 times to drain the pool even the admin_balances is small
the line of code
raw_call(receiver, b"", value=amount)
trigger the reentrancy
This is a problem because as stated by the tokemak team:
In case of external protocol integrations, are the risks of external contracts pausing or executing an emergency withdrawal acceptable? If not, Watsons will submit issues related to these situations that can harm your protocol's functionality.
Pausing or emergency withdrawals are not acceptable for Tokemak.
As you can see above, pausing or emergency withdrawals are not acceptable, and this is possible for cuve pools so this is a valid issue according to the protocol and according to the read me
Impact
curve admins can drain pool via reentrancy
Code Snippet
https://etherscan.io/address/0x21E27a5E5513D6e65C4f830167390997aA84843a#code#L1121
Tool used
Manual Review
Recommendation
N/A
Discussion
sherlock-admin2
1 comment(s) were left on this issue during the judging contest.
Trumpero commented:
invalid, as the submission stated: "Admin of curve pools can easily drain curve pools via reentrancy", so no vulnerability for tokemak here
JeffCX
Escalate
as the protocol docs mentioned
https://audits.sherlock.xyz/contests/101
In case of external protocol integrations, are the risks of external contracts pausing or executing an emergency withdrawal acceptable? If not, Watsons will submit issues related to these situations that can harm your protocol's functionality.
Pausing or emergency withdrawals are not acceptable for Tokemak.
in the issue got exploit in this report, user from tokenmak lose fund as well
sherlock-admin2
Escalate
as the protocol docs mentioned
https://audits.sherlock.xyz/contests/101
In case of external protocol integrations, are the risks of external contracts pausing or executing an emergency withdrawal acceptable? If not, Watsons will submit issues related to these situations that can harm your protocol's functionality.
Pausing or emergency withdrawals are not acceptable for Tokemak.
in the issue got exploit in this report, user from tokenmak lose fund as well
You've created a valid escalation!
To remove the escalation from consideration: Delete your comment.
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
Trumpero
Hi @JeffCX, based on this comment of sponsors in the contest channel, I think this issue should be marked as low/invalid: https://discord.com/channels/812037309376495636/1130514263522410506/1143588977962647582
JeffCX
Sponsor said emergency withdrawal or pause is an unacceptable risk.
Did you read it as "acceptable" sir?
JeffCX
Some discussion is happening https://github.com/sherlock-audit/2023-06-tokemak-judging/issues/899
but this is a separate external integration risk than the balancer one that can impact tokemak user :) and don't think this is a known issue
Trumpero
Hello @JeffCX,
Upon further consideration of this matter, I find it to be valid. The potential for the curve admin to exploit the reentrancy-attack and drain the curve pool could have a direct impact on the Tokemak protocol.
I suggest that you review this issue as well, @codenutt.
JeffCX
Hello @JeffCX,
Upon further consideration of this matter, I find it to be valid. The potential for the curve admin to exploit the reentrancy-attack and drain the curve pool could have a direct impact on the Tokemak protocol.
I suggest that you review this issue as well, @codenutt.
Thank you very much! 😄🎉!!
codenutt
Thanks @Trumpero / @JeffCX! Just to confirm, this is an issue with some Curve pools just in general, correct? Not necessarily with a particular interaction we have with them.
Trumpero
Yes, you are right
Evert0x
Planning to accept escalation and label issue as valid
JeffCX
thanks👍🙏
Evert0x
@Trumpero would you agree with high severity?
Trumpero
No I think it should be medium since it assume the curve admin become malicious
JeffCX
Agree with medium, https://github.com/sherlock-audit/2023-06-tokemak-judging/issues/570 similar finding about external admin turn into malicious risk is marked as medium as well
Evert0x
Result: Medium Unique
sherlock-admin2
Escalations have been resolved successfully!
Escalation status:
- JEFFCX: accepted
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the withdraw_admin_fees function sends Ether to an external address before resetting the admin balance, allowing reentrancy.
Impact
A malicious Curve pool admin could drain the pool, which may indirectly cause Tokemak users to lose funds if Tokemak uses that pool.
What the attacker needed
Curve pool admin is malicious; Tokemak uses the affected Curve pool
How it was found
- The Curve pool admin sets the fee receiver to a malicious smart contract.
- The malicious contract calls withdraw_admin_fees and, upon receiving Ether, reenters the function.
- The reentrancy is repeated many times to drain the pool.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A reentrancy attack happens when a contract calls another contract before updating its own records, letting the called contract call back into the original function repeatedly. Here, the Curve pool sends Ether to a fee receiver before resetting the admin balance, so a malicious receiver can call withdraw_admin_fees again and again to take more funds than it should. This requires the Curve pool admin to be malicious.
What is Race condition?
Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.