Dfx Finance Rounding Error Bug Fix Review
A rounding error in DFX Finance's AssimilatorV2 contract allowed an attacker to deposit a tiny amount of EURS tokens, have the transfer amount round down to zero, yet still receive curve LP tokens. By repeating this in a loop, an attacker could drain the vulnerable pool, which held about $237,143.
immunefi.com
Published on immunefi.com
On April 28, 2023, a whitehat with the pseudonym perseverance submitted a critical vulnerability to DFX Finance via Immunefi, which consisted of a rounding error with the EURS token due to the non-standard decimal value of two. At the time of the submission, $237,143 was in the vulnerable pool and at risk of being…
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 an integer division in the deposit calculation could round the amount to transfer down to zero when the rate exceeded the numerator, and the code did not check that the transferred amount was greater than zero.
Impact
An attacker could have stolen the entire $237,143 in the vulnerable pool by repeatedly exploiting the rounding error, though the bug was isolated to the EURS token and no funds were lost because the issue was fixed quickly.
What the attacker needed
EURS token with 2 decimals; ability to call deposit repeatedly; some initial capital for gas
How it was found
- The attacker calls the deposit function on the Curve pool with a very small amount of EURS.
- The contract calculates the amount to transfer, which rounds down to zero, so no EURS is taken from the attacker.
- The attacker still receives curve LP tokens representing a share of the pool.
- The attacker repeats this deposit many times (around 10,000) in a single transaction.
- The attacker withdraws the accumulated LP tokens to receive a proportion of the pool's EURS and USDC.
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.
When you deposit money into a pool, the contract calculates how many pool tokens to give you. Due to a rounding mistake, a very small deposit could be treated as zero, so you paid nothing but still got pool tokens. Repeating this many times let an attacker take value from the pool.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.