Polygon Hack

Reported loss $2.0M
Polygon
Improper Access Control

What happened

In early December 2021, an attacker, or a group of attackers, stole 801,601 MATIC from Polygon's PoS genesis MRC20 contract, the system contract that holds the chain's native MATIC. They used a bug that could have drained all of the roughly 9.28 billion MATIC the contract held. Whitehat Leon Spacewalker reported the flaw through Immunefi on December 3. While Polygon prepared a fix, a second whitehat reported the same bug on December 4, and the blackhat theft took place that day according to CoinDesk. Validators applied an emergency hard fork on December 5 at block 22,156,660, which removed the vulnerable function.

Reported USD values for the stolen MATIC range from about $1.4 million (CoinDesk) to over $2 million (The Block), depending on the price used. Polygon said it would bear the loss. It paid Leon Spacewalker $2.2 million in stablecoins and the second reporter 500,000 MATIC, about $3.46 million in bounties combined, and disclosed the incident publicly on December 29, 2021, citing the practice of silent patching for critical bugs.

How it happened

  1. The MRC20 contract offered transferWithSig() for gasless transfers. It recovers the token owner from a packed signature using ecrecovery, a wrapper around ecrecover, and passes that address as from to _transferFrom().
  2. ecrecovery returns the zero address when the packed signature is not exactly 65 bytes, and transferWithSig() never rejected a zero-address signer, so no valid signature was needed.
  3. Neither _transferFrom() nor _transfer() checked that from had enough balance or allowance. _transfer() only checked that the recipient was not the MRC20 contract itself.
  4. By sending a malformed signature with the attacker as to and an arbitrary amount, a caller could move MATIC out of the contract's balance. A blackhat used this to take 801,601 MATIC before the December 5 fork removed transferWithSig.

Protocol details

Classification Access Control
Protocol Type DeFi Protocol
Implementation language Solidity

Understand the attack patterns

Build your security review skills

Work through hands-on labs covering real exploit mechanics, review techniques, and defensive patterns.