Skip to content
Access control Write-up Advanced

Moonbeam

A design flaw in Moonbeam's ERC-20 precompiles allowed a malicious contract to use delegatecall to impersonate its caller and manipulate token allowances or transfer balances. An attacker could trick a victim contract into calling the malicious contract, then steal the victim's tokens or drain DeFi protocols.

pwning.mirror.xyz

Published on pwning.mirror.xyz

My blockchains adventure continues! This time I protected Moonbeam network by disclosing a critical design flaw, safeguarding more than $100M assets at risk in various DeFi projects.

The author, on pwning.mirror.xyz

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 ERC-20 precompiles did not account for delegatecall, so they trusted the msg.sender passed via delegatecall, allowing impersonation.

Impact

An attacker could steal tokens from DeFi protocols, potentially draining up to $100M in borrowable assets and $12M in vulnerable DEX pairs, though the text notes that actual attacks could be stealthy by keeping the unauthorized privilege instead of stealing immediately.

What the attacker needed

Victim contract calls attacker's contract; attacker deploys malicious contract; victim contract holds tokens

The fix

The Moonbeam team patched the issue by removing the flawed delegatecall handling code.

How it was found

  1. Deploy a malicious contract that uses delegatecall to the vulnerable precompile.
  2. Trick a victim contract into calling the malicious contract, for example via a flash loan callback.
  3. The malicious contract uses delegatecall to make the precompile act as if the victim called it, increasing allowance or transferring tokens.
  4. The attacker then transfers the victim's tokens to themselves.

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 delegatecall lets one smart contract run another contract's code but keep its own identity, so the called code sees the original caller as the sender. In Moonbeam, some built-in token contracts did not account for this and trusted the sender, letting a malicious contract pretend to be someone else. This could let an attacker steal tokens from any contract that interacted with the malicious one.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.