Skip to main content

Overview

A Starknet block is a list of transactions and a block header that contains multiple fields, including the hash of the previous block and a commitment to their state diff, as well as commitments to the transactions, events, and receipts it includes.

Block header fields

Block hash

A block hash is defined by:
Where:
  • h is the Poseidon hash function
  • transaction_count || event_count || state_diff_length || l1_da_mode is the concatenation of the 64-bit representations of transaction_count, event_count, and state_diff_length with 0 if l1_da_mode is CALLDATA and 1 if l1_da_mode is BLOB
  • gas_prices_hash is defined by:
    where h is the Poseidon hash function and l1_gas_price_wei, l1_gas_price_fri, l1_data_gas_price_wei, l1_data_gas_price_fri, l2_gas_price_wei, and l2_gas_price_fri are the wei and fri denominated prices for the three resource types.
For a reference implementation, see block_hash_calculator.rs in the Starknet sequencer’s GitHub repository

State diff commitment

The state diff commitment is defined by:
Where:
  • h is the Poseidon hash function
  • s is the number of deployed and replaced contracts in the block
  • deployed_or_replaced_address1, ... , deployed_or_replaced_addresss are the deployed and replaced addresses sorted in numerical increasing order according to the addresses
    • For a replaced address, each value is replaced_contract_address, new_class_hash
  • d is the number of declared and migrated classes in the block
  • declared_or_migrated_class_hash1, declared_or_migrated_compiled_class_hash1..., declared_or_migrated_class_hashd, declared_or_migrated_class_hashd are the declared or replaced class hashes sorted in a numerical increasing order.
    • declared_or_migrated_class_hash is the hash of the Sierra code
    • declared_or_migrated_compiled_class_hash is the hash of the CASM code
  • 1 and 0 are placeholders that may be used in the future
  • n is the number of contracts whose storage was updated
  • c_i, k_i_1, v_i_1, … , k_i_mi,v_i_mi are mi updates (k_i_1, v_i_1), … ,(k_i_mi, v_i_mi) to contract addresses c_i. Where k_i_j is the j-th key and v_i_j is the j-th new value
  • k is the number of accounts whose nonce was updatedTransactions, events, and receipts commitments

Transactions, events, and receipts commitments

The commitment to transactions, the commitment to events and the commitment to receipts are all roots of height-64 binary Merkle Patricia tries where the leaf at index i corresponds to:
  • For transactions: h(transaction_hash, signature) for the i’th transaction included in the block, where transaction_hash is calculated as follows and h is the Poseidon hash function. Note that the signature is itself a (possibly empty) array of field elements.
  • For events: The event hash of the i’th emitted event included in the block
  • For receipts: The receipt hash of the i’th transaction receipt included in the block

Event hash

The hash of an event emitted by a contract whose address is emitter_address and a transaction whose hash is tx_hash is defined by:
Where h is the Poseidon hash function.

Receipt hash

The hash of a transaction receipt is defined by:
Where:
  • h is the Poseidon hash function
  • h(messages) for messages = (from1, to1, payload1), … , (fromn, ton, payloadn) is defined by: