owned this note
owned this note
Published
Linked with GitHub
# Verkle serialization format in SSZ
```python
BandersnatchGroupElement = Bytes32
BandersnatchFieldElement = Bytes32
Stem = Bytes31
MAX_STEMS = 2**16
MAX_COMMITMENTS_PER_STEM = 33 # = 31 for inner nodes + 2 (C1/C2)
VERKLE_WIDTH = 256
IPA_PROOF_DEPTH = 8 # = log2(VERKLE_WIDTH)
class SuffixStateDiff(Container):
suffix: Byte
# Null means not currently present
current_value: Union[Null, Bytes32]
# Null means value not updated
new_value: Union[Null, Bytes32]
class StemStateDiff(Container):
stem: Stem
# Valid only if list is sorted by suffixes
suffix_diffs: List[SuffixStateDiff, VERKLE_WIDTH]
# Valid only if list is sorted by stems
StateDiff = List[StemStateDiff, MAX_STEMS]
class IpaProof(Container):
C_L = Vector[BandersnatchGroupElement, IPA_PROOF_DEPTH]
C_R = Vector[BandersnatchGroupElement, IPA_PROOF_DEPTH]
final_evaluation = BandersnatchFieldElement
class VerkleProof(Container):
other_stems: List[Bytes32, MAX_STEMS]
depth_extension_present: List[uint8, MAX_STEMS]
commitments_by_path: List[BandersnatchGroupElement, MAX_STEMS * MAX_COMMITMENTS_PER_STEM]
D: BandersnatchGroupElement
ipa_proof: IpaProof
class ExecutionWitness(container):
state_diff: StateDiff
verkle_proof: VerkleProof
```
# Alternative version with bitfields instead of unions
```python
BandersnatchGroupElement = Bytes32
BandersnatchFieldElement = Bytes32
Stem = Bytes31
MAX_STEMS = 2**16
MAX_COMMITMENTS_PER_STEM = 33 # = 31 for inner nodes + 2 (C1/C2)
VERKLE_WIDTH = 256
IPA_PROOF_DEPTH = 8 # = log2(VERKLE_WIDTH)
class SuffixStateDiff(Container):
suffix: Byte
# Null means not currently present
current_value: Union[Null, Bytes32]
# Null means value not updated
new_value: Union[Null, Bytes32]
class StemStateDiff(Container):
stem: Stem
# Suffixes can be either a list of bytes or a Bitvector
# List of bytes MUST be used if <=31 suffixes are present.
# The list MUST be sorted starting with the smallest index
suffixes: Union[List[Byte, 31], Bitvector[VERKLE_WIDTH]]
# Each bit in the bitlist represents one of the suffixes in `suffixes`
# 0: The suffix is currently not present/has never been written
# 1: The suffix is present.
current_values_present: Bitlist[VERKLE_WIDTH]
# Values for all the present suffixes
current_values: List[Bytes32, VERKLE_WIDTH]
# Each bit in the bitlist represents one of the suffixes in `suffixes`
# 0: The value for the suffix was not updated
# 1: The value for the suffix was updated
values_updated: Bitlist[VERKLE_WIDTH]
# New values for all suffixes that were updated
new_values: List[Bytes32, VERKLE_WIDTH]
suffix_diffs: List[SuffixStateDiff, VERKLE_WIDTH]
# Valid only if list is sorted by stems
StateDiff = List[StemStateDiff, MAX_STEMS]
class IpaProof(Container):
C_L = Vector[BandersnatchGroupElement, IPA_PROOF_DEPTH]
C_R = Vector[BandersnatchGroupElement, IPA_PROOF_DEPTH]
final_evaluation = BandersnatchFieldElement
class VerkleProof(Container):
other_stems: List[Bytes32, MAX_STEMS]
depth_extension_present: List[uint8, MAX_STEMS]
commitments_by_path: List[BandersnatchGroupElement, MAX_STEMS * MAX_COMMITMENTS_PER_STEM]
D: BandersnatchGroupElement
ipa_proof: IpaProof
class ExecutionWitness(container):
state_diff: StateDiff
verkle_proof: VerkleProof
```