Block structure
A Starknet block is a list of transactions and a block header that contains the following fields:
Name | Type | Description |
---|---|---|
|
|
The number, that is, the height, of this block. |
|
|
The hash of the block’s parent. |
|
|
The state commitment after the block. |
|
|
The Starknet address of the sequencer that created the block. |
|
|
The time at which the sequencer began building the block, in seconds since the Unix epoch. |
|
|
The number of transactions in the block. |
|
|
The number of events in the block. |
|
|
The sum of number of storage diffs, nonce updates, deployed contracts and declared classes. |
|
|
The poseidon hash of the state diff of the block, see below for more details. |
|
|
A commitment to the transactions included in the block. The root of a height-64 binary Merkle Patricia trie. The leaf at index \(i\) corresponds to \({h(\text{transaction_hash}, \text{signature})}\). |
|
|
The root of a height-64 binary Merkle Patricia trie. The leaf at index \(i\) corresponds to the hash of the \(i'th\) event emitted in the block. See below for a description on how event hashes are computed. |
|
|
The root of a height-64 Merkle-Patricia trie. The leaf at index \(i\) corresponds to the hash of the \(i'th\) transaction receipt. See below for a description on how receipt hashes are computed. |
|
|
The price of L1 gas that was used while constructing the block. L1 gas prices apply to storage updates and L1→L2 messages. As of March 2023, computation is also priced in terms of L1 gas, but this will change in the future.
The first |
|
|
The price of L1 blob gas that was used while constructing the block. If the |
|
|
|
|
|
The version of the Starknet protocol used when creating the block. |
Block hash
A block hash is defined as the Poseidon hash of the header’s fields, as follows:
h(𝐵) = h( "STARKNET_BLOCK_HASH0", block_number, global_state_root, sequencer_address, block_timestamp, transaction_count || event_count || state_diff_length || l1_da_mode, state_diff_commitment, transactions_commitment events_commitment, l1_gas_price_in_wei, l1_gas_price_in_fri, l1_data_gas_price_in_wei, l1_data_gas_price_in_fri receipts_commitment 0, parent_block_hash )
Where:
-
h
is the Poseidon hash. -
||
denotes concatenation,transaction_count
,event_count
andstate_diff_length
are given 64 bits each, andl1_da_mode
is one bit where 0 denotesCALLDATA
and 1 denotesBLOB
.
For a reference implementation, see the sequencer repository.
State diff commitment
The state diff commitment is obtained by the chain-hash of the following:
-
updates to contract addresses \(c_1,...,c_n\), with diffs \((k^1_1, v^1_1),...,(k^1_{m_1}, v^1_{m_1}),...,(k^n_1, v^n_1),...,(k^n_{m_n},v^n_{m_n})\)
-
deployed contracts \((\text{deployed_address}_1, \text{deployed_class_hash}_1),...,(\text{deployed_address}_\ell,\text{deployed_class_hash}_\ell)\)
-
declared classes \((\text{declared_class_hash}_1, \text{declared_compiled_class_hash}_1), ..., (\text{declared_class_hash}_d, \text{declared_compiled_class_hash}_d)\)
-
replaced classes \((\text{replaced_contract_address}_1, \text{new_class_hash}_1),...,(\text{replaced_contract_address}_r, \text{new_class_hash}_r)\)
-
updated nonces \((\text{account}_1, \text{new_nonce}_1),...,(\text{account}_k, \text{new_nonce}_k)\)
More formally, the state-diff hash is given by:
Where:
-
\(h\) is the Poseidon hash function
-
\(1, 0\) in the hash computation are placeholders that may be used in the future
Receipt hash
A transaction receipt consists of the following fields:
Name | Type | Description |
---|---|---|
|
|
the hash of the transaction |
|
|
the fee paid on-chain |
|
|
ordered list of the events emitted by the transaction |
|
|
ordered list of the l2→l1 messages sent by the transaction |
|
|
The revert reason, in case the transaction was reverted |
|
|
The amount of l1 gas that was consumed |
|
|
The amount of l1 data (blob) gas that was consumed |
|
|
The amount of l2 gas that was consumed |
The hash of the transaction receipt is given by:
h(receipt) = h( transaction_hash, actual_fee, h(messages), sn_keccak(revert_reason), h(l2_gas_consumed, l1_gas_consumed, l1_data_gas_consumed) )
Where:
-
h is the Poseidon hash function
-
given messages \(m_1=(\text{from}_1, \text{to}_1, \text{payload}_1)...m_n=(\text{from}_n, \text{to}_n, \text{payload}_n)\), their hash is given by:
where each message’s payload is length-prefixed.
-
events are omitted from the receipt’s hash since they are committed separately in the block.
Event hash
The hash of an event \((\text{keys}, \text{data})\) emitted by a contract whose address is emitter_address
and a transaction whose hash is tx_hash
is given by:
Where \(h\) is the Poseidon hash function.
Zeros inside the hash computation of an object are used as placeholders, to be replaced in the future by meaningful fields. |