#37295 [SC-High] Rewards can be stolen by depositing immediately after reward tokens get sent to vault
Submitted on Dec 1st 2024 at 23:15:36 UTC by @Emmanuel001 for Audit Comp | Jito Restaking
Report ID: #37295
Report Type: Smart Contract
Report severity: High
Target: https://github.com/jito-foundation/restaking/tree/master/vault_program
Impacts:
Theft of unclaimed yield
Description
Brief/Intro
The update_vault_balance function is designed to reward VRT holders by redistributing staking rewards. However, it has a vulnerability: deposits made after reward tokens are sent to the vault but before update_vault_balance is called become eligible for those rewards. This allows attackers to monitor for rewards sent to the vault, deposit tokens immediately, and unfairly gain extra rewards at the expense of existing VRT holders
Vulnerability Details
In order to reward vrt holders, protocol exposes a update_vault_balance
function, which does the following:
gets the current st token balance of the vault(new_st_balance)(https://github.com/jito-foundation/restaking/blob/master/vault_program/src/update_vault_balance.rs#L44)
st_rewards received is gotten by subtracting the vault.tokens_deposited(token balance accounted for by the vault) from the new_st_balance.(https://github.com/jito-foundation/restaking/blob/master/vault_program/src/update_vault_balance.rs#L47)
necessary fees, if any, gets deducted from the st_rewards
tokens_deposited gets updated to the new_st_balance, which means that each vrt is worth more(https://github.com/jito-foundation/restaking/blob/master/vault_program/src/update_vault_balance.rs#L60)
So we can see that to reward vrt holders, rewarder first sends st_tokens to the vault, then calls update_vault_balance
. The issue is, any deposits made in between the rewarder sending st tokens, and calling update_vault_balance
, will make the deposit elligible for the rewards. So an attacker can monitor blockchain for any st_tokens sent to the vault, and then deposit immediately after, which would immediately make his deposited tokens to be worth more(at the expense of other vrt holders) when update_vault_balance
gets called. This is a theft of rewards.
Consider the following scenario(summary of what happened in PoC):
Alice deposits 1000 st tokens, gets minted 1000 vrt
Fast forward an epoch, rewarder sends 1000 st tokens to vault
Bob sees this, and immediately deposits 1000 st tokens, and gets minted 1000 vrt tokens
Bob calls
update_vault_balance
Now, both Alice and Bob's vrt tokens are worth 1500 st each
Impact Details
The vulnerability allows attackers to steal rewards meant for existing VRT holders by depositing tokens just before the update_vault_balance function is called, diluting the rewards for honest participants. This leads to economic loss for legitimate users.
References
https://github.com/jito-foundation/restaking/blob/master/vault_program/src/update_vault_balance.rs#L44 https://github.com/jito-foundation/restaking/blob/master/vault_program/src/update_vault_balance.rs#L47 https://github.com/jito-foundation/restaking/blob/master/vault_program/src/update_vault_balance.rs#L60
Proof of Concept
Proof of Concept
Within integration_tests/tests/vault folder, create a file named "whitehat.rs"
Be sure to include the whitehat.rs test file in integration_tests/tests/vault/mod.rs
Paste the following into the whitehat.rs file:
Run the PoC test