[ConcurRewardPool] Possible reentrancy when claiming rewards
The reward pool contract transferred reward tokens to the caller before resetting the caller's recorded balance to zero. If the reward token supports a sender callback (such as an ERC777 token), an attacker could re-enter the claim function during the transfer and drain the pool's rewards.
Originally disclosed on Code4rena
Submitted by ShadowyNoobDev, also found by 0xw4rd3n, CertoraInc, ckksec, Czar102, defsec, Alex the Entreprenerd, Heartless, IllIllI, Jujic, kirk-baird, leastwood, pauliax, peritoflores, Randyyy, reassor, Rhynorater, Sleepy, SolidityScan, and wuwe1
Since the reward tokens are transferred before the balances are set to 0, it is possible to perform a reentrancy attack if the reward token has some kind of call back functionality e.g. ERC777. pBTC is an ERC777 token that is currently available on Convex. A similar attack occurred with imBTC on uniswap v1.
Proof of Concept
-
Preparation
- Assume that pBTC is used as extra rewards for this victim convex pool.
- A malicious user interacts with Concur through a smart contract. He follows the standard flow and has some rewards to be claimed.
- The malicious user interacts with this smart contract to register a bad
tokensToSend()callback function through the ERC-1820 contract. - In this
tokensToSend()function, he callsConcurRewardPool.claimRewards()n-1 more times to drain contract.
-
Attack
- When he calls
ConcurRewardPool.claimRewards()for the first time, the pBTC reward tokens are transferred. - You can see from the pBTC contract on line 871 that
_callTokensToSend(from, from, recipient, amount, "", "");is called inside thetransfer()function. - If you trace to the
_callTokensToSendfunction definition to line 1147, you will notice that it callsIERC777Sender(implementer).tokensToSend(operator, from, to, amount, userData, operatorData);on line 1159. - Since the malicious user already registered a bad
tokensToSend()function, this function will be called thus draining majority of the pBTC rewards available on theConcurRewardPoolcontract.
- When he calls
You can also find a walkthrough replicating a similar attack here.
Recommended Mitigation Steps
- Use a nonReentrant modifier
- set balances to 0 first before disbursing the rewards
Alex the Entreprenerd (judge) commented:
The warden has shown how using a specific reward token can lead to reentrancy for the function
claimRewards.Because the finding is contingent on a specific token that enables the exploit, I believe Medium Severity to be appropriate.
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 claim function sends reward tokens before zeroing the claimant's stored balance, so a token with a transfer callback allows re-entry into the same claim.
Impact
An attacker could drain most of the reward tokens held by the pool, but only if the reward token is one that invokes a sender callback during transfers.
What the attacker needed
Reward token has a transfer callback (e.g. ERC777); attacker uses a contract with a registered callback; attacker has claimable rewards
The fix
The contract should set the claimant's balance to zero before sending rewards and should use a nonReentrant modifier.
How it was found
- Assume an ERC777-style token such as pBTC is used as extra rewards for the pool.
- The attacker interacts through a smart contract and registers a malicious tokensToSend callback via ERC-1820.
- The attacker calls claimRewards, which transfers the reward tokens.
- The token's transfer calls the attacker's tokensToSend callback, which calls claimRewards again to drain the contract.
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 is when a contract calls out to another contract, and that other contract calls back into the first one before it has finished updating its records. Here the pool pays out rewards before marking them as paid, so a malicious recipient can ask for the payout again and again while the first payment is still in progress. This only works if the reward token itself lets the recipient run code during a transfer.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.