Skip to content

Commit 4f60f7c

Browse files
kevaundrayacolytec3gabrocheleau
authored
chore: Add method to verify the prestate in the execution witness (#44)
* local build won't compile without adding babel-cli * update package-lock.json (mostly babel-cli) * update Cargo.toml to point to the latest rust-verkle commit * add code to expose verifyExecutionWitnessPrestate * add Gabriels simple test case * remove babel-cli * add brief comment * update test data --------- Co-authored-by: acolytec3 <[email protected]> Co-authored-by: Gabriel Rocheleau <[email protected]>
1 parent 1070659 commit 4f60f7c

File tree

8 files changed

+2802
-5
lines changed

8 files changed

+2802
-5
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,4 @@
7373
"dependencies": {
7474
"@scure/base": "^1.1.5"
7575
}
76-
}
76+
}

src.rs/src/verkle_ffi_api.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,15 @@ pub fn zero_commitment() -> Uint8Array {
205205
bytes_to_js_value(ffi_interface::ZERO_POINT).into()
206206
}
207207

208+
/// Verifies an execution witness' pre-state values and proof against a prestate root
209+
/// At a high level, this method verifies that the reads in the pre-state are consistent with the
210+
/// root.
211+
#[allow(deprecated)]
212+
#[wasm_bindgen(js_name = "verifyExecutionWitnessPreState")]
213+
pub fn verify_execution_witness_prestate(prestate_root: &str, execution_witness: &str) -> bool {
214+
ffi_interface::verify_execution_witness(prestate_root, execution_witness)
215+
}
216+
208217
/// Converts a JsValue to an array of size `N` or return an JsValue object representing an
209218
/// error
210219
fn js_value_to_bytes<const N: usize>(value: JsValue) -> Result<[u8; N], JsError> {

src.ts/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
getTreeKeyHash as getTreeKeyHashBase,
55
updateCommitment as updateCommitmentBase,
66
zeroCommitment as zeroCommitmentBase,
7+
verifyExecutionWitnessPreState as verifyExecutionWitnessPreStateBase,
78
} from './verkleFFIBindings/index.js'
89
import { Context as VerkleFFI } from './wasm/rust_verkle_wasm.js'
910

@@ -26,13 +27,17 @@ export const loadVerkleCrypto = async (): Promise<VerkleCrypto> => {
2627
): Commitment =>
2728
updateCommitmentBase(verkleFFI, commitment, commitmentIndex, oldScalarValue, newScalarValue)
2829

30+
const verifyExecutionWitnessPreState = (prestateRoot: string, execution_witness_json: string): boolean =>
31+
verifyExecutionWitnessPreStateBase(prestateRoot, execution_witness_json)
32+
2933
const zeroCommitment = zeroCommitmentBase()
3034

3135
return {
3236
getTreeKey,
3337
getTreeKeyHash,
3438
updateCommitment,
3539
zeroCommitment,
40+
verifyExecutionWitnessPreState
3641
}
3742
}
3843

@@ -46,6 +51,7 @@ export interface VerkleCrypto {
4651
newScalarValue: Uint8Array
4752
) => Commitment
4853
zeroCommitment: Uint8Array
54+
verifyExecutionWitnessPreState: (prestateRoot: string, execution_witness_json: string) => boolean
4955
}
5056

5157
// This is a 32 byte serialized field element
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
{
2+
"header": {
3+
"blockNumber": "0x48",
4+
"parentHash": "0xf3ecb69d884749d580a08fed05e05ee3967dffc66844715c0d6640c853962d3b",
5+
"coinbase": "0xf97e180c050e5ab072211ad2c213eb5aee4df134",
6+
"stateRoot": "0x18d1dfcc6ccc6f34d14af48a865895bf34bde7f3571d9ba24a4b98122841048c",
7+
"receiptsRoot": "0xd95b673818fa493deec414e01e610d97ee287c9421c8eff4102b1647c1a184e4",
8+
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
9+
"gasLimit": "0x1993dd7",
10+
"gasUsed": "0xa410",
11+
"timestamp": "0x6619131c",
12+
"extraData": "0xd983010c01846765746889676f312e32302e3134856c696e7578",
13+
"baseFeePerGas": "0x1737d",
14+
"blockHash": "0xa8a30b41c2f4704492437c072dda9bcc2cdff8f72301abf756163385e72b9e98",
15+
"prevRandao": "0x25284f9fdce33fe2989a89d36beaef23ca4379230bdbc8e1b7e462bc1762832c",
16+
"transactionsTrie": "0xe32d8329353256c4f60f7f029b8c26eb0638c9a32bfdfd37ad224b140e8c3b9f"
17+
},
18+
"transactions": [
19+
"0xf86d0c843b9c728e82f618946177843db3138ae69679a54b95cf345ed759450d87b5303ad38b80008083021e7ba0d8b5a41fb5586ba0324acd075263efebfab044b86deba9aaffec8d137ec7c514a066725dd2ed9457e15f1bb5fd763b65f32febfaf55254cbd792096498538f8cf2",
20+
"0xf86d0d843b9c728e82f61894687704db07e902e9a8b3754031d168d46e3d586e87b5303ad38b80008083021e7ba08ff0849279b1d455cacb5593eeafbd005e77464f1c3f960ff2b543beb8f05218a02ec4a3c2271bee8d358cedc2ef00f950b00e70aed1a415442414d90d8ba58d34"
21+
],
22+
"withdrawals": [],
23+
"executionWitness": {
24+
"stateDiff": [
25+
{
26+
"stem": "0x242271cf1aaa13ede9bb0a1550d6f181c6135afb92be8270221f03cc8a721e",
27+
"suffixDiffs": [
28+
{
29+
"suffix": 0,
30+
"currentValue": "0x0000000000000000000000000000000000000000000000000000000000000000",
31+
"newValue": null
32+
},
33+
{
34+
"suffix": 1,
35+
"currentValue": "0x5fd4526134640504000000000000000000000000000000000000000000000000",
36+
"newValue": "0x5f54de346f94ba04000000000000000000000000000000000000000000000000"
37+
},
38+
{
39+
"suffix": 2,
40+
"currentValue": "0x2c01000000000000000000000000000000000000000000000000000000000000",
41+
"newValue": null
42+
},
43+
{
44+
"suffix": 3,
45+
"currentValue": "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470",
46+
"newValue": null
47+
},
48+
{
49+
"suffix": 4,
50+
"currentValue": null,
51+
"newValue": null
52+
}
53+
]
54+
},
55+
{
56+
"stem": "0x96ed99018bcdb2439b664559f70a95ec161cfc6ef2b8e1b42ff61733e87f8e",
57+
"suffixDiffs": [
58+
{
59+
"suffix": 0,
60+
"currentValue": "0x0000000000000000000000000000000000000000000000000000000000000000",
61+
"newValue": null
62+
},
63+
{
64+
"suffix": 1,
65+
"currentValue": "0xebc17af0f95f7800000000000000000000000000000000000000000000000000",
66+
"newValue": "0xfb9691f52c867800000000000000000000000000000000000000000000000000"
67+
},
68+
{
69+
"suffix": 2,
70+
"currentValue": "0x0000000000000000000000000000000000000000000000000000000000000000",
71+
"newValue": null
72+
},
73+
{
74+
"suffix": 3,
75+
"currentValue": "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470",
76+
"newValue": null
77+
},
78+
{
79+
"suffix": 4,
80+
"currentValue": null,
81+
"newValue": null
82+
}
83+
]
84+
},
85+
{
86+
"stem": "0xab8fbede899caa6a95ece66789421c7777983761db3cfb33b5e47ba10f413b",
87+
"suffixDiffs": [
88+
{
89+
"suffix": 71,
90+
"currentValue": null,
91+
"newValue": "0xf3ecb69d884749d580a08fed05e05ee3967dffc66844715c0d6640c853962d3b"
92+
}
93+
]
94+
},
95+
{
96+
"stem": "0xd5f60a22f578b01222216496e3322676c2bd1a27f4814fff924ff5795b9dae",
97+
"suffixDiffs": [
98+
{
99+
"suffix": 0,
100+
"currentValue": "0x0000000000000000000000000000000000000000000000000000000000000000",
101+
"newValue": null
102+
},
103+
{
104+
"suffix": 1,
105+
"currentValue": "0x50cbdee5305851973c2e3b030000000000000000000000000000000000000000",
106+
"newValue": "0x70aa9d4b87d1e6953c2e3b030000000000000000000000000000000000000000"
107+
},
108+
{
109+
"suffix": 2,
110+
"currentValue": "0x0c00000000000000000000000000000000000000000000000000000000000000",
111+
"newValue": "0x0e00000000000000000000000000000000000000000000000000000000000000"
112+
},
113+
{
114+
"suffix": 3,
115+
"currentValue": "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470",
116+
"newValue": null
117+
},
118+
{
119+
"suffix": 4,
120+
"currentValue": null,
121+
"newValue": null
122+
}
123+
]
124+
},
125+
{
126+
"stem": "0xdf67dea9181141d6255ac05c7ada5a590fb30a375023f16c31223f067319e3",
127+
"suffixDiffs": [
128+
{
129+
"suffix": 0,
130+
"currentValue": "0x0000000000000000000000000000000000000000000000000000000000000000",
131+
"newValue": null
132+
},
133+
{
134+
"suffix": 1,
135+
"currentValue": "0x923672e5275a0104000000000000000000000000000000000000000000000000",
136+
"newValue": "0x92b6fdb8628ab604000000000000000000000000000000000000000000000000"
137+
},
138+
{
139+
"suffix": 2,
140+
"currentValue": "0x2c01000000000000000000000000000000000000000000000000000000000000",
141+
"newValue": null
142+
},
143+
{
144+
"suffix": 3,
145+
"currentValue": "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470",
146+
"newValue": null
147+
},
148+
{
149+
"suffix": 4,
150+
"currentValue": null,
151+
"newValue": null
152+
}
153+
]
154+
}
155+
],
156+
"verkleProof": {
157+
"otherStems": [],
158+
"depthExtensionPresent": "0x0a120a1212",
159+
"commitmentsByPath": [
160+
"0x12aea8e64b9762111a3b905875add74eab373159bfe597ea781ca8cb50b3d909",
161+
"0x6f49fa46e120d831d7cf73129d3a30cde094382ee39c78bfdef3b4843951ec74",
162+
"0x59d23e83ab112656855502a69724bd03f2922abb389e11e6ad0df408afa02c9b",
163+
"0x29297ab7e82f02e368f2d7c8719ff26ffffbcdf9c28ca636849189648139eb96",
164+
"0x3f36c433053f65ccc3c6e522db509bd62a6b019cdf0dea5f6228e76763bb84fa",
165+
"0x599eead7a274c667c6ac8c5c42e9a8a0ffb47e6d2e75818e21ff304e9273f08a",
166+
"0x0e029761fcf20de22f3f3e5cfff0b20e7b2510d81422ba70a92608b0672aac21",
167+
"0x6d112adf802bf565a2486bbe9511a53df41fad3b643025b4534d0cfc490a3070",
168+
"0x1c47dd00f5ecb06a3fa720f1dc767959acf418fdb5ed841b68a4017e426d2864",
169+
"0x105381b6bc5ce78b4b8bce6f4461d9669fc298f1ecab2f7ffcca3c82fa7e052e",
170+
"0x72e1694b8989f651c3e0b8ffc0673259442cff8aebadb93173a48d78cb658ef1",
171+
"0x3ec5a18b934ee02eb8223aea330a5689dc7714b441e29d7dccc0e1e2b02d97ff",
172+
"0x6ff5a48312a2d4e85ea7f3daf645cc021abff01ecf68ab414abff1dc35baed4a"
173+
],
174+
"d": "0x4cfe43b3414734150b9802c65151e75d5d92fc320ce2140270fc16417b7c323c",
175+
"ipaProof": {
176+
"cl": [
177+
"0x36a46804a95f56c4a7158b330b1c5eb84ac656c4feaee52ea7851fac41e42d42",
178+
"0x3ad84841a0cd19cd35b1797ddf99fba8138b0e4b5abf427951f8f88d47c6e7c3",
179+
"0x4b92628640181c77e9d1f6738d628dbf98fe092c37d83b4c90c275753d90dcb5",
180+
"0x0d1ad8cf83f9fbaa6de06b11c126e57d6a2a2cddec5b428607751b88f5b2bc1b",
181+
"0x36d385c06fc8ece1ad2a19986255de3d2f30bb6eff51a77b8d432087b3abb2ad",
182+
"0x52f0b473975a14a772a95ff8fa48c760f7dd22782c79172ef41caca3aacbb53b",
183+
"0x34a922c9f680409ccfd4b99986f6ffd612552bdfce9c2f918588528fa9f820d7",
184+
"0x0163b071289cbf08855d04cef13d0a535d1118435453e377425ce2065366c312"
185+
],
186+
"cr": [
187+
"0x47c3fbeeaa52d109f66593ce906c5ccf68b7a0cdd8990e91c39d6b1870bd8292",
188+
"0x1abc2aea76b3c95e991183a80347ff95b97b31401cad3e869a5f751bebd9ca4a",
189+
"0x257b8a32afa91bdc49594a15dbcbe9e7559b7f428ad884dfb4bad181363b1d35",
190+
"0x2009c886c328a936eba8602afedbbe0f4d205dc57166f4ab9f8dd23e3297abef",
191+
"0x17543c43190105af91150b93b30e9a93a14ed3572d8ee270b34145a70cd18c64",
192+
"0x6f55003eb26376a41ec43194b52c483c58dbdf2c4aef0056a457440e67455379",
193+
"0x7002d5427dcc3ce7b1f5fe03284b8d9d2e2ea4f2fe05383fe5d7a755dcd13485",
194+
"0x3d3d0f44ff77c53c58155f514df27edbdbb9585f7666038f478209997cf1ffb8"
195+
],
196+
"finalEvaluation": "0x10c46a855d6be4f7e48f287ce25c219c0f469cc00d83888d44efbd1342da1d2b"
197+
}
198+
}
199+
}
200+
}

0 commit comments

Comments
 (0)