DFX Finance
A rounding error in the AssimilatorV2 contract allowed an attacker to deposit a tiny amount of EURS tokens, have zero tokens transferred due to integer division, but still receive LP tokens representing a share of the pool. By repeating this many times in one transaction, the attacker could profit and potentially drain the pool.
medium.com
Published on medium.com
Immunefi
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.
Context
DFX Finance is a decentralised foreign exchange (FX) protocol. It runs a decentralised marketplace where users swap non-USD stablecoins pegged to various foreign currencies, such as CADC, EUROC and XSGD, and it incentivises liquidity providers to supply capital by offering yield on deposited funds. The exchange is an automated market maker (AMM) that prices swaps along a bonding curve, dynamically adjusted from real world price feeds supplied by Chainlink. Each currency is paired with USDC, which acts as the bridge currency between all the other stablecoins in the DFX AMM.
The protocol has two main parts: Assimilators and Curve. Assimilators let the AMM handle pairs of different values while integrating the reported oracle prices for each currency. Curve allows custom parametrisation of the bonding curve with dynamic fee, price scaling and more.
Assimilators matter because every asset is paired with USDC. The AssimilatorV2 contract converts all amounts to a numeraire, a base value used for computations across the protocol. DFX maintains the assimilators, which integrate with Curve to provide proportional liquidity to pools. A user who wants to provide liquidity calls the deposit function on the Curve pool and receives liquidity provider (LP) tokens representing their proportion of the underlying asset deposited.
When a user deposits EURS, the function checks that the deposit amount is greater than zero and then delegates most of the logic to the library call ProportionalLiquidity.proportionalDeposit. Inside proportionalDeposit, the Curve pool calls intakeNumeraireLPRatio on AssimilatorV2 to calculate the corresponding amount of euros to transfer from the user, computed on line 145 from the LP ratio passed to the function. Once the transfer is handled and liquidity has moved from the user to the contract, proportionalDeposit mints the LP tokens representing the user's share of the pool, and the deposit function returns the value of deposits and shares minted.
Setup
On 28 April 2023 a whitehat using the pseudonym perseverance submitted a critical vulnerability to DFX Finance through Immunefi. The submission concerned a rounding error affecting the EURS token, caused by that token's non-standard decimal value of two. At the time of submission the vulnerable pool held $237,143, all of it at risk of being stolen by a malicious hacker.
The bug was isolated to the EURS token and did not affect any other tokens DFX supports at the time. The relevant EURS token is the one on the Polygon network. DFX Finance paid a bounty of 100,000 USDT to the whitehat.
Finding it
The vulnerability stemmed from the calculation of the transfer amount in the AssimilatorV2 contract on line 145. The issue arises when the _rate exceeds the numerator value, producing an integer division that results in zero tokens being transferred from the user. Despite transferring zero tokens, the user still receives curve tokens representing their portion of the curve pool.
To exploit this, an attacker deposits a minuscule amount of tokens, so that the transferred amount rounds down to zero while the attacker still receives minted curve tokens in exchange for the small proportion of tokens "deposited".
What makes this profitable rather than a curiosity is the token's precision. Tokens typically have at least six decimals, which limits the potential profit to an amount lower than the gas cost of the transaction. The EURS token on Polygon, however, has only two decimals.
Exploitation
Step 1: Deposit a minuscule amount of EURS
The attacker calls the deposit function on the Curve pool with a very small EURS amount. Because _rate exceeds the numerator, the integer division on line 145 yields zero, so no EURS is taken from the attacker.
Step 2: Receive LP tokens anyway
The deposit path still mints curve tokens to the attacker, representing a share of the pool, even though nothing was transferred in.
Step 3: Repeat within a single transaction
By using the EURS token and repeatedly depositing a small amount, around 10,000 times, within a single transaction, the attacker accumulates minted curve tokens at no cost.
Step 4: Withdraw
The attacker withdraws the minted curve tokens, generating a profit of approximately 172 EURO or 190 USDC per attack.
Step 5: Scale up
At the time of submission the vulnerable pool held $237,143. An attacker could have stolen it by progressively acquiring a larger portion of the pool through successive attacks.
The Immunefi team prepared a proof of concept to demonstrate the vulnerability.

Root cause
The mistake is an integer division in the transfer amount calculation on line 145 of AssimilatorV2. When _rate exceeds the numerator, the division truncates to zero, and the code proceeds to mint LP tokens for a deposit that transferred nothing. The deposit function checks that the deposit amount is greater than zero, and the transfer amount is calculated on line 145. The EURS token on Polygon has only two decimals, so a small amount can be deposited around 10,000 times within a single transaction.
Impact
An attacker could mint curve tokens without paying for them and withdraw them for a profit of approximately 172 EURO or 190 USDC per attack. Repeated attacks would let the attacker progressively acquire a larger portion of the pool, putting the full $237,143 held in the vulnerable pool at risk. The impact was confined to the EURS token and did not extend to any other token DFX supports. DFX Finance acted quickly to remediate the bug after receiving the report, and no user funds were lost.
Fix
DFX Finance fixed the issue by deploying a new version of the AssimilatorV2 contract and adding a require statement that checks the amount to be transferred from the user is greater than zero. The existing Curve pool was migrated to use the new Assimilator.
Variants to test
- Low-decimal tokens in any AMM or vault. Look for tokens with fewer decimals than the protocol assumes (two, or even zero). A positive result is a deposit or swap where the computed transfer amount truncates to zero while shares or LP tokens are still minted.
- Ratio-based deposit paths. Examine functions that scale a user amount by a rate or LP ratio before dividing. A positive result is a path where
_ratecan exceed the numerator and the result is used without a zero check. - Batch or looped deposits in one transaction. Check whether a dust deposit can be repeated many times inside a single transaction. A positive result is measurable profit per transaction after gas, as with the roughly 10,000 repetitions here.
- Rounding in the other direction. Test withdrawals and swaps where the protocol pays out after a division. A positive result is a user receiving more than the exact proportional amount because the remainder is dropped in their favour.
- Oracle-driven rates. Since assimilators integrate reported oracle prices, test whether a rate movement can push a division past the numerator. A positive result is a deposit that transfers nothing once the oracle rate crosses the threshold.
What happened, in plain words
DFX Finance is a service on the internet where people can trade digital currencies (cryptocurrencies) that are tied to real-world national currencies, such as a digital version of the euro or the Singapore dollar. People can also put their own digital money into it to earn a return, a bit like putting money in a savings account.
On 28 April 2023, a security researcher using the name perseverance found a serious flaw in DFX Finance. A security researcher (often called a "whitehat") is someone who looks for weaknesses in computer systems and reports them so they can be fixed, instead of using them to steal. The flaw was a rounding error involving one particular digital currency called EURS. At the time, the pool (a shared pot of money that users trade against) held $237,143, and a malicious hacker could have taken it.
DFX Finance fixed the problem quickly after receiving the report. No user money was lost. The flaw only affected EURS and no other currency DFX supports. DFX paid the researcher a reward (a "bounty") of 100,000 USDT, which is a digital currency designed to be worth one US dollar.

The basics you need first
Before the details make sense, here are a few ideas explained from scratch.
- Cryptocurrency: digital money that exists only on a computer network, not as notes or coins.
- Stablecoin: a cryptocurrency designed to keep a steady value, usually tied to a real currency. CADC is tied to the Canadian dollar, EUROC to the euro, XSGD to the Singapore dollar, and USDC and USDT to the US dollar.
- Blockchain: a shared, public record of transactions that many computers keep copies of. Polygon is one such network, and it is where the EURS token in this story lives.
- Token: a unit of digital value on a blockchain. Each token has a setting for how many decimal places it can be split into, called its "decimals".
- Smart contract: a computer program that lives on the blockchain and runs automatically. It is like a vending machine: you put something in, it follows its coded rules, and it gives something out. The rules are set in code, though contracts can be replaced by new versions.
- Protocol: a set of smart contracts and rules that together make a service, in this case DFX Finance.
- Decentralised: run by code on a blockchain rather than by a single company's private computer.
- AMM (automated market maker): a way of trading where a program, not a person, sets the prices and holds the money. Think of a self-service currency exchange booth that always has cash on hand and calculates its rates by a formula.
- Liquidity: money sitting in the pool, available to be traded against. "Providing liquidity" means putting your money into that pool.
- Liquidity provider (LP): a person who puts money into the pool. In return they get LP tokens, which are like receipts proving how much of the pool is theirs. Later they can hand back the receipt and take their share out.
- Yield: the return or profit earned for leaving money in the pool.
- Bonding curve: the mathematical formula an AMM uses to decide how the price changes as people buy and sell. Picture a slide whose shape decides how fast you speed up.
- Oracle: a service that feeds outside information, such as real-world currency prices, into a smart contract. Chainlink is the oracle service used here.
- USDC as a bridge currency: every other currency in DFX is paired with USDC, so to swap euros for Singapore dollars you effectively go euros to USDC to Singapore dollars. USDC is the middleman, like a common language two people use to talk.
- Numeraire: a common base unit that a program converts every amount into, so it can compare and calculate with them. It is like converting every price into one currency before doing the maths.
- Integer division: division done with whole numbers only. If the answer would be a fraction, the leftover part is simply thrown away. For example, 7 divided by 2 gives 3, not 3.5. This throwing away is called truncation or rounding down.
- Decimals: how many digits a token can have after the point. A token with two decimals can be split into hundredths, like cents in a euro. A token with six decimals can be split into millionths.
- Gas: a small fee paid to the blockchain network to run a transaction. It is like a postage stamp: every action costs something, so tiny profits are usually eaten by the fee.
- Transaction: one action sent to the blockchain, which either fully happens or fully fails.
- Proof of concept (PoC): a small demonstration, often code, that proves a flaw is real.
- Bounty: a reward paid to a researcher for responsibly reporting a flaw.
- Responsible disclosure: reporting a flaw privately to the people who can fix it, rather than telling the world or exploiting it.
What DFX Finance is and how it works
DFX Finance is a decentralised foreign exchange protocol. It creates a marketplace where users swap stablecoins tied to different national currencies, such as CADC, EUROC and XSGD. It also pays yield to people who supply capital to the pool.
The exchange is an AMM: it prices swaps along a bonding curve that is adjusted using real-world price feeds from Chainlink. Every currency is paired with USDC, which acts as the bridge currency between all the other stablecoins.
The protocol has two main parts:
- Assimilators: these let the AMM handle pairs of currencies with different values, and they bring in the oracle prices for each currency.
- Curve: this allows the bonding curve to be customised with a dynamic fee, price scaling and more.
Assimilators matter because every asset is paired with USDC. The AssimilatorV2 contract converts all amounts into a numeraire, the common base value used for calculations across the protocol. DFX maintains the assimilators, which work with Curve to provide proportional liquidity to pools.
When a user wants to provide liquidity, they call the deposit function on the Curve pool and receive LP tokens representing their share of what they put in.
When a user deposits EURS, the function first checks that the deposit amount is greater than zero. It then hands most of the work to a library call named ProportionalLiquidity.proportionalDeposit. Inside that function, the Curve pool calls intakeNumeraireLPRatio on AssimilatorV2 to work out how many euros to take from the user. That amount is calculated on line 145, based on the LP ratio passed to the function. Once the transfer is handled and the money has moved from the user to the contract, proportionalDeposit creates ("mints") the LP tokens representing the user's share of the pool, and the deposit function returns the value of deposits and shares minted.
The setup: who found it and when
On 28 April 2023, a whitehat using the pseudonym perseverance submitted a critical vulnerability to DFX Finance through Immunefi, a platform where researchers report bugs and projects pay rewards. The submission concerned a rounding error affecting the EURS token, caused by that token's non-standard decimal value of two. At the time, the vulnerable pool held $237,143, all of it at risk.
The bug was isolated to EURS and did not affect any other token DFX supported at the time. The relevant EURS token is the one on the Polygon network. DFX Finance paid a bounty of 100,000 USDT to the whitehat.
Finding it: where the flaw lives
The vulnerability came from how the transfer amount is calculated in the AssimilatorV2 contract on line 145. The problem appears when a value called _rate is larger than the numerator, the top number of the division. When that happens, the integer division produces zero, so zero tokens are transferred from the user.
Despite transferring zero tokens, the user still receives curve tokens representing a share of the pool. To exploit this, an attacker deposits a minuscule amount of tokens, so the amount actually transferred rounds down to zero, while the attacker still receives newly minted curve tokens in exchange for the tiny proportion they "deposited".
What makes this profitable rather than a harmless curiosity is the token's precision. Tokens usually have at least six decimals, which limits any potential profit to less than the gas cost of the transaction. The EURS token on Polygon, however, has only two decimals.
Exploitation: how the attack would work
Step 1: Deposit a minuscule amount of EURS
The attacker calls the deposit function on the Curve pool with a very small EURS amount. Because _rate is larger than the numerator, the integer division on line 145 gives zero, so no EURS is taken from the attacker.
Step 2: Receive LP tokens anyway
The deposit path still mints curve tokens to the attacker, representing a share of the pool, even though nothing was paid in.
Step 3: Repeat within a single transaction
Using the EURS token, the attacker repeatedly deposits a small amount, around 10,000 times, inside a single transaction. Each repetition mints more curve tokens at no cost.
Step 4: Withdraw
The attacker withdraws the minted curve tokens, making a profit of approximately 172 EURO or 190 USDC per attack.
Step 5: Scale up
At the time of submission the vulnerable pool held $237,143. An attacker could have taken it by progressively acquiring a larger share of the pool through successive attacks.
The Immunefi team prepared a proof of concept to demonstrate the vulnerability.

Root cause: the mistake in one sentence
The mistake is an integer division in the transfer amount calculation on line 145 of AssimilatorV2. When _rate is larger than the numerator, the division truncates to zero, and the code goes on to mint LP tokens for a deposit that transferred nothing. The deposit function checks that the deposit amount is greater than zero, and the transfer amount is calculated on line 145. The EURS token on Polygon has only two decimals, so a small amount can be deposited around 10,000 times within a single transaction.
Impact: what was at stake
An attacker could mint curve tokens without paying for them and withdraw them for a profit of approximately 172 EURO or 190 USDC per attack. Repeated attacks would let the attacker progressively acquire a larger share of the pool, putting the full $237,143 held in the vulnerable pool at risk. The impact was confined to the EURS token and did not extend to any other token DFX supports. DFX Finance acted quickly to fix the bug after receiving the report, and no user funds were lost.
Fix: how it was closed
DFX Finance fixed the issue by deploying a new version of the AssimilatorV2 contract and adding a require statement that checks the amount to be transferred from the user is greater than zero. A require statement is a guard inside a smart contract: if its condition is not met, the whole action is cancelled. The existing Curve pool was migrated to use the new Assimilator.
Variants to test: where else this pattern might appear
- Low-decimal tokens in any AMM or vault. Look for tokens with fewer decimals than the protocol assumes (two, or even zero). A positive result is a deposit or swap where the computed transfer amount truncates to zero while shares or LP tokens are still minted.
- Ratio-based deposit paths. Examine functions that scale a user amount by a rate or LP ratio before dividing. A positive result is a path where
_ratecan exceed the numerator and the result is used without a zero check. - Batch or looped deposits in one transaction. Check whether a dust deposit can be repeated many times inside a single transaction. A positive result is measurable profit per transaction after gas, as with the roughly 10,000 repetitions here.
- Rounding in the other direction. Test withdrawals and swaps where the protocol pays out after a division. A positive result is a user receiving more than the exact proportional amount because the remainder is dropped in their favour.
- Oracle-driven rates. Since assimilators integrate reported oracle prices, test whether a rate movement can push a division past the numerator. A positive result is a deposit that transfers nothing once the oracle rate crosses the threshold.
Glossary
- AMM (automated market maker): a program that holds money and sets trading prices by a formula instead of matching buyers and sellers by hand.
- Assimilator: a DFX contract that converts amounts between currencies and the common base value, using oracle prices.
- Blockchain: a shared public record of transactions kept by many computers.
- Bonding curve: the formula an AMM uses to decide how prices change as people trade.
- Bridge currency: a common currency used in the middle of two swaps, here USDC.
- Chainlink: an oracle service that supplies real-world price data to smart contracts.
- Critical vulnerability: a flaw serious enough that it could cause major loss, here the theft of pool funds.
- Curve pool: the DFX contract that holds the pooled money and handles deposits and withdrawals.
- Decimals: how many digits after the point a token can be split into.
- Decentralised: run by code on a blockchain rather than a single company's private computer.
- Deposit function: the part of the pool contract a user calls to put money in and receive LP tokens.
- Gas: the fee paid to the blockchain network to run a transaction.
- Integer division: division using whole numbers only, where any fraction is thrown away.
- LP token: a receipt token showing how much of a pool belongs to a liquidity provider.
- Liquidity: money sitting in a pool, available to trade against.
- Liquidity provider (LP): someone who puts money into a pool to earn yield.
- Mint: to create new tokens by code.
- Numeraire: a common base unit that amounts are converted into for calculations.
- Oracle: a service that feeds outside data, such as prices, into a smart contract.
- Polygon: a blockchain network where the EURS token in this story lives.
- Proof of concept (PoC): a small demonstration that proves a flaw is real.
- Protocol: a set of smart contracts and rules that together make a service.
- Require statement: a guard in a smart contract that cancels the action if a condition is not met.
- Responsible disclosure: reporting a flaw privately to the people who can fix it.
- Rounding error: a mistake caused by a calculation dropping a fraction and giving a slightly wrong result.
- Smart contract: a program on a blockchain that runs automatically according to its coded rules.
- Truncation: cutting off the fractional part of a number instead of rounding it.
- USDC / USDT: digital currencies designed to be worth one US dollar each.
- Whitehat: a security researcher who finds flaws and reports them to be fixed.
- Yield: the return earned for leaving money in a pool.