Function stateless_validation

Source
pub fn stateless_validation<ChainSpec, E>(
    current_block: Block,
    witness: ExecutionWitness,
    chain_spec: Arc<ChainSpec>,
    evm_config: E,
) -> Result<B256, StatelessValidationError>
where ChainSpec: Send + Sync + EthChainSpec + EthereumHardforks + Debug, E: ConfigureEvm<Primitives = EthPrimitives> + Clone + 'static,
Expand description

Performs stateless validation of a block using the provided witness data.

This function attempts to fully validate a given current_block statelessly, ie without access to a persistent database. It relies entirely on the witness data and ancestor_headers provided alongside the block.

The witness data is validated in the following way:

  1. Ancestor Header Verification: Checks if the ancestor_headers are present, form a contiguous chain back from current_block’s parent, and do not exceed the BLOCKHASH opcode limit using compute_ancestor_hashes. We must have at least one ancestor header, even if the BLOCKHASH opcode is not used because we need the state root of the previous block to verify the pre state reads.

  2. Pre-State Verification: Retrieves the expected pre_state_root from the parent header from ancestor_headers. Verifies the provided ExecutionWitness against this root using verify_execution_witness.

  3. Chain Verification: The code currently does not verify the [EthChainSpec] and expects a higher level function to assert that this is correct by, for example, asserting that it is equal to the Ethereum Mainnet ChainSpec or asserting against the genesis hash that this ChainSpec defines.

High Level Overview of functionality:

  • Verify all state accesses against a trusted pre-state root
  • Put all state accesses into an in-memory database
  • Use the in-memory database to execute the block
  • Validate the output of block execution (e.g. receipts, logs, requests)
  • Compute the post-state root using the state-diff from block execution
  • Check that the post-state root is the state root in the block.

If all steps succeed the function returns Some containing the hash of the validated current_block.