@aztec-labs/ivc-integration 6.0.0-nightly.20260829
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/artifacts/app_creator.d.json.ts +3 -0
- package/artifacts/app_creator.json +210 -0
- package/artifacts/app_reader.d.json.ts +3 -0
- package/artifacts/app_reader.json +210 -0
- package/artifacts/mock_hiding.d.json.ts +3 -0
- package/artifacts/mock_hiding.json +256 -0
- package/artifacts/mock_private_kernel_init.d.json.ts +3 -0
- package/artifacts/mock_private_kernel_init.json +783 -0
- package/artifacts/mock_private_kernel_inner.d.json.ts +3 -0
- package/artifacts/mock_private_kernel_inner.json +833 -0
- package/artifacts/mock_private_kernel_reset.d.json.ts +3 -0
- package/artifacts/mock_private_kernel_reset.json +342 -0
- package/artifacts/mock_private_kernel_tail.d.json.ts +3 -0
- package/artifacts/mock_private_kernel_tail.json +306 -0
- package/artifacts/mock_rollup_root.d.json.ts +3 -0
- package/artifacts/mock_rollup_root.json +331 -0
- package/artifacts/mock_rollup_tx_base_private.d.json.ts +3 -0
- package/artifacts/mock_rollup_tx_base_private.json +322 -0
- package/artifacts/mock_rollup_tx_base_public.d.json.ts +3 -0
- package/artifacts/mock_rollup_tx_base_public.json +1484 -0
- package/artifacts/mock_rollup_tx_merge.d.json.ts +3 -0
- package/artifacts/mock_rollup_tx_merge.json +387 -0
- package/dest/batch_verifier_test_helpers.d.ts +14 -0
- package/dest/batch_verifier_test_helpers.d.ts.map +1 -0
- package/dest/batch_verifier_test_helpers.js +19 -0
- package/dest/bb_working_directory.d.ts +2 -0
- package/dest/bb_working_directory.d.ts.map +1 -0
- package/dest/bb_working_directory.js +10 -0
- package/dest/index.d.ts +2 -0
- package/dest/index.d.ts.map +1 -0
- package/dest/index.js +1 -0
- package/dest/prove_native.d.ts +15 -0
- package/dest/prove_native.d.ts.map +1 -0
- package/dest/prove_native.js +188 -0
- package/dest/scripts/generate_declaration_files.d.ts +2 -0
- package/dest/scripts/generate_declaration_files.d.ts.map +1 -0
- package/dest/scripts/generate_declaration_files.js +21 -0
- package/dest/scripts/generate_ts_from_abi.d.ts +2 -0
- package/dest/scripts/generate_ts_from_abi.d.ts.map +1 -0
- package/dest/scripts/generate_ts_from_abi.js +49 -0
- package/dest/serve.d.ts +2 -0
- package/dest/serve.d.ts.map +1 -0
- package/dest/serve.js +79 -0
- package/dest/types/index.d.ts +227 -0
- package/dest/types/index.d.ts.map +1 -0
- package/dest/types/index.js +102 -0
- package/dest/witgen.d.ts +87 -0
- package/dest/witgen.d.ts.map +1 -0
- package/dest/witgen.js +328 -0
- package/package.json +112 -0
- package/src/batch_verifier_test_helpers.ts +32 -0
- package/src/bb_working_directory.ts +9 -0
- package/src/index.html +9 -0
- package/src/index.ts +1 -0
- package/src/prove_native.ts +171 -0
- package/src/scripts/generate_declaration_files.ts +24 -0
- package/src/scripts/generate_ts_from_abi.ts +57 -0
- package/src/serve.ts +128 -0
- package/src/types/index.ts +349 -0
- package/src/witgen.ts +444 -0
package/src/witgen.ts
ADDED
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
import { CircuitKind } from '@aztec/bb.js';
|
|
2
|
+
import { type ForeignCallInput, type ForeignCallOutput, Noir } from '@aztec/noir-noir_js';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
AVM_CIRCUIT_PUBLIC_INPUTS_LENGTH,
|
|
6
|
+
AVM_V2_PROOF_LENGTH_IN_FIELDS,
|
|
7
|
+
MEGA_APP_VK_LENGTH_IN_FIELDS,
|
|
8
|
+
MEGA_KERNEL_VK_LENGTH_IN_FIELDS,
|
|
9
|
+
} from '@aztec-labs/constants';
|
|
10
|
+
import { padArrayEnd } from '@aztec-labs/foundation/collection';
|
|
11
|
+
import { Fr } from '@aztec-labs/foundation/curves/bn254';
|
|
12
|
+
import { applyStringFormatting, createLogger } from '@aztec-labs/foundation/log';
|
|
13
|
+
import type { AvmCircuitPublicInputs } from '@aztec-labs/stdlib/avm';
|
|
14
|
+
import type { RecursiveProof } from '@aztec-labs/stdlib/proofs';
|
|
15
|
+
import { VerificationKeyAsFields } from '@aztec-labs/stdlib/vks';
|
|
16
|
+
import { strict as assert } from 'assert';
|
|
17
|
+
import { ungzip } from 'pako';
|
|
18
|
+
|
|
19
|
+
import MockAppCreatorCircuit from '../artifacts/app_creator.json' with { type: 'json' };
|
|
20
|
+
import MockAppReaderCircuit from '../artifacts/app_reader.json' with { type: 'json' };
|
|
21
|
+
import MockHidingCircuit from '../artifacts/mock_hiding.json' with { type: 'json' };
|
|
22
|
+
import MockPrivateKernelInitCircuit from '../artifacts/mock_private_kernel_init.json' with { type: 'json' };
|
|
23
|
+
import MockPrivateKernelInnerCircuit from '../artifacts/mock_private_kernel_inner.json' with { type: 'json' };
|
|
24
|
+
import MockPrivateKernelResetCircuit from '../artifacts/mock_private_kernel_reset.json' with { type: 'json' };
|
|
25
|
+
import MockPrivateKernelTailCircuit from '../artifacts/mock_private_kernel_tail.json' with { type: 'json' };
|
|
26
|
+
import MockRollupRootCircuit from '../artifacts/mock_rollup_root.json' with { type: 'json' };
|
|
27
|
+
import MockRollupTxBasePrivateCircuit from '../artifacts/mock_rollup_tx_base_private.json' with { type: 'json' };
|
|
28
|
+
import MockRollupTxBasePublicCircuit from '../artifacts/mock_rollup_tx_base_public.json' with { type: 'json' };
|
|
29
|
+
import MockRollupTxMergeCircuit from '../artifacts/mock_rollup_tx_merge.json' with { type: 'json' };
|
|
30
|
+
import type {
|
|
31
|
+
AppCreatorInputType,
|
|
32
|
+
AppPublicInputs,
|
|
33
|
+
AppReaderInputType,
|
|
34
|
+
FixedLengthArray,
|
|
35
|
+
KernelPublicInputs,
|
|
36
|
+
MockHidingInputType,
|
|
37
|
+
MockPrivateKernelInitInputType,
|
|
38
|
+
MockPrivateKernelInnerInputType,
|
|
39
|
+
MockPrivateKernelResetInputType,
|
|
40
|
+
MockPrivateKernelTailInputType,
|
|
41
|
+
MockRollupRootInputType,
|
|
42
|
+
MockRollupTxBasePrivateInputType,
|
|
43
|
+
MockRollupTxBasePublicInputType,
|
|
44
|
+
MockRollupTxMergeInputType,
|
|
45
|
+
PrivateKernelPublicInputs,
|
|
46
|
+
RollupPublicInputs,
|
|
47
|
+
VerificationKey,
|
|
48
|
+
} from './types/index.js';
|
|
49
|
+
|
|
50
|
+
// Helper to extract VK from circuit artifact
|
|
51
|
+
function extractVkFromCircuit(circuit: any) {
|
|
52
|
+
return {
|
|
53
|
+
keyAsBytes: circuit.verificationKey.bytes,
|
|
54
|
+
keyAsFields: circuit.verificationKey.fields,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Extract VKs from circuit artifacts
|
|
59
|
+
const MockAppCreatorVk = extractVkFromCircuit(MockAppCreatorCircuit);
|
|
60
|
+
const MockAppReaderVk = extractVkFromCircuit(MockAppReaderCircuit);
|
|
61
|
+
const MockPrivateKernelInitVk = extractVkFromCircuit(MockPrivateKernelInitCircuit);
|
|
62
|
+
const MockPrivateKernelInnerVk = extractVkFromCircuit(MockPrivateKernelInnerCircuit);
|
|
63
|
+
const MockPrivateKernelResetVk = extractVkFromCircuit(MockPrivateKernelResetCircuit);
|
|
64
|
+
const MockPrivateKernelTailVk = extractVkFromCircuit(MockPrivateKernelTailCircuit);
|
|
65
|
+
const MockHidingVk = extractVkFromCircuit(MockHidingCircuit);
|
|
66
|
+
const MockRollupTxBasePrivateVk = extractVkFromCircuit(MockRollupTxBasePrivateCircuit);
|
|
67
|
+
const MockRollupTxBasePublicVk = extractVkFromCircuit(MockRollupTxBasePublicCircuit);
|
|
68
|
+
const MockRollupTxMergeVk = extractVkFromCircuit(MockRollupTxMergeCircuit);
|
|
69
|
+
const MockRollupRootVk = extractVkFromCircuit(MockRollupRootCircuit);
|
|
70
|
+
|
|
71
|
+
// Re export the circuit jsons
|
|
72
|
+
export {
|
|
73
|
+
MockAppCreatorCircuit,
|
|
74
|
+
MockAppCreatorVk,
|
|
75
|
+
MockAppReaderCircuit,
|
|
76
|
+
MockAppReaderVk,
|
|
77
|
+
MockPrivateKernelInitCircuit,
|
|
78
|
+
MockPrivateKernelInitVk,
|
|
79
|
+
MockPrivateKernelInnerCircuit,
|
|
80
|
+
MockPrivateKernelInnerVk,
|
|
81
|
+
MockPrivateKernelResetCircuit,
|
|
82
|
+
MockPrivateKernelResetVk,
|
|
83
|
+
MockPrivateKernelTailCircuit,
|
|
84
|
+
MockHidingCircuit,
|
|
85
|
+
MockPrivateKernelTailVk,
|
|
86
|
+
MockRollupTxBasePrivateCircuit,
|
|
87
|
+
MockRollupTxBasePrivateVk,
|
|
88
|
+
MockRollupTxBasePublicCircuit,
|
|
89
|
+
MockRollupTxBasePublicVk,
|
|
90
|
+
MockRollupTxMergeCircuit,
|
|
91
|
+
MockRollupTxMergeVk,
|
|
92
|
+
MockRollupRootCircuit,
|
|
93
|
+
MockRollupRootVk,
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/* eslint-disable camelcase */
|
|
97
|
+
|
|
98
|
+
const log = createLogger('aztec:ivc-test');
|
|
99
|
+
|
|
100
|
+
export async function getVkAsFields<N extends number>(
|
|
101
|
+
{ keyAsFields }: { keyAsFields: string[] },
|
|
102
|
+
length: N,
|
|
103
|
+
): Promise<VerificationKey<N>> {
|
|
104
|
+
const key = keyAsFields.map(f => Fr.fromString(f));
|
|
105
|
+
const vk = await VerificationKeyAsFields.fromKey(key);
|
|
106
|
+
return mapVerificationKeyToNoir(vk, length);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export const MOCK_MAX_COMMITMENTS_PER_TX = 4;
|
|
110
|
+
|
|
111
|
+
function foreignCallHandler(name: string, args: ForeignCallInput[]): Promise<ForeignCallOutput[]> {
|
|
112
|
+
if (name === 'debugLog') {
|
|
113
|
+
assert(args.length === 3, 'expected 3 arguments for debugLog: msg, fields_length, fields');
|
|
114
|
+
const [msgRaw, _ignoredFieldsSize, fields] = args;
|
|
115
|
+
const msg: string = msgRaw.map(acvmField => String.fromCharCode(Fr.fromString(acvmField).toNumber())).join('');
|
|
116
|
+
const fieldsFr: Fr[] = fields.map((field: string) => Fr.fromString(field));
|
|
117
|
+
log.verbose('debug_log ' + applyStringFormatting(msg, fieldsFr));
|
|
118
|
+
} else {
|
|
119
|
+
throw new Error('Unexpected foreign call');
|
|
120
|
+
}
|
|
121
|
+
return Promise.resolve([]);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export interface WitnessGenResult<PublicInputsType> {
|
|
125
|
+
witness: Uint8Array;
|
|
126
|
+
publicInputs: PublicInputsType;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export async function witnessGenCreatorAppMockCircuit(
|
|
130
|
+
args: AppCreatorInputType,
|
|
131
|
+
): Promise<WitnessGenResult<AppPublicInputs>> {
|
|
132
|
+
const program = new Noir(MockAppCreatorCircuit);
|
|
133
|
+
const { witness, returnValue } = await program.execute(args, foreignCallHandler);
|
|
134
|
+
return {
|
|
135
|
+
witness,
|
|
136
|
+
publicInputs: returnValue as AppPublicInputs,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export async function witnessGenReaderAppMockCircuit(
|
|
141
|
+
args: AppReaderInputType,
|
|
142
|
+
): Promise<WitnessGenResult<AppPublicInputs>> {
|
|
143
|
+
const program = new Noir(MockAppReaderCircuit);
|
|
144
|
+
const { witness, returnValue } = await program.execute(args, foreignCallHandler);
|
|
145
|
+
return {
|
|
146
|
+
witness,
|
|
147
|
+
publicInputs: returnValue as AppPublicInputs,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export async function witnessGenMockPrivateKernelInitCircuit(
|
|
152
|
+
args: MockPrivateKernelInitInputType,
|
|
153
|
+
): Promise<WitnessGenResult<PrivateKernelPublicInputs>> {
|
|
154
|
+
const program = new Noir(MockPrivateKernelInitCircuit);
|
|
155
|
+
const { witness, returnValue } = await program.execute(args, foreignCallHandler);
|
|
156
|
+
return {
|
|
157
|
+
witness,
|
|
158
|
+
publicInputs: returnValue as PrivateKernelPublicInputs,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export async function witnessGenMockPrivateKernelInnerCircuit(
|
|
163
|
+
args: MockPrivateKernelInnerInputType,
|
|
164
|
+
): Promise<WitnessGenResult<PrivateKernelPublicInputs>> {
|
|
165
|
+
const program = new Noir(MockPrivateKernelInnerCircuit);
|
|
166
|
+
const { witness, returnValue } = await program.execute(args, foreignCallHandler);
|
|
167
|
+
return {
|
|
168
|
+
witness,
|
|
169
|
+
publicInputs: returnValue as PrivateKernelPublicInputs,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export async function witnessGenMockPrivateKernelResetCircuit(
|
|
174
|
+
args: MockPrivateKernelResetInputType,
|
|
175
|
+
): Promise<WitnessGenResult<PrivateKernelPublicInputs>> {
|
|
176
|
+
const program = new Noir(MockPrivateKernelResetCircuit);
|
|
177
|
+
const { witness, returnValue } = await program.execute(args, foreignCallHandler);
|
|
178
|
+
return {
|
|
179
|
+
witness,
|
|
180
|
+
publicInputs: returnValue as PrivateKernelPublicInputs,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export async function witnessGenMockPrivateKernelTailCircuit(
|
|
185
|
+
args: MockPrivateKernelTailInputType,
|
|
186
|
+
): Promise<WitnessGenResult<KernelPublicInputs>> {
|
|
187
|
+
const program = new Noir(MockPrivateKernelTailCircuit);
|
|
188
|
+
const { witness, returnValue } = await program.execute(args, foreignCallHandler);
|
|
189
|
+
return {
|
|
190
|
+
witness,
|
|
191
|
+
publicInputs: returnValue as KernelPublicInputs,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export async function witnessGenMockHidingCircuit(
|
|
196
|
+
args: MockHidingInputType,
|
|
197
|
+
): Promise<WitnessGenResult<KernelPublicInputs>> {
|
|
198
|
+
const program = new Noir(MockHidingCircuit);
|
|
199
|
+
const { witness, returnValue } = await program.execute(args, foreignCallHandler);
|
|
200
|
+
return {
|
|
201
|
+
witness,
|
|
202
|
+
publicInputs: returnValue as KernelPublicInputs,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export async function witnessGenMockPublicBaseCircuit(
|
|
207
|
+
args: MockRollupTxBasePublicInputType,
|
|
208
|
+
): Promise<WitnessGenResult<RollupPublicInputs>> {
|
|
209
|
+
const program = new Noir(MockRollupTxBasePublicCircuit);
|
|
210
|
+
const { witness, returnValue } = await program.execute(args, foreignCallHandler);
|
|
211
|
+
return {
|
|
212
|
+
witness,
|
|
213
|
+
publicInputs: returnValue as RollupPublicInputs,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export async function witnessGenMockRollupTxBasePrivateCircuit(
|
|
218
|
+
args: MockRollupTxBasePrivateInputType,
|
|
219
|
+
): Promise<WitnessGenResult<RollupPublicInputs>> {
|
|
220
|
+
const program = new Noir(MockRollupTxBasePrivateCircuit);
|
|
221
|
+
const { witness, returnValue } = await program.execute(args, foreignCallHandler);
|
|
222
|
+
return {
|
|
223
|
+
witness,
|
|
224
|
+
publicInputs: returnValue as RollupPublicInputs,
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export async function witnessGenMockRollupTxMergeCircuit(
|
|
229
|
+
args: MockRollupTxMergeInputType,
|
|
230
|
+
): Promise<WitnessGenResult<RollupPublicInputs>> {
|
|
231
|
+
const program = new Noir(MockRollupTxMergeCircuit);
|
|
232
|
+
const { witness, returnValue } = await program.execute(args, foreignCallHandler);
|
|
233
|
+
return {
|
|
234
|
+
witness,
|
|
235
|
+
publicInputs: returnValue as RollupPublicInputs,
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export async function witnessGenMockRollupRootCircuit(
|
|
240
|
+
args: MockRollupRootInputType,
|
|
241
|
+
): Promise<WitnessGenResult<RollupPublicInputs>> {
|
|
242
|
+
const program = new Noir(MockRollupRootCircuit);
|
|
243
|
+
const { witness, returnValue } = await program.execute(args, foreignCallHandler);
|
|
244
|
+
return {
|
|
245
|
+
witness,
|
|
246
|
+
publicInputs: returnValue as RollupPublicInputs,
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export async function generateTestingIVCStack(
|
|
251
|
+
// A call to the creator app creates 1 commitment. A tx can have at most 2 commitments.
|
|
252
|
+
numCreatorAppCalls: number,
|
|
253
|
+
// A call to the reader app creates 1 read request. A reset kernel will be run if there are 2 read requests in the
|
|
254
|
+
// public inputs. All read requests must be cleared before running the tail kernel.
|
|
255
|
+
numReaderAppCalls: number,
|
|
256
|
+
): Promise<[Uint8Array[], Uint8Array[], KernelPublicInputs, Uint8Array[], CircuitKind[]]> {
|
|
257
|
+
if (numCreatorAppCalls > 2) {
|
|
258
|
+
throw new Error('The creator app can only be called at most twice.');
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const tx = {
|
|
262
|
+
number_of_calls: `0x${(numCreatorAppCalls + numReaderAppCalls).toString(16)}`,
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
const witnessStack: Uint8Array[] = [];
|
|
266
|
+
const bytecodes: string[] = [];
|
|
267
|
+
const vks: string[] = [];
|
|
268
|
+
const circuitKinds: CircuitKind[] = [];
|
|
269
|
+
const pushCircuit = (witness: Uint8Array, bytecode: string, vk: string, kind: CircuitKind) => {
|
|
270
|
+
witnessStack.push(witness);
|
|
271
|
+
bytecodes.push(bytecode);
|
|
272
|
+
vks.push(vk);
|
|
273
|
+
circuitKinds.push(kind);
|
|
274
|
+
};
|
|
275
|
+
let previousKernel: {
|
|
276
|
+
publicInputs: PrivateKernelPublicInputs;
|
|
277
|
+
keyAsFields: string[];
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
const createInit = async (appResult: WitnessGenResult<AppPublicInputs>, appVkAsFields: string[]) => {
|
|
281
|
+
const result = await witnessGenMockPrivateKernelInitCircuit({
|
|
282
|
+
app_inputs: appResult.publicInputs,
|
|
283
|
+
tx,
|
|
284
|
+
app_vk: await getVkAsFields({ keyAsFields: appVkAsFields }, MEGA_APP_VK_LENGTH_IN_FIELDS),
|
|
285
|
+
});
|
|
286
|
+
pushCircuit(
|
|
287
|
+
result.witness,
|
|
288
|
+
MockPrivateKernelInitCircuit.bytecode,
|
|
289
|
+
MockPrivateKernelInitVk.keyAsBytes,
|
|
290
|
+
CircuitKind.Kernel,
|
|
291
|
+
);
|
|
292
|
+
previousKernel = {
|
|
293
|
+
publicInputs: result.publicInputs,
|
|
294
|
+
keyAsFields: MockPrivateKernelInitVk.keyAsFields,
|
|
295
|
+
};
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
const createInner = async (appResult: WitnessGenResult<AppPublicInputs>, appVkAsFields: string[]) => {
|
|
299
|
+
const result = await witnessGenMockPrivateKernelInnerCircuit({
|
|
300
|
+
prev_kernel_public_inputs: previousKernel.publicInputs,
|
|
301
|
+
kernel_vk: await getVkAsFields(previousKernel, MEGA_KERNEL_VK_LENGTH_IN_FIELDS),
|
|
302
|
+
app_inputs: appResult.publicInputs,
|
|
303
|
+
app_vk: await getVkAsFields({ keyAsFields: appVkAsFields }, MEGA_APP_VK_LENGTH_IN_FIELDS),
|
|
304
|
+
});
|
|
305
|
+
pushCircuit(
|
|
306
|
+
result.witness,
|
|
307
|
+
MockPrivateKernelInnerCircuit.bytecode,
|
|
308
|
+
MockPrivateKernelInnerVk.keyAsBytes,
|
|
309
|
+
CircuitKind.Kernel,
|
|
310
|
+
);
|
|
311
|
+
previousKernel = {
|
|
312
|
+
publicInputs: result.publicInputs,
|
|
313
|
+
keyAsFields: MockPrivateKernelInnerVk.keyAsFields,
|
|
314
|
+
};
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
const createReset = async (commitmentToReset: string[]) => {
|
|
318
|
+
const result = await witnessGenMockPrivateKernelResetCircuit({
|
|
319
|
+
prev_kernel_public_inputs: previousKernel.publicInputs,
|
|
320
|
+
kernel_vk: await getVkAsFields(previousKernel, MEGA_KERNEL_VK_LENGTH_IN_FIELDS),
|
|
321
|
+
commitment_read_hints: padArrayEnd(
|
|
322
|
+
commitmentToReset.map(r => commitments.findIndex(c => c === r)!.toString(16)),
|
|
323
|
+
MOCK_MAX_COMMITMENTS_PER_TX.toString(),
|
|
324
|
+
4,
|
|
325
|
+
),
|
|
326
|
+
});
|
|
327
|
+
pushCircuit(
|
|
328
|
+
result.witness,
|
|
329
|
+
MockPrivateKernelResetCircuit.bytecode,
|
|
330
|
+
MockPrivateKernelResetVk.keyAsBytes,
|
|
331
|
+
CircuitKind.Kernel,
|
|
332
|
+
);
|
|
333
|
+
previousKernel = {
|
|
334
|
+
publicInputs: result.publicInputs,
|
|
335
|
+
keyAsFields: MockPrivateKernelResetVk.keyAsFields,
|
|
336
|
+
};
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
const commitments = ['0x1', '0x2'];
|
|
340
|
+
for (let i = 0; i < numCreatorAppCalls; i++) {
|
|
341
|
+
const result = await witnessGenCreatorAppMockCircuit({ commitments_to_create: [commitments[i], '0x0'] });
|
|
342
|
+
pushCircuit(result.witness, MockAppCreatorCircuit.bytecode, MockAppCreatorVk.keyAsBytes, CircuitKind.App);
|
|
343
|
+
|
|
344
|
+
if (i === 0) {
|
|
345
|
+
await createInit(result, MockAppCreatorVk.keyAsFields);
|
|
346
|
+
} else {
|
|
347
|
+
await createInner(result, MockAppCreatorVk.keyAsFields);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
let commitmentToReset: string[] = [];
|
|
352
|
+
for (let i = 0; i < numReaderAppCalls; i++) {
|
|
353
|
+
const commitmentToRead = commitments[Math.min(i, numCreatorAppCalls) % 2];
|
|
354
|
+
const result = await witnessGenReaderAppMockCircuit({ commitments_to_read: [commitmentToRead, '0x0'] });
|
|
355
|
+
pushCircuit(result.witness, MockAppReaderCircuit.bytecode, MockAppReaderVk.keyAsBytes, CircuitKind.App);
|
|
356
|
+
commitmentToReset.push(commitmentToRead);
|
|
357
|
+
|
|
358
|
+
if (i === 0 && !numCreatorAppCalls) {
|
|
359
|
+
await createInit(result, MockAppReaderVk.keyAsFields);
|
|
360
|
+
} else {
|
|
361
|
+
await createInner(result, MockAppReaderVk.keyAsFields);
|
|
362
|
+
}
|
|
363
|
+
if (i % 2 === 0 || i === numReaderAppCalls - 1) {
|
|
364
|
+
await createReset(commitmentToReset);
|
|
365
|
+
commitmentToReset = [];
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
const tailWitnessGenResult = await witnessGenMockPrivateKernelTailCircuit({
|
|
370
|
+
prev_kernel_public_inputs: previousKernel!.publicInputs,
|
|
371
|
+
kernel_vk: await getVkAsFields(previousKernel!, MEGA_KERNEL_VK_LENGTH_IN_FIELDS),
|
|
372
|
+
});
|
|
373
|
+
pushCircuit(
|
|
374
|
+
tailWitnessGenResult.witness,
|
|
375
|
+
MockPrivateKernelTailCircuit.bytecode,
|
|
376
|
+
MockPrivateKernelTailVk.keyAsBytes,
|
|
377
|
+
CircuitKind.Kernel,
|
|
378
|
+
);
|
|
379
|
+
|
|
380
|
+
const hidingWitnessGenResult = await witnessGenMockHidingCircuit({
|
|
381
|
+
prev_kernel_public_inputs: tailWitnessGenResult.publicInputs,
|
|
382
|
+
kernel_vk: await getVkAsFields(MockPrivateKernelTailVk, MEGA_KERNEL_VK_LENGTH_IN_FIELDS),
|
|
383
|
+
});
|
|
384
|
+
pushCircuit(
|
|
385
|
+
hidingWitnessGenResult.witness,
|
|
386
|
+
MockHidingCircuit.bytecode,
|
|
387
|
+
MockHidingVk.keyAsBytes,
|
|
388
|
+
CircuitKind.HidingKernel,
|
|
389
|
+
);
|
|
390
|
+
|
|
391
|
+
function base64ToUint8Array(base64: string): Uint8Array {
|
|
392
|
+
return Uint8Array.from(atob(base64), c => c.charCodeAt(0));
|
|
393
|
+
}
|
|
394
|
+
function hexToUint8Array(hex: string): Uint8Array {
|
|
395
|
+
const cleaned = hex.replace(/^0x/i, '');
|
|
396
|
+
const bytes = new Uint8Array(cleaned.length / 2);
|
|
397
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
398
|
+
bytes[i] = parseInt(cleaned.slice(i * 2, i * 2 + 2), 16);
|
|
399
|
+
}
|
|
400
|
+
return bytes;
|
|
401
|
+
}
|
|
402
|
+
const rawBytecodes = bytecodes.map(base64ToUint8Array).map((arr: Uint8Array) => ungzip(arr));
|
|
403
|
+
const rawWitnessStack = witnessStack.map((arr: Uint8Array) => ungzip(arr));
|
|
404
|
+
const rawVks = vks.map(hexToUint8Array);
|
|
405
|
+
|
|
406
|
+
return [rawBytecodes, rawWitnessStack, hidingWitnessGenResult.publicInputs, rawVks, circuitKinds];
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
export function mapRecursiveProofToNoir<N extends number>(proof: RecursiveProof<N>): FixedLengthArray<string, N> {
|
|
410
|
+
return proof.proof.map(field => field.toString()) as FixedLengthArray<string, N>;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
export function mapAvmProofToNoir(proof: Fr[]): FixedLengthArray<string, typeof AVM_V2_PROOF_LENGTH_IN_FIELDS> {
|
|
414
|
+
if (proof.length != AVM_V2_PROOF_LENGTH_IN_FIELDS) {
|
|
415
|
+
throw new Error('Invalid number of AVM proof fields');
|
|
416
|
+
}
|
|
417
|
+
return proof.map(field => field.toString()) as FixedLengthArray<string, typeof AVM_V2_PROOF_LENGTH_IN_FIELDS>;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
export function mapVerificationKeyToNoir<N extends number>(
|
|
421
|
+
vk: VerificationKeyAsFields,
|
|
422
|
+
len: N,
|
|
423
|
+
): {
|
|
424
|
+
key: FixedLengthArray<string, N>;
|
|
425
|
+
hash: string;
|
|
426
|
+
} {
|
|
427
|
+
if (len !== vk.key.length) {
|
|
428
|
+
throw new Error(`Verification key length ${len} does not match expected length ${vk.key.length}`);
|
|
429
|
+
}
|
|
430
|
+
return {
|
|
431
|
+
key: vk.key.map(field => field.toString()) as FixedLengthArray<string, N>,
|
|
432
|
+
hash: vk.hash.toString(),
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
export function mapAvmPublicInputsToNoir(
|
|
437
|
+
publicInputs: AvmCircuitPublicInputs,
|
|
438
|
+
): FixedLengthArray<string, typeof AVM_CIRCUIT_PUBLIC_INPUTS_LENGTH> {
|
|
439
|
+
const serialized = publicInputs.toFields();
|
|
440
|
+
if (serialized.length != AVM_CIRCUIT_PUBLIC_INPUTS_LENGTH) {
|
|
441
|
+
throw new Error('Invalid number of AVM public inputs');
|
|
442
|
+
}
|
|
443
|
+
return serialized.map(x => x.toString()) as FixedLengthArray<string, typeof AVM_CIRCUIT_PUBLIC_INPUTS_LENGTH>;
|
|
444
|
+
}
|