Skip to content

Commit

Permalink
Amend holocene spec to specify eip-1559 parameters should be in extra…
Browse files Browse the repository at this point in the history
…Data instead of nonce.
  • Loading branch information
Roberto Bayardo authored and roberto-bayardo committed Oct 16, 2024
1 parent c6903a3 commit d700fcf
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 34 deletions.
66 changes: 34 additions & 32 deletions specs/protocol/holocene/exec-engine.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
- [Rationale](#rationale)
- [`eip1559Params` in Header](#eip1559params-in-header)
- [Header Validity Rules](#header-validity-rules)
- [Encoding](#encoding)
- [Rationale](#rationale-1)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## Overview

The EIP-1559 parameters are encoded in the block header's `nonce` field and can be
The EIP-1559 parameters are encoded in the block header's `extraData` field and can be
configured dynamically through the `SystemConfig`.

## Timestamp Activation
Expand All @@ -46,13 +45,13 @@ PayloadAttributesV3: {
transactions: array of DATA
noTxPool: bool
gasLimit: QUANTITY or null
eip1559Params: DATA (8 bytes)
eip1559Params: DATA (8 bytes) or null
}
```

#### PayloadID computation

If `eip1559Params != null`, the `eip1559Params` is included in the `PayloadID` hasher directly after the `gasLimit`
If `eip1559Params` != null`, the `eip1559Params` is included in the `PayloadID` hasher directly after the `gasLimit`
field.

#### `eip1559Params` encoding
Expand All @@ -64,19 +63,26 @@ field.

### Execution

During execution, the EIP-1559 parameters used to calculate the next block base fee should come from the
parent header's `nonce` field rather than the previous protocol constants, if it is non-zero.
During execution, the EIP-1559 parameters used to calculate the next block base fee should come from the parent header's
`extraData` field rather than the previous protocol constants, if it is non-empty.

- Prior to Holocene activation, `eip1559Parameters` in the `PayloadAttributesV3` must be null and is otherwise
considered invalid.

- If, before Holocene activation, `eip1559Parameters` in the `PayloadAttributesV3` is non-null, the attributes are to
be considered invalid by the engine.
- At and after Holocene activation:
- if `eip1559Params` in the `PayloadAttributesV3` is null, the attributes are to be considered invalid by the
engine.
- if `eip1559Params`' `denominator` is `0`, the attributes are to be considered invalid by the engine.
- if `parent_header.nonce` is zero, the [canyon base fee parameter constants](../exec-engine.md#1559-parameters) are
used for the block's base fee parameters.
- if `parent_header.nonce` is non-zero, the EIP-1559 parameters encoded within the parent header's `nonce` field are
used for the block's base fee parameters.
- if `eip1559Params` in the `PayloadAttributesV3` is null, the attributes are considered invalid.
- if `eip1559Params`' `denominator` is `0`, the attributes are considered invalid.
- if Holocene is not active in `parent_header.timestamp`, the [canyon base fee parameter
constants](../exec-engine.md#1559-parameters) or prior EIP-1559 constants are used for the block's base fee
parameters. While `parent_header.extraData` is typically empty prior to Holocene, there are some legacy cases where
it may be set arbitrarily, so it must not be assumed to be empty.
- if Holocene is active in `parent_header.timestamp`, then `parent_header.extraData` is exactly 9 bytes with the
following format:
- the first byte is set to `0`, used as version byte for the content.
- the next 8 bytes are used to encode the 1559 params following the [`eip1559Params` encoding](#eip1559params-encoding).

Note that `extraData` has a maximum capacity of 32 bytes (to fit in the L1 beacon-chain `extraData` data-type) and may
be modified/extended in future versions.

### Rationale

Expand All @@ -87,27 +93,23 @@ how it must reference the `SystemConfig` for the `gasLimit` field.

### `eip1559Params` in Header

Upon Holocene activation, the L2 block header's `nonce` field will consist of the 8-byte `eip1559Params` value from
the `PayloadAttributesV3`, or the canyon EIP-1559 constants if `eip1559Params` is equal to zero.
Upon Holocene activation, the L2 block header's `extraData` field will consist of a version byte with value
byte(0), followed by an 8-byte `eip1559Params` value from the `PayloadAttributesV3`, or the canyon EIP-1559
constants if `eip1559Params` is equal to zero.

#### Header Validity Rules

Prior to Holocene activation, the L2 block header's `nonce` field is valid iff it is equal to `u64(0)`.

At and after Holocene activation, The L2 block header's `nonce` field is valid iff it is non-zero.
Prior to Holocene activation, the L2 block header's `extraData` field is valid iff it is empty.

#### Encoding

The encoding of the `eip1559Params` value is described in [`eip1559Params` encoding](#eip1559params-encoding).
At and after Holocene activation, The L2 block header's `extraData` field is valid iff it consists of a leading version
byte with value 0 followed by the eip-1559 parameters encoded as described in [`eip1559Params`
encoding](#eip1559params-encoding).

#### Rationale

By chosing to put the `eip1559Params` in the `PayloadAttributes` rather than in the L1 block info transaction,
the EIP-1559 parameters for the chain are not available within history. This would place a burden on performing
historical execution, as L1 would have to be consulted for fetching the values from the `SystemConfig` contract.
Instead, we re-use an unused field in the L1 block header as to make these parameters available, retaining the
purity of the function that computes the next block's base fee from the chain configuration, parent block header,
and next block timestamp.

[l2-to-l1-mp]: ../../protocol/predeploys.md#L2ToL1MessagePasser
[output-root]: ../../glossary.md#l2-output-root
By choosing to put the `eip1559Params` in the `PayloadAttributes` rather than in the L1 block info transaction, the
EIP-1559 parameters for the chain are not available within history. This would place a burden on performing historical
execution, as L1 would have to be consulted for fetching the values from the `SystemConfig` contract. Instead, we
re-use an unused field in the L2 block header as to make these parameters available, retaining the purity of the
function that computes the next block's base fee from the chain configuration, parent block header, and next block
timestamp.
6 changes: 4 additions & 2 deletions specs/protocol/holocene/system-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ The following `ConfigUpdate` event is defined where the `CONFIG_VERSION` is `uin
| Name | Value | Definition | Usage |
| ---- | ----- | --- | -- |
| `BATCHER` | `uint8(0)` | `abi.encode(address)` | Modifies the account that is authorized to progress the safe chain |
| `FEE_SCALARS` | `uint8(1)` | `(uint256(0x01) << 248) \| (uint256(_blobbasefeeScalar) << 32) \| _basefeeScalar` | Modifies the fee scalars |
| `FEE_SCALARS` | `uint8(1)` | `abi.encode(uint256(0), (uint256(0x01) << 248) \| (uint256(_blobbasefeeScalar) << 32) \| _basefeeScalar)` | Modifies the fee scalars |
| `GAS_LIMIT` | `uint8(2)` | `abi.encode(uint64 _gasLimit)` | Modifies the L2 gas limit |
| `UNSAFE_BLOCK_SIGNER` | `uint8(3)` | `abi.encode(address)` | Modifies the account that is authorized to progress the unsafe chain |
| `EIP_1559_PARAMS` | `uint8(4)` | `(uint256(_denominator) << 32) \| _elasticity` | Modifies the EIP-1559 denominator and elasticity |
| `EIP_1559_PARAMS` | `uint8(4)` | `abi.encode((uint256(_denominator) << 32) \| _elasticity)` | Modifies the EIP-1559 denominator and elasticity |

Note that the above encoding is the format emitted by the SystemConfig event, which differs from the format in extraData from the block header.

### Initialization

Expand Down

0 comments on commit d700fcf

Please sign in to comment.