[web3] Finding a Critical Vulnerability in Astar Network's dApp Staking
A type confusion in Astar's ERC-20 precompile allowed an attacker to pass a uint256 amount that was truncated to u128, causing a transfer of zero tokens while the calling contract believed a large transfer had occurred. This could be exploited to drain certain liquidity pools that lacked balance checks, with up to $400,000 at risk.
zellic.io
Published on zellic.io
In November 2023, a security researcher at Zellic found a vulnerability in Astar that could have been exploited by a malicious actor to steal ~$400,000 USD worth of tokens. This vulnerability would allow any attacker to steal large amounts of funds from certain types of smart contracts that are deployed on the Astar…
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 precompile read a uint256 amount from calldata but stored it in a u128 variable without checking for truncation, so values above the u128 maximum wrapped to zero.
Impact
An attacker could drain certain liquidity pools that hold native assets, with up to $400,000 at risk, though pools with balance checks were not exploitable.
What the attacker needed
Astar EVM with native assets; vulnerable liquidity pool without balance check; attacker can call transferFrom
The fix
The vulnerability was fixed by adding manual truncation checks to the precompile and modifying the EvmDataReader::read() function to include truncation checks.
How it was found
- Deploy a local Astar development node and fund an EVM address with gas tokens.
- Create a native asset with ID 1, which deploys its precompile at a known address.
- Call transferFrom on the precompile with an amount of type(uint128).max + 1.
- Observe that the transaction succeeds instead of reverting, transferring zero tokens.
- Use this behaviour to drain a vulnerable liquidity pool that lacks a balance 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.
Smart contracts on Astar can use a special built-in token contract (a precompile) to move tokens. The token contract expected a smaller number type than the one used by the caller, so a very large number wrapped around to zero. The token contract then reported success without moving any tokens, letting an attacker trick a pool into giving away other tokens for free.
What is Crypto?
Encryption, signatures, randomness or certificate checks that do not protect what they claim to.