Skip to content

Commit 4645bd7

Browse files
spencer-tbjsign
authored andcommitted
fix(fw): fix tests for witness model.
1 parent ed32c9e commit 4645bd7

File tree

3 files changed

+177
-84
lines changed

3 files changed

+177
-84
lines changed

src/ethereum_test_types/verkle/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
Ethereum Verkle Test Types.
33
"""
44

5-
from .types import StateDiff, VerkleProof, VerkleTree, Witness
5+
from .types import IpaProof, StateDiff, SuffixStateDiff, VerkleProof, VerkleTree, Witness
66

77
__all__ = (
8-
"VerkleTree",
9-
"VerkleProof",
8+
"IpaProof",
109
"StateDiff",
10+
"SuffixStateDiff",
11+
"VerkleProof",
12+
"VerkleTree",
1113
"Witness",
1214
)
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
"""
2+
Test suite for the verkle witness.
3+
"""
4+
5+
import pytest
6+
7+
from ethereum_test_types.verkle import IpaProof, StateDiff, SuffixStateDiff, VerkleProof, Witness
8+
9+
10+
@pytest.fixture
11+
def ipa_proof_data():
12+
"""
13+
Valid verkle proof data.
14+
"""
15+
return {
16+
"cl": [
17+
"0x64b54668075852328d955f6f2336a9a06defa7a8b49718a013a3849212988c5a",
18+
"0x360403c03f7e21825e7ff76be9d5b6067032230c6f91c618298796bfc47a0c11",
19+
"0x064fbaf6f5ff7e7d126cec7665789a0a62f43b68f2e6e8167b7cca82455ab6c7",
20+
"0x3b02cb202ecbb384215e8ad74a9be278fb762f667bade979f8f9a39088918af0",
21+
"0x57fa59af60061d72fc92e4264bad153885c0d06991dc6736e4f4b081326a1cdc",
22+
"0x24dd138cd53f71e075a07fe4532168de6d6061bfe491e7768bcc1d7713bc3bcb",
23+
"0x5da706b290cee4ca425d13c49bbe4da202de79010051d9d3b1c052142fb2e7aa",
24+
"0x238f6f59bc86c521e6fce993f84f4b666fcf25248aee148d898a9e614c3fee13",
25+
],
26+
"cr": [
27+
"0x2aa66cbd97293e3524945cb9660c97a42b71e29718cdda0841fcf18636b57a1b",
28+
"0x73e20d72f31583e21e5bb204d262a737d190d993af234b3cb4b6ecdddc49b61b",
29+
"0x4b8602d3f96d61c74dc19f771c907224b086086e0207fbe2e24d511627102ba4",
30+
"0x446ac6121c2fbc0a4cc656121c160f049a07f0d63307aae23815c1a7ec80cfdf",
31+
"0x6d5a3fbd3356e5df2d93052cc9e402dab4ef5014af9b35fc32977c584e7613bc",
32+
"0x4399dfaf28ee7a4fda83a04ea189201b0f63b897b74f5d5dc51535ff23d48124",
33+
"0x4441409deb28990e3b51235f7ea131a2772237167fe266fbcd0ba19f422364e3",
34+
"0x39966d71a2cf09311940c164ef8e5f37e09a64226535c4aeaf26944f3f5f1b2e",
35+
],
36+
"finalEvaluation": "0x0773f10637892f75d48ef0ed3e421b6e435220d17a99ec2914af567d46c70988",
37+
}
38+
39+
40+
def test_ipa_proof_validation(ipa_proof_data):
41+
"""
42+
Performs basic IPA proof format validation.
43+
"""
44+
ipa_proof = IpaProof(**ipa_proof_data)
45+
assert ipa_proof.cl[0] == 0x64B54668075852328D955F6F2336A9A06DEFA7A8B49718A013A3849212988C5A
46+
assert ipa_proof.cr[0] == 0x2AA66CBD97293E3524945CB9660C97A42B71E29718CDDA0841FCF18636B57A1B
47+
assert ipa_proof.final_evaluation == (
48+
0x0773F10637892F75D48EF0ED3E421B6E435220D17A99EC2914AF567D46C70988
49+
)
50+
51+
52+
@pytest.fixture
53+
def verkle_proof_data(ipa_proof_data):
54+
"""
55+
Valid verkle proof data.
56+
"""
57+
return {
58+
"otherStems": [
59+
"0x5b5fdfedd6a0e932da408ac7d772a36513d1eee9b9926e52620c43a433aad7",
60+
"0x5b5fdfedd6a0e932da408ac7d772a36513d1eee9b9926e52620c43a433aad7",
61+
],
62+
"depthExtensionPresent": "0x0a",
63+
"commitmentsByPath": [
64+
"0x73bd3673ee58f638feb0e21ba8b0cfeadbc9b280716915338b4f46556aa68226",
65+
"0x12fe9ad68c17edfed0861a1b19f0bc178836f56abf3514742cb2d4645b35ba92",
66+
],
67+
"d": "0x392ac76ac887f79c7c6fd5fd26ec9cfd44664a69aa5075477cbdfdcb522d2a7a",
68+
"ipaProof": ipa_proof_data,
69+
}
70+
71+
72+
def test_verkle_proof_validation(verkle_proof_data):
73+
"""
74+
Performs basic verkle proof format validation.
75+
"""
76+
verkle_proof = VerkleProof(**verkle_proof_data)
77+
assert verkle_proof.other_stems[0] == (
78+
0x5B5FDFEDD6A0E932DA408AC7D772A36513D1EEE9B9926E52620C43A433AAD7
79+
)
80+
assert verkle_proof.depth_extension_present == 0x0A
81+
assert (
82+
verkle_proof.commitments_by_path[0]
83+
== 0x73BD3673EE58F638FEB0E21BA8B0CFEADBC9B280716915338B4F46556AA68226
84+
)
85+
assert (
86+
verkle_proof.commitments_by_path[1]
87+
== 0x12FE9AD68C17EDFED0861A1B19F0BC178836F56ABF3514742CB2D4645B35BA92
88+
)
89+
assert verkle_proof.d == 0x392AC76AC887F79C7C6FD5FD26EC9CFD44664A69AA5075477CBDFDCB522D2A7A
90+
assert verkle_proof.ipa_proof.final_evaluation == (
91+
0x0773F10637892F75D48EF0ED3E421B6E435220D17A99EC2914AF567D46C70988
92+
)
93+
94+
95+
@pytest.fixture
96+
def suffix_diff_data():
97+
"""
98+
Valid verkle suffix diff data.
99+
"""
100+
return {
101+
"suffix": 66,
102+
"currentValue": "0x647ed3c87a4f764421ea2f5bfc73195812f6b7dd15ac2b8d295730c1dede1edf",
103+
"newValue": None,
104+
}
105+
106+
107+
def test_suffix_diff_validation(suffix_diff_data):
108+
"""
109+
Performs basic suffix diff format validation.
110+
"""
111+
suffix_diff = SuffixStateDiff(**suffix_diff_data)
112+
assert suffix_diff.suffix == 66
113+
assert suffix_diff.current_value == (
114+
0x647ED3C87A4F764421EA2F5BFC73195812F6B7DD15AC2B8D295730C1DEDE1EDF
115+
)
116+
assert suffix_diff.new_value is None
117+
118+
119+
@pytest.fixture
120+
def state_diff_data(suffix_diff_data):
121+
"""
122+
Valid verkle state diff data.
123+
"""
124+
return [
125+
{
126+
"stem": "0x5b5fdfedd6a0e932da408ac7d772a36513d1eee9b9926e52620c43a433aad7",
127+
"suffixDiffs": [suffix_diff_data],
128+
}
129+
]
130+
131+
132+
def test_state_diff_validation(state_diff_data):
133+
"""
134+
Performs basic state diff format validation.
135+
"""
136+
state_diff = StateDiff(state_diff_data)
137+
assert state_diff.root[0].stem == (
138+
0x5B5FDFEDD6A0E932DA408AC7D772A36513D1EEE9B9926E52620C43A433AAD7
139+
)
140+
assert state_diff.root[0].suffix_diffs[0].suffix == 66
141+
assert state_diff.root[0].suffix_diffs[0].current_value == (
142+
0x647ED3C87A4F764421EA2F5BFC73195812F6B7DD15AC2B8D295730C1DEDE1EDF
143+
)
144+
assert state_diff.root[0].suffix_diffs[0].new_value is None
145+
146+
147+
@pytest.fixture
148+
def witness_data(state_diff_data, verkle_proof_data):
149+
"""
150+
Valid verkle witness data.
151+
"""
152+
return {
153+
"stateDiff": state_diff_data,
154+
"verkleProof": verkle_proof_data,
155+
}
156+
157+
158+
def test_witness_validation(witness_data):
159+
"""
160+
Performs basic witness format validation.
161+
"""
162+
witness = Witness(**witness_data)
163+
assert witness.verkle_proof.depth_extension_present == 0x0A
164+
assert (
165+
witness.verkle_proof.commitments_by_path[0]
166+
== 0x73BD3673EE58F638FEB0E21BA8B0CFEADBC9B280716915338B4F46556AA68226
167+
)
168+
assert (
169+
witness.state_diff.root[0].suffix_diffs[0].current_value
170+
== 0x647ED3C87A4F764421EA2F5BFC73195812F6B7DD15AC2B8D295730C1DEDE1EDF
171+
)
172+
assert witness.state_diff.root[0].suffix_diffs[0].new_value is None

src/ethereum_test_types/verkle/test_witness.py

Lines changed: 0 additions & 81 deletions
This file was deleted.

0 commit comments

Comments
 (0)