Skip to content

Commit

Permalink
Increase RateModel gas allowance
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenshively committed Sep 8, 2023
1 parent 9af75cf commit c7a545a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion core/src/RateModel.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ library SafeRateLib {
// but this is slightly more gas efficient.
bytes memory encodedCall = abi.encodeCall(IRateModel.getYieldPerSecond, (utilization, address(this)));
assembly ("memory-safe") {
let success := staticcall(10000, rateModel, add(encodedCall, 32), mload(encodedCall), 0, 32)
let success := staticcall(100000, rateModel, add(encodedCall, 32), mload(encodedCall), 0, 32)
rate := mul(success, mload(0))
}

Expand Down
26 changes: 25 additions & 1 deletion core/test/RateModel.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,26 @@ pragma solidity 0.8.17;
import "forge-std/Test.sol";

import {MAX_LEVERAGE} from "src/libraries/constants/Constants.sol";
import {RateModel, SafeRateLib} from "src/RateModel.sol";
import {IRateModel, RateModel, SafeRateLib} from "src/RateModel.sol";

contract EvilRateModel is IRateModel {
function getYieldPerSecond(uint256 utilization, address) external view returns (uint256) {
console2.log(gasleft());

if (utilization % 3 == 0) return type(uint256).max;
else if (utilization % 3 == 1) {
while (true) {
utilization = gasleft();
}
return utilization;
}
revert();
}
}

contract RateModelTest is Test {
using SafeRateLib for RateModel;
using SafeRateLib for IRateModel;

RateModel model;

Expand All @@ -20,6 +36,14 @@ contract RateModelTest is Test {
assertEq(result, 1e12);
}

function test_accrualFactorBehavesDespiteEvilModel(uint256 elapsedTime, uint256 utilization) public {
IRateModel evilModel = new EvilRateModel();
uint256 result = evilModel.getAccrualFactor(utilization, elapsedTime);

assertGe(result, 1e12);
assertLt(result, 1.533e12);
}

function test_accrualFactorIsWithinBounds( uint256 elapsedTime, uint256 utilization) public {
uint256 result = model.getAccrualFactor(utilization, elapsedTime);

Expand Down

0 comments on commit c7a545a

Please sign in to comment.