Skip to content

Commit

Permalink
feat: Browser tests for UltraHonk (#9047)
Browse files Browse the repository at this point in the history
Make the browser tests use UltraHonk, and we moreover choose the hardest
path by doing recursive verification. The logs show performance issues
that are being investigated.
  • Loading branch information
codygunton authored Oct 10, 2024
1 parent 375c017 commit f0d45dd
Show file tree
Hide file tree
Showing 19 changed files with 95 additions and 72 deletions.
20 changes: 10 additions & 10 deletions barretenberg/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,17 @@ barretenberg-acir-tests-bb.js:
# We have diminishing returns after 32 cores, and unnecessarily use resources
ENV HARDWARE_CONCURRENCY=32

# TODO(https://github.com/AztecProtocol/aztec-packages/issues/6672): Try to enable double_verify
# Run UltraHonk recursive verification through bb.js on chrome testing multi-threaded browser support.
# TODO: Currently headless webkit doesn't seem to have shared memory so skipping multi-threaded test.
RUN BROWSER=chrome THREAD_MODEL=mt ./run_acir_tests_browser.sh verify_honk_proof
# Run UltraHonk recursive verification through bb.js on chrome testing single-threaded browser support.
RUN BROWSER=chrome THREAD_MODEL=st ./run_acir_tests_browser.sh verify_honk_proof
# Commenting for now as fails intermittently. Unreproducable on mainframe.
# See https://github.com/AztecProtocol/aztec-packages/issues/2104
#RUN BROWSER=webkit THREAD_MODEL=st ./run_acir_tests_browser.sh 1_mul
# TODO(https://github.com/noir-lang/noir/issues/5106)
# TODO(https://github.com/AztecProtocol/aztec-packages/issues/6672)c
# TODO(https://github.com/AztecProtocol/aztec-packages/issues/6672)
# Run ecdsa_secp256r1_3x through bb.js on node to check 256k support.
RUN BIN=../ts/dest/node/main.js FLOW=prove_then_verify ./run_acir_tests.sh ecdsa_secp256r1_3x
# Run a single arbitrary test not involving recursion through bb.js for UltraHonk
Expand All @@ -124,12 +133,3 @@ barretenberg-acir-tests-bb.js:
RUN BIN=../ts/dest/node/main.js FLOW=fold_and_verify_program ./run_acir_tests.sh fold_basic
# Run 1_mul through bb.js build, all_cmds flow, to test all cli args.
RUN BIN=../ts/dest/node/main.js FLOW=all_cmds ./run_acir_tests.sh 1_mul
# TODO(https://github.com/AztecProtocol/aztec-packages/issues/6672)
# Run 6_array through bb.js on chrome testing multi-threaded browser support.
# TODO: Currently headless webkit doesn't seem to have shared memory so skipping multi-threaded test.
RUN BROWSER=chrome THREAD_MODEL=mt ./run_acir_tests_browser.sh 6_array
# Run 1_mul through bb.js on chrome/webkit testing single threaded browser support.
RUN BROWSER=chrome THREAD_MODEL=st ./run_acir_tests_browser.sh 1_mul
# Commenting for now as fails intermittently. Unreproducable on mainframe.
# See https://github.com/AztecProtocol/aztec-packages/issues/2104
#RUN BROWSER=webkit THREAD_MODEL=st ./run_acir_tests_browser.sh 1_mul
18 changes: 11 additions & 7 deletions barretenberg/acir_tests/browser-test-app/src/index.ts

Large diffs are not rendered by default.

7 changes: 1 addition & 6 deletions barretenberg/acir_tests/browser-test-app/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


"@aztec/bb.js@../../ts":
version "0.27.2"
version "0.57.0"
dependencies:
comlink "^4.4.1"
commander "^10.0.1"
Expand Down Expand Up @@ -2973,8 +2973,3 @@ yallist@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72"
integrity sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==

yarn-upgrade-all@^0.7.2:
version "0.7.2"
resolved "https://registry.yarnpkg.com/yarn-upgrade-all/-/yarn-upgrade-all-0.7.2.tgz#5d2afa9230661c55f22d3f848f22258db732ae20"
integrity sha512-iVxmoBuNdpxeahAIehJ039Pp6S8zQ/qTENQRMV5hp7x/2tLGUzytCODIKZFjfUwcRRKT3boGgHheUEWC7+VlQw==
13 changes: 4 additions & 9 deletions barretenberg/acir_tests/headless-test/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,10 @@ color-name@~1.1.4:
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2"
integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==

commander@^12.0.0:
version "12.0.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-12.0.0.tgz#b929db6df8546080adfd004ab215ed48cf6f2592"
integrity sha512-MwVNWlYjDTtOjX5PiD7o5pK0UrFU/OYgcJfjjK4RaHZETNtjJqrZa9Y9ds88+A+f+d5lv+561eZ+yCKoS3gbAA==
commander@^12.1.0:
version "12.1.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-12.1.0.tgz#01423b36f501259fdaac4d0e4d60c96c991585d3"
integrity sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA==

[email protected]:
version "9.0.0"
Expand Down Expand Up @@ -931,11 +931,6 @@ [email protected]:
y18n "^5.0.5"
yargs-parser "^21.1.1"

yarn-upgrade-all@^0.7.2:
version "0.7.2"
resolved "https://registry.yarnpkg.com/yarn-upgrade-all/-/yarn-upgrade-all-0.7.2.tgz#5d2afa9230661c55f22d3f848f22258db732ae20"
integrity sha512-iVxmoBuNdpxeahAIehJ039Pp6S8zQ/qTENQRMV5hp7x/2tLGUzytCODIKZFjfUwcRRKT3boGgHheUEWC7+VlQw==

yauzl@^2.10.0:
version "2.10.0"
resolved "https://registry.yarnpkg.com/yauzl/-/yauzl-2.10.0.tgz#c7eb17c93e112cb1086fa6d8e51fb0667b79a5f9"
Expand Down
6 changes: 3 additions & 3 deletions barretenberg/acir_tests/run_acir_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ function test() {
cd $1

set +e
start=$(date +%s%3N)
start=$SECONDS
$FLOW_SCRIPT
result=$?
end=$(date +%s%3N)
end=$SECONDS
duration=$((end - start))
set -eu

if [ $result -eq 0 ]; then
echo -e "\033[32mPASSED\033[0m ($duration ms)"
echo -e "\033[32mPASSED\033[0m ($duration s)"
else
echo -e "\033[31mFAILED\033[0m"
touch "$error_file"
Expand Down
2 changes: 2 additions & 0 deletions barretenberg/cpp/CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@
"WASI_SDK_PREFIX": "/opt/wasi-sdk",
"CC": "$env{WASI_SDK_PREFIX}/bin/clang",
"CXX": "$env{WASI_SDK_PREFIX}/bin/clang++",
"CXXFLAGS": "-DBB_VERBOSE",
"AR": "$env{WASI_SDK_PREFIX}/bin/llvm-ar",
"RANLIB": "$env{WASI_SDK_PREFIX}/bin/llvm-ranlib"
},
Expand All @@ -392,6 +393,7 @@
{
"name": "wasm-dbg",
"displayName": "Build for debug WASM",
"binaryDir": "build-wasm-dbg",
"description": "Build with wasi-sdk to create debug wasm",
"inherits": "wasm",
"environment": {
Expand Down
2 changes: 1 addition & 1 deletion barretenberg/cpp/src/barretenberg/common/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef __wasm__
bool verbose_logging = std::getenv("BB_VERBOSE") == nullptr ? false : std::string(std::getenv("BB_VERBOSE")) == "1";
#else
bool verbose_logging = false;
bool verbose_logging = true;
#endif

// Used for `debug` in log.hpp.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ UltraCircuitBuilder create_circuit(AcirFormat& constraint_system,
build_constraints(
builder, constraint_system, has_valid_witness_assignments, honk_recursion, collect_gates_per_opcode);

vinfo("created circuit");

return builder;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,6 @@ secp256k1_ct::g1_ct ecdsa_convert_inputs(Builder* ctx, const bb::secp256k1::g1::
return { x, y };
}

// vector of bytes here, assumes that the witness indices point to a field element which can be represented
// with just a byte.
// notice that this function truncates each field_element to a byte
template <std::size_t SIZE, typename Builder>
bb::stdlib::byte_array<Builder> ecdsa_array_of_bytes_to_byte_array(Builder& builder,
std::array<uint32_t, SIZE> vector_of_bytes)
{
using byte_array_ct = bb::stdlib::byte_array<Builder>;
using field_ct = bb::stdlib::field_t<Builder>;

byte_array_ct arr(&builder);

// Get the witness assignment for each witness index
// Write the witness assignment to the byte_array
for (const auto& witness_index : vector_of_bytes) {

field_ct element = field_ct::from_witness_index(&builder, witness_index);
size_t num_bytes = 1;

byte_array_ct element_bytes(element, num_bytes);
arr.write(element_bytes);
}
return arr;
}
witness_ct ecdsa_index_to_witness(Builder& builder, uint32_t index)
{
fr value = builder.get_variable(index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,25 @@ template <typename Builder> void dummy_ecdsa_constraint(Builder& builder, EcdsaS
witness_ct ecdsa_index_to_witness(Builder& builder, uint32_t index);
template <std::size_t SIZE, typename Builder>
bb::stdlib::byte_array<Builder> ecdsa_array_of_bytes_to_byte_array(Builder& builder,
std::array<uint32_t, SIZE> vector_of_bytes);
std::array<uint32_t, SIZE> vector_of_bytes)
{
using byte_array_ct = bb::stdlib::byte_array<Builder>;
using field_ct = bb::stdlib::field_t<Builder>;

byte_array_ct arr(&builder);

// Get the witness assignment for each witness index
// Write the witness assignment to the byte_array
for (const auto& witness_index : vector_of_bytes) {

field_ct element = field_ct::from_witness_index(&builder, witness_index);
size_t num_bytes = 1;

byte_array_ct element_bytes(element, num_bytes);
arr.write(element_bytes);
}
return arr;
}

// We have the implementation of this template in the header as this method is used
// by other ecdsa constraints over different curves (e.g. secp256r1).
Expand Down
2 changes: 2 additions & 0 deletions barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ template <typename Flavor> class SumcheckProver {
// release memory? // All but final round
// We operate on partially_evaluated_polynomials in place.
}
vinfo("completed sumcheck round 0");
for (size_t round_idx = 1; round_idx < multivariate_d; round_idx++) {

#ifdef TRACY_MEMORY
Expand All @@ -254,6 +255,7 @@ template <typename Flavor> class SumcheckProver {

gate_separators.partially_evaluate(round_challenge);
round.round_size = round.round_size >> 1;
vinfo("completed sumcheck round ", round_idx);
}
// Check that the challenges \f$ u_0,\ldots, u_{d-1} \f$ do not satisfy the equation \f$ u_0(1-u_0) + \ldots +
// u_{d-1} (1 - u_{d-1}) = 0 \f$. This equation is satisfied with probability ~ 1/|FF|, in such cases the prover
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ template <IsUltraFlavor Flavor> void DeciderProver_<Flavor>::execute_pcs_rounds(
proving_key->proving_key.commitment_key =
std::make_shared<CommitmentKey>(proving_key->proving_key.circuit_size);
}
vinfo("made commitment key");
using OpeningClaim = ProverOpeningClaim<Curve>;

const OpeningClaim prover_opening_claim =
Expand All @@ -62,7 +63,9 @@ template <IsUltraFlavor Flavor> void DeciderProver_<Flavor>::execute_pcs_rounds(
sumcheck_output.challenge,
proving_key->proving_key.commitment_key,
transcript);
vinfo("executed multivariate-to-univarite reduction");
PCS::compute_opening_proof(proving_key->proving_key.commitment_key, prover_opening_claim, transcript);
vinfo("computed opening proof");
}

template <IsUltraFlavor Flavor> HonkProof DeciderProver_<Flavor>::export_proof()
Expand All @@ -76,10 +79,12 @@ template <IsUltraFlavor Flavor> HonkProof DeciderProver_<Flavor>::construct_proo
BB_OP_COUNT_TIME_NAME("Decider::construct_proof");

// Run sumcheck subprotocol.
vinfo("executing relation checking rounds...");
execute_relation_check_rounds();

// Fiat-Shamir: rho, y, x, z
// Execute Zeromorph multilinear PCS
vinfo("executing pcd opening rounds...");
execute_pcs_rounds();

return export_proof();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ template <IsHonkFlavor Flavor> class DeciderProvingKey_ {
std::shared_ptr<typename Flavor::CommitmentKey> commitment_key = nullptr)
{
BB_OP_COUNT_TIME_NAME("DeciderProvingKey(Circuit&)");
vinfo("creating decider proving key");

circuit.finalize_circuit(/*ensure_nonzero=*/true);

// Set flag indicating whether the polynomials will be constructed with fixed block sizes for each gate type
Expand Down Expand Up @@ -76,6 +78,7 @@ template <IsHonkFlavor Flavor> class DeciderProvingKey_ {
#ifdef TRACY_MEMORY
ZoneScopedN("constructing proving key");
#endif
vinfo("constructing proving key");
proving_key = ProvingKey(dyadic_circuit_size, circuit.public_inputs.size(), commitment_key);
if (IsGoblinFlavor<Flavor> && !is_structured) {
// Allocate full size polynomials
Expand All @@ -86,6 +89,7 @@ template <IsHonkFlavor Flavor> class DeciderProvingKey_ {
#ifdef TRACY_MEMORY
ZoneScopedN("allocating wires");
#endif
vinfo("allocating wires");
for (auto& wire : proving_key.polynomials.get_wires()) {
wire = Polynomial::shiftable(proving_key.circuit_size);
}
Expand All @@ -94,6 +98,7 @@ template <IsHonkFlavor Flavor> class DeciderProvingKey_ {
#ifdef TRACY_MEMORY
ZoneScopedN("allocating gate selectors");
#endif
vinfo("allocating gate selectors");
// Define gate selectors over the block they are isolated to
for (auto [selector, block] :
zip_view(proving_key.polynomials.get_gate_selectors(), circuit.blocks.get_gate_blocks())) {
Expand All @@ -116,6 +121,7 @@ template <IsHonkFlavor Flavor> class DeciderProvingKey_ {
#ifdef TRACY_MEMORY
ZoneScopedN("allocating non-gate selectors");
#endif
vinfo("allocating non-gate selectors");
// Set the other non-gate selector polynomials to full size
for (auto& selector : proving_key.polynomials.get_non_gate_selectors()) {
selector = Polynomial(proving_key.circuit_size);
Expand All @@ -125,6 +131,7 @@ template <IsHonkFlavor Flavor> class DeciderProvingKey_ {
#ifdef TRACY_MEMORY
ZoneScopedN("allocating ecc op wires and selector");
#endif
vinfo("allocating ecc op wires and selector");
// Allocate the ecc op wires and selector
const size_t ecc_op_block_size = circuit.blocks.ecc_op.get_fixed_size(is_structured);
const size_t op_wire_offset = Flavor::has_zero_row ? 1 : 0;
Expand Down Expand Up @@ -164,6 +171,7 @@ template <IsHonkFlavor Flavor> class DeciderProvingKey_ {
#ifdef TRACY_MEMORY
ZoneScopedN("allocating table polynomials");
#endif
vinfo("allocating table polynomials");
ASSERT(dyadic_circuit_size > max_tables_size);

// Allocate the table polynomials
Expand All @@ -177,6 +185,7 @@ template <IsHonkFlavor Flavor> class DeciderProvingKey_ {
#ifdef TRACY_MEMORY
ZoneScopedN("allocating sigmas and ids");
#endif
vinfo("allocating sigmas and ids");
for (auto& sigma : proving_key.polynomials.get_sigmas()) {
sigma = typename Flavor::Polynomial(proving_key.circuit_size);
}
Expand All @@ -187,6 +196,7 @@ template <IsHonkFlavor Flavor> class DeciderProvingKey_ {
{
ZoneScopedN("allocating lookup read counts and tags");
// Allocate the read counts and tags polynomials
vinfo("allocating lookup read counts and tags");
proving_key.polynomials.lookup_read_counts =
typename Flavor::Polynomial(max_tables_size, dyadic_circuit_size, table_offset);
proving_key.polynomials.lookup_read_tags =
Expand All @@ -195,6 +205,7 @@ template <IsHonkFlavor Flavor> class DeciderProvingKey_ {
{
ZoneScopedN("allocating lookup and databus inverses");
// Allocate the lookup_inverses polynomial
vinfo("allocating lookup and databus inverses");
const size_t lookup_offset = static_cast<size_t>(circuit.blocks.lookup.trace_offset);
// TODO(https://github.com/AztecProtocol/barretenberg/issues/1033): construct tables and counts
// at top of trace
Expand Down Expand Up @@ -224,6 +235,7 @@ template <IsHonkFlavor Flavor> class DeciderProvingKey_ {
#ifdef TRACY_MEMORY
ZoneScopedN("constructing z_perm");
#endif
vinfo("constructing z_perm");
// Allocate the z_perm polynomial
proving_key.polynomials.z_perm = Polynomial::shiftable(proving_key.circuit_size);
}
Expand All @@ -232,6 +244,7 @@ template <IsHonkFlavor Flavor> class DeciderProvingKey_ {
#ifdef TRACY_MEMORY
ZoneScopedN("allocating lagrange polynomials");
#endif
vinfo("allocating lagrange polynomials");
// First and last lagrange polynomials (in the full circuit size)
proving_key.polynomials.lagrange_first = Polynomial(1, dyadic_circuit_size, 0);
proving_key.polynomials.lagrange_last = Polynomial(1, dyadic_circuit_size, dyadic_circuit_size - 1);
Expand All @@ -248,12 +261,14 @@ template <IsHonkFlavor Flavor> class DeciderProvingKey_ {
#ifdef TRACY_MEMORY
ZoneScopedN("constructing prover instance after trace populate");
#endif
vinfo("constructing prover instance after trace populate");

// If Goblin, construct the databus polynomials
if constexpr (IsGoblinFlavor<Flavor>) {
#ifdef TRACY_MEMORY
ZoneScopedN("constructing databus polynomials");
#endif
vinfo("constructing databus polynomials");
construct_databus_polynomials(circuit);
}

Expand All @@ -265,6 +280,7 @@ template <IsHonkFlavor Flavor> class DeciderProvingKey_ {
#ifdef TRACY_MEMORY
ZoneScopedN("constructing lookup table polynomials");
#endif
vinfo("constructing lookup table polynomials");
construct_lookup_table_polynomials<Flavor>(
proving_key.polynomials.get_tables(), circuit, dyadic_circuit_size);
}
Expand All @@ -273,6 +289,7 @@ template <IsHonkFlavor Flavor> class DeciderProvingKey_ {
#ifdef TRACY_MEMORY
ZoneScopedN("constructing lookup read counts");
#endif
vinfo("constructing lookup read counts");
construct_lookup_read_counts<Flavor>(proving_key.polynomials.lookup_read_counts,
proving_key.polynomials.lookup_read_tags,
circuit,
Expand Down
3 changes: 3 additions & 0 deletions barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,14 @@ template <IsUltraFlavor Flavor> void UltraProver_<Flavor>::generate_gate_challen
template <IsUltraFlavor Flavor> HonkProof UltraProver_<Flavor>::construct_proof()
{
OinkProver<Flavor> oink_prover(proving_key, transcript);
vinfo("created oink prover");
oink_prover.prove();
vinfo("created oink proof");

generate_gate_challenges();

DeciderProver_<Flavor> decider_prover(proving_key, transcript);
vinfo("created decider prover");
return decider_prover.construct_proof();
}

Expand Down
4 changes: 2 additions & 2 deletions barretenberg/ts/scripts/build_wasm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ set -e
if [ -z "$SKIP_CPP_BUILD" ]; then
# Build the wasms and strip debug symbols.
cd ../cpp
cmake --preset wasm-threads && cmake --build --preset wasm-threads
cmake --preset wasm && cmake --build --preset wasm
cmake --preset wasm-threads -DCMAKE_MESSAGE_LOG_LEVEL=Warning && cmake --build --preset wasm-threads
cmake --preset wasm -DCMAKE_MESSAGE_LOG_LEVEL=Warning && cmake --build --preset wasm
./scripts/strip-wasm.sh
cd ../ts
fi
Expand Down
3 changes: 2 additions & 1 deletion barretenberg/ts/src/barretenberg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export class Barretenberg extends BarretenbergApi {

async initSRSForCircuitSize(circuitSize: number): Promise<void> {
const crs = await Crs.new(circuitSize + Math.floor((circuitSize * 6) / 10) + 1, this.options.crsPath);
await this.commonInitSlabAllocator(circuitSize);
// TODO(https://github.com/AztecProtocol/barretenberg/issues/1129): Do slab allocator initialization?
// await this.commonInitSlabAllocator(circuitSize);
await this.srsInitSrs(new RawBuffer(crs.getG1Data()), crs.numPoints, new RawBuffer(crs.getG2Data()));
}

Expand Down
Loading

0 comments on commit f0d45dd

Please sign in to comment.