@aztec/ivc-integration 0.86.0 → 0.87.0
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/artifacts/app_creator.json +1 -1
- package/artifacts/app_reader.json +1 -1
- package/artifacts/keys/mock_private_kernel_init.vk.data.json +83 -83
- package/artifacts/keys/mock_private_kernel_inner.vk.data.json +83 -83
- package/artifacts/keys/mock_private_kernel_reset.vk.data.json +87 -87
- package/artifacts/keys/mock_private_kernel_tail.vk.data.json +83 -83
- package/artifacts/keys/mock_rollup_base_private.vk.data.json +85 -85
- package/artifacts/keys/mock_rollup_base_public.vk.data.json +85 -85
- package/artifacts/keys/mock_rollup_merge.vk.data.json +85 -85
- package/artifacts/keys/mock_rollup_root.vk.data.json +85 -85
- package/artifacts/keys/mock_rollup_root_verifier.sol +52 -52
- package/artifacts/mock_private_kernel_init.json +1 -1
- package/artifacts/mock_private_kernel_inner.json +1 -1
- package/artifacts/mock_private_kernel_reset.json +1 -1
- package/artifacts/mock_private_kernel_tail.json +1 -1
- package/artifacts/mock_rollup_base_private.json +1 -1
- package/artifacts/mock_rollup_base_public.json +1 -1
- package/artifacts/mock_rollup_merge.json +1 -1
- package/artifacts/mock_rollup_root.json +1 -1
- package/dest/prove_native.d.ts +1 -1
- package/dest/prove_native.d.ts.map +1 -1
- package/dest/prove_native.js +7 -3
- package/dest/types/index.d.ts +106 -2
- package/dest/types/index.d.ts.map +1 -1
- package/dest/types/index.js +2 -2
- package/dest/witgen.d.ts +14 -4
- package/dest/witgen.d.ts.map +1 -1
- package/dest/witgen.js +58 -36
- package/package.json +19 -18
- package/src/prove_native.ts +15 -1
- package/src/types/index.ts +125 -3
- package/src/witgen.ts +68 -40
package/dest/witgen.js
CHANGED
|
@@ -1,76 +1,86 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AVM_CIRCUIT_PUBLIC_INPUTS_LENGTH, AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED, AVM_V2_VERIFICATION_KEY_LENGTH_IN_FIELDS_PADDED } from '@aztec/constants';
|
|
2
2
|
import { Fr } from '@aztec/foundation/fields';
|
|
3
|
+
import { applyStringFormatting, createLogger } from '@aztec/foundation/log';
|
|
3
4
|
import { Noir } from '@aztec/noir-noir_js';
|
|
4
|
-
import
|
|
5
|
-
import MockAppCreatorCircuit from '../artifacts/app_creator.json'
|
|
5
|
+
import { strict as assert } from 'assert';
|
|
6
|
+
import MockAppCreatorCircuit from '../artifacts/app_creator.json' with {
|
|
6
7
|
type: 'json'
|
|
7
8
|
};
|
|
8
|
-
import MockAppReaderCircuit from '../artifacts/app_reader.json'
|
|
9
|
+
import MockAppReaderCircuit from '../artifacts/app_reader.json' with {
|
|
9
10
|
type: 'json'
|
|
10
11
|
};
|
|
11
|
-
import MockAppCreatorVk from '../artifacts/keys/app_creator.vk.data.json'
|
|
12
|
+
import MockAppCreatorVk from '../artifacts/keys/app_creator.vk.data.json' with {
|
|
12
13
|
type: 'json'
|
|
13
14
|
};
|
|
14
|
-
import MockAppReaderVk from '../artifacts/keys/app_reader.vk.data.json'
|
|
15
|
+
import MockAppReaderVk from '../artifacts/keys/app_reader.vk.data.json' with {
|
|
15
16
|
type: 'json'
|
|
16
17
|
};
|
|
17
|
-
import MockPrivateKernelInitVk from '../artifacts/keys/mock_private_kernel_init.vk.data.json'
|
|
18
|
+
import MockPrivateKernelInitVk from '../artifacts/keys/mock_private_kernel_init.vk.data.json' with {
|
|
18
19
|
type: 'json'
|
|
19
20
|
};
|
|
20
|
-
import MockPrivateKernelInnerVk from '../artifacts/keys/mock_private_kernel_inner.vk.data.json'
|
|
21
|
+
import MockPrivateKernelInnerVk from '../artifacts/keys/mock_private_kernel_inner.vk.data.json' with {
|
|
21
22
|
type: 'json'
|
|
22
23
|
};
|
|
23
|
-
import MockPrivateKernelResetVk from '../artifacts/keys/mock_private_kernel_reset.vk.data.json'
|
|
24
|
+
import MockPrivateKernelResetVk from '../artifacts/keys/mock_private_kernel_reset.vk.data.json' with {
|
|
24
25
|
type: 'json'
|
|
25
26
|
};
|
|
26
|
-
import MockPrivateKernelTailVk from '../artifacts/keys/mock_private_kernel_tail.vk.data.json'
|
|
27
|
+
import MockPrivateKernelTailVk from '../artifacts/keys/mock_private_kernel_tail.vk.data.json' with {
|
|
27
28
|
type: 'json'
|
|
28
29
|
};
|
|
29
|
-
import MockRollupBasePrivateVk from '../artifacts/keys/mock_rollup_base_private.vk.data.json'
|
|
30
|
+
import MockRollupBasePrivateVk from '../artifacts/keys/mock_rollup_base_private.vk.data.json' with {
|
|
30
31
|
type: 'json'
|
|
31
32
|
};
|
|
32
|
-
import MockRollupBasePublicVk from '../artifacts/keys/mock_rollup_base_public.vk.data.json'
|
|
33
|
+
import MockRollupBasePublicVk from '../artifacts/keys/mock_rollup_base_public.vk.data.json' with {
|
|
33
34
|
type: 'json'
|
|
34
35
|
};
|
|
35
|
-
import MockRollupMergeVk from '../artifacts/keys/mock_rollup_merge.vk.data.json'
|
|
36
|
+
import MockRollupMergeVk from '../artifacts/keys/mock_rollup_merge.vk.data.json' with {
|
|
36
37
|
type: 'json'
|
|
37
38
|
};
|
|
38
|
-
import MockRollupRootVk from '../artifacts/keys/mock_rollup_root.vk.data.json'
|
|
39
|
+
import MockRollupRootVk from '../artifacts/keys/mock_rollup_root.vk.data.json' with {
|
|
39
40
|
type: 'json'
|
|
40
41
|
};
|
|
41
|
-
import MockPrivateKernelInitCircuit from '../artifacts/mock_private_kernel_init.json'
|
|
42
|
+
import MockPrivateKernelInitCircuit from '../artifacts/mock_private_kernel_init.json' with {
|
|
42
43
|
type: 'json'
|
|
43
44
|
};
|
|
44
|
-
import MockPrivateKernelInnerCircuit from '../artifacts/mock_private_kernel_inner.json'
|
|
45
|
+
import MockPrivateKernelInnerCircuit from '../artifacts/mock_private_kernel_inner.json' with {
|
|
45
46
|
type: 'json'
|
|
46
47
|
};
|
|
47
|
-
import MockPrivateKernelResetCircuit from '../artifacts/mock_private_kernel_reset.json'
|
|
48
|
+
import MockPrivateKernelResetCircuit from '../artifacts/mock_private_kernel_reset.json' with {
|
|
48
49
|
type: 'json'
|
|
49
50
|
};
|
|
50
|
-
import MockPrivateKernelTailCircuit from '../artifacts/mock_private_kernel_tail.json'
|
|
51
|
+
import MockPrivateKernelTailCircuit from '../artifacts/mock_private_kernel_tail.json' with {
|
|
51
52
|
type: 'json'
|
|
52
53
|
};
|
|
53
|
-
import MockRollupBasePrivateCircuit from '../artifacts/mock_rollup_base_private.json'
|
|
54
|
+
import MockRollupBasePrivateCircuit from '../artifacts/mock_rollup_base_private.json' with {
|
|
54
55
|
type: 'json'
|
|
55
56
|
};
|
|
56
|
-
import MockRollupBasePublicCircuit from '../artifacts/mock_rollup_base_public.json'
|
|
57
|
+
import MockRollupBasePublicCircuit from '../artifacts/mock_rollup_base_public.json' with {
|
|
57
58
|
type: 'json'
|
|
58
59
|
};
|
|
59
|
-
import MockRollupMergeCircuit from '../artifacts/mock_rollup_merge.json'
|
|
60
|
+
import MockRollupMergeCircuit from '../artifacts/mock_rollup_merge.json' with {
|
|
60
61
|
type: 'json'
|
|
61
62
|
};
|
|
62
|
-
import MockRollupRootCircuit from '../artifacts/mock_rollup_root.json'
|
|
63
|
+
import MockRollupRootCircuit from '../artifacts/mock_rollup_root.json' with {
|
|
63
64
|
type: 'json'
|
|
64
65
|
};
|
|
65
66
|
// Re export the circuit jsons
|
|
66
67
|
export { MockAppCreatorCircuit, MockAppReaderCircuit, MockPrivateKernelInitCircuit, MockPrivateKernelInnerCircuit, MockPrivateKernelResetCircuit, MockPrivateKernelTailCircuit, MockRollupBasePublicCircuit, MockRollupBasePrivateCircuit, MockRollupMergeCircuit, MockRollupRootCircuit, MockAppCreatorVk, MockAppReaderVk, MockPrivateKernelInitVk, MockPrivateKernelInnerVk, MockPrivateKernelResetVk, MockPrivateKernelTailVk, MockRollupBasePublicVk, MockRollupBasePrivateVk, MockRollupMergeVk, MockRollupRootVk };
|
|
67
|
-
/* eslint-disable camelcase */ const
|
|
68
|
+
/* eslint-disable camelcase */ const log = createLogger('aztec:ivc-test');
|
|
68
69
|
export function getVkAsFields(vk) {
|
|
69
70
|
return vk.keyAsFields;
|
|
70
71
|
}
|
|
71
72
|
export const MOCK_MAX_COMMITMENTS_PER_TX = 4;
|
|
72
|
-
function foreignCallHandler() {
|
|
73
|
-
|
|
73
|
+
function foreignCallHandler(name, args) {
|
|
74
|
+
if (name === 'debugLog') {
|
|
75
|
+
assert(args.length === 3, 'expected 3 arguments for debugLog: msg, fields_length, fields');
|
|
76
|
+
const [msgRaw, _ignoredFieldsSize, fields] = args;
|
|
77
|
+
const msg = msgRaw.map((acvmField)=>String.fromCharCode(Fr.fromString(acvmField).toNumber())).join('');
|
|
78
|
+
const fieldsFr = fields.map((field)=>Fr.fromString(field));
|
|
79
|
+
log.verbose('debug_log ' + applyStringFormatting(msg, fieldsFr));
|
|
80
|
+
} else {
|
|
81
|
+
throw new Error('Unexpected foreign call');
|
|
82
|
+
}
|
|
83
|
+
return Promise.resolve([]);
|
|
74
84
|
}
|
|
75
85
|
export async function witnessGenCreatorAppMockCircuit(args) {
|
|
76
86
|
const program = new Noir(MockAppCreatorCircuit);
|
|
@@ -163,18 +173,18 @@ export async function generate3FunctionTestingIVCStack() {
|
|
|
163
173
|
'0x2'
|
|
164
174
|
]
|
|
165
175
|
});
|
|
166
|
-
|
|
176
|
+
log.debug('generated app mock circuit witness');
|
|
167
177
|
const initWitnessGenResult = await witnessGenMockPrivateKernelInitCircuit({
|
|
168
178
|
app_inputs: appWitnessGenResult.publicInputs,
|
|
169
179
|
tx,
|
|
170
180
|
app_vk: getVkAsFields(MockAppCreatorVk)
|
|
171
181
|
});
|
|
172
|
-
|
|
182
|
+
log.debug('generated mock private kernel init witness');
|
|
173
183
|
const tailWitnessGenResult = await witnessGenMockPrivateKernelTailCircuit({
|
|
174
184
|
prev_kernel_public_inputs: initWitnessGenResult.publicInputs,
|
|
175
|
-
kernel_vk: getVkAsFields(
|
|
185
|
+
kernel_vk: getVkAsFields(MockPrivateKernelInitVk)
|
|
176
186
|
});
|
|
177
|
-
|
|
187
|
+
log.debug('generated mock private kernel tail witness');
|
|
178
188
|
// Create client IVC proof
|
|
179
189
|
const bytecodes = [
|
|
180
190
|
MockAppCreatorCircuit.bytecode,
|
|
@@ -186,10 +196,16 @@ export async function generate3FunctionTestingIVCStack() {
|
|
|
186
196
|
initWitnessGenResult.witness,
|
|
187
197
|
tailWitnessGenResult.witness
|
|
188
198
|
];
|
|
199
|
+
const precomputedVks = [
|
|
200
|
+
MockAppCreatorVk.keyAsBytes,
|
|
201
|
+
MockPrivateKernelInitVk.keyAsBytes,
|
|
202
|
+
MockPrivateKernelTailVk.keyAsBytes
|
|
203
|
+
];
|
|
189
204
|
return [
|
|
190
205
|
bytecodes,
|
|
191
206
|
witnessStack,
|
|
192
|
-
tailWitnessGenResult.publicInputs
|
|
207
|
+
tailWitnessGenResult.publicInputs,
|
|
208
|
+
precomputedVks
|
|
193
209
|
];
|
|
194
210
|
}
|
|
195
211
|
export async function generate6FunctionTestingIVCStack() {
|
|
@@ -251,10 +267,19 @@ export async function generate6FunctionTestingIVCStack() {
|
|
|
251
267
|
resetWitnessGenResult.witness,
|
|
252
268
|
tailWitnessGenResult.witness
|
|
253
269
|
];
|
|
270
|
+
const precomputedVks = [
|
|
271
|
+
MockAppCreatorVk.keyAsBytes,
|
|
272
|
+
MockPrivateKernelInitVk.keyAsBytes,
|
|
273
|
+
MockAppReaderVk.keyAsBytes,
|
|
274
|
+
MockPrivateKernelInnerVk.keyAsBytes,
|
|
275
|
+
MockPrivateKernelResetVk.keyAsBytes,
|
|
276
|
+
MockPrivateKernelTailVk.keyAsBytes
|
|
277
|
+
];
|
|
254
278
|
return [
|
|
255
279
|
bytecodes,
|
|
256
280
|
witnessStack,
|
|
257
|
-
tailWitnessGenResult.publicInputs
|
|
281
|
+
tailWitnessGenResult.publicInputs,
|
|
282
|
+
precomputedVks
|
|
258
283
|
];
|
|
259
284
|
}
|
|
260
285
|
export function mapRecursiveProofToNoir(proof) {
|
|
@@ -282,11 +307,8 @@ export function mapAvmVerificationKeyToNoir(vk) {
|
|
|
282
307
|
return vk.map((field)=>field.toString());
|
|
283
308
|
}
|
|
284
309
|
export function mapAvmPublicInputsToNoir(publicInputs) {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
new Fr(publicInputs.reverted)
|
|
288
|
-
];
|
|
289
|
-
if (serialized.length != AVM_V2_PUBLIC_INPUTS_FLATTENED_SIZE) {
|
|
310
|
+
const serialized = publicInputs.toFields();
|
|
311
|
+
if (serialized.length != AVM_CIRCUIT_PUBLIC_INPUTS_LENGTH) {
|
|
290
312
|
throw new Error('Invalid number of AVM public inputs');
|
|
291
313
|
}
|
|
292
314
|
return serialized.map((x)=>x.toString());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/ivc-integration",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.87.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
@@ -58,14 +58,14 @@
|
|
|
58
58
|
]
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@aztec/bb.js": "0.
|
|
62
|
-
"@aztec/constants": "0.
|
|
63
|
-
"@aztec/foundation": "0.
|
|
64
|
-
"@aztec/noir-noir_codegen": "0.
|
|
65
|
-
"@aztec/noir-noir_js": "0.
|
|
66
|
-
"@aztec/noir-noirc_abi": "0.
|
|
67
|
-
"@aztec/noir-types": "0.
|
|
68
|
-
"@aztec/stdlib": "0.
|
|
61
|
+
"@aztec/bb.js": "0.87.0",
|
|
62
|
+
"@aztec/constants": "0.87.0",
|
|
63
|
+
"@aztec/foundation": "0.87.0",
|
|
64
|
+
"@aztec/noir-noir_codegen": "0.87.0",
|
|
65
|
+
"@aztec/noir-noir_js": "0.87.0",
|
|
66
|
+
"@aztec/noir-noirc_abi": "0.87.0",
|
|
67
|
+
"@aztec/noir-types": "0.87.0",
|
|
68
|
+
"@aztec/stdlib": "0.87.0",
|
|
69
69
|
"chalk": "^5.3.0",
|
|
70
70
|
"change-case": "^5.4.4",
|
|
71
71
|
"pako": "^2.1.0",
|
|
@@ -74,16 +74,17 @@
|
|
|
74
74
|
"tslib": "^2.4.0"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
|
-
"@aztec/bb-prover": "0.
|
|
78
|
-
"@aztec/kv-store": "0.
|
|
79
|
-
"@aztec/noir-
|
|
80
|
-
"@aztec/
|
|
81
|
-
"@aztec/
|
|
82
|
-
"@aztec/
|
|
77
|
+
"@aztec/bb-prover": "0.87.0",
|
|
78
|
+
"@aztec/kv-store": "0.87.0",
|
|
79
|
+
"@aztec/noir-protocol-circuits-types": "0.87.0",
|
|
80
|
+
"@aztec/noir-test-contracts.js": "0.87.0",
|
|
81
|
+
"@aztec/simulator": "0.87.0",
|
|
82
|
+
"@aztec/telemetry-client": "0.87.0",
|
|
83
|
+
"@aztec/world-state": "0.87.0",
|
|
83
84
|
"@jest/globals": "^29.5.0",
|
|
84
85
|
"@playwright/test": "1.49.0",
|
|
85
86
|
"@types/jest": "^29.5.0",
|
|
86
|
-
"@types/node": "^22.
|
|
87
|
+
"@types/node": "^22.15.17",
|
|
87
88
|
"@types/pako": "^2.0.3",
|
|
88
89
|
"copy-webpack-plugin": "^12.0.2",
|
|
89
90
|
"debug": "^4.3.4",
|
|
@@ -95,7 +96,7 @@
|
|
|
95
96
|
"serve": "^14.2.1",
|
|
96
97
|
"ts-loader": "^9.5.1",
|
|
97
98
|
"ts-node": "^10.9.1",
|
|
98
|
-
"typescript": "^5.
|
|
99
|
+
"typescript": "^5.3.3",
|
|
99
100
|
"webpack": "^5.99.6",
|
|
100
101
|
"webpack-cli": "^6.0.1",
|
|
101
102
|
"webpack-dev-server": "^5.2.1"
|
|
@@ -108,6 +109,6 @@
|
|
|
108
109
|
],
|
|
109
110
|
"types": "./dest/index.d.ts",
|
|
110
111
|
"engines": {
|
|
111
|
-
"node": ">=
|
|
112
|
+
"node": ">=20.10"
|
|
112
113
|
}
|
|
113
114
|
}
|
package/src/prove_native.ts
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
generateTubeProof,
|
|
12
12
|
readClientIVCProofFromOutputDirectory,
|
|
13
13
|
readProofAsFields,
|
|
14
|
+
verifyAvmProofV2,
|
|
14
15
|
verifyProof,
|
|
15
16
|
} from '@aztec/bb-prover';
|
|
16
17
|
import {
|
|
@@ -38,13 +39,14 @@ export async function proveClientIVC(
|
|
|
38
39
|
bbWorkingDirectory: string,
|
|
39
40
|
witnessStack: Uint8Array[],
|
|
40
41
|
bytecodes: string[],
|
|
42
|
+
vks: string[],
|
|
41
43
|
logger: Logger,
|
|
42
44
|
): Promise<ClientIvcProof> {
|
|
43
45
|
const stepToStruct = (bytecode: string, index: number) => {
|
|
44
46
|
return {
|
|
45
47
|
bytecode: Buffer.from(bytecode, 'base64'),
|
|
46
48
|
witness: witnessStack[index],
|
|
47
|
-
vk: Buffer.from([]),
|
|
49
|
+
vk: Buffer.from(vks[index], 'hex'),
|
|
48
50
|
functionName: `unknown_${index}`,
|
|
49
51
|
};
|
|
50
52
|
};
|
|
@@ -235,6 +237,18 @@ export async function proveAvm(
|
|
|
235
237
|
vk.push(new Fr(0));
|
|
236
238
|
}
|
|
237
239
|
|
|
240
|
+
const verificationResult = await verifyAvmProofV2(
|
|
241
|
+
bbPath,
|
|
242
|
+
workingDirectory,
|
|
243
|
+
proofRes.proofPath!,
|
|
244
|
+
avmCircuitInputs.publicInputs,
|
|
245
|
+
proofRes.vkPath!,
|
|
246
|
+
logger,
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
if (verificationResult.status === BB_RESULT.FAILURE) {
|
|
250
|
+
throw new Error(`AVM V2 proof verification failed: ${verificationResult.reason}`);
|
|
251
|
+
}
|
|
238
252
|
return {
|
|
239
253
|
proof,
|
|
240
254
|
vk,
|
package/src/types/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ export { type ForeignCallHandler } from "@aztec/noir-noir_js"
|
|
|
10
10
|
export type FixedLengthArray<T, L extends number> = L extends 0 ? never[]: T[] & { length: L }
|
|
11
11
|
export type Field = string;
|
|
12
12
|
export type u32 = string;
|
|
13
|
+
export type u64 = string;
|
|
13
14
|
|
|
14
15
|
export type AppPublicInputs = {
|
|
15
16
|
commitments: FixedLengthArray<Field, 2>;
|
|
@@ -41,6 +42,127 @@ export type VerificationKey = {
|
|
|
41
42
|
hash: Field;
|
|
42
43
|
}
|
|
43
44
|
|
|
45
|
+
export type AvmCircuitPublicInputs = {
|
|
46
|
+
global_variables: GlobalVariables;
|
|
47
|
+
start_tree_snapshots: TreeSnapshots;
|
|
48
|
+
start_gas_used: Gas;
|
|
49
|
+
gas_settings: GasSettings;
|
|
50
|
+
fee_payer: AztecAddress;
|
|
51
|
+
public_setup_call_requests: FixedLengthArray<PublicCallRequest, 32>;
|
|
52
|
+
public_app_logic_call_requests: FixedLengthArray<PublicCallRequest, 32>;
|
|
53
|
+
public_teardown_call_request: PublicCallRequest;
|
|
54
|
+
previous_non_revertible_accumulated_data_array_lengths: PrivateToAvmAccumulatedDataArrayLengths;
|
|
55
|
+
previous_revertible_accumulated_data_array_lengths: PrivateToAvmAccumulatedDataArrayLengths;
|
|
56
|
+
previous_non_revertible_accumulated_data: PrivateToAvmAccumulatedData;
|
|
57
|
+
previous_revertible_accumulated_data: PrivateToAvmAccumulatedData;
|
|
58
|
+
end_tree_snapshots: TreeSnapshots;
|
|
59
|
+
end_gas_used: Gas;
|
|
60
|
+
accumulated_data: AvmAccumulatedData;
|
|
61
|
+
transaction_fee: Field;
|
|
62
|
+
reverted: boolean;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export type GlobalVariables = {
|
|
66
|
+
chain_id: Field;
|
|
67
|
+
version: Field;
|
|
68
|
+
block_number: Field;
|
|
69
|
+
slot_number: Field;
|
|
70
|
+
timestamp: u64;
|
|
71
|
+
coinbase: EthAddress;
|
|
72
|
+
fee_recipient: AztecAddress;
|
|
73
|
+
gas_fees: GasFees;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export type TreeSnapshots = {
|
|
77
|
+
l1_to_l2_message_tree: AppendOnlyTreeSnapshot;
|
|
78
|
+
note_hash_tree: AppendOnlyTreeSnapshot;
|
|
79
|
+
nullifier_tree: AppendOnlyTreeSnapshot;
|
|
80
|
+
public_data_tree: AppendOnlyTreeSnapshot;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export type Gas = {
|
|
84
|
+
da_gas: u32;
|
|
85
|
+
l2_gas: u32;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export type GasSettings = {
|
|
89
|
+
gas_limits: Gas;
|
|
90
|
+
teardown_gas_limits: Gas;
|
|
91
|
+
max_fees_per_gas: GasFees;
|
|
92
|
+
max_priority_fees_per_gas: GasFees;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export type AztecAddress = {
|
|
96
|
+
inner: Field;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export type PublicCallRequest = {
|
|
100
|
+
msg_sender: AztecAddress;
|
|
101
|
+
contract_address: AztecAddress;
|
|
102
|
+
is_static_call: boolean;
|
|
103
|
+
calldata_hash: Field;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export type PrivateToAvmAccumulatedDataArrayLengths = {
|
|
107
|
+
note_hashes: u32;
|
|
108
|
+
nullifiers: u32;
|
|
109
|
+
l2_to_l1_msgs: u32;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export type PrivateToAvmAccumulatedData = {
|
|
113
|
+
note_hashes: FixedLengthArray<Field, 64>;
|
|
114
|
+
nullifiers: FixedLengthArray<Field, 64>;
|
|
115
|
+
l2_to_l1_msgs: FixedLengthArray<ScopedL2ToL1Message, 8>;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export type AvmAccumulatedData = {
|
|
119
|
+
note_hashes: FixedLengthArray<Field, 64>;
|
|
120
|
+
nullifiers: FixedLengthArray<Field, 64>;
|
|
121
|
+
l2_to_l1_msgs: FixedLengthArray<ScopedL2ToL1Message, 8>;
|
|
122
|
+
public_logs: FixedLengthArray<PublicLog, 8>;
|
|
123
|
+
public_data_writes: FixedLengthArray<PublicDataWrite, 64>;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export type EthAddress = {
|
|
127
|
+
inner: Field;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export type GasFees = {
|
|
131
|
+
fee_per_da_gas: Field;
|
|
132
|
+
fee_per_l2_gas: Field;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export type AppendOnlyTreeSnapshot = {
|
|
136
|
+
root: Field;
|
|
137
|
+
next_available_leaf_index: u32;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export type ScopedL2ToL1Message = {
|
|
141
|
+
message: L2ToL1Message;
|
|
142
|
+
contract_address: AztecAddress;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export type PublicLog = {
|
|
146
|
+
log: Log;
|
|
147
|
+
contract_address: AztecAddress;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export type PublicDataWrite = {
|
|
151
|
+
leaf_slot: Field;
|
|
152
|
+
value: Field;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export type L2ToL1Message = {
|
|
156
|
+
recipient: EthAddress;
|
|
157
|
+
content: Field;
|
|
158
|
+
counter: u32;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export type Log = {
|
|
162
|
+
fields: FixedLengthArray<Field, 13>;
|
|
163
|
+
length: u32;
|
|
164
|
+
}
|
|
165
|
+
|
|
44
166
|
export type RollupPublicInputs = {
|
|
45
167
|
accumulated: u32;
|
|
46
168
|
}
|
|
@@ -142,15 +264,15 @@ export type MockRollupBasePublicInputType = {
|
|
|
142
264
|
tube_data: TubeData;
|
|
143
265
|
verification_key: FixedLengthArray<Field, 1000>;
|
|
144
266
|
proof: FixedLengthArray<Field, 20000>;
|
|
145
|
-
|
|
267
|
+
public_inputs: AvmCircuitPublicInputs;
|
|
146
268
|
}
|
|
147
269
|
|
|
148
270
|
export type MockRollupBasePublicReturnType = RollupPublicInputs;
|
|
149
271
|
|
|
150
272
|
|
|
151
|
-
export async function MockRollupBasePublic(tube_data: TubeData, verification_key: FixedLengthArray<Field, 1000>, proof: FixedLengthArray<Field, 20000>,
|
|
273
|
+
export async function MockRollupBasePublic(tube_data: TubeData, verification_key: FixedLengthArray<Field, 1000>, proof: FixedLengthArray<Field, 20000>, public_inputs: AvmCircuitPublicInputs, MockRollupBasePublic_circuit: CompiledCircuit, foreignCallHandler?: ForeignCallHandler): Promise<RollupPublicInputs> {
|
|
152
274
|
const program = new Noir(MockRollupBasePublic_circuit);
|
|
153
|
-
const args: InputMap = { tube_data, verification_key, proof,
|
|
275
|
+
const args: InputMap = { tube_data, verification_key, proof, public_inputs };
|
|
154
276
|
const { returnValue } = await program.execute(args, foreignCallHandler);
|
|
155
277
|
return returnValue as RollupPublicInputs;
|
|
156
278
|
}
|
package/src/witgen.ts
CHANGED
|
@@ -1,37 +1,38 @@
|
|
|
1
1
|
import {
|
|
2
|
+
AVM_CIRCUIT_PUBLIC_INPUTS_LENGTH,
|
|
2
3
|
AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED,
|
|
3
|
-
AVM_V2_PUBLIC_INPUTS_FLATTENED_SIZE,
|
|
4
4
|
AVM_V2_VERIFICATION_KEY_LENGTH_IN_FIELDS_PADDED,
|
|
5
5
|
CLIENT_IVC_VERIFICATION_KEY_LENGTH_IN_FIELDS,
|
|
6
6
|
} from '@aztec/constants';
|
|
7
7
|
import { Fr } from '@aztec/foundation/fields';
|
|
8
|
-
import {
|
|
8
|
+
import { applyStringFormatting, createLogger } from '@aztec/foundation/log';
|
|
9
|
+
import { type ForeignCallInput, type ForeignCallOutput, Noir } from '@aztec/noir-noir_js';
|
|
9
10
|
import type { AvmCircuitPublicInputs } from '@aztec/stdlib/avm';
|
|
10
11
|
import type { RecursiveProof } from '@aztec/stdlib/proofs';
|
|
11
12
|
import type { VerificationKeyAsFields } from '@aztec/stdlib/vks';
|
|
12
13
|
|
|
13
|
-
import
|
|
14
|
-
|
|
15
|
-
import MockAppCreatorCircuit from '../artifacts/app_creator.json'
|
|
16
|
-
import MockAppReaderCircuit from '../artifacts/app_reader.json'
|
|
17
|
-
import MockAppCreatorVk from '../artifacts/keys/app_creator.vk.data.json'
|
|
18
|
-
import MockAppReaderVk from '../artifacts/keys/app_reader.vk.data.json'
|
|
19
|
-
import MockPrivateKernelInitVk from '../artifacts/keys/mock_private_kernel_init.vk.data.json'
|
|
20
|
-
import MockPrivateKernelInnerVk from '../artifacts/keys/mock_private_kernel_inner.vk.data.json'
|
|
21
|
-
import MockPrivateKernelResetVk from '../artifacts/keys/mock_private_kernel_reset.vk.data.json'
|
|
22
|
-
import MockPrivateKernelTailVk from '../artifacts/keys/mock_private_kernel_tail.vk.data.json'
|
|
23
|
-
import MockRollupBasePrivateVk from '../artifacts/keys/mock_rollup_base_private.vk.data.json'
|
|
24
|
-
import MockRollupBasePublicVk from '../artifacts/keys/mock_rollup_base_public.vk.data.json'
|
|
25
|
-
import MockRollupMergeVk from '../artifacts/keys/mock_rollup_merge.vk.data.json'
|
|
26
|
-
import MockRollupRootVk from '../artifacts/keys/mock_rollup_root.vk.data.json'
|
|
27
|
-
import MockPrivateKernelInitCircuit from '../artifacts/mock_private_kernel_init.json'
|
|
28
|
-
import MockPrivateKernelInnerCircuit from '../artifacts/mock_private_kernel_inner.json'
|
|
29
|
-
import MockPrivateKernelResetCircuit from '../artifacts/mock_private_kernel_reset.json'
|
|
30
|
-
import MockPrivateKernelTailCircuit from '../artifacts/mock_private_kernel_tail.json'
|
|
31
|
-
import MockRollupBasePrivateCircuit from '../artifacts/mock_rollup_base_private.json'
|
|
32
|
-
import MockRollupBasePublicCircuit from '../artifacts/mock_rollup_base_public.json'
|
|
33
|
-
import MockRollupMergeCircuit from '../artifacts/mock_rollup_merge.json'
|
|
34
|
-
import MockRollupRootCircuit from '../artifacts/mock_rollup_root.json'
|
|
14
|
+
import { strict as assert } from 'assert';
|
|
15
|
+
|
|
16
|
+
import MockAppCreatorCircuit from '../artifacts/app_creator.json' with { type: 'json' };
|
|
17
|
+
import MockAppReaderCircuit from '../artifacts/app_reader.json' with { type: 'json' };
|
|
18
|
+
import MockAppCreatorVk from '../artifacts/keys/app_creator.vk.data.json' with { type: 'json' };
|
|
19
|
+
import MockAppReaderVk from '../artifacts/keys/app_reader.vk.data.json' with { type: 'json' };
|
|
20
|
+
import MockPrivateKernelInitVk from '../artifacts/keys/mock_private_kernel_init.vk.data.json' with { type: 'json' };
|
|
21
|
+
import MockPrivateKernelInnerVk from '../artifacts/keys/mock_private_kernel_inner.vk.data.json' with { type: 'json' };
|
|
22
|
+
import MockPrivateKernelResetVk from '../artifacts/keys/mock_private_kernel_reset.vk.data.json' with { type: 'json' };
|
|
23
|
+
import MockPrivateKernelTailVk from '../artifacts/keys/mock_private_kernel_tail.vk.data.json' with { type: 'json' };
|
|
24
|
+
import MockRollupBasePrivateVk from '../artifacts/keys/mock_rollup_base_private.vk.data.json' with { type: 'json' };
|
|
25
|
+
import MockRollupBasePublicVk from '../artifacts/keys/mock_rollup_base_public.vk.data.json' with { type: 'json' };
|
|
26
|
+
import MockRollupMergeVk from '../artifacts/keys/mock_rollup_merge.vk.data.json' with { type: 'json' };
|
|
27
|
+
import MockRollupRootVk from '../artifacts/keys/mock_rollup_root.vk.data.json' with { type: 'json' };
|
|
28
|
+
import MockPrivateKernelInitCircuit from '../artifacts/mock_private_kernel_init.json' with { type: 'json' };
|
|
29
|
+
import MockPrivateKernelInnerCircuit from '../artifacts/mock_private_kernel_inner.json' with { type: 'json' };
|
|
30
|
+
import MockPrivateKernelResetCircuit from '../artifacts/mock_private_kernel_reset.json' with { type: 'json' };
|
|
31
|
+
import MockPrivateKernelTailCircuit from '../artifacts/mock_private_kernel_tail.json' with { type: 'json' };
|
|
32
|
+
import MockRollupBasePrivateCircuit from '../artifacts/mock_rollup_base_private.json' with { type: 'json' };
|
|
33
|
+
import MockRollupBasePublicCircuit from '../artifacts/mock_rollup_base_public.json' with { type: 'json' };
|
|
34
|
+
import MockRollupMergeCircuit from '../artifacts/mock_rollup_merge.json' with { type: 'json' };
|
|
35
|
+
import MockRollupRootCircuit from '../artifacts/mock_rollup_root.json' with { type: 'json' };
|
|
35
36
|
import type {
|
|
36
37
|
AppCreatorInputType,
|
|
37
38
|
AppPublicInputs,
|
|
@@ -76,7 +77,7 @@ export {
|
|
|
76
77
|
|
|
77
78
|
/* eslint-disable camelcase */
|
|
78
79
|
|
|
79
|
-
const
|
|
80
|
+
const log = createLogger('aztec:ivc-test');
|
|
80
81
|
|
|
81
82
|
export function getVkAsFields(vk: {
|
|
82
83
|
keyAsBytes: string;
|
|
@@ -87,8 +88,17 @@ export function getVkAsFields(vk: {
|
|
|
87
88
|
|
|
88
89
|
export const MOCK_MAX_COMMITMENTS_PER_TX = 4;
|
|
89
90
|
|
|
90
|
-
function foreignCallHandler(): Promise<ForeignCallOutput[]> {
|
|
91
|
-
|
|
91
|
+
function foreignCallHandler(name: string, args: ForeignCallInput[]): Promise<ForeignCallOutput[]> {
|
|
92
|
+
if (name === 'debugLog') {
|
|
93
|
+
assert(args.length === 3, 'expected 3 arguments for debugLog: msg, fields_length, fields');
|
|
94
|
+
const [msgRaw, _ignoredFieldsSize, fields] = args;
|
|
95
|
+
const msg: string = msgRaw.map(acvmField => String.fromCharCode(Fr.fromString(acvmField).toNumber())).join('');
|
|
96
|
+
const fieldsFr: Fr[] = fields.map((field: string) => Fr.fromString(field));
|
|
97
|
+
log.verbose('debug_log ' + applyStringFormatting(msg, fieldsFr));
|
|
98
|
+
} else {
|
|
99
|
+
throw new Error('Unexpected foreign call');
|
|
100
|
+
}
|
|
101
|
+
return Promise.resolve([]);
|
|
92
102
|
}
|
|
93
103
|
|
|
94
104
|
export interface WitnessGenResult<PublicInputsType> {
|
|
@@ -206,27 +216,29 @@ export async function witnessGenMockRollupRootCircuit(
|
|
|
206
216
|
};
|
|
207
217
|
}
|
|
208
218
|
|
|
209
|
-
export async function generate3FunctionTestingIVCStack(): Promise<
|
|
219
|
+
export async function generate3FunctionTestingIVCStack(): Promise<
|
|
220
|
+
[string[], Uint8Array[], KernelPublicInputs, string[]]
|
|
221
|
+
> {
|
|
210
222
|
const tx = {
|
|
211
223
|
number_of_calls: '0x1',
|
|
212
224
|
};
|
|
213
225
|
|
|
214
226
|
// Witness gen app and kernels
|
|
215
227
|
const appWitnessGenResult = await witnessGenCreatorAppMockCircuit({ commitments_to_create: ['0x1', '0x2'] });
|
|
216
|
-
|
|
228
|
+
log.debug('generated app mock circuit witness');
|
|
217
229
|
|
|
218
230
|
const initWitnessGenResult = await witnessGenMockPrivateKernelInitCircuit({
|
|
219
231
|
app_inputs: appWitnessGenResult.publicInputs,
|
|
220
232
|
tx,
|
|
221
233
|
app_vk: getVkAsFields(MockAppCreatorVk),
|
|
222
234
|
});
|
|
223
|
-
|
|
235
|
+
log.debug('generated mock private kernel init witness');
|
|
224
236
|
|
|
225
237
|
const tailWitnessGenResult = await witnessGenMockPrivateKernelTailCircuit({
|
|
226
238
|
prev_kernel_public_inputs: initWitnessGenResult.publicInputs,
|
|
227
|
-
kernel_vk: getVkAsFields(
|
|
239
|
+
kernel_vk: getVkAsFields(MockPrivateKernelInitVk),
|
|
228
240
|
});
|
|
229
|
-
|
|
241
|
+
log.debug('generated mock private kernel tail witness');
|
|
230
242
|
|
|
231
243
|
// Create client IVC proof
|
|
232
244
|
const bytecodes = [
|
|
@@ -236,10 +248,18 @@ export async function generate3FunctionTestingIVCStack(): Promise<[string[], Uin
|
|
|
236
248
|
];
|
|
237
249
|
const witnessStack = [appWitnessGenResult.witness, initWitnessGenResult.witness, tailWitnessGenResult.witness];
|
|
238
250
|
|
|
239
|
-
|
|
251
|
+
const precomputedVks = [
|
|
252
|
+
MockAppCreatorVk.keyAsBytes,
|
|
253
|
+
MockPrivateKernelInitVk.keyAsBytes,
|
|
254
|
+
MockPrivateKernelTailVk.keyAsBytes,
|
|
255
|
+
];
|
|
256
|
+
|
|
257
|
+
return [bytecodes, witnessStack, tailWitnessGenResult.publicInputs, precomputedVks];
|
|
240
258
|
}
|
|
241
259
|
|
|
242
|
-
export async function generate6FunctionTestingIVCStack(): Promise<
|
|
260
|
+
export async function generate6FunctionTestingIVCStack(): Promise<
|
|
261
|
+
[string[], Uint8Array[], KernelPublicInputs, string[]]
|
|
262
|
+
> {
|
|
243
263
|
const tx = {
|
|
244
264
|
number_of_calls: '0x2',
|
|
245
265
|
};
|
|
@@ -293,7 +313,16 @@ export async function generate6FunctionTestingIVCStack(): Promise<[string[], Uin
|
|
|
293
313
|
tailWitnessGenResult.witness,
|
|
294
314
|
];
|
|
295
315
|
|
|
296
|
-
|
|
316
|
+
const precomputedVks = [
|
|
317
|
+
MockAppCreatorVk.keyAsBytes,
|
|
318
|
+
MockPrivateKernelInitVk.keyAsBytes,
|
|
319
|
+
MockAppReaderVk.keyAsBytes,
|
|
320
|
+
MockPrivateKernelInnerVk.keyAsBytes,
|
|
321
|
+
MockPrivateKernelResetVk.keyAsBytes,
|
|
322
|
+
MockPrivateKernelTailVk.keyAsBytes,
|
|
323
|
+
];
|
|
324
|
+
|
|
325
|
+
return [bytecodes, witnessStack, tailWitnessGenResult.publicInputs, precomputedVks];
|
|
297
326
|
}
|
|
298
327
|
|
|
299
328
|
export function mapRecursiveProofToNoir<N extends number>(proof: RecursiveProof<N>): FixedLengthArray<string, N> {
|
|
@@ -337,11 +366,10 @@ export function mapAvmVerificationKeyToNoir(
|
|
|
337
366
|
|
|
338
367
|
export function mapAvmPublicInputsToNoir(
|
|
339
368
|
publicInputs: AvmCircuitPublicInputs,
|
|
340
|
-
): FixedLengthArray<string, typeof
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
if (serialized.length != AVM_V2_PUBLIC_INPUTS_FLATTENED_SIZE) {
|
|
369
|
+
): FixedLengthArray<string, typeof AVM_CIRCUIT_PUBLIC_INPUTS_LENGTH> {
|
|
370
|
+
const serialized = publicInputs.toFields();
|
|
371
|
+
if (serialized.length != AVM_CIRCUIT_PUBLIC_INPUTS_LENGTH) {
|
|
344
372
|
throw new Error('Invalid number of AVM public inputs');
|
|
345
373
|
}
|
|
346
|
-
return serialized.map(x => x.toString()) as FixedLengthArray<string, typeof
|
|
374
|
+
return serialized.map(x => x.toString()) as FixedLengthArray<string, typeof AVM_CIRCUIT_PUBLIC_INPUTS_LENGTH>;
|
|
347
375
|
}
|