Skip to content
Smart contracts Write-up Advanced

Polygon Consensus Bypass Bug Fix Review

A flaw in Polygon's staking contract allowed a delegator to migrate tokens from a validator and then unstake that validator, causing the total staking power to be reduced twice. By repeating this, an attacker could lower the total staking power enough to bypass the two-thirds consensus threshold and submit malicious checkpoints to drain funds.

immunefi.com

Published on immunefi.com

The consensus mechanism in the blockchain plays a significant role in validating the authenticity of transactions and maintaining the underlying blockchain’s security. It is a system that users of a blockchain network follow to agree on the legitimacy of transactions.

The author, on immunefi.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

The migrateOut function subtracted the delegated amount from the total staking power without checking whether the validator had already unstaked, leading to a double subtraction when the validator unstaked later.

Impact

An attacker could bypass the two-thirds consensus majority check and send malicious checkpoints to drain all tokens from the deposit manager, but the exploit required specific market conditions and high capital, and the text does not confirm that such an attack was actually carried out.

What the attacker needed

A validator spot must be open; high capital to pay miners and maintain the spot; ability to wait for checkpoints (every 30-45 minutes)

How it was found

  1. Create a new validator using the stakeFor function.
  2. Call the buyVoucher function with a large delegated amount to buy shares of the validator.
  3. Catch an available validator slot via an on-chain auction process.
  4. Migrate staking tokens into that validator by calling migrateDelegation.
  5. Unstake the validator, which decreases validatorState.amount again.
  6. Wait for a checkpoint for the validator slot to open, then repeat from step 3 until the total staking power is low enough to bypass the two-thirds consensus check.

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 write-up has not been written yet. The Original tab links to the source.

In a proof-of-stake blockchain, the total amount of tokens staked determines voting power. This bug let someone make that total appear smaller than it really was by moving their stake and then unstaking the original validator, so the same stake was subtracted twice. With a small enough total, one validator could control most of the voting power and approve fake withdrawals.

What is Smart contracts?

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

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.