jam.state.merkle.merkle module

class jam.state.merkle.merkle.StateMerkle(hash_function: ~jam.types.protocol.crypto.Hash = <function Hash.blake2b>)[source]

Bases: object

State Merklization implementation as defined in D.2

This class implements the Mσ function which transforms a serialized state mapping into a cryptographic commitment using a binary Merkle Patricia trie.

__init__(hash_function: ~jam.types.protocol.crypto.Hash = <function Hash.blake2b>)[source]

Initialize state merkle with optional hash function

_get_bit(key: ByteArray32, index: int) bool[source]

Get bit at index from key.

Parameters:
  • key – 32-byte array to extract bit from

  • index – Position of bit to extract (0-255)

Returns:

Value of bit at specified index

Return type:

bool

_merkelize_recursive(items: List[Tuple[ByteArray32, ByteArray32]], bit_index: int) Tuple[ByteArray32, ByteArray64][source]

Recursive merkelization

merkelize(state_dict: Dict[ByteArray32, ByteArray32]) ByteArray32[source]

Merkelize a state dictionary into a cryptographic commitment (Mσ function)

Parameters:

state_dict – Dictionary mapping state keys to their serialized values

Returns:

The root hash of the resulting Merkle trie

Return type:

bytes

get_nodes() Dict[ByteArray32, ByteArray64][source]

Get all nodes in the trie, useful for proof generation

clear() None[source]

Clear the trie state