[Review] Restore BaseFee opcode/header field #384
Closed
gastonponti
started this conversation in
CIP Discussions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Simple Summary
Move the
minimumGasPrice
of Celo from our core contract to the header of the block, and activate the EIP-3198 (add thebaseFee
opcode)Abstract
This CIP proposes to remove the
minimumGasPrice
update made by our consensus layer at the end of each block, to be calculated at the beginning of every block proposed, and storing it in the header. Also, the implementation of the EIP-3198 which adds thebaseFee
opcode to the EVM.Motivation
This CIP aims to reduce the complexity of our consensus layer, and get us closer to the Ethereum’s implementation of the EIP-1559. This will facilitate future upstream merges and the plans to separate our execution and consensus layers.
Specification
Definitions
blockGasLimit
is a governable parameter from the BlockchainParametersContract that represents the gas limit of the blockblockGasTotal
is the gas used for an specific blockblockDensity
is a number in the interval[0, 1]
that represents the usage rate of the block ⇒blockGasTotal / blockGasLimit
adjustmentSpeed
is a governable parameter from the GasPriceMinimumContract that represents the speed of gas price minimum adjustment due to congestiontargetDensity
is a governable parameter from the GasPriceMinimumContract that represents the block congestion level targeted by the gas price minimum calculationgasPriceMinimumFloor
is a governable parameter from the GasPriceMinimumContract that represents the minimum gas price thresholdBlockchain node
Add the
baseFee
field to the header structure.Implement the EIP-3198 that adds the
BASEFEE (0x48)
opcode.Switch the way we are storing the
gasPriceMinimum
(requires to be enabled during a hardfork)Currently the
GasPriceMinimum
is modified and saved calling theGasPriceMinimum
contract in the finalize stage of the consensus here. This must be avoided from the Hardfork Block.Then, in the
prepareBlock
function (here) will need toFor the G_HARDFORK_BLOCK:
Retrieve the
gasPriceMinimum
of the actual state (which was updated at the end of theG_HARDFORK_BLOCK - 1
) and add that number as thebaseFee
of the headerFrom the
G_HARDFORK_BLOCK + 1
:newCalculatedBaseFee = parent.baseFee * (1 + (adjustmentSpeed * (parent.blockDensity - targetDensity))) + 1
baseFee = newCalculatedBaseFee >= gasPriceMinimumFloor ? newCalculatedBaseFee : gasPriceMinimumFloor
Alternatively the client should call the
getUpdatedGasPriceMinimum
of the modifiedgasPriceMinimum
contract with the state of the parent block, to retrieve the newbaseFee
Contracts
Before the hardfork, we will need to deploy a new version of the
GasPriceMinimum
contract with the following changes:Rename the
gasPriceMinimum
variable todeprecated_gasPriceMinimum
This step is required to be able to define a new function
gasPriceMinimum
that will return the renamed variabledeprecated_gasPriceMinimum
or theblock.basefee
depending on theG_HARDFORK_BLOCK
Change the way the
gasPriceMinimum
getter was defined and override it:Change the implementation of
getGasPriceMinimum
(line 116) to:Update the
getUpdatedGasPriceMinimum
function to maintain compatibilityThe
updateGasPriceMinimum
is only called by the VM, and must not call this function after the HardFork. There is not need to change it other than having a cleaner contract.Rationale
The decision of moving the
gasPriceMinimum
to the header as thebaseFee
give us a few benefits:gasPriceMinimum
variable in our core contract, it won’t modify the final state of the block, thus it won’t generate a block receipt, which is something we want to reduce as much as possiblegasPriceMinimum
of the blockBackwards Compatibility
This needs to be added as part of a fork. To maintain full backwards compatibility, we will also need to re deploy the
GasPriceMinimum
contract consuming thebaseFee
opcode.Block Hash Changing
The datastructure that is passed into keccak256 to calculate the block hash is changing, and all applications that are validating blocks are valid or using the block hash to verify block contents will need to be adapted to support the new datastructure (one additional item). If you only take the block header bytes and hash them you should still correctly get a hash, but if you construct a block header from its constituent elements you will need to add in the new one at the end.
Test Cases
Nominal case
Assuming current block base fee is
7 wei
. This should push the value7
(left padded byte32) to the stack.Bytecode:
0x4800
(BASEFEE, STOP
)Output:
0x
Consumed gas:2
Implementation
Contract: celo-org/celo-monorepo#10379
Client [WIP]: celo-org/celo-blockchain#2128
Security Considerations
Just as a consideration, even if it won’t be a big change, this CIP adds a field to the header which will increases its size.
License
This work is licensed under the Apache License, Version 2.0.
Beta Was this translation helpful? Give feedback.
All reactions