From 96728f89ac175286c183b43e2dbfa14e028ea82c Mon Sep 17 00:00:00 2001 From: anikaraghu Date: Tue, 12 Dec 2023 15:59:16 -0800 Subject: [PATCH] Update pricing function --- .../src/L2/GasPriceOracle.sol | 39 ++++++++++++++----- packages/contracts-bedrock/src/L2/L1Block.sol | 27 +++++++------ 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/packages/contracts-bedrock/src/L2/GasPriceOracle.sol b/packages/contracts-bedrock/src/L2/GasPriceOracle.sol index 30ab88c19d248..2cfab8444f63a 100644 --- a/packages/contracts-bedrock/src/L2/GasPriceOracle.sol +++ b/packages/contracts-bedrock/src/L2/GasPriceOracle.sol @@ -24,8 +24,8 @@ contract GasPriceOracle is ISemver { uint256 public constant DECIMALS = 6; /// @notice Semantic version. - /// @custom:semver 1.1.0 - string public constant version = "1.1.0"; + /// @custom:semver 1.2.0 + string public constant version = "1.2.0"; /// @notice Computes the L1 portion of the fee based on the size of the rlp encoded input /// transaction, the current L1 base fee, and the various dynamic parameters. @@ -33,9 +33,10 @@ contract GasPriceOracle is ISemver { /// @return L1 fee that should be paid for the tx function getL1Fee(bytes memory _data) external view returns (uint256) { uint256 l1GasUsed = getL1GasUsed(_data); - uint256 l1Fee = l1GasUsed * l1BaseFee(); + uint256 scaledBaseFee = baseFeeScalar() * l1BaseFee(); + uint256 scaledBlobBaseFee = blobBaseFeeScalar() * blobBaseFee(); uint256 divisor = 10 ** DECIMALS; - uint256 unscaled = l1Fee * scalar(); + uint256 unscaled = l1GasUsed * (scaledBaseFee + scaledBlobBaseFee); uint256 scaled = unscaled / divisor; return scaled; } @@ -52,12 +53,14 @@ contract GasPriceOracle is ISemver { return block.basefee; } + /// @custom:legacy /// @notice Retrieves the current fee overhead. /// @return Current fee overhead. function overhead() public view returns (uint256) { return L1Block(Predeploys.L1_BLOCK_ATTRIBUTES).l1FeeOverhead(); } + /// @custom:legacy /// @notice Retrieves the current fee scalar. /// @return Current fee scalar. function scalar() public view returns (uint256) { @@ -70,6 +73,24 @@ contract GasPriceOracle is ISemver { return L1Block(Predeploys.L1_BLOCK_ATTRIBUTES).basefee(); } + /// @notice Retrieves the current blob base fee. + /// @return Current blob base fee. + function blobBaseFee() public view returns (uint256) { + return L1Block(Predeploys.L1_BLOCK_ATTRIBUTES).blobBaseFee(); + } + + /// @notice Retrieves the current base fee scalar. + /// @return Current base fee scalar. + function baseFeeScalar() public view returns (uint256) { + return L1Block(Predeploys.L1_BLOCK_ATTRIBUTES).baseFeeScalar(); + } + + /// @notice Retrieves the current blob base fee scalar. + /// @return Current blob base fee scalar. + function blobBaseFeeScalar() public view returns (uint256) { + return L1Block(Predeploys.L1_BLOCK_ATTRIBUTES).blobBaseFeeScalar(); + } + /// @custom:legacy /// @notice Retrieves the number of decimals used in the scalar. /// @return Number of decimals used in the scalar. @@ -77,10 +98,8 @@ contract GasPriceOracle is ISemver { return DECIMALS; } - /// @notice Computes the amount of L1 gas used for a transaction. Adds the overhead which - /// represents the per-transaction gas overhead of posting the transaction and state - /// roots to L1. Adds 68 bytes of padding to account for the fact that the input does - /// not have a signature. + /// @notice Computes the amount of L1 gas used for a transaction. Adds 68 bytes + /// of padding to account for the fact that the input does not have a signature. /// @param _data Unsigned fully RLP-encoded transaction to get the L1 gas for. /// @return Amount of L1 gas used to publish the transaction. function getL1GasUsed(bytes memory _data) public view returns (uint256) { @@ -93,7 +112,7 @@ contract GasPriceOracle is ISemver { total += 16; } } - uint256 unsigned = total + overhead(); - return unsigned + (68 * 16); + uint256 compressedTxSize = total / 16; + return compressedTxSize + (68 * 16); } } diff --git a/packages/contracts-bedrock/src/L2/L1Block.sol b/packages/contracts-bedrock/src/L2/L1Block.sol index 56e1f9649e38f..13ea588c27efd 100644 --- a/packages/contracts-bedrock/src/L2/L1Block.sol +++ b/packages/contracts-bedrock/src/L2/L1Block.sol @@ -33,23 +33,26 @@ contract L1Block is ISemver { bytes32 public batcherHash; /// @notice The overhead value applied to the L1 portion of the transaction fee. + /// @custom:legacy uint256 public l1FeeOverhead; /// @notice The scalar value applied to the L1 portion of the transaction fee. + /// @custom:legacy uint256 public l1FeeScalar; /// @notice The scalar value applied to the L1 base fee portion of the blob-capable L1 cost func - uint256 public basefeeScalar; + uint256 public baseFeeScalar; /// @notice The scalar value applied to the L1 blob base fee portion of the blob-capable L1 cost func - uint256 public blobBasefeeScalar; + uint256 public blobBaseFeeScalar; /// @notice The latest L1 blob basefee. - uint256 public blobBasefee; + uint256 public blobBaseFee; /// @custom:semver 1.2.0 string public constant version = "1.2.0"; + /// @custom:legacy /// @notice Updates the L1 block values. /// @param _number L1 blocknumber. /// @param _timestamp L1 timestamp. @@ -87,22 +90,22 @@ contract L1Block is ISemver { /// @param _number L1 blocknumber. /// @param _timestamp L1 timestamp. /// @param _basefee L1 basefee. - /// @param _blobBasefee L1 blobBasefee. + /// @param _blobBaseFee L1 blobBaseFee. /// @param _hash L1 blockhash. /// @param _sequenceNumber Number of L2 blocks since epoch start. /// @param _batcherHash Versioned hash to authenticate batcher by. - /// @param _basefeeScalar L1 base fee scalar - /// @param _blobBasefeeScalar L1 blob base fee scalar + /// @param _baseFeeScalar L1 base fee scalar + /// @param _blobBaseFeeScalar L1 blob base fee scalar function setL1BlockValuesV2( uint64 _number, uint64 _timestamp, uint256 _basefee, - uint256 _blobBasefee, + uint256 _blobBaseFee, bytes32 _hash, uint64 _sequenceNumber, bytes32 _batcherHash, - uint256 _basefeeScalar, - uint256 _blobBasefeeScalar + uint256 _baseFeeScalar, + uint256 _blobBaseFeeScalar ) external { @@ -111,11 +114,11 @@ contract L1Block is ISemver { number = _number; timestamp = _timestamp; basefee = _basefee; - blobBasefee = _blobBasefee; + blobBasefee = _blobBaseFee; hash = _hash; sequenceNumber = _sequenceNumber; batcherHash = _batcherHash; - basefeeScalar = _basefeeScalar; - blobBasefeeScalar = _blobBasefeeScalar; + basefeeScalar = _baseFeeScalar; + blobBasefeeScalar = _blobBaseFeeScalar; } }