Polygon Lack Of Balance Check Bug Fix Review 2 2m Bounty
The MRC20 contract's transferWithSig function lacked a balance check and did not verify that ecrecovery returned a non-zero address, allowing an attacker to transfer the contract's entire MATIC balance to themselves. The report claims an attacker could have stolen all ~9.27 billion MATIC from the contract.
immunefi.com
Published on immunefi.com
Whitehat Leon Spacewalker reported a critical vulnerability in Polygon on December 3. The vulnerability consisted of a lack of balance/allowance check in the transfer function of Polygon’s MRC20 contract and would have allowed an attacker to steal all ~9,276,584,332 MATIC (as of December 5, the date of the fix) from…
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
Likely the transferWithSig function did not check that the recovered signer address was non-zero and did not verify the sender's balance before transferring tokens.
Impact
An attacker could have stolen all ~9,276,584,332 MATIC from the MRC20 contract, though a blackhat managed to steal 801,601 MATIC before the fix was implemented.
What the attacker needed
None
The fix
The transferWithSig function was removed.
How it was found
- Create a byte string of length other than 65 to make ecrecovery return the zero address.
- Set the amount to the full balance of the MRC20 contract.
- Set the to address to an attacker-controlled address.
- Call transferWithSig with the invalid signature, causing _transferFrom to be called with the zero address as from.
- The contract calls _transfer without checking balances, transferring the amount to the attacker.
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.
A smart contract held a large amount of a cryptocurrency called MATIC. A function meant to let someone transfer tokens on behalf of the owner did not check whether the owner actually had enough tokens, and it also accepted an invalid signature that pointed to the zero address. This meant anyone could call the function and drain the contract's entire balance.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.