Skip to content
Business logic Audit finding Intermediate

Faulty Escrow config will lock up reward tokens in Staking contract

A vault owner can add a reward token with an escrow configuration that has a zero duration and a very low percentage, which passes without validation. When users later try to claim rewards, the escrow lock always reverts, so the reward tokens become permanently stuck in the staking contract.

gjaldon Follow with Aymen0909, 0x52 and 3 others

Originally disclosed on Code4rena

Submitted by gjaldon, also found by Aymen0909, 0x52, hansfriese, KIntern_NA, and rvierdiiev

https://github.com/code-423n4/2023-01-popcorn/blob/main/src/vault/VaultController.sol#L443-L471

https://github.com/code-423n4/2023-01-popcorn/blob/main/src/utils/MultiRewardStaking.sol#L265-L270

https://github.com/code-423n4/2023-01-popcorn/blob/main/src/utils/MultiRewardStaking.sol#L178-L179

https://github.com/code-423n4/2023-01-popcorn/blob/main/src/utils/MultiRewardStaking.sol#L201

https://github.com/code-423n4/2023-01-popcorn/blob/main/src/utils/MultiRewardEscrow.sol#L97-L98

Impact

When a Vault owner creates/adds a reward token to the Staking contract with faulty escrow config parameters, the reward tokens sent to the Staking contract will forever be locked up. This can happen since there are no validity checks on the values of the Escrow config for the reward tokens when adding a reward token to the Staking contract via the VaultController.

Proof of Concept

Below are the steps to reproduce the issue:

  1. Vault Creator/Owner adds a reward token to the Staking contract of a vault they own/created, passing Escrow configuration parameters of useEscrow = true, escrowDuration = 0 and escrowPercentage = 1. This passes without issue since there are no validity checks for the Escrow config in the following lines:

    https://github.com/code-423n4/2023-01-popcorn/blob/main/src/vault/VaultController.sol#L443-L471

    https://github.com/code-423n4/2023-01-popcorn/blob/main/src/utils/MultiRewardStaking.sol#L265-L271

  2. This issue not noticeable until someone attempts to claimRewards for that misconfigured rewardToken from the Staking contract. This will always revert for all users trying to claim rewards for the affected rewardToken since it always attempts to lock some funds in escrow:

    https://github.com/code-423n4/2023-01-popcorn/blob/main/src/utils/MultiRewardStaking.sol#L178-L180

    And one of these checks in Escrow.lock will always fail since escrowDuration was set to 0 and escrowPercentage is so low that rewards must be so high for the escrow amount to not be 0: https://github.com/code-423n4/2023-01-popcorn/blob/main/src/utils/MultiRewardEscrow.sol#L97-L98

  3. Reward tokens for that misconfigured rewardToken contract will now forever be locked in the Staking contract leading to loss of funds vault creator/owner.

Tools Used

VS Code

Recommended Mitigation Steps

  1. Add validity checks for escrowDuration and escrowPercentage before these lines: https://github.com/code-423n4/2023-01-popcorn/blob/main/src/utils/MultiRewardStaking.sol#L265-L270

Make sure that escrowDuration is greater than 0 and that escrowPercentage is high enough that it won’t always trigger reverts when users claim rewards.

  1. If reward amounts are too small, the escrow amount will be 0 and that will revert the claimRewards so users will not be able to claim rewards. Maybe check if there are escrowed amounts greater than 0 and only call Escrow.lock if it is. That way, users with small rewards will always be able to claim funds. Note that only users with larger rewards at time of claiming will have funds escrowed for smaller escrow percentages.

RedVeil (Popcorn) confirmed


The original report as published on Code4rena, by gjaldon. 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 lack of validation on escrow configuration parameters when adding a reward token, allowing a zero duration and a percentage so low that the escrow amount rounds to zero and causes a revert.

Impact

Reward tokens for the misconfigured reward token are permanently locked, causing a loss of funds for the vault creator or owner.

What the attacker needed

Vault owner adds reward token; faulty escrow config (duration 0, low percentage); users attempt to claim rewards

The fix

Add validity checks so that escrowDuration is greater than zero and escrowPercentage is high enough to avoid always reverting, and only call Escrow.lock when the escrow amount is greater than zero.

How it was found

  1. Vault owner adds a reward token to the staking contract with useEscrow true, escrowDuration 0, and escrowPercentage 1.
  2. The configuration is accepted because no validity checks exist.
  3. A user attempts to claim rewards for that reward token.
  4. The claim reverts because the escrow lock check fails due to the zero duration and tiny percentage.
  5. The reward tokens remain locked in the staking 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 vault owner sets up a reward token with escrow settings that are invalid, like a zero lock time. The system does not check these settings, so the setup succeeds. Later, when anyone tries to claim rewards, the escrow step fails and the tokens cannot be moved, leaving them stuck forever.

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 gjaldon

View all

6 more disclosed reports, best first.

More from Popcorn 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.