@aztec/ivc-integration 3.0.0-canary.a9708bd → 3.0.0-devnet.2-patch.1
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 +190 -1
- package/artifacts/app_reader.json +190 -1
- package/artifacts/keys/avm.vk +0 -0
- package/artifacts/keys/mock_hiding.ivc.vk +0 -0
- package/artifacts/keys/mock_rollup_root_verifier.sol +2219 -5052
- package/artifacts/mock_hiding.json +224 -1
- package/artifacts/mock_private_kernel_init.json +287 -1
- package/artifacts/mock_private_kernel_inner.json +337 -1
- package/artifacts/mock_private_kernel_reset.json +273 -1
- package/artifacts/mock_private_kernel_tail.json +242 -1
- package/artifacts/mock_rollup_root.json +241 -1
- package/artifacts/mock_rollup_tx_base_private.json +232 -0
- package/artifacts/mock_rollup_tx_base_public.json +1420 -0
- package/artifacts/mock_rollup_tx_merge.json +297 -0
- package/dest/bb_working_directory.d.ts +1 -1
- package/dest/index.d.ts +1 -1
- package/dest/prove_native.d.ts +6 -6
- package/dest/prove_native.d.ts.map +1 -1
- package/dest/prove_native.js +22 -39
- package/dest/scripts/generate_declaration_files.d.ts +1 -1
- package/dest/scripts/generate_declaration_files.js +0 -6
- package/dest/scripts/generate_ts_from_abi.d.ts +1 -1
- package/dest/scripts/generate_ts_from_abi.js +3 -3
- package/dest/serve.d.ts +1 -1
- package/dest/serve.js +34 -17
- package/dest/types/index.d.ts +26 -26
- package/dest/types/index.d.ts.map +1 -1
- package/dest/types/index.js +8 -8
- package/dest/witgen.d.ts +52 -22
- package/dest/witgen.d.ts.map +1 -1
- package/dest/witgen.js +48 -47
- package/package.json +23 -25
- package/src/prove_native.ts +26 -59
- package/src/scripts/generate_declaration_files.ts +0 -8
- package/src/scripts/generate_ts_from_abi.ts +3 -3
- package/src/serve.ts +43 -16
- package/src/types/index.ts +31 -31
- package/src/witgen.ts +60 -34
- package/artifacts/keys/app_creator.vk.data.d.json.ts +0 -2
- package/artifacts/keys/app_creator.vk.data.json +0 -132
- package/artifacts/keys/app_reader.vk.data.d.json.ts +0 -2
- package/artifacts/keys/app_reader.vk.data.json +0 -132
- package/artifacts/keys/mock_hiding.vk.data.d.json.ts +0 -2
- package/artifacts/keys/mock_hiding.vk.data.json +0 -132
- package/artifacts/keys/mock_private_kernel_init.vk.data.d.json.ts +0 -2
- package/artifacts/keys/mock_private_kernel_init.vk.data.json +0 -132
- package/artifacts/keys/mock_private_kernel_inner.vk.data.d.json.ts +0 -2
- package/artifacts/keys/mock_private_kernel_inner.vk.data.json +0 -132
- package/artifacts/keys/mock_private_kernel_reset.vk.data.d.json.ts +0 -2
- package/artifacts/keys/mock_private_kernel_reset.vk.data.json +0 -132
- package/artifacts/keys/mock_private_kernel_tail.vk.data.d.json.ts +0 -2
- package/artifacts/keys/mock_private_kernel_tail.vk.data.json +0 -132
- package/artifacts/keys/mock_rollup_base_private.vk.data.d.json.ts +0 -2
- package/artifacts/keys/mock_rollup_base_private.vk.data.json +0 -120
- package/artifacts/keys/mock_rollup_base_public.vk.data.d.json.ts +0 -2
- package/artifacts/keys/mock_rollup_base_public.vk.data.json +0 -120
- package/artifacts/keys/mock_rollup_merge.vk.data.d.json.ts +0 -2
- package/artifacts/keys/mock_rollup_merge.vk.data.json +0 -120
- package/artifacts/keys/mock_rollup_root.vk.data.d.json.ts +0 -2
- package/artifacts/keys/mock_rollup_root.vk.data.json +0 -64
- package/artifacts/mock_rollup_base_private.json +0 -1
- package/artifacts/mock_rollup_base_public.json +0 -1
- package/artifacts/mock_rollup_merge.json +0 -1
- package/dest/prove_wasm.d.ts +0 -4
- package/dest/prove_wasm.d.ts.map +0 -1
- package/dest/prove_wasm.js +0 -36
- package/src/prove_wasm.ts +0 -57
- /package/artifacts/{mock_rollup_base_private.d.json.ts → mock_rollup_tx_base_private.d.json.ts} +0 -0
- /package/artifacts/{mock_rollup_base_public.d.json.ts → mock_rollup_tx_base_public.d.json.ts} +0 -0
- /package/artifacts/{mock_rollup_merge.d.json.ts → mock_rollup_tx_merge.d.json.ts} +0 -0
package/src/prove_native.ts
CHANGED
|
@@ -4,70 +4,51 @@ import {
|
|
|
4
4
|
PUBLIC_INPUTS_FILENAME,
|
|
5
5
|
type UltraHonkFlavor,
|
|
6
6
|
VK_FILENAME,
|
|
7
|
-
executeBbClientIvcProof,
|
|
8
|
-
extractVkData,
|
|
9
7
|
generateAvmProof,
|
|
10
8
|
generateProof,
|
|
11
|
-
|
|
12
|
-
readClientIVCProofFromOutputDirectory,
|
|
13
|
-
readProofAsFields,
|
|
9
|
+
readProofsFromOutputDirectory,
|
|
14
10
|
verifyAvmProof,
|
|
15
11
|
verifyProof,
|
|
16
12
|
} from '@aztec/bb-prover';
|
|
17
13
|
import {
|
|
18
14
|
AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED,
|
|
19
15
|
AVM_V2_VERIFICATION_KEY_LENGTH_IN_FIELDS_PADDED,
|
|
16
|
+
CHONK_PROOF_LENGTH,
|
|
17
|
+
HIDING_KERNEL_IO_PUBLIC_INPUTS_SIZE,
|
|
20
18
|
NESTED_RECURSIVE_PROOF_LENGTH,
|
|
21
19
|
RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
|
|
22
|
-
TUBE_PROOF_LENGTH,
|
|
23
20
|
} from '@aztec/constants';
|
|
24
|
-
import { Fr } from '@aztec/foundation/
|
|
21
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
25
22
|
import type { Logger } from '@aztec/foundation/log';
|
|
26
23
|
import { BufferReader } from '@aztec/foundation/serialize';
|
|
27
24
|
import type { AvmCircuitInputs, AvmCircuitPublicInputs } from '@aztec/stdlib/avm';
|
|
28
25
|
import { makeProofAndVerificationKey } from '@aztec/stdlib/interfaces/server';
|
|
29
26
|
import type { NoirCompiledCircuit } from '@aztec/stdlib/noir';
|
|
30
|
-
import
|
|
27
|
+
import { Proof, RecursiveProof } from '@aztec/stdlib/proofs';
|
|
31
28
|
import { enhanceProofWithPiValidationFlag } from '@aztec/stdlib/rollup';
|
|
32
|
-
import { VerificationKeyAsFields,
|
|
29
|
+
import { VerificationKeyAsFields, VerificationKeyData } from '@aztec/stdlib/vks';
|
|
33
30
|
|
|
34
31
|
import * as fs from 'fs/promises';
|
|
35
|
-
import { Encoder } from 'msgpackr';
|
|
36
32
|
import * as path from 'path';
|
|
37
33
|
|
|
38
|
-
export async function
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const stepToStruct = (bytecode: string, index: number) => {
|
|
47
|
-
return {
|
|
48
|
-
bytecode: Buffer.from(bytecode, 'base64'),
|
|
49
|
-
witness: witnessStack[index],
|
|
50
|
-
vk: Buffer.from(vks[index], 'hex'),
|
|
51
|
-
functionName: `unknown_${index}`,
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
const encoded = new Encoder({ useRecords: false }).pack(bytecodes.map(stepToStruct));
|
|
55
|
-
const ivcInputsPath = path.join(bbWorkingDirectory, 'ivc-inputs.msgpack');
|
|
56
|
-
await fs.writeFile(ivcInputsPath, encoded);
|
|
34
|
+
export async function proofBytesToRecursiveProof(
|
|
35
|
+
proofAsFields: Uint8Array[],
|
|
36
|
+
vkBytes: Uint8Array,
|
|
37
|
+
): Promise<RecursiveProof<typeof CHONK_PROOF_LENGTH>> {
|
|
38
|
+
const vk = await VerificationKeyAsFields.fromFrBuffer(Buffer.from(vkBytes));
|
|
39
|
+
const numCustomPublicInputs = vk.numPublicInputs - HIDING_KERNEL_IO_PUBLIC_INPUTS_SIZE;
|
|
40
|
+
// Convert Uint8Array fields to Fr instances
|
|
41
|
+
const fields = proofAsFields.map(f => Fr.fromBuffer(Buffer.from(f)));
|
|
57
42
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
bbWorkingDirectory,
|
|
61
|
-
ivcInputsPath,
|
|
62
|
-
logger.info,
|
|
63
|
-
true,
|
|
64
|
-
);
|
|
43
|
+
// Slice off custom public inputs from the beginning.
|
|
44
|
+
const fieldsWithoutPublicInputs = fields.slice(numCustomPublicInputs);
|
|
65
45
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
46
|
+
// Convert fields to binary buffer
|
|
47
|
+
const proofBuffer = Buffer.concat(proofAsFields.slice(numCustomPublicInputs));
|
|
69
48
|
|
|
70
|
-
|
|
49
|
+
// Create Proof directly (not using fromBuffer which expects different format)
|
|
50
|
+
const proof = new Proof(proofBuffer, numCustomPublicInputs);
|
|
51
|
+
return new RecursiveProof(fieldsWithoutPublicInputs, proof, true, CHONK_PROOF_LENGTH);
|
|
71
52
|
}
|
|
72
53
|
|
|
73
54
|
async function verifyProofWithKey(
|
|
@@ -93,22 +74,6 @@ async function verifyProofWithKey(
|
|
|
93
74
|
logger.info(`Successfully verified proof from key in ${result.durationMs} ms`);
|
|
94
75
|
}
|
|
95
76
|
|
|
96
|
-
export async function proveTube(pathToBB: string, workingDirectory: string, logger: Logger) {
|
|
97
|
-
const tubeResult = await generateTubeProof(pathToBB, workingDirectory, workingDirectory.concat('/vk'), logger.info);
|
|
98
|
-
|
|
99
|
-
if (tubeResult.status != BB_RESULT.SUCCESS) {
|
|
100
|
-
throw new Error('Failed to prove tube');
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const tubeVK = await extractVkData(tubeResult.vkDirectoryPath!);
|
|
104
|
-
const tubeProof = await readProofAsFields(tubeResult.proofPath!, tubeVK, TUBE_PROOF_LENGTH, logger);
|
|
105
|
-
|
|
106
|
-
// Sanity check the tube proof
|
|
107
|
-
await verifyProofWithKey(pathToBB, workingDirectory, tubeVK, tubeProof.binaryProof, 'ultra_rollup_honk', logger);
|
|
108
|
-
|
|
109
|
-
return makeProofAndVerificationKey(tubeProof, tubeVK);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
77
|
async function proveRollupCircuit<T extends UltraHonkFlavor, ProofLength extends number>(
|
|
113
78
|
name: string,
|
|
114
79
|
pathToBB: string,
|
|
@@ -120,11 +85,13 @@ async function proveRollupCircuit<T extends UltraHonkFlavor, ProofLength extends
|
|
|
120
85
|
proofLength: ProofLength,
|
|
121
86
|
) {
|
|
122
87
|
await fs.writeFile(path.join(workingDirectory, 'witness.gz'), witness);
|
|
88
|
+
const vkBuffer = Buffer.from(circuit.verificationKey.bytes, 'hex');
|
|
123
89
|
const proofResult = await generateProof(
|
|
124
90
|
pathToBB,
|
|
125
91
|
workingDirectory,
|
|
126
92
|
name,
|
|
127
93
|
Buffer.from(circuit.bytecode, 'base64'),
|
|
94
|
+
vkBuffer,
|
|
128
95
|
path.join(workingDirectory, 'witness.gz'),
|
|
129
96
|
flavor,
|
|
130
97
|
logger,
|
|
@@ -134,8 +101,8 @@ async function proveRollupCircuit<T extends UltraHonkFlavor, ProofLength extends
|
|
|
134
101
|
throw new Error(`Failed to generate proof for ${name} with flavor ${flavor}`);
|
|
135
102
|
}
|
|
136
103
|
|
|
137
|
-
const vk = await
|
|
138
|
-
const proof = await
|
|
104
|
+
const vk = await VerificationKeyData.fromFrBuffer(vkBuffer);
|
|
105
|
+
const proof = await readProofsFromOutputDirectory(proofResult.proofPath!, vk, proofLength, logger);
|
|
139
106
|
|
|
140
107
|
await verifyProofWithKey(pathToBB, workingDirectory, vk, proof.binaryProof, flavor, logger);
|
|
141
108
|
|
|
@@ -193,7 +160,7 @@ export async function proveAvm(
|
|
|
193
160
|
publicInputs: AvmCircuitPublicInputs;
|
|
194
161
|
}> {
|
|
195
162
|
// The paths for the barretenberg binary and the write path are hardcoded for now.
|
|
196
|
-
const bbPath = path.resolve('../../barretenberg/cpp/build/bin/bb');
|
|
163
|
+
const bbPath = path.resolve('../../barretenberg/cpp/build/bin/bb-avm');
|
|
197
164
|
|
|
198
165
|
// Then we prove.
|
|
199
166
|
const proofRes = await generateAvmProof(bbPath, workingDirectory, avmCircuitInputs, logger);
|
|
@@ -9,11 +9,6 @@ const circuit: NoirCompiledCircuit;
|
|
|
9
9
|
export = circuit;
|
|
10
10
|
`;
|
|
11
11
|
|
|
12
|
-
const vk = `\
|
|
13
|
-
const vk: { keyAsBytes: string; keyAsFields: string[] };
|
|
14
|
-
export = vk;
|
|
15
|
-
`;
|
|
16
|
-
|
|
17
12
|
async function generateDeclarationFor(target: string, content: string) {
|
|
18
13
|
const files = await readdir(target);
|
|
19
14
|
for (const file of files) {
|
|
@@ -28,6 +23,3 @@ async function generateDeclarationFor(target: string, content: string) {
|
|
|
28
23
|
|
|
29
24
|
// Generate declaration files for contracts
|
|
30
25
|
await generateDeclarationFor(fileURLToPath(new URL('../../artifacts', import.meta.url).href), contract);
|
|
31
|
-
|
|
32
|
-
// Generate declaration files for vks
|
|
33
|
-
await generateDeclarationFor(fileURLToPath(new URL('../../artifacts/keys', import.meta.url).href), vk);
|
|
@@ -15,9 +15,9 @@ const circuits = [
|
|
|
15
15
|
'mock_private_kernel_inner',
|
|
16
16
|
'mock_private_kernel_reset',
|
|
17
17
|
'mock_private_kernel_tail',
|
|
18
|
-
'
|
|
19
|
-
'
|
|
20
|
-
'
|
|
18
|
+
'mock_rollup_tx_base_public',
|
|
19
|
+
'mock_rollup_tx_base_private',
|
|
20
|
+
'mock_rollup_tx_merge',
|
|
21
21
|
'mock_rollup_root',
|
|
22
22
|
];
|
|
23
23
|
|
package/src/serve.ts
CHANGED
|
@@ -1,12 +1,27 @@
|
|
|
1
|
+
import { AztecClientBackend, Barretenberg } from '@aztec/bb.js';
|
|
1
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
3
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
4
|
+
import {
|
|
5
|
+
MockAppCreatorCircuit,
|
|
6
|
+
MockHidingCircuit,
|
|
7
|
+
MockPrivateKernelInitCircuit,
|
|
8
|
+
MockPrivateKernelTailCircuit,
|
|
9
|
+
generateTestingIVCStack,
|
|
10
|
+
} from './witgen.js';
|
|
5
11
|
|
|
6
12
|
const logger = createLogger('aztec:ivc-test');
|
|
7
13
|
|
|
8
14
|
/* eslint-disable no-console */
|
|
9
15
|
|
|
16
|
+
// Expose APIs on window for browser testing
|
|
17
|
+
(window as any).Barretenberg = Barretenberg;
|
|
18
|
+
(window as any).AztecClientBackend = AztecClientBackend;
|
|
19
|
+
(window as any).generateTestingIVCStack = generateTestingIVCStack;
|
|
20
|
+
(window as any).MockAppCreatorCircuit = MockAppCreatorCircuit;
|
|
21
|
+
(window as any).MockPrivateKernelInitCircuit = MockPrivateKernelInitCircuit;
|
|
22
|
+
(window as any).MockPrivateKernelTailCircuit = MockPrivateKernelTailCircuit;
|
|
23
|
+
(window as any).MockHidingCircuit = MockHidingCircuit;
|
|
24
|
+
|
|
10
25
|
// Function to set up the output element and redirect all console output
|
|
11
26
|
function setupConsoleOutput() {
|
|
12
27
|
const container = document.createElement('div');
|
|
@@ -78,20 +93,32 @@ function setupConsoleOutput() {
|
|
|
78
93
|
};
|
|
79
94
|
}
|
|
80
95
|
|
|
81
|
-
|
|
96
|
+
// Only set up the interactive UI if this is not being used for automated testing
|
|
97
|
+
if (!document.getElementById('status')) {
|
|
98
|
+
document.addEventListener('DOMContentLoaded', function () {
|
|
99
|
+
setupConsoleOutput(); // Initialize console output capture
|
|
100
|
+
|
|
101
|
+
const button = document.createElement('button');
|
|
102
|
+
button.innerText = 'Run Test';
|
|
103
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
104
|
+
button.addEventListener('click', async () => {
|
|
105
|
+
logger.info(`generating circuit and witness...`);
|
|
106
|
+
const [bytecodes, witnessStack, _publicInputs, precomputedVks] = await generateTestingIVCStack(1, 0);
|
|
107
|
+
logger.info(`done. proving and verifying...`);
|
|
108
|
+
|
|
109
|
+
const barretenberg = await Barretenberg.initSingleton({
|
|
110
|
+
threads: 16,
|
|
111
|
+
logger: (m: string) => logger.info(m),
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
const backend = new AztecClientBackend(bytecodes, barretenberg);
|
|
115
|
+
const [, proof, vk] = await backend.prove(witnessStack, precomputedVks);
|
|
116
|
+
const verified = await backend.verify(proof, vk);
|
|
82
117
|
|
|
83
|
-
|
|
84
|
-
setupConsoleOutput(); // Initialize console output capture
|
|
118
|
+
logger.info(`verified? ${verified}`);
|
|
85
119
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
button.addEventListener('click', async () => {
|
|
90
|
-
logger.info(`generating circuit and witness...`);
|
|
91
|
-
const [bytecodes, witnessStack, _publicInputs, precomputedVks] = await generateTestingIVCStack(1, 0);
|
|
92
|
-
logger.info(`done. proving and verifying...`);
|
|
93
|
-
const verified = await proveThenVerifyAztecClient(bytecodes, witnessStack, precomputedVks);
|
|
94
|
-
logger.info(`verified? ${verified}`);
|
|
120
|
+
await Barretenberg.destroySingleton();
|
|
121
|
+
});
|
|
122
|
+
document.body.appendChild(button);
|
|
95
123
|
});
|
|
96
|
-
|
|
97
|
-
});
|
|
124
|
+
}
|
package/src/types/index.ts
CHANGED
|
@@ -37,19 +37,21 @@ export type PrivateKernelPublicInputs = {
|
|
|
37
37
|
read_requests: FixedLengthArray<Field, 4>;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
export type
|
|
40
|
+
export type ChonkProofData = {
|
|
41
41
|
public_inputs: KernelPublicInputs;
|
|
42
|
-
proof: FixedLengthArray<Field,
|
|
43
|
-
vk_data: VerificationKey<
|
|
42
|
+
proof: FixedLengthArray<Field, 1963>;
|
|
43
|
+
vk_data: VerificationKey<127>;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
export type AvmCircuitPublicInputs = {
|
|
47
47
|
global_variables: GlobalVariables;
|
|
48
|
+
protocol_contracts: ProtocolContracts;
|
|
48
49
|
start_tree_snapshots: TreeSnapshots;
|
|
49
50
|
start_gas_used: Gas;
|
|
50
51
|
gas_settings: GasSettings;
|
|
51
52
|
effective_gas_fees: GasFees;
|
|
52
53
|
fee_payer: AztecAddress;
|
|
54
|
+
prover_id: Field;
|
|
53
55
|
public_call_request_array_lengths: PublicCallRequestArrayLengths;
|
|
54
56
|
public_setup_call_requests: FixedLengthArray<PublicCallRequest, 32>;
|
|
55
57
|
public_app_logic_call_requests: FixedLengthArray<PublicCallRequest, 32>;
|
|
@@ -77,6 +79,10 @@ export type GlobalVariables = {
|
|
|
77
79
|
gas_fees: GasFees;
|
|
78
80
|
}
|
|
79
81
|
|
|
82
|
+
export type ProtocolContracts = {
|
|
83
|
+
derived_addresses: FixedLengthArray<AztecAddress, 11>;
|
|
84
|
+
}
|
|
85
|
+
|
|
80
86
|
export type TreeSnapshots = {
|
|
81
87
|
l1_to_l2_message_tree: AppendOnlyTreeSnapshot;
|
|
82
88
|
note_hash_tree: AppendOnlyTreeSnapshot;
|
|
@@ -134,7 +140,6 @@ export type AvmAccumulatedDataArrayLengths = {
|
|
|
134
140
|
note_hashes: u32;
|
|
135
141
|
nullifiers: u32;
|
|
136
142
|
l2_to_l1_msgs: u32;
|
|
137
|
-
public_logs: u32;
|
|
138
143
|
public_data_writes: u32;
|
|
139
144
|
}
|
|
140
145
|
|
|
@@ -142,7 +147,7 @@ export type AvmAccumulatedData = {
|
|
|
142
147
|
note_hashes: FixedLengthArray<Field, 64>;
|
|
143
148
|
nullifiers: FixedLengthArray<Field, 64>;
|
|
144
149
|
l2_to_l1_msgs: FixedLengthArray<Scoped, 8>;
|
|
145
|
-
public_logs:
|
|
150
|
+
public_logs: PublicLogs;
|
|
146
151
|
public_data_writes: FixedLengthArray<PublicDataWrite, 64>;
|
|
147
152
|
}
|
|
148
153
|
|
|
@@ -152,7 +157,7 @@ export type EthAddress = {
|
|
|
152
157
|
|
|
153
158
|
export type AppendOnlyTreeSnapshot = {
|
|
154
159
|
root: Field;
|
|
155
|
-
next_available_leaf_index:
|
|
160
|
+
next_available_leaf_index: Field;
|
|
156
161
|
}
|
|
157
162
|
|
|
158
163
|
export type Scoped = {
|
|
@@ -160,9 +165,9 @@ export type Scoped = {
|
|
|
160
165
|
contract_address: AztecAddress;
|
|
161
166
|
}
|
|
162
167
|
|
|
163
|
-
export type
|
|
164
|
-
|
|
165
|
-
|
|
168
|
+
export type PublicLogs = {
|
|
169
|
+
length: u32;
|
|
170
|
+
payload: FixedLengthArray<Field, 4096>;
|
|
166
171
|
}
|
|
167
172
|
|
|
168
173
|
export type PublicDataWrite = {
|
|
@@ -175,18 +180,13 @@ export type L2ToL1Message = {
|
|
|
175
180
|
content: Field;
|
|
176
181
|
}
|
|
177
182
|
|
|
178
|
-
export type Log = {
|
|
179
|
-
fields: FixedLengthArray<Field, 13>;
|
|
180
|
-
length: u32;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
183
|
export type RollupPublicInputs = {
|
|
184
184
|
accumulated: u32;
|
|
185
185
|
}
|
|
186
186
|
|
|
187
187
|
export type PreviousRollupData = {
|
|
188
188
|
base_or_merge_public_inputs: RollupPublicInputs;
|
|
189
|
-
proof: FixedLengthArray<Field,
|
|
189
|
+
proof: FixedLengthArray<Field, 531>;
|
|
190
190
|
vk: VerificationKey<115>;
|
|
191
191
|
}
|
|
192
192
|
|
|
@@ -291,45 +291,45 @@ export async function MockPrivateKernelTail(prev_kernel_public_inputs: PrivateKe
|
|
|
291
291
|
const { returnValue } = await program.execute(args, foreignCallHandler);
|
|
292
292
|
return returnValue as KernelPublicInputs;
|
|
293
293
|
}
|
|
294
|
-
export type
|
|
295
|
-
|
|
294
|
+
export type MockRollupTxBasePublicInputType = {
|
|
295
|
+
chonk_proof_data: ChonkProofData;
|
|
296
296
|
verification_key: VerificationKey<1000>;
|
|
297
297
|
proof: FixedLengthArray<Field, 20000>;
|
|
298
298
|
public_inputs: AvmCircuitPublicInputs;
|
|
299
299
|
}
|
|
300
300
|
|
|
301
|
-
export type
|
|
301
|
+
export type MockRollupTxBasePublicReturnType = RollupPublicInputs;
|
|
302
302
|
|
|
303
303
|
|
|
304
|
-
export async function
|
|
305
|
-
const program = new Noir(
|
|
306
|
-
const args: InputMap = {
|
|
304
|
+
export async function MockRollupTxBasePublic(chonk_proof_data: ChonkProofData, verification_key: VerificationKey<1000>, proof: FixedLengthArray<Field, 20000>, public_inputs: AvmCircuitPublicInputs, MockRollupTxBasePublic_circuit: CompiledCircuit, foreignCallHandler?: ForeignCallHandler): Promise<RollupPublicInputs> {
|
|
305
|
+
const program = new Noir(MockRollupTxBasePublic_circuit);
|
|
306
|
+
const args: InputMap = { chonk_proof_data, verification_key, proof, public_inputs };
|
|
307
307
|
const { returnValue } = await program.execute(args, foreignCallHandler);
|
|
308
308
|
return returnValue as RollupPublicInputs;
|
|
309
309
|
}
|
|
310
|
-
export type
|
|
311
|
-
|
|
310
|
+
export type MockRollupTxBasePrivateInputType = {
|
|
311
|
+
chonk_proof_data: ChonkProofData;
|
|
312
312
|
}
|
|
313
313
|
|
|
314
|
-
export type
|
|
314
|
+
export type MockRollupTxBasePrivateReturnType = RollupPublicInputs;
|
|
315
315
|
|
|
316
316
|
|
|
317
|
-
export async function
|
|
318
|
-
const program = new Noir(
|
|
319
|
-
const args: InputMap = {
|
|
317
|
+
export async function MockRollupTxBasePrivate(chonk_proof_data: ChonkProofData, MockRollupTxBasePrivate_circuit: CompiledCircuit, foreignCallHandler?: ForeignCallHandler): Promise<RollupPublicInputs> {
|
|
318
|
+
const program = new Noir(MockRollupTxBasePrivate_circuit);
|
|
319
|
+
const args: InputMap = { chonk_proof_data };
|
|
320
320
|
const { returnValue } = await program.execute(args, foreignCallHandler);
|
|
321
321
|
return returnValue as RollupPublicInputs;
|
|
322
322
|
}
|
|
323
|
-
export type
|
|
323
|
+
export type MockRollupTxMergeInputType = {
|
|
324
324
|
a: PreviousRollupData;
|
|
325
325
|
b: PreviousRollupData;
|
|
326
326
|
}
|
|
327
327
|
|
|
328
|
-
export type
|
|
328
|
+
export type MockRollupTxMergeReturnType = RollupPublicInputs;
|
|
329
329
|
|
|
330
330
|
|
|
331
|
-
export async function
|
|
332
|
-
const program = new Noir(
|
|
331
|
+
export async function MockRollupTxMerge(a: PreviousRollupData, b: PreviousRollupData, MockRollupTxMerge_circuit: CompiledCircuit, foreignCallHandler?: ForeignCallHandler): Promise<RollupPublicInputs> {
|
|
332
|
+
const program = new Noir(MockRollupTxMerge_circuit);
|
|
333
333
|
const args: InputMap = { a, b };
|
|
334
334
|
const { returnValue } = await program.execute(args, foreignCallHandler);
|
|
335
335
|
return returnValue as RollupPublicInputs;
|
package/src/witgen.ts
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
MEGA_VK_LENGTH_IN_FIELDS,
|
|
5
5
|
} from '@aztec/constants';
|
|
6
6
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
7
|
-
import { Fr } from '@aztec/foundation/
|
|
7
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
8
8
|
import { applyStringFormatting, createLogger } from '@aztec/foundation/log';
|
|
9
9
|
import { type ForeignCallInput, type ForeignCallOutput, Noir } from '@aztec/noir-noir_js';
|
|
10
10
|
import type { AvmCircuitPublicInputs } from '@aztec/stdlib/avm';
|
|
@@ -12,29 +12,19 @@ import type { RecursiveProof } from '@aztec/stdlib/proofs';
|
|
|
12
12
|
import { VerificationKeyAsFields } from '@aztec/stdlib/vks';
|
|
13
13
|
|
|
14
14
|
import { strict as assert } from 'assert';
|
|
15
|
+
import { ungzip } from 'pako';
|
|
15
16
|
|
|
16
17
|
import MockAppCreatorCircuit from '../artifacts/app_creator.json' with { type: 'json' };
|
|
17
18
|
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 MockHidingVk from '../artifacts/keys/mock_hiding.vk.data.json' with { type: 'json' };
|
|
21
|
-
import MockPrivateKernelInitVk from '../artifacts/keys/mock_private_kernel_init.vk.data.json' with { type: 'json' };
|
|
22
|
-
import MockPrivateKernelInnerVk from '../artifacts/keys/mock_private_kernel_inner.vk.data.json' with { type: 'json' };
|
|
23
|
-
import MockPrivateKernelResetVk from '../artifacts/keys/mock_private_kernel_reset.vk.data.json' with { type: 'json' };
|
|
24
|
-
import MockPrivateKernelTailVk from '../artifacts/keys/mock_private_kernel_tail.vk.data.json' with { type: 'json' };
|
|
25
|
-
import MockRollupBasePrivateVk from '../artifacts/keys/mock_rollup_base_private.vk.data.json' with { type: 'json' };
|
|
26
|
-
import MockRollupBasePublicVk from '../artifacts/keys/mock_rollup_base_public.vk.data.json' with { type: 'json' };
|
|
27
|
-
import MockRollupMergeVk from '../artifacts/keys/mock_rollup_merge.vk.data.json' with { type: 'json' };
|
|
28
|
-
import MockRollupRootVk from '../artifacts/keys/mock_rollup_root.vk.data.json' with { type: 'json' };
|
|
29
19
|
import MockHidingCircuit from '../artifacts/mock_hiding.json' with { type: 'json' };
|
|
30
20
|
import MockPrivateKernelInitCircuit from '../artifacts/mock_private_kernel_init.json' with { type: 'json' };
|
|
31
21
|
import MockPrivateKernelInnerCircuit from '../artifacts/mock_private_kernel_inner.json' with { type: 'json' };
|
|
32
22
|
import MockPrivateKernelResetCircuit from '../artifacts/mock_private_kernel_reset.json' with { type: 'json' };
|
|
33
23
|
import MockPrivateKernelTailCircuit from '../artifacts/mock_private_kernel_tail.json' with { type: 'json' };
|
|
34
|
-
import MockRollupBasePrivateCircuit from '../artifacts/mock_rollup_base_private.json' with { type: 'json' };
|
|
35
|
-
import MockRollupBasePublicCircuit from '../artifacts/mock_rollup_base_public.json' with { type: 'json' };
|
|
36
|
-
import MockRollupMergeCircuit from '../artifacts/mock_rollup_merge.json' with { type: 'json' };
|
|
37
24
|
import MockRollupRootCircuit from '../artifacts/mock_rollup_root.json' with { type: 'json' };
|
|
25
|
+
import MockRollupTxBasePrivateCircuit from '../artifacts/mock_rollup_tx_base_private.json' with { type: 'json' };
|
|
26
|
+
import MockRollupTxBasePublicCircuit from '../artifacts/mock_rollup_tx_base_public.json' with { type: 'json' };
|
|
27
|
+
import MockRollupTxMergeCircuit from '../artifacts/mock_rollup_tx_merge.json' with { type: 'json' };
|
|
38
28
|
import type {
|
|
39
29
|
AppCreatorInputType,
|
|
40
30
|
AppPublicInputs,
|
|
@@ -46,15 +36,36 @@ import type {
|
|
|
46
36
|
MockPrivateKernelInnerInputType,
|
|
47
37
|
MockPrivateKernelResetInputType,
|
|
48
38
|
MockPrivateKernelTailInputType,
|
|
49
|
-
MockRollupBasePrivateInputType,
|
|
50
|
-
MockRollupBasePublicInputType,
|
|
51
|
-
MockRollupMergeInputType,
|
|
52
39
|
MockRollupRootInputType,
|
|
40
|
+
MockRollupTxBasePrivateInputType,
|
|
41
|
+
MockRollupTxBasePublicInputType,
|
|
42
|
+
MockRollupTxMergeInputType,
|
|
53
43
|
PrivateKernelPublicInputs,
|
|
54
44
|
RollupPublicInputs,
|
|
55
45
|
VerificationKey,
|
|
56
46
|
} from './types/index.js';
|
|
57
47
|
|
|
48
|
+
// Helper to extract VK from circuit artifact
|
|
49
|
+
function extractVkFromCircuit(circuit: any) {
|
|
50
|
+
return {
|
|
51
|
+
keyAsBytes: circuit.verificationKey.bytes,
|
|
52
|
+
keyAsFields: circuit.verificationKey.fields,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Extract VKs from circuit artifacts
|
|
57
|
+
const MockAppCreatorVk = extractVkFromCircuit(MockAppCreatorCircuit);
|
|
58
|
+
const MockAppReaderVk = extractVkFromCircuit(MockAppReaderCircuit);
|
|
59
|
+
const MockPrivateKernelInitVk = extractVkFromCircuit(MockPrivateKernelInitCircuit);
|
|
60
|
+
const MockPrivateKernelInnerVk = extractVkFromCircuit(MockPrivateKernelInnerCircuit);
|
|
61
|
+
const MockPrivateKernelResetVk = extractVkFromCircuit(MockPrivateKernelResetCircuit);
|
|
62
|
+
const MockPrivateKernelTailVk = extractVkFromCircuit(MockPrivateKernelTailCircuit);
|
|
63
|
+
const MockHidingVk = extractVkFromCircuit(MockHidingCircuit);
|
|
64
|
+
const MockRollupTxBasePrivateVk = extractVkFromCircuit(MockRollupTxBasePrivateCircuit);
|
|
65
|
+
const MockRollupTxBasePublicVk = extractVkFromCircuit(MockRollupTxBasePublicCircuit);
|
|
66
|
+
const MockRollupTxMergeVk = extractVkFromCircuit(MockRollupTxMergeCircuit);
|
|
67
|
+
const MockRollupRootVk = extractVkFromCircuit(MockRollupRootCircuit);
|
|
68
|
+
|
|
58
69
|
// Re export the circuit jsons
|
|
59
70
|
export {
|
|
60
71
|
MockAppCreatorCircuit,
|
|
@@ -70,12 +81,12 @@ export {
|
|
|
70
81
|
MockPrivateKernelTailCircuit,
|
|
71
82
|
MockHidingCircuit,
|
|
72
83
|
MockPrivateKernelTailVk,
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
84
|
+
MockRollupTxBasePrivateCircuit,
|
|
85
|
+
MockRollupTxBasePrivateVk,
|
|
86
|
+
MockRollupTxBasePublicCircuit,
|
|
87
|
+
MockRollupTxBasePublicVk,
|
|
88
|
+
MockRollupTxMergeCircuit,
|
|
89
|
+
MockRollupTxMergeVk,
|
|
79
90
|
MockRollupRootCircuit,
|
|
80
91
|
MockRollupRootVk,
|
|
81
92
|
};
|
|
@@ -192,9 +203,9 @@ export async function witnessGenMockHidingCircuit(
|
|
|
192
203
|
}
|
|
193
204
|
|
|
194
205
|
export async function witnessGenMockPublicBaseCircuit(
|
|
195
|
-
args:
|
|
206
|
+
args: MockRollupTxBasePublicInputType,
|
|
196
207
|
): Promise<WitnessGenResult<RollupPublicInputs>> {
|
|
197
|
-
const program = new Noir(
|
|
208
|
+
const program = new Noir(MockRollupTxBasePublicCircuit);
|
|
198
209
|
const { witness, returnValue } = await program.execute(args, foreignCallHandler);
|
|
199
210
|
return {
|
|
200
211
|
witness,
|
|
@@ -202,10 +213,10 @@ export async function witnessGenMockPublicBaseCircuit(
|
|
|
202
213
|
};
|
|
203
214
|
}
|
|
204
215
|
|
|
205
|
-
export async function
|
|
206
|
-
args:
|
|
216
|
+
export async function witnessGenMockRollupTxBasePrivateCircuit(
|
|
217
|
+
args: MockRollupTxBasePrivateInputType,
|
|
207
218
|
): Promise<WitnessGenResult<RollupPublicInputs>> {
|
|
208
|
-
const program = new Noir(
|
|
219
|
+
const program = new Noir(MockRollupTxBasePrivateCircuit);
|
|
209
220
|
const { witness, returnValue } = await program.execute(args, foreignCallHandler);
|
|
210
221
|
return {
|
|
211
222
|
witness,
|
|
@@ -213,10 +224,10 @@ export async function witnessGenMockRollupBasePrivateCircuit(
|
|
|
213
224
|
};
|
|
214
225
|
}
|
|
215
226
|
|
|
216
|
-
export async function
|
|
217
|
-
args:
|
|
227
|
+
export async function witnessGenMockRollupTxMergeCircuit(
|
|
228
|
+
args: MockRollupTxMergeInputType,
|
|
218
229
|
): Promise<WitnessGenResult<RollupPublicInputs>> {
|
|
219
|
-
const program = new Noir(
|
|
230
|
+
const program = new Noir(MockRollupTxMergeCircuit);
|
|
220
231
|
const { witness, returnValue } = await program.execute(args, foreignCallHandler);
|
|
221
232
|
return {
|
|
222
233
|
witness,
|
|
@@ -241,7 +252,7 @@ export async function generateTestingIVCStack(
|
|
|
241
252
|
// A call to the reader app creates 1 read request. A reset kernel will be run if there are 2 read requests in the
|
|
242
253
|
// public inputs. All read requests must be cleared before running the tail kernel.
|
|
243
254
|
numReaderAppCalls: number,
|
|
244
|
-
): Promise<[
|
|
255
|
+
): Promise<[Uint8Array[], Uint8Array[], KernelPublicInputs, Uint8Array[]]> {
|
|
245
256
|
if (numCreatorAppCalls > 2) {
|
|
246
257
|
throw new Error('The creator app can only be called at most twice.');
|
|
247
258
|
}
|
|
@@ -358,7 +369,22 @@ export async function generateTestingIVCStack(
|
|
|
358
369
|
bytecodes.push(MockHidingCircuit.bytecode);
|
|
359
370
|
vks.push(MockHidingVk.keyAsBytes);
|
|
360
371
|
|
|
361
|
-
|
|
372
|
+
function base64ToUint8Array(base64: string): Uint8Array {
|
|
373
|
+
return Uint8Array.from(atob(base64), c => c.charCodeAt(0));
|
|
374
|
+
}
|
|
375
|
+
function hexToUint8Array(hex: string): Uint8Array {
|
|
376
|
+
const cleaned = hex.replace(/^0x/i, '');
|
|
377
|
+
const bytes = new Uint8Array(cleaned.length / 2);
|
|
378
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
379
|
+
bytes[i] = parseInt(cleaned.slice(i * 2, i * 2 + 2), 16);
|
|
380
|
+
}
|
|
381
|
+
return bytes;
|
|
382
|
+
}
|
|
383
|
+
const rawBytecodes = bytecodes.map(base64ToUint8Array).map((arr: Uint8Array) => ungzip(arr));
|
|
384
|
+
const rawWitnessStack = witnessStack.map((arr: Uint8Array) => ungzip(arr));
|
|
385
|
+
const rawVks = vks.map(hexToUint8Array);
|
|
386
|
+
|
|
387
|
+
return [rawBytecodes, rawWitnessStack, hidingWitnessGenResult.publicInputs, rawVks];
|
|
362
388
|
}
|
|
363
389
|
|
|
364
390
|
export function mapRecursiveProofToNoir<N extends number>(proof: RecursiveProof<N>): FixedLengthArray<string, N> {
|