Skip to content
Smart contracts Audit finding Advanced

Delegation is not updated on slash and unlock

The slash and unlock functions change an account's non-voting locked gold but do not update the delegated voting power, so the delegated balance becomes incorrect. An attacker could manipulate governance voting results by having delegated power that does not reflect the actual locked gold after slashing or unlocking.

shadowHunter Follow

Originally disclosed on Immunefi

Critical View original
  • Disclosed after under an hour

#37427 [SC-Critical] Delegation is not updated on slash and unlock

Submitted on Dec 4th 2024 at 14:44:39 UTC by @shadowHunter for Audit Comp | Celo

Description

Brief/Intro

It was observed that delegation is not updated on slashing for reporter and caller in unlock operation. This causes incorrect balance accounting

Vulnerability Details

  1. Observe the 'slash' function and 'unlock` function
  2. Both of this function calls _incrementNonvotingAccountBalance and _decrementNonvotingAccountBalance which changes the non voting balance and thus AccountTotalLockedGold
function getAccountTotalLockedGold(address account) public view returns (uint256) {
    uint256 total = balances[account].nonvoting;
    return total.add(getElection().getTotalVotesByAccount(account));
  }
  1. Lets say User A is unlocking or calling slash on another User B then it is always required to call _updateDelegatedAmount on both Users so that delegated balance gets updated correctly as per new total locked
  2. But the same is missing in both functions

Impact Details

Delegated balance power will be incorrect

References

In unlock call _updateDelegatedAmount(msg.sender); In slash call _updateDelegatedAmount(reporter);

Proof of Concept

Proof of Concept

function test_ShouldReduceAccountsLockedGoldBalance_WhenAccountIsSlashedForAllOfItsLockedGoldAndIsDelegating()
    public
  {
    uint256 penalty = value;
    uint256 reward = value / 2;
    whenVoteSigner_LockedGoldDelegateGovernanceVotes();
    vm.prank(caller);
    lockedGold.delegateGovernanceVotes(delegatee1, FixidityLib.newFixedFraction(30, 100).unwrap());
    assertEq(lockedGold.getAccountNonvotingLockedGold(caller), 1000);
    assertEq(lockedGold.getAccountTotalLockedGold(caller), 1000);
    assertEq(lockedGold.getAccountTotalGovernanceVotingPower(delegatee1), 300);
    helper_WhenAccountIsSlashedForAllOfItsLockedGold(penalty, reward, delegator);
    assertEq(lockedGold.getAccountNonvotingLockedGold(delegator), 0);
    assertEq(lockedGold.getAccountTotalLockedGold(delegator), 0);
    assertNotEq(lockedGold.getAccountTotalGovernanceVotingPower(delegatee1), 300);
  }

The original report as published on Immunefi, by shadowHunter. Images and videos are our own copies; raw HTML is shown as text. View it on Immunefi.

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 slash and unlock functions fail to call _updateDelegatedAmount for the affected accounts after changing non-voting balances.

Impact

Delegated voting power could become incorrect, potentially allowing manipulation of governance voting results.

What the attacker needed

A user delegates governance votes; the user is slashed or unlocks gold

The fix

The functions should be fixed by calling _updateDelegatedAmount for the relevant accounts after balance changes.

How it was found

  1. Observe the slash and unlock functions.
  2. Note that both call _incrementNonvotingAccountBalance and _decrementNonvotingAccountBalance, changing non-voting balance and AccountTotalLockedGold.
  3. Realise that _updateDelegatedAmount is not called on the affected users, so delegated balance is not updated.

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.

In this smart contract, users can lock gold and delegate their voting power to someone else. When gold is slashed or unlocked, the total locked amount changes, but the delegated voting power is not recalculated. This means the delegatee keeps voting power that no longer matches the actual locked gold, which can distort governance votes.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by shadowHunter

View all

25 more disclosed reports, best first.

More from Celo

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.