Skip to content

Commit

Permalink
Respond to saleel
Browse files Browse the repository at this point in the history
  • Loading branch information
codygunton committed Feb 20, 2025
1 parent d1e19ea commit bbb8543
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 122 deletions.
6 changes: 3 additions & 3 deletions barretenberg/acir_tests/flows/prove_then_verify_tube.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ trap "rm -rf $outdir" EXIT

flags="-c $CRS_PATH ${VERBOSE:+-v} -o $outdir"

# TODO(https://github.com/AztecProtocol/barretenberg/issues/1252): deprecate in favor of normal proving flow
# TODO(https://github.com/AztecProtocol/barretenberg/issues/1252): deprecate in favor of normal proving flow
$BIN OLD_API write_arbitrary_valid_client_ivc_proof_and_vk_to_file $flags
$BIN OLD_API prove_tube $flags
$BIN OLD_API verify_tube $flags
$BIN prove_tube $flags
$BIN verify_tube $flags
86 changes: 45 additions & 41 deletions barretenberg/cpp/src/barretenberg/bb/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ int main(int argc, char* argv[])
"The type of proof to be constructed. This can specify a proving system, an accumulation scheme, or a "
"particular type of circuit to be constructed and proven for some implicit scheme.")
->envname("BB_SCHEME")
->check(CLI::IsMember({ "client_ivc", "avm", "tube", "ultra_honk", "ultra_keccak_honk", "ultra_plonk" })
.name("is_member"));
->default_val("ultra_honk")
->check(CLI::IsMember({ "client_ivc", "avm", "ultra_honk" }).name("is_member"));
};

const auto add_crs_path_option = [&](CLI::App* subcommand) {
Expand Down Expand Up @@ -586,25 +586,27 @@ int main(int argc, char* argv[])
#endif

/***************************************************************************************************************
* Subcommand: OLD_API prove_tube
* Subcommand: prove_tube
***************************************************************************************************************/
CLI ::App* OLD_API_prove_tube = OLD_API->add_subcommand("prove_tube", "");
add_verbose_flag(OLD_API_prove_tube);
add_debug_flag(OLD_API_prove_tube);
add_crs_path_option(OLD_API_prove_tube);
CLI ::App* prove_tube_command = app.add_subcommand("prove_tube", "");
prove_tube_command->group(""); // hide from list of subcommands
add_verbose_flag(prove_tube_command);
add_debug_flag(prove_tube_command);
add_crs_path_option(prove_tube_command);
std::string prove_tube_output_path{ "./target" };
add_output_path_option(OLD_API_prove_tube, prove_tube_output_path);
add_output_path_option(prove_tube_command, prove_tube_output_path);

/***************************************************************************************************************
* Subcommand: OLD_API verify_tube
* Subcommand: verify_tube
***************************************************************************************************************/
CLI::App* OLD_API_verify_tube = OLD_API->add_subcommand("verify_tube", "");
add_verbose_flag(OLD_API_verify_tube);
add_debug_flag(OLD_API_verify_tube);
add_crs_path_option(OLD_API_verify_tube);
CLI::App* verify_tube_command = app.add_subcommand("verify_tube", "");
verify_tube_command->group(""); // hide from list of subcommands
add_verbose_flag(verify_tube_command);
add_debug_flag(verify_tube_command);
add_crs_path_option(verify_tube_command);
// doesn't make sense that this is set by -o but that's how it was
std::string tube_proof_and_vk_path{ "./target" };
add_output_path_option(OLD_API_verify_tube, tube_proof_and_vk_path);
add_output_path_option(verify_tube_command, tube_proof_and_vk_path);

/***************************************************************************************************************
* Build the CLI11 App
Expand Down Expand Up @@ -655,31 +657,6 @@ int main(int argc, char* argv[])
std::cout << BB_VERSION_PLACEHOLDER << std::endl;
return 0;
}
// CLIENT IVC
else if (flags.scheme == "client_ivc") {
ClientIVCAPI api;
return execute_command(api);
} else if (OLD_API_gates_for_ivc->parsed()) {
gate_count_for_ivc(bytecode_path);
} else if (OLD_API_gates_mega_honk->parsed()) {
gate_count<MegaCircuitBuilder>(bytecode_path, flags.recursive, flags.honk_recursion);
} else if (OLD_API_write_arbitrary_valid_client_ivc_proof_and_vk_to_file->parsed()) {
write_arbitrary_valid_client_ivc_proof_and_vk_to_file(arbitrary_valid_proof_path);
return 0;
}
// ULTRA HONK
else if (flags.scheme == "ultra_honk") {
UltraHonkAPI api;
return execute_command(api);
} else if (OLD_API_write_recursion_inputs_ultra_honk->parsed()) {
if (flags.ipa_accumulation) {
write_recursion_inputs_ultra_honk<UltraRollupFlavor>(
bytecode_path, witness_path, recursion_inputs_output_path);
} else {
write_recursion_inputs_ultra_honk<UltraFlavor>(
bytecode_path, witness_path, recursion_inputs_output_path);
}
}
// ULTRA PLONK
else if (OLD_API_gates->parsed()) {
gate_count<UltraCircuitBuilder>(bytecode_path, flags.recursive, flags.honk_recursion);
Expand Down Expand Up @@ -722,13 +699,40 @@ int main(int argc, char* argv[])
}
#endif
// TUBE
else if (OLD_API_prove_tube->parsed()) {
else if (prove_tube_command->parsed()) {
prove_tube(prove_tube_output_path);
} else if (OLD_API_verify_tube->parsed()) {
} else if (verify_tube_command->parsed()) {
auto tube_proof_path = tube_proof_and_vk_path + "/proof";
auto tube_vk_path = tube_proof_and_vk_path + "/vk";
UltraHonkAPI api;
return api.verify({ .ipa_accumulation = true }, tube_proof_path, tube_vk_path) ? 0 : 1;
}
// CLIENT IVC EXTRA COMMAND
else if (OLD_API_gates_for_ivc->parsed()) {
gate_count_for_ivc(bytecode_path);
} else if (OLD_API_gates_mega_honk->parsed()) {
gate_count<MegaCircuitBuilder>(bytecode_path, flags.recursive, flags.honk_recursion);
} else if (OLD_API_write_arbitrary_valid_client_ivc_proof_and_vk_to_file->parsed()) {
write_arbitrary_valid_client_ivc_proof_and_vk_to_file(arbitrary_valid_proof_path);
return 0;
}
// ULTRA HONK EXTRA COMMANDS
else if (OLD_API_write_recursion_inputs_ultra_honk->parsed()) {
if (flags.ipa_accumulation) {
write_recursion_inputs_ultra_honk<UltraRollupFlavor>(
bytecode_path, witness_path, recursion_inputs_output_path);
} else {
write_recursion_inputs_ultra_honk<UltraFlavor>(
bytecode_path, witness_path, recursion_inputs_output_path);
}
}
// NEW STANDARD API
else if (flags.scheme == "client_ivc") {
ClientIVCAPI api;
return execute_command(api);
} else if (flags.scheme == "ultra_honk") {
UltraHonkAPI api;
return execute_command(api);
} else {
throw_or_abort("No match for API command");
return 1;
Expand Down
78 changes: 0 additions & 78 deletions yarn-project/bb-prover/src/bb/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,84 +171,6 @@ export async function executeBbClientIvcProof(
}
}

/**
* Used for generating verification keys of noir circuits.
* It is assumed that the working directory is a temporary and/or random directory used solely for generating this VK.
* @param pathToBB - The full path to the bb binary
* @param workingDirectory - A working directory for use by bb
* @param circuitName - An identifier for the circuit
* @param bytecode - The compiled circuit bytecode
* @param inputWitnessFile - The circuit input witness
* @param log - A logging function
* @returns An object containing a result indication, the location of the VK and the duration taken
*/
export async function computeVerificationKey(
pathToBB: string,
workingDirectory: string,
circuitName: string,
bytecode: Buffer,
recursive: boolean,
flavor: UltraHonkFlavor | 'mega_honk',
log: LogFn,
): Promise<BBFailure | BBSuccess> {
// Check that the working directory exists
try {
await fs.access(workingDirectory);
} catch (error) {
return { status: BB_RESULT.FAILURE, reason: `Working directory ${workingDirectory} does not exist` };
}

// The bytecode is written to e.g. /workingDirectory/BaseParityArtifact-bytecode
const bytecodePath = `${workingDirectory}/${circuitName}-bytecode`;

// The verification key is written to this path
const outputPath = `${workingDirectory}/vk`;

const binaryPresent = await fs
.access(pathToBB, fs.constants.R_OK)
.then(_ => true)
.catch(_ => false);
if (!binaryPresent) {
return { status: BB_RESULT.FAILURE, reason: `Failed to find bb binary at ${pathToBB}` };
}

try {
// Write the bytecode to the working directory
await fs.writeFile(bytecodePath, bytecode);
const timer = new Timer();
const logFunction = (message: string) => {
log(`computeVerificationKey(${circuitName}) BB out - ${message}`);
};
const args = ['-o', outputPath, '-b', bytecodePath, '-v'];
if (recursive) {
args.push('--init_kzg_accumulator');
}
const result = await executeBB(pathToBB, `write_vk`, args, logFunction);
if (result.status == BB_RESULT.FAILURE) {
return { status: BB_RESULT.FAILURE, reason: 'Failed writing VK.' };
}

const duration = timer.ms();

if (result.status == BB_RESULT.SUCCESS) {
return {
status: BB_RESULT.SUCCESS,
durationMs: duration,
pkPath: undefined,
vkPath: `${outputPath}`,
};
}
// Not a great error message here but it is difficult to decipher what comes from bb
return {
status: BB_RESULT.FAILURE,
reason: `Failed to write VK. Exit code ${result.exitCode}. Signal ${result.signal}.`,
retry: !!result.signal,
};
} catch (error) {
return { status: BB_RESULT.FAILURE, reason: `${error}` };
}
}

function getArgs(flavor: UltraHonkFlavor) {
switch (flavor) {
case 'ultra_honk': {
Expand Down

0 comments on commit bbb8543

Please # to comment.