Skip to content
Business logic Audit finding Intermediate

vault stakers and game players share the same reward pool

Vault stakers and game players both have a claim on the same reward pool, so when both withdraw or redeem in the same cycle, the total withdrawal requests exceed the vault's underlying assets. This can leave the last user unable to withdraw due to insufficient funds.

immeas Follow with rvierdiiev

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-01-derby-judging/issues/269

Found by

immeas, rvierdiiev

Summary

Both vault stakers earning yield and game players are taking rewards from the same reward pool. One will take rewards from the other when withdrawing/redeeming.

Vulnerability Detail

Lets simplify the whole setup a bit to show the issue here. Imagine one vault on one chain with one provider. Alice plays the game and deposits 10 DRB all allocated to the provider. Bob deposits 10k USDC to the vault.

Time passes the provider has a 10% increase. The funds are now 11k.

Both Bob and Alice are happy with this and want to collect their rewards. Alice redeems her rewards and Bob registers for a withdraw (or just withdraws).

The issue here is that both have claim to the same 1k rewards. Bob who staked should get them as yield for staking and Alice should get them as rewards for playing.

If both manage to withdraw/redeem in the same cycle this is where it will break down: https://github.com/sherlock-audit/2023-01-derby/blob/main/derby-yield-optimiser/contracts/XChainController.sol#L303

As the totalWithdrawalRequests (Bobs withdraw of all his shares and Alice redeeming of rewards) will be larger than getTotalUnderlyingVault.

The issue is not with this line of code though, its with the design of the rewards as game players and vault stakers both have a claim on the same rewards.

Impact

If a staker in the vault withdraws they will take rewards from game players and if a game player they will take yield from someone staking. If both at the same time, they will take rewards from user still staking. Resulting in the "last" user possibly not being able to withdraw due to not enough funds.

Code Snippet

https://github.com/sherlock-audit/2023-01-derby/blob/main/derby-yield-optimiser/contracts/XChainController.sol#L303

Tool used

Manual Review, hardhat

Recommendation

Honestly I don't see an easy way out of this: You could split the pools, but why would anyone stake in the vault then? Since that is just staking with less yield compared to staking in the underlying protocols directly.

You could limit staking to game players, and then make them only split the funds they actually stake. That's a large change to the protocol though and would remove the use for Derby tokens.

You could also limit rewards to only Derby tokens, but that only works as long as there is DRB to hand out. It would also require some change to the way the rewards are reserved as currently you can create a reserved rewards greater than underlying thus underflowing in stage 3.

Discussion

sjoerdsommen

Implicitly the rewards that have been paid out are accounted for in the exchangerate. However, there are some situations, like in this example, where this does not work anymore. Fixing it will be very gas intensive so we would have to see how to do it.

sjoerdsommen

Duplicate with #143

The original report as published on Sherlock, by immeas. 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 reward accounting design allows both stakers and game players to claim the same yield, so total claims can exceed the vault's actual assets.

Impact

If a staker withdraws they take rewards from game players, and if a game player redeems they take yield from stakers; if both act at the same time, the last user may be unable to withdraw due to insufficient funds.

What the attacker needed

A vault with stakers and game players; both withdraw or redeem in the same cycle

The fix

The report does not propose a clear fix, noting that splitting pools or limiting staking to game players would be large changes, and that limiting rewards to DRB tokens would require changes to reward reservation to avoid underflow.

How it was found

  1. Alice plays the game and deposits 10 DRB allocated to a provider.
  2. Bob deposits 10k USDC to the vault.
  3. The provider's value increases by 10%, making total funds 11k.
  4. Alice redeems her rewards and Bob registers for a withdrawal in the same cycle.
  5. The total withdrawal requests exceed the vault's underlying assets, causing a shortfall.

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.

Imagine two people sharing a single pot of money: one earned it by saving, the other by playing a game. If both try to take their share at the same time, there isn't enough to go around, and the last person may get nothing. This report shows that design flaw in a crypto vault.

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 immeas

View all

24 more disclosed reports, best first.

More from Derby

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.