Skip to content

Commit

Permalink
7211: TS changes to support calldata file
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanmon committed Jun 28, 2024
1 parent 9bf5671 commit aebab70
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion yarn-project/bb-prover/src/avm_proving.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,8 @@ const proveAndVerifyAvmTestContract = async (

// Then we verify.
const rawVkPath = path.join(succeededRes.vkPath!, 'vk');
const verificationRes = await verifyAvmProof(bbPath, succeededRes.proofPath!, rawVkPath, logger);
const calldataPath = path.join(bbWorkingDirectory, 'avm_calldata.bin');
const verificationRes = await verifyAvmProof(bbPath, succeededRes.proofPath!, rawVkPath, logger, calldataPath);
expect(verificationRes.status).toBe(BB_RESULT.SUCCESS);
};

Expand Down
12 changes: 10 additions & 2 deletions yarn-project/bb-prover/src/bb/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const VK_FILENAME = 'vk';
export const VK_FIELDS_FILENAME = 'vk_fields.json';
export const PROOF_FILENAME = 'proof';
export const PROOF_FIELDS_FILENAME = 'proof_fields.json';
export const CALLDATA_FILENAME = 'avm_calldata.bin';

export enum BB_RESULT {
SUCCESS,
Expand Down Expand Up @@ -277,7 +278,7 @@ export async function generateAvmProof(

// Paths for the inputs
const bytecodePath = join(workingDirectory, 'avm_bytecode.bin');
const calldataPath = join(workingDirectory, 'avm_calldata.bin');
const calldataPath = join(workingDirectory, CALLDATA_FILENAME);
const publicInputsPath = join(workingDirectory, 'avm_public_inputs.bin');
const avmHintsPath = join(workingDirectory, 'avm_hints.bin');

Expand Down Expand Up @@ -385,6 +386,7 @@ export async function verifyProof(
* @param pathToBB - The full path to the bb binary
* @param proofFullPath - The full path to the proof to be verified
* @param verificationKeyPath - The full path to the circuit verification key
* @param calldataPath - The full path to calldata
* @param log - A logging function
* @returns An object containing a result indication and duration taken
*/
Expand All @@ -393,8 +395,9 @@ export async function verifyAvmProof(
proofFullPath: string,
verificationKeyPath: string,
log: LogFn,
calldataPath?: string,
): Promise<BBFailure | BBSuccess> {
return await verifyProofInternal(pathToBB, proofFullPath, verificationKeyPath, 'avm_verify', log);
return await verifyProofInternal(pathToBB, proofFullPath, verificationKeyPath, 'avm_verify', log, calldataPath);
}

/**
Expand All @@ -404,6 +407,7 @@ export async function verifyAvmProof(
* @param verificationKeyPath - The full path to the circuit verification key
* @param command - The BB command to execute (verify/avm_verify)
* @param log - A logging function
* @param calldataPath - The full path to calldata (only relevant for avm_verify)
* @returns An object containing a result indication and duration taken
*/
async function verifyProofInternal(
Expand All @@ -412,6 +416,7 @@ async function verifyProofInternal(
verificationKeyPath: string,
command: 'verify' | 'avm_verify',
log: LogFn,
calldataPath?: string,
): Promise<BBFailure | BBSuccess> {
const binaryPresent = await fs
.access(pathToBB, fs.constants.R_OK)
Expand All @@ -423,6 +428,9 @@ async function verifyProofInternal(

try {
const args = ['-p', proofFullPath, '-k', verificationKeyPath];
if (calldataPath !== undefined) {
args.push('--avm-calldata', calldataPath);
}
const timer = new Timer();
const result = await executeBB(pathToBB, command, args, log);
const duration = timer.ms();
Expand Down
2 changes: 2 additions & 0 deletions yarn-project/bb-prover/src/prover/bb_prover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import * as path from 'path';
import {
type BBSuccess,
BB_RESULT,
CALLDATA_FILENAME,
PROOF_FIELDS_FILENAME,
PROOF_FILENAME,
VK_FILENAME,
Expand Down Expand Up @@ -640,6 +641,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
proofFileName,
verificationKeyPath!,
logFunction,
verificationFunction instanceof verifyAvmProof ? path.join(bbWorkingDirectory, CALLDATA_FILENAME) : undefined,
);

if (result.status === BB_RESULT.FAILURE) {
Expand Down

0 comments on commit aebab70

Please sign in to comment.