Skip to content
Business logic Audit finding Intermediate

Curve LP staking allows adding false tokensIn to account by setting _claim_rewards to false

The controller contracts incorrectly assume that using the full function signature for deposit or withdraw means the user is claiming rewards, so they add reward tokens to the user's account even when the claim flag is false. This can cause the user's asset tracking to be inconsistent with reality.

obront Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2022-11-sentiment-judging/issues/20

Found by

obront

Summary

In CurveLPStakingController.sol and BalancerLPStakingController.sol, canDepositAndClaim() and canWithdrawAndClaim() assume that the user is claiming reward tokens, and add these tokens to the tokensIn array (to add to their account).

However, the only requirement to go down this code path is to use the full function signature (ie deposit(uint256,address,bool)), so false tokens will be added to a user account if they use the full signature with the _claim_rewards bool set to false.

Vulnerability Detail

Each Controller returns an array of tokensIn that will be added to the user's account, if they don't already hold a balance.

In CurveLPStakingController.sol and BalancerLPStakingController.sol, there are two overlapping pairs of function signatures:

  • deposit(uint256) and deposit(uint256,address,bool) are the same function, but the middle parameter (_addr) defaults to msg.sender and the final parameter (_claim_rewards) defaults to false
  • withdraw(uint256) and withdraw(uint256,bool) are the same function, but the final parameter (_claim_rewards) defaults to false

The assumption in the Controller logic is that, if a user uses the full signature, they are claiming their rewards. However, this isn't always the case. It is perfectly valid for a user to use the full function and pass false (the default argument) to the _claim_rewards parameter.

In this case, the function signature would lead to canDepositAndClaim() or canWithdrawAndClaim(), and all the rewards tokens would be added to the user's account.

Impact

Accounting on user accounts can be thrown off (intentionally or unintentionally), resulting in mismatches between their assets array and hasAsset mapping and the reality of their account.

Code Snippet

https://github.com/sherlock-audit/2022-11-sentiment/blob/main/controller-merged/src/balancer/BalancerLPStakingController.sol#L24-L25

https://github.com/sherlock-audit/2022-11-sentiment/blob/main/controller-merged/src/balancer/BalancerLPStakingController.sol#L52

https://github.com/sherlock-audit/2022-11-sentiment/blob/main/controller-merged/src/balancer/BalancerLPStakingController.sol#L72-L92

Tool used

Manual Review

Recommendation

In canCall(), decode the calldata to get the value of the _claim_rewards bool. If this value is false, call the non-claim version of the function (ie canDeposit() instead of canDepositAndClaim()).

Discussion

ruvaag

While I agree with the issue, I'm not sure if it qualifies as a medium because I don't think this can lead to loss of funds or functionality.

zobront

Confirmed fix in https://github.com/sentimentxyz/controller/pull/48

Evert0x

I think a medium severity is valid as there is a risk of to let users add tokens to their account that they don't really have.

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

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 controller determines whether rewards are being claimed based solely on the function signature used, rather than decoding the actual boolean argument that indicates whether to claim.

Impact

User account accounting can be thrown off, leading to mismatches between the recorded assets and the actual holdings, but no direct loss of funds is demonstrated.

What the attacker needed

User calls deposit or withdraw with full signature; sets _claim_rewards to false

The fix

The controller should decode the calldata to check the `_claim_rewards` boolean and call the non-claim version of the function when it is false; the text confirms a fix was made.

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.

In this system, a controller keeps track of which tokens a user has. When a user calls a function with extra parameters, the controller wrongly thinks they are claiming rewards and adds reward tokens to their account, even if they said not to claim. This makes the user's recorded balance wrong.

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 obront

View all

46 more disclosed reports, best first.

More from Sentiment Update #3

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.