[web3] Critical bug in Cronos found by 0xDjango worth 1.6K
A reentrancy flaw in the Tectonic staking pool's token conversion function let an attacker inject a malicious token into the swap path and stake their own TONIC mid-swap, so the pool counted it as extra swap proceeds and rewarded it back while minting xTonic for free. The attacker could then unstake and drain the pool, with the proof of concept showing over $2.5 million taken from a $23,000 starting position.
gist.github.com
Published on gist.github.com
Clone this repository at <script src="https://gist.github.com/fatherGoose1/690fa2d8245488b6750b67a0fdeb34bc.js"></script> - Save fatherGoose1/690fa2d8245488b6750b67a0fdeb34bc to your computer and use it in GitHub Desktop.
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 conversion function measured the pool's TONIC balance before and after an external swap and treated any increase as swap proceeds, without guarding against reentrancy or restricting the swap path, so a caller could stake during the swap and have that stake counted as extra TONIC.
Impact
An attacker could drain funds from the pool and distort the TONIC/xTonic exchange rate, with the proof of concept showing over $2.5 million stolen from a $23,000 starting position in a single transaction.
What the attacker needed
Public access to the conversion function; attacker holds some TONIC; attacker can create tokens and pairs
The fix
The conversion function should be guarded and the entire swap path should be whitelisted, not just the input and output tokens.
How it was found
- Create a malicious token and liquidity pairs for it against WCRO and TONIC.
- Build a swap path from WCRO through the malicious token to TONIC and call the conversion function.
- When the malicious token's transfer runs, stake the attacker's TONIC into the pool.
- The pool counts the staked TONIC as extra swap proceeds and rewards it back while minting xTonic.
- Repeat the conversion many times, then unstake and release xTonic back into TONIC.
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 staking pool lets people deposit a token and get a receipt token in return. This pool also had a function that swapped other tokens into its main token and paid any 'extra' received to whoever called it. Because the caller could slip in their own token that ran code mid-swap, they could deposit at exactly the right moment so their own deposit looked like profit and was paid back to them, while they kept the receipt tokens.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.