diff --git a/EIPS/eip-4844.md b/EIPS/eip-4844.md index c0af580d875d9e..61a628a9355baa 100644 --- a/EIPS/eip-4844.md +++ b/EIPS/eip-4844.md @@ -39,8 +39,6 @@ Compared to full data sharding, this EIP has a reduced cap on the number of thes | Constant | Value | | - | - | -| `SYSTEM_STATE_ADDRESS` | `0x000.....0100`| -| `TOTAL_BLOB_TXS_STORAGE_SLOT` | `0` | | `BLOB_TX_TYPE` | `Bytes1(0x05)` | | `FIELD_ELEMENTS_PER_BLOB` | `4096` | | `BLS_MODULUS` | `52435875175126190479447740508185965837690552500527637822603658699938581184513` | @@ -234,6 +232,44 @@ def get_origin(tx: SignedBlobTransaction) -> Address: return ecrecover(tx_hash(tx), int(sig.y_parity)+27, sig.r, sig.s) ``` +### Header extension + +The current header encoding is extended with a new 256-bit unsigned integer field `blob_txs`. This is the running +total of blob txs included on chain since this EIP was activated. The resulting RLP encoding of the header is therefore: + +``` +rlp([ + parent_hash, + ommers_hash, + coinbase, + state_root, + tx_root, + receipt_root, + bloom, + difficulty, + number, + gas_limit, + gas_used, + time, + extra, + mix_digest, + nonce, + base_fee, + blob_txs +]) +``` + +The value of `blob_txs` can be calculated using the parent header and number of blob transactions in the block. + +```python +def calc_blob_gas(parent: Header, blob_txs_in_block: int) -> int: + # Don't let the new total fall behind the targeted total to avoid + # accumulating a long period of very low fees + blocks_since_start = header.Number - FORK_BLKNUM + targeted_total = blocks_since_start * TARGET_BLOB_TXS_PER_BLOCK + return max(header.blob_txs + blob_txs_in_block, targeted_total) +``` + ### Beacon chain validation On the consensus-layer the blobs are now referenced, but not fully encoded, in the beacon block body. @@ -290,8 +326,8 @@ For early draft implementations, we simply change `get_blob_gas(pre_state)` to a ### Gas price update rule (Full version) We propose a simple independent EIP-1559-style targeting rule to compute the gas cost of the transaction. -We use the `TOTAL_BLOB_TXS_STORAGE_SLOT` storage slot of the `SYSTEM_STATE_ADDRESS` address -to store persistent data needed to compute the cost. +We use the `blob_txs` header field to store persistent data needed to compute the cost. + Note that unlike existing transaction types, the gas cost is dependent on the pre-state of the block. ```python @@ -307,14 +343,10 @@ def get_intrinsic_gas(tx: SignedBlobTransaction, pre_state: ExecState) -> int: intrinsic_gas += len(tx.message.blob_versioned_hashes) * get_blob_gas(pre_state) return intrinsic_gas -def get_blob_gas(pre_state: ExecState) -> int: +def get_blob_gas(header: Header) -> int: blocks_since_start = get_current_block(pre_state) - FORK_BLKNUM targeted_total = blocks_since_start * TARGET_BLOB_TXS_PER_BLOCK - actual_total = read_storage( - pre_state, - SYSTEM_STATE_ADDRESS, - TOTAL_BLOB_TXS_STORAGE_SLOT - ) + actual_total = header.blob_txs if actual_total < targeted_total: return 0 else: @@ -324,28 +356,6 @@ def get_blob_gas(pre_state: ExecState) -> int: ) ``` -We update at the end of a block, as follows: - -```python -def update_blob_gas(state: ExecState, blob_txs_in_block: int): - current_total = read_storage( - state, - SYSTEM_STATE_ADDRESS, - TOTAL_BLOB_TXS_STORAGE_SLOT - ) - # Don't let the new total fall behind the targeted total to avoid - # accumulating a long period of very low fees - blocks_since_start = get_current_block(pre_state) - FORK_BLKNUM - targeted_total = blocks_since_start * TARGET_BLOB_TXS_PER_BLOCK - new_total = max(current_total + blob_txs_in_block, targeted_total) - write_storage( - state, - SYSTEM_STATE_ADDRESS, - TOTAL_BLOB_TXS_STORAGE_SLOT, - new_total - ) -``` - ### Networking Transactions are presented as `TransactionType || TransactionNetworkPayload` on the execution layer network, @@ -465,7 +475,6 @@ This EIP also sets the stage for longer-term protocol cleanups: and paves the precedent that all new transaction types should be SSZ * It defines `TransactionNetworkPayload` to separate network and block encodings of a transaction type * Its (cleaner) gas price update rule could be applied to the primary basefee. - It also starts the trend toward using the state to store system state instead of having "implied state" such as historical blocks and hashes. ### How rollups would function