Reproduced Exploit

Filament: a second joiner replaces the option token, so the first winner is paid nothing

joinDuel deploys a new OptionToken for every join and stores that address at optionIndexToOptionToken[duelId][optionIndex]. Alice joins first and is minted 1000 tokens. Bob joins the same duel, the same option string, and the same index. His token replaces Alice's in the mapping. Payout uses _getUs…

Nov 2024•Other•logic•3 min read

Loss

Alice wagered 1000 USDC on the winning option and receives 0. Bob nets +1000 USDC

Chain

Other

Category

logic

Date

Nov 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: 45831-users-can-lose-all-their-rewards-even-if-their-option-won-th. Standalone Foundry PoC and full write-up: 45831-users-can-lose-all-their-rewards-even-if-their-option-won-th_exp in the evm-hack-registry mirror.


Vulnerability classes: vuln/logic/state-update

Key info#

FieldValue
LossAlice wagered 1000 USDC on the winning option and receives 0. Bob nets +1000 USDC
Vulnerable contractDuel.joinDuel
Attacker EOA0x1111111111111111111111111111111111111111
Attack contractExploit (Bob)
Attack txExploit.run()
Chain / block / dateLocal synthetic · 2024-11
Compilersolc 0.8.27, cancun, via IR
Bug classOption token is redeployed per joiner and the mapping is overwritten

TL;DR#

joinDuel deploys a new OptionToken for every join and stores that address at optionIndexToOptionToken[duelId][optionIndex]. Alice joins first and is minted 1000 tokens. Bob joins the same duel, the same option string, and the same index. His token replaces Alice's in the mapping. Payout uses _getUserDuelOptionShare on whatever address is stored now. Alice's balance of that token is 0, so her share is 0. Bob receives the whole 2000 USDC pot.

The vulnerable code#

SOLIDITY
OptionToken newOptionToken = new OptionToken(_option, _option); // @> VULN
optionIndexToOptionToken[_duelId][_optionsIndex] = address(newOptionToken);
SOLIDITY
address optionToken = optionIndexToOptionToken[_duelId][_optionIndex];
uint256 optionTokenBalance = IERC20(optionToken).balanceOf(_user);
uint256 totalOptionTokenSupply = IERC20(optionToken).totalSupply();
optionShare = (optionTokenBalance * 1e18) / totalOptionTokenSupply;

joinDuelFixed mints the token already stored for that index. Both bettors then hold 1000 of the same token, each share is one half, and each receives 1000 USDC back.

Root cause#

The option index is supposed to identify one token for every bettor on that outcome. Deploying a new token on every join means only the last bettor's balance is visible at settlement.

Preconditions#

  • Two users join the same duelId and the same option index.
  • The option wins, so settlement pays that index's token balances.
  • The first user has not been migrated onto the replacement token.

Attack walkthrough#

  1. Alice deposits 1000 USDC. Her option token is stored for duel "1", index 0.
  2. Bob calls joinDuel with the same ids and deposits 1000 USDC. A second token is deployed and stored over the first.
  3. distribute reads Bob's token. Alice's share is 0. Bob's share is 1e18.
  4. The 2000 USDC pot is transferred to Bob. Alice's balance stays 0. Bob started the call with 1000 USDC, so the measured profit is 1000.

Diagrams#

flowchart TD A["Alice is minted 1000 of option token A"] --> B["Bob joins the same option index"] B --> C["A new token B is stored over token A"] C --> D["Share math reads token B and Alice's balance is 0"] D --> E["Bob receives the 2000 USDC pot and Alice receives 0"]

Impact#

A user who backed the winning option loses the entire stake and any share of the pot. Here that is Alice's 1000 USDC, taken by the later joiner.

How to reproduce#

BASH
cd 45831-users-can-lose-all-their-rewards-even-if-their-option-won-th_exp
forge test -vv

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.