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
38 changes: 18 additions & 20 deletions barretenberg/cpp/format.sh
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
#!/usr/bin/env bash
set -e
function format_files {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added by me tired of waiting to format files

if [ -n "$1" ]; then
echo "$1" | parallel -j+0 'clang-format-20 -i {} && sed -i.bak "s/\r$//" {} && rm {}.bak'
fi
}

if [ "$1" == "staged" ]; then
echo Formatting barretenberg staged files...
for FILE in $(git diff-index --diff-filter=d --relative --cached --name-only HEAD | grep -e '\.\(cpp\|hpp\|tcc\)$'); do
clang-format-20 -i $FILE
sed -i.bak 's/\r$//' $FILE && rm ${FILE}.bak
git add $FILE
done
files=$(git diff-index --diff-filter=d --relative --cached --name-only HEAD | grep -e '\.\(cpp\|hpp\|tcc\)$')
format_files "$files"
if [ -n "$files" ]; then
git add "$files"
fi
elif [ "$1" == "changed" ]; then
echo Formatting barretenberg changed files...
for FILE in $(git diff-index --diff-filter=d --relative --name-only HEAD | grep -e '\.\(cpp\|hpp\|tcc\)$'); do
clang-format-20 -i $FILE
sed -i.bak 's/\r$//' $FILE && rm ${FILE}.bak
done
files=$(git diff-index --diff-filter=d --relative --name-only HEAD | grep -e '\.\(cpp\|hpp\|tcc\)$')
format_files "$files"
elif [ "$1" == "check" ]; then
find ./src -iname *.hpp -o -iname *.cpp -o -iname *.tcc | grep -v src/msgpack-c | grep -v bb/deps | \
parallel -N10 clang-format-20 --dry-run --Werror
files=$(find ./src -iname *.hpp -o -iname *.cpp -o -iname *.tcc | grep -v bb/deps)
echo "$files" | parallel -N10 clang-format-20 --dry-run --Werror
elif [ -n "$1" ]; then
for FILE in $(git diff-index --relative --name-only $1 | grep -e '\.\(cpp\|hpp\|tcc\)$'); do
clang-format-20 -i $FILE
sed -i.bak 's/\r$//' $FILE && rm ${FILE}.bak
done
files=$(git diff-index --relative --name-only $1 | grep -e '\.\(cpp\|hpp\|tcc\)$')
format_files "$files"
else
for FILE in $(find ./src -iname *.hpp -o -iname *.cpp -o -iname *.tcc | grep -v src/msgpack-c); do
clang-format-20 -i $FILE
sed -i.bak 's/\r$//' $FILE && rm ${FILE}.bak
done
files=$(find ./src -iname *.hpp -o -iname *.cpp -o -iname *.tcc)
format_files "$files"
fi
2 changes: 1 addition & 1 deletion barretenberg/cpp/scripts/bench_hardware_concurrency.sh
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ for test_case in test_cases:
for cpu, metrics in all_data.items():
for metric_name, time_ms in metrics.items():
# Categorize metrics based on name
if "Chonk" in metric_name or "SumcheckChonk" in metric_name:
if "Chonk" in metric_name or "Chonk" in metric_name:
components["Main"][metric_name][cpu] = time_ms
elif "ProtogalaxyProver" in metric_name:
components["ProtogalaxyProver"][metric_name][cpu] = time_ms
Expand Down
24 changes: 12 additions & 12 deletions barretenberg/cpp/src/barretenberg/api/api_chonk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
#include "barretenberg/api/file_io.hpp"
#include "barretenberg/api/log.hpp"
#include "barretenberg/bbapi/bbapi.hpp"
#include "barretenberg/chonk/chonk.hpp"
#include "barretenberg/chonk/mock_circuit_producer.hpp"
#include "barretenberg/chonk/private_execution_steps.hpp"
#include "barretenberg/chonk/sumcheck_chonk.hpp"
#include "barretenberg/chonk/sumcheck_mock_circuit_producer.hpp"
#include "barretenberg/common/get_bytecode.hpp"
#include "barretenberg/common/map.hpp"
#include "barretenberg/common/throw_or_abort.hpp"
#include "barretenberg/common/try_catch_shim.hpp"
#include "barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp"
#include "barretenberg/dsl/acir_format/pg_recursion_constraint.hpp"
#include "barretenberg/dsl/acir_format/hypernova_recursion_constraint.hpp"
#include "barretenberg/serialize/msgpack.hpp"
#include "barretenberg/serialize/msgpack_check_eq.hpp"
#include <algorithm>
Expand Down Expand Up @@ -44,7 +44,7 @@ void write_standalone_vk(std::vector<uint8_t> bytecode, const std::filesystem::p
void write_chonk_vk(std::vector<uint8_t> bytecode, const std::filesystem::path& output_dir)
{
// compute the hiding kernel's vk
info("SumcheckChonk: computing IVC vk for hiding kernel circuit");
info("Chonk: computing IVC vk for hiding kernel circuit");
auto response = bbapi::ChonkComputeIvcVk{ .circuit{ .bytecode = std::move(bytecode) } }.execute();
const bool output_to_stdout = output_dir == "-";
if (output_to_stdout) {
Expand All @@ -65,14 +65,14 @@ void ChonkAPI::prove(const Flags& flags,
std::vector<PrivateExecutionStepRaw> raw_steps = PrivateExecutionStepRaw::load_and_decompress(input_path);

bbapi::ChonkStart{ .num_circuits = raw_steps.size() }.execute(request);
info("SumcheckChonk: starting with ", raw_steps.size(), " circuits");
info("Chonk: starting with ", raw_steps.size(), " circuits");
for (const auto& step : raw_steps) {
bbapi::ChonkLoad{
.circuit = { .name = step.function_name, .bytecode = step.bytecode, .verification_key = step.vk }
}.execute(request);

// NOLINTNEXTLINE(bugprone-unchecked-optional-access): we know the optional has been set here.
info("SumcheckChonk: accumulating " + step.function_name);
info("Chonk: accumulating " + step.function_name);
bbapi::ChonkAccumulate{ .witness = step.witness }.execute(request);
}

Expand All @@ -85,18 +85,18 @@ void ChonkAPI::prove(const Flags& flags,
const auto write_proof = [&]() {
const auto buf = to_buffer(proof.to_field_elements());
if (output_to_stdout) {
vinfo("writing SumcheckChonk proof to stdout");
vinfo("writing Chonk proof to stdout");
write_bytes_to_stdout(buf);
} else {
vinfo("writing SumcheckChonk proof in directory ", output_dir);
vinfo("writing Chonk proof in directory ", output_dir);
write_file(output_dir / "proof", buf);
}
};

write_proof();

if (flags.write_vk) {
vinfo("writing SumcheckChonk vk in directory ", output_dir);
vinfo("writing Chonk vk in directory ", output_dir);
// write CHONK vk using the bytecode of the hiding circuit (the last step of the execution)
write_chonk_vk(raw_steps[raw_steps.size() - 1].bytecode, output_dir);
}
Expand All @@ -109,7 +109,7 @@ bool ChonkAPI::verify([[maybe_unused]] const Flags& flags,
{
BB_BENCH_NAME("ChonkAPI::verify");
auto proof_fields = many_from_buffer<fr>(read_file(proof_path));
auto proof = SumcheckChonk::Proof::from_field_elements(proof_fields);
auto proof = Chonk::Proof::from_field_elements(proof_fields);

auto vk_buffer = read_file(vk_path);

Expand All @@ -123,11 +123,11 @@ bool ChonkAPI::prove_and_verify(const std::filesystem::path& input_path)
PrivateExecutionSteps steps;
steps.parse(PrivateExecutionStepRaw::load_and_decompress(input_path));

std::shared_ptr<SumcheckChonk> ivc = steps.accumulate();
std::shared_ptr<Chonk> ivc = steps.accumulate();
// Construct the hiding kernel as the final step of the IVC

auto proof = ivc->prove();
const bool verified = SumcheckChonk::verify(proof, ivc->get_vk());
const bool verified = Chonk::verify(proof, ivc->get_vk());
return verified;
}

Expand Down
15 changes: 7 additions & 8 deletions barretenberg/cpp/src/barretenberg/api/api_chonk.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#include "barretenberg/bbapi/bbapi.hpp"
#include "barretenberg/bbapi/bbapi_execute.hpp"
#include "barretenberg/chonk/acir_bincode_mocks.hpp"
#include "barretenberg/chonk/chonk.hpp"
#include "barretenberg/chonk/mock_circuit_producer.hpp"
#include "barretenberg/chonk/private_execution_steps.hpp"
#include "barretenberg/chonk/sumcheck_chonk.hpp"
#include "barretenberg/chonk/sumcheck_mock_circuit_producer.hpp"
#include "barretenberg/common/serialize.hpp"
#include "barretenberg/dsl/acir_format/acir_format.hpp"
#include "barretenberg/dsl/acir_format/acir_format_mocks.hpp"
Expand Down Expand Up @@ -105,7 +105,7 @@ std::vector<uint8_t> compress(const std::vector<uint8_t>& input);
} // namespace bb

// Helper to get an IVC verification key for testing
SumcheckChonk::MegaVerificationKey get_ivc_vk(const std::filesystem::path& test_dir)
Chonk::MegaVerificationKey get_ivc_vk(const std::filesystem::path& test_dir)
{
auto [app_bytecode, app_witness_data] = acir_bincode_mocks::create_simple_circuit_bytecode();
bbapi::BBApiRequest request;
Expand All @@ -128,7 +128,7 @@ SumcheckChonk::MegaVerificationKey get_ivc_vk(const std::filesystem::path& test_
api.write_vk(write_vk_flags, bytecode_path, test_dir);

auto buffer = read_file(test_dir / "vk");
return from_buffer<SumcheckChonk::MegaVerificationKey>(buffer);
return from_buffer<Chonk::MegaVerificationKey>(buffer);
};

// Test the ChonkAPI::prove flow, making sure --write_vk
Expand All @@ -153,18 +153,17 @@ TEST_F(ChonkAPITests, DISABLED_ProveAndVerifyFileBasedFlow)
};

// Helper lambda to verify VK equivalence
auto verify_vk_equivalence = [&](const std::filesystem::path& vk1_path,
const SumcheckChonk::MegaVerificationKey& vk2) {
auto verify_vk_equivalence = [&](const std::filesystem::path& vk1_path, const Chonk::MegaVerificationKey& vk2) {
auto vk1_data = read_file(vk1_path);
auto vk1 = from_buffer<SumcheckChonk::MegaVerificationKey>(vk1_data);
auto vk1 = from_buffer<Chonk::MegaVerificationKey>(vk1_data);
ASSERT_EQ(vk1, vk2);
};

// Helper lambda to verify proof
auto verify_proof = [&]() {
std::filesystem::path proof_path = output_dir / "proof";
std::filesystem::path vk_path = output_dir / "vk";
std::filesystem::path public_inputs_path; // Not used for SumcheckChonk
std::filesystem::path public_inputs_path; // Not used for Chonk

ChonkAPI::Flags flags;
ChonkAPI verify_api;
Expand Down
12 changes: 5 additions & 7 deletions barretenberg/cpp/src/barretenberg/bb/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ int parse_and_run_cli_command(int argc, char* argv[])
"verification). `standalone_hiding` is similar to `standalone` but is used for the last step "
"where the structured trace is not utilized. `ivc` produces a verification key for verifying "
"the stack of run though a dedicated ivc verifier class (currently the only option is the "
"SumcheckChonk class)")
"Chonk class)")
->check(CLI::IsMember({ "standalone", "standalone_hiding", "ivc" }).name("is_member"));
};

Expand Down Expand Up @@ -654,9 +654,8 @@ int parse_and_run_cli_command(int argc, char* argv[])
ChonkAPI api;
if (prove->parsed()) {
if (!std::filesystem::exists(ivc_inputs_path)) {
throw_or_abort(
"The prove command for SumcheckChonk expect a valid file passed with --ivc_inputs_path "
"<ivc-inputs.msgpack> (default ./ivc-inputs.msgpack)");
throw_or_abort("The prove command for Chonk expect a valid file passed with --ivc_inputs_path "
"<ivc-inputs.msgpack> (default ./ivc-inputs.msgpack)");
}
api.prove(flags, ivc_inputs_path, output_path);
#ifndef __wasm__
Expand All @@ -676,9 +675,8 @@ int parse_and_run_cli_command(int argc, char* argv[])
}
if (check->parsed()) {
if (!std::filesystem::exists(ivc_inputs_path)) {
throw_or_abort(
"The check command for SumcheckChonk expect a valid file passed with --ivc_inputs_path "
"<ivc-inputs.msgpack> (default ./ivc-inputs.msgpack)");
throw_or_abort("The check command for Chonk expect a valid file passed with --ivc_inputs_path "
"<ivc-inputs.msgpack> (default ./ivc-inputs.msgpack)");
}
return api.check_precomputed_vks(flags, ivc_inputs_path) ? 0 : 1;
}
Expand Down
Loading
Loading