Skip to content

Commit

Permalink
Merge pull request #93 from FilOzone/fix/fee-safety-checks-for-estima…
Browse files Browse the repository at this point in the history
…tion

Allow fee safety checks to pass when gas estimating
  • Loading branch information
ZenGround0 authored Jan 24, 2025
2 parents 51ba429 + 9dcc8a4 commit 34be592
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/Fees.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ library PDPFees {
int32 filUsdPriceExpo,
uint256 rawSize,
uint256 nProofEpochs
) internal pure returns (uint256) {
require(estimatedGasFee > 0, "failed to validate: estimated gas fee must be greater than 0");
) internal view returns (uint256) {
require(estimatedGasFee > 0 || block.basefee == 0, "failed to validate: estimated gas fee must be greater than 0");
require(filUsdPrice > 0, "failed to validate: AttoFIL price must be greater than 0");
require(rawSize > 0, "failed to validate: raw size must be greater than 0");

Expand Down
19 changes: 10 additions & 9 deletions test/Fees.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ contract PDPFeesTest is Test {

function testProofFeeWithGasFeeBoundZeroGasFee() public {
vm.expectRevert("failed to validate: estimated gas fee must be greater than 0");
vm.fee(1000);
PDPFees.proofFeeWithGasFeeBound(0, 5, 0, 1e18, epochs_per_day);
}

Expand All @@ -35,7 +36,7 @@ contract PDPFeesTest is Test {
PDPFees.proofFeeWithGasFeeBound(1, 5, 0, 0, epochs_per_day);
}

function testProofFeeWithGasFeeBoundHighGasFee() public pure {
function testProofFeeWithGasFeeBoundHighGasFee() public view {
uint64 filUsdPrice = 5;
int32 filUsdPriceExpo = 0;
uint256 rawSize = 1e18;
Expand All @@ -51,7 +52,7 @@ contract PDPFeesTest is Test {
assertEq(fee, 0, "Fee should be 0 when gas fee is high");
}

function testProofFeeWithGasFeeBoundMediumGasFee() public pure {
function testProofFeeWithGasFeeBoundMediumGasFee() public view {
uint64 filUsdPrice = 5;
int32 filUsdPriceExpo = 0;
uint256 rawSize = 1e18;
Expand All @@ -70,7 +71,7 @@ contract PDPFeesTest is Test {
assertEq(fee, expectedFee, "Fee should be partially discounted");
}

function testProofFeeWithGasFeeBoundLowGasFee() public pure {
function testProofFeeWithGasFeeBoundLowGasFee() public view {
uint64 filUsdPrice = 5;
int32 filUsdPriceExpo = 0;
uint256 rawSize = 1e18;
Expand All @@ -88,7 +89,7 @@ contract PDPFeesTest is Test {
assertEq(fee, expectedFee, "Fee should be full proof fee when gas fee is low");
}

function testProofFeeWithGasFeeBoundNegativeExponent() public pure {
function testProofFeeWithGasFeeBoundNegativeExponent() public view {
uint64 filUsdPrice = 5000;
int32 filUsdPriceExpo = -3;
uint256 rawSize = 1e18;
Expand All @@ -98,7 +99,7 @@ contract PDPFeesTest is Test {
assertTrue(fee > 0, "Fee should be positive with negative exponent");
}

function testProofFeeWithGasFeeBoundLargeRawSize() public pure {
function testProofFeeWithGasFeeBoundLargeRawSize() public view {
uint64 filUsdPrice = 5;
int32 filUsdPriceExpo = 0;
uint256 rawSize = 1e30;
Expand All @@ -108,7 +109,7 @@ contract PDPFeesTest is Test {
assertTrue(fee > 0, "Fee should be positive for large raw size");
}

function testProofFeeWithGasFeeBoundSmallRawSize() public pure {
function testProofFeeWithGasFeeBoundSmallRawSize() public view {
uint64 filUsdPrice = 5;
int32 filUsdPriceExpo = 0;
uint256 rawSize = 1;
Expand All @@ -125,7 +126,7 @@ contract PDPFeesTest is Test {
assertEq(fee, expectedFee, "Fee should be full proof fee when gas fee is low");
}

function testProofFeeWithGasFeeBoundHalfDollarFil() public pure {
function testProofFeeWithGasFeeBoundHalfDollarFil() public view {
uint64 filUsdPrice = 5;
int32 filUsdPriceExpo = -1; // 0.5 USD per FIL
uint256 rawSize = 1e18;
Expand All @@ -144,7 +145,7 @@ contract PDPFeesTest is Test {
assertEq(fee, PDPFees.SYBIL_FEE, "Sybil fee should match the constant");
}

function testProofFeeWithGasFeeBoundAtLeftBoundary() public pure {
function testProofFeeWithGasFeeBoundAtLeftBoundary() public view {
uint64 filUsdPrice = 5;
int32 filUsdPriceExpo = 0;
uint256 rawSize = 1e18;
Expand All @@ -161,7 +162,7 @@ contract PDPFeesTest is Test {
assertEq(fee, expectedFee, "Fee should be full proof fee at left boundary");
}

function testProofFeeWithGasFeeBoundNearRightBoundary() public pure {
function testProofFeeWithGasFeeBoundNearRightBoundary() public view {
uint64 filUsdPrice = 5;
int32 filUsdPriceExpo = 0;
uint256 rawSize = 1e18;
Expand Down

0 comments on commit 34be592

Please sign in to comment.