Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function check_circuit_vks {
local exit_code=0

if [[ "${2:-}" == "--update_inputs" ]]; then
output=$($bb check --update_inputs --scheme chonk --ivc_inputs_path "$flow_folder/ivc-inputs.msgpack" 2>&1) || exit_code=$?
output=$($bb check --vk_policy=rewrite --scheme chonk --ivc_inputs_path "$flow_folder/ivc-inputs.msgpack" 2>&1) || exit_code=$?
else
output=$($bb check --scheme chonk --ivc_inputs_path "$flow_folder/ivc-inputs.msgpack" 2>&1) || exit_code=$?
fi
Expand Down
1 change: 0 additions & 1 deletion barretenberg/cpp/src/barretenberg/api/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class API {
bool include_gates_per_opcode{ false }; // should we include gates_per_opcode in the gates command output
bool slow_low_memory{ false }; // use file backed memory for polynomials
std::string storage_budget; // storage budget for file backed memory (e.g. "500m", "2g")
bool update_inputs{ false }; // update inputs when check fails
std::string vk_policy{ "default" }; // policy for handling VKs during IVC accumulation

bool optimized_solidity_verifier{ false }; // should we use the optimized sol verifier? (temp)
Expand Down
3 changes: 2 additions & 1 deletion barretenberg/cpp/src/barretenberg/api/api_chonk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ bool ChonkAPI::check_precomputed_vks(const Flags& flags, const std::filesystem::
bbapi::BBApiRequest request;
std::vector<PrivateExecutionStepRaw> raw_steps = PrivateExecutionStepRaw::load_and_decompress(input_path);

bbapi::VkPolicy vk_policy = bbapi::parse_vk_policy(flags.vk_policy);
bool check_failed = false;
for (auto& step : raw_steps) {
if (step.vk.empty()) {
Expand All @@ -163,7 +164,7 @@ bool ChonkAPI::check_precomputed_vks(const Flags& flags, const std::filesystem::

if (!response.valid) {
info("VK mismatch detected for function ", step.function_name);
if (!flags.update_inputs) {
if (vk_policy != bbapi::VkPolicy::REWRITE) {
info("Computed VK differs from precomputed VK in ivc-inputs.msgpack");
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions barretenberg/cpp/src/barretenberg/api/api_chonk.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ TEST_F(ChonkAPITests, CheckPrecomputedVksMismatch)
bool result = api.check_precomputed_vks(ChonkAPI::Flags{}, input_path);
EXPECT_FALSE(result);

// Check with --update_input should still fail but update the VK in the input.
result = api.check_precomputed_vks(ChonkAPI::Flags{ .update_inputs = true }, input_path);
// Check with --vk_policy=rewrite should still fail but update the VK in the input.
result = api.check_precomputed_vks(ChonkAPI::Flags{ .vk_policy = "rewrite" }, input_path);
EXPECT_FALSE(result);

// Check again and it should succeed with the updated VK.
Expand Down
15 changes: 6 additions & 9 deletions barretenberg/cpp/src/barretenberg/bb/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,18 +280,15 @@ int parse_and_run_cli_command(int argc, char* argv[])
"back to RAM (requires --slow_low_memory).");
};

const auto add_update_inputs_flag = [&](CLI::App* subcommand) {
return subcommand->add_flag("--update_inputs", flags.update_inputs, "Update inputs if vk check fails.");
};

const auto add_vk_policy_option = [&](CLI::App* subcommand) {
return subcommand
->add_option("--vk_policy",
flags.vk_policy,
"Policy for handling verification keys during IVC accumulation. 'default' uses the provided "
"VK as-is, 'check' verifies the provided VK matches the computed VK (throws error on "
"mismatch), 'recompute' always ignores the provided VK and treats it as nullptr.")
->check(CLI::IsMember({ "default", "check", "recompute" }).name("is_member"));
"Policy for handling verification keys. 'default' uses the provided VK as-is, 'check' "
"verifies the provided VK matches the computed VK (throws error on mismatch), 'recompute' "
"always ignores the provided VK and treats it as nullptr, 'rewrite' checks the VK and "
"rewrites the input file with the correct VK if there's a mismatch (for check command).")
->check(CLI::IsMember({ "default", "check", "recompute", "rewrite" }).name("is_member"));
};

const auto add_optimized_solidity_verifier_flag = [&](CLI::App* subcommand) {
Expand Down Expand Up @@ -342,7 +339,7 @@ int parse_and_run_cli_command(int argc, char* argv[])
add_bytecode_path_option(check);
add_witness_path_option(check);
add_ivc_inputs_path_options(check);
add_update_inputs_flag(check);
add_vk_policy_option(check);

/***************************************************************************************************************
* Subcommand: gates
Expand Down
10 changes: 7 additions & 3 deletions barretenberg/cpp/src/barretenberg/bbapi/bbapi_shared.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ namespace bb::bbapi {
* @brief Policy for handling verification keys during IVC accumulation
*/
enum class VkPolicy {
DEFAULT, // Use the provided VK as-is (default behavior)
CHECK, // Verify the provided VK matches the computed VK, throw error if mismatch
RECOMPUTE // Always ignore the provided VK and treat it as nullptr
DEFAULT, // Use the provided VK as-is (default behavior)
CHECK, // Verify the provided VK matches the computed VK, throw error if mismatch
RECOMPUTE, // Always ignore the provided VK and treat it as nullptr
REWRITE // Check the VK and rewrite the input file with correct VK if mismatch (for check command)
};

/**
Expand Down Expand Up @@ -137,6 +138,9 @@ inline VkPolicy parse_vk_policy(const std::string& policy)
if (policy == "recompute") {
return VkPolicy::RECOMPUTE;
}
if (policy == "rewrite") {
return VkPolicy::REWRITE;
}
return VkPolicy::DEFAULT; // default
}

Expand Down
Loading