Unbonding validator random selection can be predicted
The unbonding function chose which validator to unstake from using a random number seeded only by the block height, which is predictable. An attacker could repeatedly bond to their own validator and unbond when the predictable choice favoured them, eventually capturing all Anchor bond stake and rewards.
Submitted by cmichel
When unbonding, the pick_validator function is supposed to choose a random validator to unstake from.
However, this randomness can be predicted knowing the block height which is very easy to predict.
let mut iteration_index = 0;
while claimed.u128() > 0 {
let mut rng = XorShiftRng::seed_from_u64(block_height + iteration_index);
let random_index = rng.gen_range(0, deletable_delegations.len());
// ...
}
As validators are paid rewards proportional to their stake, choosing where to bond and unbond from directly impacts validator rewards.
Combined with being able to choose the validator when bonding (see execute_bond) a validator can steal rewards and increase their own.
Proof of Concept
- Validator A wishes to increase their rewards. They call
execute_bond(, validator = A)with their validator. - Validator A precomputes the randomness for unbonding if the block was mined at the next block height. If it’s a different validator, they call
unbond. The stake is removed from some other validator and the user receives it back. Note that validator A’s stake did not decrease and contains the initial bond amount. - They repeat this process until every single bond of the Anchor platform is now staked to validator A and they earn huge rewards while everyone else does not earn anything from Anchor bonds anymore.
Recommended Mitigation Steps
An unbond must always remove stake from the validator the stake was originally bonded to, otherwise, it’s exploitable by the attack above.
Consider keeping track of all bonds with a bond_id and create a map of bond_id -> validator.
If a validator’s stake decreased due to slashing, take the remaining unstake amount proportionally from all other validators.
bitn8 (Anchor) disagreed with severity
Alex the Entreprenerd (triage) commented:
Looks like weak RNG, Medium or High seem proper.
Albert Chon (judge) decreased severity to Medium and commented:
Indeed, block height should definitely not be used as a source of randomness.
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 random selection used a seed derived solely from the block height, which is public and predictable, instead of a secure source of randomness.
Impact
A validator could steal rewards and increase their own stake, potentially capturing all Anchor bond stake and rewards, while other validators earn nothing from Anchor bonds.
What the attacker needed
Attacker controls a validator; ability to bond and unbond repeatedly
The fix
The unbond function should always remove stake from the validator it was originally bonded to, for example by tracking bond_id to validator mappings, and only proportionally unstake from others if slashing reduced that validator's stake.
How it was found
- Validator A calls execute_bond with their own validator to bond stake.
- Validator A precomputes the unbonding randomness for the next block height; if it selects a different validator, they call unbond.
- They repeat this process until all Anchor bond stake is staked to validator A.
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 picks a validator to remove them from. It used a 'random' number that was actually based on the current block number, which anyone can look up or guess. So an attacker could predict the pick and only unstake when it would take tokens from someone else, slowly moving all the stake to their own validator.
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.