Skip to content
Business logic Audit finding Intermediate

Possible lost msg.value

The depositCollateral function in GeneralVault and its implementations (LidoVault, ConvexCurveLPVault) can lose ETH sent as msg.value when the asset is an ERC20 token, or when more ETH than the specified amount is sent for an ETH deposit. An attacker or careless user could permanently lose funds by calling depositCollateral with mismatched asset and value.

rotcivegaf Follow

Originally disclosed on Code4rena

Submitted by rotcivegaf, also found by AuditsAreUS, berndartmueller, cccz, MaratCerby, dipp, and StErMi

GeneralVault.sol#L75-L89 LidoVault.sol#L79-L104 ConvexCurveLPVault.sol#L131-L149

Possible lost value in depositCollateral function call

Proof of Concept

In call depositCollateral can will send value and the asset can be an ERC20(!= address(0)), if LidoVault and ConvexCurveLPVault contract receive this call the fouds will lost. Also in LidoVault, L88, if send as asset ETH(== address(0)) and send more value than _amount(msg.value > _amount), the exedent will lost.

Recommended Mitigation Steps

In GeneralVault, depositCollateral function:

  • Check if the msg.value is zero when the _asset is ERC20(!= address(0))
  • Check if the msg.value is equeal to _amount when the _asset ETH(== address(0))
function depositCollateral(address _asset, uint256 _amount) external payable virtual {
  if (_asset != address(0)) { // asset = ERC20
    require(msg.value == 0, <AN ERROR FROM Errors LIBRARY>);
  } else { // asset = ETH
    require(msg.value == _amount, <AN ERROR FROM Errors LIBRARY>);
  }

  // Deposit asset to vault and receive stAsset
  // Ex: if user deposit 100ETH, this will deposit 100ETH to Lido and receive 100stETH TODO No Lido
  (address _stAsset, uint256 _stAssetAmount) = _depositToYieldPool(_asset, _amount);

  // Deposit stAsset to lendingPool, then user will get aToken of stAsset
  ILendingPool(_addressesProvider.getLendingPool()).deposit(
    _stAsset,
    _stAssetAmount,
    msg.sender,
    0
  );

  emit DepositCollateral(_asset, msg.sender, _amount);
}

Also can remove the require(msg.value > 0, Errors.VT_COLLATERAL_DEPOSIT_REQUIRE_ETH); in LidoVault, L88

sforman2000 (Sturdy) confirmed

atozICT20 (Sturdy) commented:

Fix the issue of ETH loss sturdyfi/code4rena-may-2022#3


The original report as published on Code4rena, by rotcivegaf. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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 depositCollateral function does not validate that msg.value is zero for ERC20 deposits or equal to _amount for ETH deposits, so excess or misdirected ETH is trapped in the contract.

Impact

Users could lose ETH sent as msg.value when depositing ERC20 tokens or when sending more than the specified amount for an ETH deposit.

What the attacker needed

User calls depositCollateral with ERC20 asset and msg.value…; or user sends ETH with msg.value > _amount

The fix

The depositCollateral function should require msg.value to be zero for ERC20 assets and equal to _amount for ETH assets, and the redundant check in LidoVault should be removed.

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.

When you send cryptocurrency to a smart contract, you can attach extra funds (called msg.value) to the call. If the contract does not check that the attached funds match what it expects, those extra funds can get stuck in the contract forever. This report shows that a deposit function could accept extra funds without using them, causing a loss.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by rotcivegaf

View all

4 more disclosed reports, best first.

More from Sturdy contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.