Skip to content
Business logic Audit finding Intermediate

`validatorMaxStake` can be bypassed by using `setValidatorAddress()`

The setValidatorAddress function allows a validator to migrate their stake to a new address without checking the validatorMaxStake limit, so the combined stake can exceed the maximum. An attacker can repeatedly migrate to accumulate more stake than allowed, earning unfair rewards and increasing their delegator cap.

Al-Qa-qa Follow with PUSH0, SadBase and 5 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-11-covalent-judging/issues/66

Found by

Al-Qa-qa, PUSH0, SadBase, aslanbek, cergyk, petro1912, qmdddd, zach223

Summary

setValidatorAddress() allows a validator to migrate to a new address of their choice. However, the current logic only stacks up the old address' stake to the new one, never checking validatorMaxStake.

Vulnerability Detail

The current logic for setValidatorAddress() is as follow:

Solidity
function setValidatorAddress(uint128 validatorId, address newAddress) external whenNotPaused {
    // ...
    v.stakings[newAddress].shares += v.stakings[msg.sender].shares;
    v.stakings[newAddress].staked += v.stakings[msg.sender].staked;
    delete v.stakings[msg.sender];
    // ...
}

The old address' stake is simply stacked on top of the new address' stake. There are no other checks for this amount, even though the new address may already have contained a stake.

Then the combined total of the two stakings may exceed validatorMaxStake. This accordingly allows the new (validator) staker's amount to bypass said threshold, breaking an important invariant of the protocol.

Proof of concept

  1. Bob the validator has a self-stake equal to validatorMaxStake.
  2. Bob has another address, B2, with some stake delegated to Bob's validator.
  3. Bob migrates to B2.
  4. Bob's stake is stacked on top of B2. B2 becomes the new validator address, but their stake has exceeded validatorMaxStake.
  5. B2 can then repeated this procedure to addresses B3, B4, ..., despite B2 already holding more than the max allowed amount.

Bob now holds more stake than he should be able to, allowing him to earn an unfair amount of rewards compared to other validators.

We also note that, even if the admin tries to freeze Bob, he can front-run the freeze with an unstake, since unstakes are not blocked from withdrawing (after cooldown ends).

Impact

  • Breaking an important invariant of the protocol.
  • Allowing any validator to bypass the max stake amount. In turn allows them to earn an unfair amount of validator rewards in the process.
  • Allows a validator to unfairly increase their max delegator amount, as an effect of increasing (validator stake) * maxCapMultiplier.

Code Snippet

https://github.com/sherlock-audit/2023-11-covalent/blob/main/cqt-staking/contracts/OperationalStaking.sol#L689-L711

Tool used

Manual Review

Recommendation

Check that the new address's total stake does not exceed validatorMaxStake before proceeding with the migration.

Discussion

sherlock-admin2

1 comment(s) were left on this issue during the judging contest.

takarez commented:

valid: user can exceed max deposit and potentially increase his max delegator amoun; high(1)

noslav

fixed by prevent new validator address stake from exceeding max stake - sa66/s…

CergyK

Fix LGTM

sherlock-admin

The protocol team fixed this issue in PR/commit https://github.com/covalenthq/cqt-staking/pull/125/commits/0eba6b318b9400e4a5d6511ba4c96922b83b9abd.

sherlock-admin

The Lead Senior Watson signed off on the fix.

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

Impact

A validator can bypass the maximum stake limit, earn unfair rewards, and increase their delegator cap; the text also notes that a validator can front-run a freeze with an unstake.

What the attacker needed

Validator with stake at max; second address with delegated stake; ability to call setValidatorAddress

The fix

The issue was fixed by preventing the new validator address's stake from exceeding the maximum stake.

How it was found

  1. Bob the validator has a self-stake equal to validatorMaxStake.
  2. Bob has another address, B2, with some stake delegated to Bob's validator.
  3. Bob migrates to B2.
  4. Bob's stake is stacked on top of B2, exceeding validatorMaxStake.
  5. B2 can repeat this procedure to addresses B3, B4, etc.

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 staking contract has a rule that no validator can hold more than a certain maximum amount of stake. The function that lets a validator move their stake to a new address simply adds the old stake to the new address without checking the limit. By moving stake around, a validator can end up with more than the maximum, which lets them earn more rewards than they should.

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 Al-Qa-qa

View all

7 more disclosed reports, best first.

More from Covalent

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.