@aztec/bb-prover 0.87.2 → 0.87.3-nightly.20250528
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/dest/avm_proving_tests/avm_proving_tester.d.ts +3 -10
- package/dest/avm_proving_tests/avm_proving_tester.d.ts.map +1 -1
- package/dest/avm_proving_tests/avm_proving_tester.js +18 -62
- package/dest/bb/execute.d.ts +5 -24
- package/dest/bb/execute.d.ts.map +1 -1
- package/dest/bb/execute.js +31 -106
- package/dest/prover/server/bb_prover.d.ts +5 -5
- package/dest/prover/server/bb_prover.d.ts.map +1 -1
- package/dest/prover/server/bb_prover.js +22 -13
- package/dest/test/test_circuit_prover.d.ts +2 -2
- package/dest/test/test_circuit_prover.d.ts.map +1 -1
- package/dest/test/test_circuit_prover.js +2 -2
- package/dest/verification_key/verification_key_data.d.ts +6 -0
- package/dest/verification_key/verification_key_data.d.ts.map +1 -1
- package/dest/verification_key/verification_key_data.js +16 -16
- package/package.json +18 -16
- package/src/avm_proving_tests/avm_proving_tester.ts +30 -87
- package/src/bb/execute.ts +37 -125
- package/src/prover/server/bb_prover.ts +48 -30
- package/src/test/test_circuit_prover.ts +7 -5
- package/src/verification_key/verification_key_data.ts +20 -13
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED,
|
|
3
3
|
NESTED_RECURSIVE_PROOF_LENGTH,
|
|
4
4
|
NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
|
|
5
5
|
PAIRING_POINTS_SIZE,
|
|
@@ -37,7 +37,7 @@ import {
|
|
|
37
37
|
import { ServerCircuitVks } from '@aztec/noir-protocol-circuits-types/server/vks';
|
|
38
38
|
import type { WitnessMap } from '@aztec/noir-types';
|
|
39
39
|
import { NativeACVMSimulator } from '@aztec/simulator/server';
|
|
40
|
-
import type { AvmCircuitInputs } from '@aztec/stdlib/avm';
|
|
40
|
+
import type { AvmCircuitInputs, AvmCircuitPublicInputs } from '@aztec/stdlib/avm';
|
|
41
41
|
import { ProvingError } from '@aztec/stdlib/errors';
|
|
42
42
|
import {
|
|
43
43
|
type ProofAndVerificationKey,
|
|
@@ -48,19 +48,20 @@ import {
|
|
|
48
48
|
} from '@aztec/stdlib/interfaces/server';
|
|
49
49
|
import type { BaseParityInputs, ParityPublicInputs, RootParityInputs } from '@aztec/stdlib/parity';
|
|
50
50
|
import { Proof, RecursiveProof, makeRecursiveProofFromBinary } from '@aztec/stdlib/proofs';
|
|
51
|
-
import
|
|
52
|
-
BaseOrMergeRollupPublicInputs,
|
|
53
|
-
BlockMergeRollupInputs,
|
|
54
|
-
BlockRootOrBlockMergePublicInputs,
|
|
55
|
-
BlockRootRollupInputs,
|
|
56
|
-
EmptyBlockRootRollupInputs,
|
|
57
|
-
MergeRollupInputs,
|
|
58
|
-
PrivateBaseRollupInputs,
|
|
51
|
+
import {
|
|
52
|
+
type BaseOrMergeRollupPublicInputs,
|
|
53
|
+
type BlockMergeRollupInputs,
|
|
54
|
+
type BlockRootOrBlockMergePublicInputs,
|
|
55
|
+
type BlockRootRollupInputs,
|
|
56
|
+
type EmptyBlockRootRollupInputs,
|
|
57
|
+
type MergeRollupInputs,
|
|
58
|
+
type PrivateBaseRollupInputs,
|
|
59
59
|
PublicBaseRollupInputs,
|
|
60
|
-
RootRollupInputs,
|
|
61
|
-
RootRollupPublicInputs,
|
|
62
|
-
SingleTxBlockRootRollupInputs,
|
|
63
|
-
TubeInputs,
|
|
60
|
+
type RootRollupInputs,
|
|
61
|
+
type RootRollupPublicInputs,
|
|
62
|
+
type SingleTxBlockRootRollupInputs,
|
|
63
|
+
type TubeInputs,
|
|
64
|
+
enhanceProofWithPiValidationFlag,
|
|
64
65
|
} from '@aztec/stdlib/rollup';
|
|
65
66
|
import type { CircuitProvingStats, CircuitWitnessGenerationStats } from '@aztec/stdlib/stats';
|
|
66
67
|
import type { VerificationKeyData } from '@aztec/stdlib/vks';
|
|
@@ -185,9 +186,13 @@ export class BBNativeRollupProver implements ServerCircuitProver {
|
|
|
185
186
|
}))
|
|
186
187
|
public async getAvmProof(
|
|
187
188
|
inputs: AvmCircuitInputs,
|
|
188
|
-
|
|
189
|
+
skipPublicInputsValidation: boolean = false,
|
|
190
|
+
): Promise<ProofAndVerificationKey<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED>> {
|
|
189
191
|
const proofAndVk = await this.createAvmProof(inputs);
|
|
190
|
-
await this.verifyAvmProof(proofAndVk.proof.binaryProof, proofAndVk.verificationKey);
|
|
192
|
+
await this.verifyAvmProof(proofAndVk.proof.binaryProof, proofAndVk.verificationKey, inputs.publicInputs);
|
|
193
|
+
|
|
194
|
+
// TODO(#14234)[Unconditional PIs validation]: remove next lines and directly return proofAndVk
|
|
195
|
+
proofAndVk.proof.proof = enhanceProofWithPiValidationFlag(proofAndVk.proof.proof, skipPublicInputsValidation);
|
|
191
196
|
return proofAndVk;
|
|
192
197
|
}
|
|
193
198
|
|
|
@@ -536,13 +541,13 @@ export class BBNativeRollupProver implements ServerCircuitProver {
|
|
|
536
541
|
|
|
537
542
|
private async createAvmProof(
|
|
538
543
|
input: AvmCircuitInputs,
|
|
539
|
-
): Promise<ProofAndVerificationKey<typeof
|
|
544
|
+
): Promise<ProofAndVerificationKey<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED>> {
|
|
540
545
|
const operation = async (bbWorkingDirectory: string) => {
|
|
541
546
|
const provingResult = await this.generateAvmProofWithBB(input, bbWorkingDirectory);
|
|
542
547
|
|
|
543
548
|
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/6773): this VK data format is wrong.
|
|
544
549
|
// In particular, the number of public inputs, etc will be wrong.
|
|
545
|
-
const verificationKey = await extractAvmVkData(provingResult.
|
|
550
|
+
const verificationKey = await extractAvmVkData(provingResult.vkDirectoryPath!);
|
|
546
551
|
const avmProof = await this.readAvmProofAsFields(provingResult.proofPath!, verificationKey);
|
|
547
552
|
|
|
548
553
|
const circuitType = 'avm-circuit' as const;
|
|
@@ -579,7 +584,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
|
|
|
579
584
|
|
|
580
585
|
// Read the proof as fields
|
|
581
586
|
// TODO(AD): this is the only remaining use of extractVkData.
|
|
582
|
-
const tubeVK = await extractVkData(provingResult.
|
|
587
|
+
const tubeVK = await extractVkData(provingResult.vkDirectoryPath!);
|
|
583
588
|
const tubeProof = await readProofAsFields(provingResult.proofPath!, tubeVK, TUBE_PROOF_LENGTH, logger);
|
|
584
589
|
|
|
585
590
|
this.instrumentation.recordDuration('provingDuration', 'tubeCircuit', provingResult.durationMs);
|
|
@@ -673,9 +678,13 @@ export class BBNativeRollupProver implements ServerCircuitProver {
|
|
|
673
678
|
return await this.verifyWithKey(getUltraHonkFlavorForCircuit(circuitType), verificationKey, proof);
|
|
674
679
|
}
|
|
675
680
|
|
|
676
|
-
public async verifyAvmProof(
|
|
681
|
+
public async verifyAvmProof(
|
|
682
|
+
proof: Proof,
|
|
683
|
+
verificationKey: VerificationKeyData,
|
|
684
|
+
publicInputs: AvmCircuitPublicInputs,
|
|
685
|
+
) {
|
|
677
686
|
return await this.verifyWithKeyInternal(proof, verificationKey, (proofPath, vkPath) =>
|
|
678
|
-
verifyAvmProof(this.config.bbBinaryPath, proofPath, vkPath, logger),
|
|
687
|
+
verifyAvmProof(this.config.bbBinaryPath, this.config.bbWorkingDirectory, proofPath, publicInputs, vkPath, logger),
|
|
679
688
|
);
|
|
680
689
|
}
|
|
681
690
|
|
|
@@ -728,16 +737,25 @@ export class BBNativeRollupProver implements ServerCircuitProver {
|
|
|
728
737
|
private async readAvmProofAsFields(
|
|
729
738
|
proofFilename: string,
|
|
730
739
|
vkData: VerificationKeyData,
|
|
731
|
-
): Promise<RecursiveProof<typeof
|
|
732
|
-
const
|
|
733
|
-
|
|
734
|
-
const
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
740
|
+
): Promise<RecursiveProof<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED>> {
|
|
741
|
+
const rawProofBuffer = await fs.readFile(proofFilename);
|
|
742
|
+
const reader = BufferReader.asReader(rawProofBuffer);
|
|
743
|
+
const proofFields = reader.readArray(rawProofBuffer.length / Fr.SIZE_IN_BYTES, Fr);
|
|
744
|
+
|
|
745
|
+
// We extend to a fixed-size padded proof as during development any new AVM circuit column changes the
|
|
746
|
+
// proof length and we do not have a mechanism to feedback a cpp constant to noir/TS.
|
|
747
|
+
// TODO(#13390): Revive a non-padded AVM proof
|
|
748
|
+
if (proofFields.length > AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED) {
|
|
749
|
+
throw new Error(
|
|
750
|
+
`Proof has ${proofFields.length} fields, expected no more than ${AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED}.`,
|
|
751
|
+
);
|
|
752
|
+
}
|
|
753
|
+
const proofFieldsPadded = proofFields.concat(
|
|
754
|
+
Array(AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED - proofFields.length).fill(new Fr(0)),
|
|
755
|
+
);
|
|
739
756
|
|
|
740
|
-
|
|
757
|
+
const proof = new Proof(rawProofBuffer, vkData.numPublicInputs);
|
|
758
|
+
return new RecursiveProof(proofFieldsPadded, proof, true, AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED);
|
|
741
759
|
}
|
|
742
760
|
|
|
743
761
|
private runInDirectory<T>(fn: (dir: string) => Promise<T>) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED,
|
|
3
|
+
AVM_V2_VERIFICATION_KEY_LENGTH_IN_FIELDS_PADDED,
|
|
4
4
|
NESTED_RECURSIVE_PROOF_LENGTH,
|
|
5
5
|
NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
|
|
6
6
|
RECURSIVE_PROOF_LENGTH,
|
|
@@ -302,14 +302,16 @@ export class TestCircuitProver implements ServerCircuitProver {
|
|
|
302
302
|
);
|
|
303
303
|
}
|
|
304
304
|
|
|
305
|
-
public getAvmProof(
|
|
305
|
+
public getAvmProof(
|
|
306
|
+
_inputs: AvmCircuitInputs,
|
|
307
|
+
): Promise<ProofAndVerificationKey<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED>> {
|
|
306
308
|
// We can't simulate the AVM because we don't have enough context to do so (e.g., DBs).
|
|
307
309
|
// We just return an empty proof and VK data.
|
|
308
310
|
this.logger.debug('Skipping AVM simulation in TestCircuitProver.');
|
|
309
311
|
return this.applyDelay(ProvingRequestType.PUBLIC_VM, () =>
|
|
310
312
|
makeProofAndVerificationKey(
|
|
311
|
-
makeEmptyRecursiveProof(
|
|
312
|
-
VerificationKeyData.makeFake(
|
|
313
|
+
makeEmptyRecursiveProof(AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED),
|
|
314
|
+
VerificationKeyData.makeFake(AVM_V2_VERIFICATION_KEY_LENGTH_IN_FIELDS_PADDED),
|
|
313
315
|
),
|
|
314
316
|
);
|
|
315
317
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AVM_V2_VERIFICATION_KEY_LENGTH_IN_FIELDS_PADDED } from '@aztec/constants';
|
|
2
2
|
import { Fr } from '@aztec/foundation/fields';
|
|
3
|
+
import { BufferReader } from '@aztec/foundation/serialize';
|
|
3
4
|
import { hashVK } from '@aztec/stdlib/hash';
|
|
4
5
|
import { VerificationKeyAsFields, VerificationKeyData } from '@aztec/stdlib/vks';
|
|
5
6
|
|
|
@@ -27,19 +28,25 @@ export async function extractVkData(vkDirectoryPath: string): Promise<Verificati
|
|
|
27
28
|
return new VerificationKeyData(vkAsFields, rawBinary);
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Reads the verification key data stored in a binary file at the specified directory location and parses into a VerificationKeyData.
|
|
33
|
+
* We do not assume any JSON file available but only the binary version, contrary to the above extractVkData() method.
|
|
34
|
+
* @param vkDirectoryPath - The directory containing the verification key binary data file.
|
|
35
|
+
* @returns The verification key data
|
|
36
|
+
*/
|
|
31
37
|
export async function extractAvmVkData(vkDirectoryPath: string): Promise<VerificationKeyData> {
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
const rawBinary = await fs.readFile(path.join(vkDirectoryPath, VK_FILENAME));
|
|
39
|
+
|
|
40
|
+
const numFields = rawBinary.length / Fr.SIZE_IN_BYTES;
|
|
41
|
+
assert(numFields <= AVM_V2_VERIFICATION_KEY_LENGTH_IN_FIELDS_PADDED, 'Invalid AVM verification key length');
|
|
42
|
+
const reader = BufferReader.asReader(rawBinary);
|
|
43
|
+
const fieldsArray = reader.readArray(numFields, Fr);
|
|
44
|
+
|
|
45
|
+
const fieldsArrayPadded = fieldsArray.concat(
|
|
46
|
+
Array(AVM_V2_VERIFICATION_KEY_LENGTH_IN_FIELDS_PADDED - fieldsArray.length).fill(new Fr(0)),
|
|
47
|
+
);
|
|
48
|
+
// Currently, we do not need the vk hash for the AVM as we are not adding in the vk tree.
|
|
49
|
+
const vkAsFields = new VerificationKeyAsFields(fieldsArrayPadded, new Fr(0));
|
|
43
50
|
const vk = new VerificationKeyData(vkAsFields, rawBinary);
|
|
44
51
|
return vk;
|
|
45
52
|
}
|