Core Contracts

Regnum Aurum Acquisition Corp
HardhatReal World AssetsNFT
77,280 USDC
View results
Submission Details
Severity: high
Valid

User can get RAAC rewards by depositing and withdrawing simultaneously.

Summary

The withdraw function contains a mechanism for distributing RAAC rewards by calculating `(totalRewards * userDeposit) / totalDeposits;`. An attacker can exploit this to get rewards by depositing and withdrawing either in the same block or the latter block. This leads to the attacker getting risk free rewards which is meant for genuine users depositing in the protocol.

Vulnerability Details

When a user deposits their rToken into a stability pool:

  • rToken gets transferred from user

  • deToken gets minted to user.

  • the mapping userDeposits[msg.sender] gets updated.

When withdrawing :

  • raacRewards gets calculated by calling the calculateRaacRewards(msg.sender)

  • subtracts the amount from userDeposits[msg.sender]

  • burns the deToken from msg.sender

  • transfers rToken and raacRewards to the user

The vulnerability lies in the calculateRaacRewards function:

function calculateRaacRewards(address user) public view returns (uint256) {
uint256 userDeposit = userDeposits[user];
uint256 totalDeposits = deToken.totalSupply();
uint256 totalRewards = raacToken.balanceOf(address(this));
if (totalDeposits < 1e6) return 0;
return (totalRewards * userDeposit) / totalDeposits;
}

Consider the following:

(For simplifying let the exchange rate be consistent and decimals be 18)

  • Alice deposit 100e18 rToken and gets back 100e18 deToken. Therefore deToken.totalSupply() = 100e18.

  • Some time passes and 10e18 RAAC token rewards gets accured.

  • Bob deposits 100e18 rToken to 100e18 deToken.

  • Bob immediately withdraws 100e18 deTokens. Per the calculateRaacRewards totalRewards=10e18, userDeposit=100e18, totalDeposits = 200e18.

  • (10e18 * 100e18) / 200e18 = 5e18 raac rewards tokens. Repeating the steps would gain Bob another 2.5, then 1.25 and so on.

  • Bob can do this multiple times to gain most of the rewards tokens with no risk leaving Alice with a small percent of the entitled tokens.

Impact

Attacker can steal most of the reward.

Tools Used

VS Code

Updates

Lead Judging Commences

inallhonesty Lead Judge 6 months ago
Submission Judgement Published
Validated
Assigned finding tags:

StabilityPool::calculateRaacRewards is vulnerable to just in time deposits

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.