Reproduced Exploit

Xyro: the UpDown payout rate rounds to zero

calculateUpDownRate divides the net losing pot, times FEE_DENOMINATOR, by the net winning pot. With 100 on the losing side and 100,000,000 on the winning side, that quotient is 0. distributeWithoutFee then pays the winner their deposit minus the 1 percent fee and none of the other side. 1,000,100 t…

Aug 2024•Ethereum•arithmetic•3 min read

Loss

Winning side deposited 100,000,000 and is paid 99,000,000. 1,000,100 tokens stay in the treasury

Chain

Ethereum

Category

arithmetic

Date

Aug 2024

Source

AuditVault

EVM Playground

Source-level debugger — step opcodes and Solidity in sync

evm-hack-analyzer

The attack is replayed in an in-browser EVM preloaded with the exact dumped fork state. The execution tree shows every call; step by Solidity line or by opcode across all depths — source, Stack, Memory, Storage, Balances (native / ERC-20 / NFT), Transient storage and Return value stay in sync. Click a tree node, opcode, or source line to jump. Query opens a search over the trace: previous and next writes, balance changes and calls, breakpoints, and a diff of everything that changed between two steps. No backend, no live RPC.

Loading fork state…

Source & credit. Reproduction of a public audit finding curated by AuditVault — the original finding: 45671-users-would-lose-rewards-if-a-huge-majority-bets-on-the-winn. Standalone Foundry PoC and full write-up: 45671-users-would-lose-rewards-if-a-huge-majority-bets-on-the-winn_exp in the evm-hack-registry mirror.


Vulnerability classes: vuln/arithmetic/precision-loss · vuln/logic/reward-calculation

Key info#

FieldValue
LossWinning side deposited 100,000,000 and is paid 99,000,000. 1,000,100 tokens stay in the treasury
Vulnerable contractTreasury.calculateUpDownRate
Attacker EOA0x1111111111111111111111111111111111111111
Attack contractExploit
Attack txExploit.run()
Chain / block / dateEthereum model · local · 2024-08
Compilersolc 0.8.27, cancun
Bug classPayout rate rounded to 0 when winners dominate

TL;DR#

calculateUpDownRate divides the net losing pot, times FEE_DENOMINATOR, by the net winning pot. With 100 on the losing side and 100,000,000 on the winning side, that quotient is 0. distributeWithoutFee then pays the winner their deposit minus the 1 percent fee and none of the other side. 1,000,100 tokens remain in the treasury.

Background#

Zokyo's 29 August 2024 Xyro review. The report shows the rate used by the UpDown game, and notes the same shape in the setup-game rate. The fee used here is 100 and FEE_DENOMINATOR is 10,000, which is 1 percent. The huge side is the winner, which is the case the title describes and the case in which the published division rounds to 0.

The vulnerable code#

SOLIDITY
lostTeamTotal *= 10 ** token.decimals();
wonTeamTotal *= 10 ** token.decimals();
uint256 lostTeamFee = (lostTeamTotal * updownFee) / FEE_DENOMINATOR;
uint256 wonTeamFee = (wonTeamTotal * updownFee) / FEE_DENOMINATOR;
rate = ((lostTeamTotal - lostTeamFee) * FEE_DENOMINATOR) / (wonTeamTotal - wonTeamFee); // @> VULN: rounds to 0
SOLIDITY
uint256 wonAmount = (initialDeposit - withdrawnFees) + ((initialDeposit - withdrawnFees) * rate) / FEE_DENOMINATOR;

Root cause#

The numerator is the small losing pot. The denominator is the large winning pot. No extra precision is applied, so the integer quotient is 0 whenever the losers are a small fraction of the winners.

Preconditions#

  • Fee is 1 percent.
  • Losing deposits are 100 tokens and winning deposits are 100,000,000 tokens.
  • One player holds the winning side and is paid with distributeWithoutFee.

Attack walkthrough#

  1. The losing side deposits 100 tokens.
  2. The winning side deposits 100,000,000 tokens.
  3. Finalize calls calculateUpDownRate(100, 100_000_000, 100).
  4. Both totals are scaled by 1e18, fees are subtracted, and the division is 0.
  5. The winner is paid 99,000,000 tokens.
  6. The treasury keeps 1,000,100 tokens: the 1,000,000 winner fee plus the 100 losing pot.

Diagrams#

flowchart TD A["Losing side deposits 100"] --> B["Winning side deposits 100,000,000"] B --> C["Finalize scales both pots by 1e18"] C --> D["VULN net lost times 10,000 divided by net won is 0"] D --> E["Winner is paid 99,000,000"] E --> F["Treasury keeps 1,000,100"]

Impact#

The winning depositor receives 1,000,000 tokens less than they deposited, and none of the losing pot. The treasury balance after the payout is 1,000,100 ether units. A rate that keeps an extra 1e18 in the numerator is non-zero for the same inputs.

Remediation#

Scale the rate numerator by an extra fixed-point factor before dividing, and divide the payout by the same factor, so a small losing pot still produces a non-zero rate.

How to reproduce#

BASH
cd 45671-users-would-lose-rewards-if-a-huge-majority-bets-on-the-winn_exp
forge test -vv

test_exploit_rate_zero_pays_winner_99_and_locks_the_pot asserts rate 0, a 99,000,000 payout, and a 1,000,100 treasury balance. test_control_extra_precision_rate_is_nonzero asserts the scaled rate is above 0. Captured output is output.txt.

Sources#


Sources & further analysis#

Reproductions & code

Alerts & third-party analyses

  • Web3Sec X hacked database: search.
  • Rekt leaderboard: search.
  • Solodit incident search: search.

These dashboards index community alerts tweets, post-mortems, and independent write-ups. Reach them through the protocol name above to cross-check this reproduction against other analyses.