Skip to content
Business logic Audit finding Intermediate

if Slash Validator occurs, UNSTAKING_QUEUE's unstake amount will not be accurate

The UNSTAKING_QUEUE records the initial_balance of an unbonding delegation, but if a validator is slashed, the actual balance received is lower. This causes execute_withdraw_fund() to fail due to insufficient balance, blocking the queue.

J4X_ Follow with Kow and bin2chen

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-05-andromeda-ado-judging/issues/44

Found by

J4X_, Kow, bin2chen

Summary

UNSTAKING_QUEUE holds UnbondingDelegationEntry.initial_balance. If a Slash Validator occurs, which actually unstake amount is UnbondingDelegationEntry.balance, this value will be smaller than UnbondingDelegationEntry.initial_balance which will cause execute_withdraw_fund() to fail.

Vulnerability Detail

in andromeda-validator-staking We can get the stake funds back in the following ways

  1. call execute_unstake(100) , UnbondingDelegationEntry.initial_balance = 100 ,
    • UNSTAKING_QUEUE.push_back(100)
  2. wait UnbondingTime , x/staking transfer funds (UnbondingDelegationEntry.balance=100) to andromeda-validator-staking
  3. call execute_withdraw_fund()
    • UNSTAKING_QUEUE.pop_front(100)
    • transfer 100 to sender from andromeda-validator-staking

If it doesn't happen Slash Validator, balance == initial_balance https://github.com/cosmos/cosmos-sdk/blob/207b30262fc4ae62cb6fc7c2f6df1dfaf7bc1c4d/x/staking/proto/cosmos/staking/v1beta1/staking.proto#L238

PROTO
message UnbondingDelegationEntry {
...
  google.protobuf.Timestamp completion_time = 2
      [(gogoproto.nullable) = false, (amino.dont_omitempty) = true, (gogoproto.stdtime) = true];
  // initial_balance defines the tokens initially scheduled to receive at completion.
@>string initial_balance = 3 [
    (cosmos_proto.scalar)  = "cosmos.Int",
    (gogoproto.customtype) = "cosmossdk.io/math.Int",
    (gogoproto.nullable)   = false
  ];
  // balance defines the tokens to receive at completion.
@>string balance = 4 [
    (cosmos_proto.scalar)  = "cosmos.Int",
    (gogoproto.customtype) = "cosmossdk.io/math.Int",
    (gogoproto.nullable)   = false
  ];
...
}

However, happen Slash Validator, the actual funds received will be less than the value recorded in the `UNSTAKING_QUEUE' record. https://github.com/cosmos/cosmos-sdk/tree/main/x/staking#slash-unbonding-delegation

Slash Unbonding Delegation

When a validator is slashed, so are those unbonding delegations from the validator that began unbonding after the time of the infraction. Every entry in every unbonding delegation from the validator is slashed by slashFactor. The amount slashed is calculated from the InitialBalance of the delegation and is capped to prevent a resulting negative balance. Completed (or mature) unbondings are not slashed.

Impact

If a Slash Validator occurs, the value of the UNSTAKING_QUEUE record will be less than the actual value received Resulting in

  1. failure due to insufficient balance
  2. blocking the normal queue behind

Code Snippet

https://github.com/sherlock-audit/2024-05-andromeda-ado/blob/main/andromeda-core/contracts/finance/andromeda-validator-staking/src/contract.rs#L333

Tool used

Manual Review

Recommendation

when the balance is insufficient, only the balance is returned

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/andromedaprotocol/andromeda-core/pull/551

cowboy0015

withdraw_fund function is now working as an emergency for withdrawing funds (including locked rewards and funds to handle unexpected cases)

bin2chen66

fix-reviews note: https://github.com/andromedaprotocol/andromeda-core/pull/551 This PR removes the logic of execute_withdraw_fund() to calculate the quantity, and directly withdraws all the balance, solving the problem of Slash quantity difference

The original report as published on Sherlock, by J4X_. 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

The contract uses the initial_balance from the unbonding delegation entry instead of the actual balance after potential slashing.

What the attacker needed

Validator is slashed; user has unstaked and waited unbonding time

The fix

The protocol team fixed this issue by removing the quantity calculation in execute_withdraw_fund() and directly withdrawing all the balance.

How it was found

  1. Call execute_unstake(100), which pushes 100 to UNSTAKING_QUEUE.
  2. Wait for the unbonding time to complete.
  3. Call execute_withdraw_fund(), which pops 100 from the queue and attempts to transfer 100 to the sender.
  4. If a slash occurred, the contract's balance is less than 100, causing the transfer to fail.

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 unstake tokens, the system records the original amount you asked to unstake. If the validator you staked with misbehaves, a portion of your staked tokens can be taken away (a slash). Then, when you try to withdraw, the system expects the full original amount but only has less, so the withdrawal fails and blocks others in the queue.

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 J4X_

View all

6 more disclosed reports, best first.

More from Andromeda – Validator Staking ADO and Vesting ADO

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.