1
+ import { concatBytes } from '@ethereumjs/util'
2
+
1
3
import { Context as VerkleFFI } from '../wasm/rust_verkle_wasm.js'
2
4
3
5
// This is equal to 2n + 256n * 64n.
@@ -114,10 +116,65 @@ export function updateCommitment(
114
116
return verkleFFI . updateCommitment ( commitment , commitmentIndex , oldScalarValue , newScalarValue )
115
117
}
116
118
117
- export function createProof ( verkleFFI : VerkleFFI , bytes : Uint8Array ) : Uint8Array {
118
- return verkleFFI . createProof ( bytes )
119
+ export function createProof ( verkleFFI : VerkleFFI , proverInputs : ProverInput [ ] ) : Uint8Array {
120
+ const serializedProofInputs = serializedProverInputs ( proverInputs )
121
+ return verkleFFI . createProof ( serializedProofInputs )
122
+ }
123
+
124
+ export function verifyProof (
125
+ verkleFFI : VerkleFFI ,
126
+ proof : Uint8Array ,
127
+ verifierInputs : VerifierInput [ ] ,
128
+ ) : boolean {
129
+ const serializedVerifierInput = serializeVerifierInputs ( proof , verifierInputs )
130
+ return verkleFFI . verifyProof ( serializedVerifierInput )
131
+ }
132
+
133
+ export interface ProverInput {
134
+ // Commitment to the vector we want to create a proof for
135
+ serializedCommitment : Uint8Array
136
+ // The vector that we want to make proofs over
137
+ vector : Uint8Array [ ]
138
+ // The indices that we want to prove exist in the vector
139
+ indices : number [ ]
119
140
}
120
141
121
- export function verifyProof ( verkleFFI : VerkleFFI , proof : Uint8Array ) : boolean {
122
- return verkleFFI . verifyProof ( proof )
123
- }
142
+ function serializedProverInputs ( proofInputs : ProverInput [ ] ) : Uint8Array {
143
+ const serializedProverInputs = proofInputs . flatMap ( ( { serializedCommitment, vector, indices } ) =>
144
+ indices . flatMap ( ( index ) => [
145
+ serializedCommitment ,
146
+ ...vector ,
147
+ new Uint8Array ( [ index ] ) ,
148
+ vector [ index ] ,
149
+ ] ) ,
150
+ )
151
+
152
+ return concatBytes ( ...serializedProverInputs )
153
+ }
154
+
155
+ export interface VerifierInput {
156
+ // A commitment to the vector that we want to verify
157
+ // proofs over.
158
+ serializedCommitment : Uint8Array
159
+ // A tuple of index and values that we want to verify about the
160
+ // committed vector.
161
+ //
162
+ // ie (index_i, value_i) will verify that the value of the committed
163
+ // vector at index `index_i` was `value_i`
164
+ indexValuePairs : Array < { index : number ; value : Uint8Array } >
165
+ }
166
+
167
+ function serializeVerifierInputs ( proof : Uint8Array , verifierInputs : VerifierInput [ ] ) : Uint8Array {
168
+ const serializedVerifierInputs = [
169
+ proof ,
170
+ ...verifierInputs . flatMap ( ( { serializedCommitment, indexValuePairs } ) =>
171
+ indexValuePairs . flatMap ( ( { index, value } ) => [
172
+ serializedCommitment ,
173
+ new Uint8Array ( [ index ] ) ,
174
+ value ,
175
+ ] ) ,
176
+ ) ,
177
+ ]
178
+
179
+ return concatBytes ( ...serializedVerifierInputs )
180
+ }
0 commit comments