The _depositIntoVault
function in the LendingPool contract attempts to deposit crvUSD tokens directly into the Curve vault without first transferring them from the RToken contract where they are actually stored. This results in failed transactions as the LendingPool contract does not have the necessary token balance.
Pre-condition:
CurveVault
contract is deployed and set in LendingPool via setCurveVault()
User wants to deposit crvUSD into the LendingPool and calls the deposit()
function:
The _rebalanceLiquidity()
function gets called :
The _depositIntoVault()
function gets called if the currentBuffer is larger than the desiredBuffer:
The issue is that the function attempts to deposit crvUSD tokens directly from the LendingPool contract into the Curve vault. However, all crvUSD tokens are actually stored in the RToken contract, as evidenced by the transferAsset function in RToken
:
In order to run the test you need to:
Run foundryup
to get the latest version of Foundry
Install hardhat-foundry: npm install --save-dev @nomicfoundation/hardhat-foundry
Import it in your Hardhat config: require("@nomicfoundation/hardhat-foundry");
Make sure you've set the BASE_RPC_URL
in the .env
file or comment out the forking
option in the hardhat config.
Run npx hardhat init-foundry
There is one file in the test folder that will throw an error during compilation so rename the file in test/unit/libraries/ReserveLibraryMock.sol
to => ReserveLibraryMock.sol_broken
so it doesn't get compiled anymore (we don't need it anyways).
Create a new folder test/foundry
Paste the below code into a new test file i.e.: FoundryTest.t.sol
Run the test: forge test --mc FoundryTest -vvvv
I rate this as medium because the problem might not exist from the beginning but once the curveVault address has been set, all deposits will start to fail because of this issue. There is no way to set the curveVault address back to address(0) due to this check in the setCurveVault()
function [https://github.com/Cyfrin/2025-02-raac/blob/89ccb062e2b175374d40d824263a4c0b601bcb7f/contracts/core/pools/LendingPool/LendingPool.sol#L704] to disable the _rebalanceLiquidity() function.
This will cause:
All deposit transactions that trigger vault deposits will fail
The protocol's yield generation mechanism through Curve vaults is non-functional
Users cannot deposit funds when the protocol needs to rebalance liquidity into the vault
The protocol cannot maintain its intended liquidity buffer ratio
The protocol needs to redeploy
Manual review
Foundry
Modify the _depositIntoVault function to first transfer the assets from the RToken contract before depositing into the vault:
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.