Block Structure and Hash


Page content:

  • Block Hash – Go
  • Transactions Commitment – Go
  • Pending Block – Go

In StarkNet, the block is defined as a list of transactions and a block header. The following fields define the block header:

Name Type Description Is Part of the Header? Implemented in the current version?
parent_block_hash Field Element The hash of this block’s parent Yes Yes
block_number Integer The number (height) of this block Yes Yes
new_global_root Field Element The StarkNet state new root, as updated in this block Yes Yes
sequencer Ethereum Address The ethereum address of the sequencer submitting the state update that creates this block. Yes Yes
creation_time Timestamp The time the sequencer created this block before executing transactions.

Formatted as a simple UTC timestamp (# of seconds since the Unix epoch).

Yes No
transaction_count Field Element The number of transactions in the block Yes Yes
transaction_commitment Field Element A commitment on the list of transactions that are part of the block Yes Yes
event_count Field Element The number of events in the block Yes No
event_commitment Field Element A commitment to the events produced in this block Yes No
protocol_version Integer The version of the SN protocol used when creating this block Yes No
extra_data Field Element Extraneous data that might be useful for running transactions. Yes No

 

Block Hash

A block hash is a hash of the block’s header elements.

Specifically:

pedersen_hash(
   parent_block_hash,block_number,
   new_global_root,sequencer,
   creation_time, transaction_commitment, transaction_count
   event_commitment, event_count, protocol_version, 
   extra_data
)

In StarkNet Alpha, each component that is not yet implemented is replaced with 0.

The code for the block hash generation can be found here.

 

Transactions Commitment

Transactions are part of the block definition. The block header includes a transactions commitment field. This commitment to the included transaction set is calculated using a Patricia1 tree of the transactions. Each leaf in the tree is a tuple of the form: <txn hash, signature>.

 

Pending Block

Today, StarkNet supports querying the new block before its construction is complete. This feature improves the liveness of the system prior to the decentralization phase, but will probably become obsolete once the system is decentralized, as full nodes will only propagate finalized blocks through the network.

During the construction of the block, as it is accumulating new transactions, the block’s status is PENDING. While PENDING, new transactions are dynamically added to the block. Once the sequencer decides to “close” the block, it becomes ACCEPTED_ON_L2 and its hash is computed.

The following example is a query for the pending Mainnet block:

https://alpha-mainnet.starknet.io/feeder_gateway/get_block?blockNumber=pending

See the CLI section on how to call the gateway with respect to the pending block. 


1  Merkle Patricia tree with a fixed height of 64


<< Technical DocumentationTransaction Structure and Hash >>