@@ -7,6 +7,7 @@ import { Fork } from "scripts/libraries/Config.sol";
77
88// Libraries
99import { Encoding } from "src/libraries/Encoding.sol " ;
10+ import { stdError } from "forge-std/Test.sol " ;
1011
1112contract GasPriceOracle_Test is CommonTest {
1213 address depositor;
@@ -26,6 +27,10 @@ contract GasPriceOracle_Test is CommonTest {
2627 uint32 constant operatorFeeScalar = 4_000_000 ;
2728 uint64 constant operatorFeeConstant = 300 ;
2829
30+ uint256 constant MAX_UINT256 = type (uint256 ).max;
31+ uint64 constant MAX_UINT64 = type (uint64 ).max;
32+ uint32 constant MAX_UINT32 = type (uint32 ).max;
33+
2934 /// @dev Sets up the test suite.
3035 function setUp () public virtual override {
3136 super .setUp ();
@@ -447,6 +452,26 @@ contract GasPriceOracleJovian_Test is GasPriceOracle_Test {
447452 assertEq (gasPriceOracle.isJovian (), true , "Jovian activation failed " );
448453 }
449454
455+ function _setOperatorFeeParams (uint32 _operatorFeeScalar , uint64 _operatorFeeConstant ) internal {
456+ vm.prank (depositor);
457+ (bool success ,) = address (l1Block).call (
458+ Encoding.encodeSetL1BlockValuesIsthmus (
459+ baseFeeScalar,
460+ blobBaseFeeScalar,
461+ sequenceNumber,
462+ timestamp,
463+ number,
464+ baseFee,
465+ blobBaseFee,
466+ hash,
467+ batcherHash,
468+ _operatorFeeScalar,
469+ _operatorFeeConstant
470+ )
471+ );
472+ require (success, "GasPriceOracleJovian_Test: L1Block setup failed " );
473+ }
474+
450475 /// @dev Tests that `operatorFee` is set correctly using the new Jovian formula (multiply by 100).
451476 function test_getOperatorFee_succeeds () external {
452477 _activateJovian ();
@@ -468,19 +493,67 @@ contract GasPriceOracleJovian_Test is GasPriceOracle_Test {
468493 }
469494
470495 /// @dev Tests the transition from Isthmus formula to Jovian formula.
471- function test_formulaTransition_succeeds () external {
472- // Check Isthmus formula (divide by 1e6)
496+ function test_formulaTransition_edgeCases_works () external {
497+ // Check Isthmus formula with a low gasUsed value (divide by 1e6)
498+ _setOperatorFeeParams (operatorFeeScalar, operatorFeeConstant);
473499 uint256 isthmusFee = gasPriceOracle.getOperatorFee (10 );
474- assertEq (isthmusFee, 10 * operatorFeeScalar / 1e6 + operatorFeeConstant);
500+ assertEq (
501+ isthmusFee,
502+ uint256 (10 ) * operatorFeeScalar / 1e6 + operatorFeeConstant,
503+ "Isthmus operator fee incorrect with 10 gas used "
504+ );
505+
506+ // Use maximum values permitted by data types for scalars.
507+ // Use maximum value for gasUsed according to client implementations.
508+ // Assert that the fee is as expected (no overflow).
509+ _setOperatorFeeParams (MAX_UINT32, MAX_UINT64);
510+ isthmusFee = gasPriceOracle.getOperatorFee (MAX_UINT64);
511+ assertEq (
512+ isthmusFee,
513+ uint256 (MAX_UINT64) * MAX_UINT32 / 1e6 + MAX_UINT64,
514+ "Isthmus operator fee incorrect with max uint64 gas used "
515+ );
516+
517+ // Show that the math saturates if the maximum
518+ // value for gasUsed (according to data type) is used.
519+ _setOperatorFeeParams (1e6 , 1 );
520+ uint256 saturatedIsthmusFee = gasPriceOracle.getOperatorFee (MAX_UINT256);
521+ assertEq (
522+ saturatedIsthmusFee,
523+ 115792089237316195423570985008687907853269984665640564039457584007913130 ,
524+ "Incorrect value for fee under Isthmus (saturating arithmetic triggered) "
525+ );
475526
476527 // Activate Jovian
477528 _activateJovian ();
478529
479- // Check Jovian formula (multiply by 100)
530+ // Check Jovian formula with a low gasUsed value (multiply by 100)
531+ _setOperatorFeeParams (operatorFeeScalar, operatorFeeConstant);
480532 uint256 jovianFee = gasPriceOracle.getOperatorFee (10 );
481- assertEq (jovianFee, 10 * operatorFeeScalar * 100 + operatorFeeConstant);
533+ assertEq (
534+ jovianFee,
535+ uint256 (10 ) * operatorFeeScalar * 100 + operatorFeeConstant,
536+ "Jovian operator fee incorrect with 10 gas used "
537+ );
538+
539+ // Use maximum values permitted by data types for scalars.
540+ // Use maximum value for gasUsed according to client implementations.
541+ // Assert that the fee is as expected (no overflow).
542+ _setOperatorFeeParams (MAX_UINT32, MAX_UINT64);
543+ jovianFee = gasPriceOracle.getOperatorFee (MAX_UINT64);
544+ assertEq (
545+ jovianFee,
546+ uint256 (MAX_UINT64) * MAX_UINT32 * 100 + MAX_UINT64,
547+ "Jovian operator fee incorrect with max uint64 gas used "
548+ );
549+
550+ // Show that a revert is possible if the maximum
551+ // value for gasUsed (according to data type) is used.
552+ _setOperatorFeeParams (1 , 1 );
553+ vm.expectRevert (stdError.arithmeticError);
554+ gasPriceOracle.getOperatorFee (MAX_UINT256);
482555
483556 // Verify the fee increased significantly
484- assertGt (jovianFee, isthmusFee);
557+ assertGt (jovianFee, isthmusFee, " Jovian formula fee should be greater than Isthmus formula fee " );
485558 }
486559}
0 commit comments