Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: bb uses goblin #3636

Merged
merged 54 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
770025e
Pre-convo work
codygunton Dec 8, 2023
a575d00
Shared notes
codygunton Dec 7, 2023
6f54166
Revert false start from yesterday
codygunton Dec 8, 2023
4e3b38c
It builds
codygunton Dec 8, 2023
ecc154a
Notes etc from chat at EOD Friday
codygunton Dec 8, 2023
057e5e8
Put stuff in AcirComposer; everything builds.
codygunton Dec 11, 2023
3fae305
Immunotherapy break
codygunton Dec 11, 2023
8a4ee02
wip
ledwards2225 Dec 11, 2023
5417d50
building and running up to eccvm
ledwards2225 Dec 11, 2023
41965e8
woops
ledwards2225 Dec 11, 2023
cab2300
getting through proof construction
ledwards2225 Dec 11, 2023
4a4e529
Add comment
codygunton Dec 12, 2023
cf43e2c
No composer member
codygunton Dec 12, 2023
794dfa0
Should work but doesn't
codygunton Dec 12, 2023
6ce8c2a
Proofs constructed; ver fails
codygunton Dec 12, 2023
26ea142
Try just Ultra
codygunton Dec 12, 2023
f5be667
Test "passes"
codygunton Dec 12, 2023
bf9d162
Prune and update comments.
codygunton Dec 12, 2023
824b07a
More touching up
codygunton Dec 12, 2023
019d85f
Final touch-up before split
codygunton Dec 12, 2023
76d90f0
Add proof_ assignment
codygunton Dec 12, 2023
545c247
Separate into clean function.
codygunton Dec 12, 2023
8918362
Clean up more
codygunton Dec 13, 2023
d490f74
More cleanup
codygunton Dec 13, 2023
0318707
Add note
codygunton Dec 13, 2023
160ddad
More cleanup and notes
codygunton Dec 13, 2023
e9afe8e
feat: run prove_then_verify_goblin in CI
ludamad0 Dec 13, 2023
79fc7dd
templated necessary acir format fctns
ledwards2225 Dec 13, 2023
36e4de1
one more template fctn
ledwards2225 Dec 13, 2023
fed307d
yet another
ledwards2225 Dec 13, 2023
0d335f8
holy fuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuk
ledwards2225 Dec 13, 2023
12b3599
simplify pnvGoblin plus debug
ledwards2225 Dec 14, 2023
21f1f07
new method properly accounts for noir bug
ledwards2225 Dec 15, 2023
a39a0e0
stable state
ledwards2225 Dec 15, 2023
168b3d5
builder wire offset method works
ledwards2225 Dec 15, 2023
15caf36
debug utility uses labels and db relation passes
ledwards2225 Dec 17, 2023
1eb579f
proof over goblin circuit verifies!
ledwards2225 Dec 18, 2023
6dc5734
quick cleanup pass
ledwards2225 Dec 18, 2023
aa90a4d
more cleanup
ledwards2225 Dec 18, 2023
30b818e
fix conversion issue plus goblin cleanup
ledwards2225 Dec 18, 2023
16b5d1a
provide builder with goblin owned op queue
ledwards2225 Dec 18, 2023
e626337
separate goblin hacks for acir
ledwards2225 Dec 18, 2023
1064031
accum prove and verify returned to original state
ledwards2225 Dec 18, 2023
a70ab09
typename
ledwards2225 Dec 18, 2023
d58d60d
fix: creating too few vars
ludamad0 Dec 18, 2023
3d0afca
woops, actually fix rec verifier this time
ledwards2225 Dec 18, 2023
843a94c
fix: creating too few vars
ludamad0 Dec 18, 2023
c2f8dfc
feat: bb.js calling goblin ultrahonk (#3690)
ludamad Dec 18, 2023
954a878
Merge branch 'master' into cg-lde/expose-goblin
ludamad Dec 18, 2023
5940232
Get ci working
ludamad0 Dec 18, 2023
a533a4d
Update index.ts
ludamad Dec 18, 2023
fdc66f6
update WORKTODOs
ledwards2225 Dec 18, 2023
bb900d6
Merge branch 'cg-lde/expose-goblin' of github.com:AztecProtocol/aztec…
ledwards2225 Dec 18, 2023
c9fb91a
respond to feedback and clean up
ledwards2225 Dec 18, 2023
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
2 changes: 2 additions & 0 deletions barretenberg/acir_tests/Dockerfile.bb
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ COPY . .
# Run every acir test through native bb build prove_then_verify flow.
# This ensures we test independent pk construction through real/garbage witness data paths.
RUN FLOW=prove_then_verify ./run_acir_tests.sh
# TODO(https://github.com/AztecProtocol/barretenberg/issues/811) make this able to run the default test
RUN FLOW=prove_and_verify_goblin ./run_acir_tests.sh assert_statement
# Run 1_mul through native bb build, all_cmds flow, to test all cli args.
RUN VERBOSE=1 FLOW=all_cmds ./run_acir_tests.sh 1_mul
2 changes: 2 additions & 0 deletions barretenberg/acir_tests/Dockerfile.bb.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ COPY . .
ENV VERBOSE=1
# Run double_verify_proof through bb.js on node to check 512k support.
RUN BIN=../ts/dest/node/main.js FLOW=prove_then_verify ./run_acir_tests.sh double_verify_proof
# TODO(https://github.com/AztecProtocol/barretenberg/issues/811) make this able to run double_verify_proof
RUN BIN=../ts/dest/node/main.js FLOW=prove_and_verify_goblin ./run_acir_tests.sh assert_statement
# 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
# Run double_verify_proof through bb.js on chrome testing multi-threaded browser support.
Expand Down
6 changes: 6 additions & 0 deletions barretenberg/acir_tests/flows/prove_and_verify_goblin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
set -eu

VFLAG=${VERBOSE:+-v}

$BIN prove_and_verify_goblin $VFLAG -c $CRS_PATH -b ./target/acir.gz
1 change: 1 addition & 0 deletions barretenberg/cpp/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

# Important srs_db files.
!srs_db/download_ignition.sh
!srs_db/download_grumpkin.sh
!srs_db/ignition/checksums

# Source code.
Expand Down
1 change: 1 addition & 0 deletions barretenberg/cpp/dockerfiles/Dockerfile.wasm-linux-clang
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ RUN ./scripts/strip-wasm.sh
FROM scratch
WORKDIR /usr/src/barretenberg/cpp
COPY . .
COPY --from=builder /usr/src/barretenberg/cpp/srs_db /usr/src/barretenberg/cpp/srs_db
COPY --from=builder /usr/src/barretenberg/cpp/build-wasm/bin/barretenberg.wasm /usr/src/barretenberg/cpp/build-wasm/bin/barretenberg.wasm
COPY --from=builder /usr/src/barretenberg/cpp/build-wasm-threads/bin/barretenberg.wasm /usr/src/barretenberg/cpp/build-wasm-threads/bin/barretenberg.wasm
19 changes: 10 additions & 9 deletions barretenberg/cpp/dockerfiles/Dockerfile.x86_64-linux-clang-assert
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@ FROM alpine:3.17 AS builder
RUN apk update \
&& apk upgrade \
&& apk add --no-cache \
build-base \
clang15 \
cmake \
ninja \
git \
curl \
perl \
clang-extra-tools \
bash
build-base \
clang15 \
cmake \
ninja \
git \
curl \
perl \
clang-extra-tools \
bash
WORKDIR /usr/src/barretenberg/cpp
COPY . .
# Build everything to ensure everything builds. All tests will be run from the result of this build.
RUN ./format.sh check && cmake --preset default -DCMAKE_BUILD_TYPE=RelWithAssert -DCI=ON && cmake --build --preset default
RUN srs_db/download_grumpkin.sh

FROM alpine:3.17
RUN apk update && apk add curl libstdc++
Expand Down
4 changes: 2 additions & 2 deletions barretenberg/cpp/scripts/bb-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ TESTS_STR="${TESTS[@]}"
docker run --rm -t $IMAGE_URI /bin/sh -c "\
set -xe; \
cd /usr/src/barretenberg/cpp; \
(cd srs_db && ./download_ignition.sh 1); \
srs_db/download_ignition.sh 1; \
srs_db/download_grumpkin.sh; \
cd build; \
./bin/grumpkin_srs_gen 1048576; \
for BIN in $TESTS_STR; do ./bin/\$BIN; done"
5 changes: 2 additions & 3 deletions barretenberg/cpp/scripts/run_tests
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ fi

docker run --rm -t $IMAGE_URI /bin/sh -c "\
set -xe; \
cd /usr/src/barretenberg/cpp/srs_db; \
./download_ignition.sh $NUM_TRANSCRIPTS; \
/usr/src/barretenberg/cpp/srs_db/download_ignition.sh $NUM_TRANSCRIPTS; \
/usr/src/barretenberg/cpp/srs_db/download_grumpkin.sh; \
cd /usr/src/barretenberg/cpp/build; \
./bin/grumpkin_srs_gen 1048576; \
for BIN in $TESTS; do ./bin/\$BIN $@; done"
55 changes: 20 additions & 35 deletions barretenberg/cpp/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ include(GNUInstallDirs)
# libbarretenberg + libwasi = a wasi "reactor" that implements it's own env (e.g. logstr), e.g. barretenberg.wasm.
# libbarretenberg + env = a wasi "command" that expects a full wasi runtime (e.g. wasmtime), e.g. test binaries.
message(STATUS "Compiling all-in-one barretenberg archive")
add_library(
barretenberg
STATIC

set(BARRETENBERG_TARGET_OBJECTS
$<TARGET_OBJECTS:commitment_schemes_objects>
$<TARGET_OBJECTS:common_objects>
$<TARGET_OBJECTS:crypto_aes128_objects>
$<TARGET_OBJECTS:crypto_blake2s_objects>
Expand All @@ -111,12 +111,17 @@ add_library(
$<TARGET_OBJECTS:crypto_sha256_objects>
$<TARGET_OBJECTS:dsl_objects>
$<TARGET_OBJECTS:ecc_objects>
$<TARGET_OBJECTS:eccvm_objects>
$<TARGET_OBJECTS:examples_objects>
$<TARGET_OBJECTS:flavor_objects>
$<TARGET_OBJECTS:goblin_objects>
$<TARGET_OBJECTS:honk_objects>
$<TARGET_OBJECTS:numeric_objects>
$<TARGET_OBJECTS:plonk_objects>
$<TARGET_OBJECTS:polynomials_objects>
$<TARGET_OBJECTS:proof_system_objects>
$<TARGET_OBJECTS:protogalaxy_objects>
$<TARGET_OBJECTS:relations_objects>
$<TARGET_OBJECTS:srs_objects>
$<TARGET_OBJECTS:stdlib_aes128_objects>
$<TARGET_OBJECTS:stdlib_blake2s_objects>
Expand All @@ -126,9 +131,18 @@ add_library(
$<TARGET_OBJECTS:stdlib_pedersen_commitment_objects>
$<TARGET_OBJECTS:stdlib_pedersen_hash_objects>
$<TARGET_OBJECTS:stdlib_primitives_objects>
$<TARGET_OBJECTS:stdlib_recursion_objects>
$<TARGET_OBJECTS:stdlib_schnorr_objects>
$<TARGET_OBJECTS:stdlib_sha256_objects>
$<TARGET_OBJECTS:sumcheck_objects>
$<TARGET_OBJECTS:transcript_objects>
$<TARGET_OBJECTS:translator_vm_objects>
$<TARGET_OBJECTS:ultra_honk_objects>)

add_library(
barretenberg
STATIC
${BARRETENBERG_TARGET_OBJECTS}
)

if(WASM)
Expand All @@ -144,36 +158,7 @@ if(WASM)
# to implement the functions in env.
add_executable(
barretenberg.wasm
$<TARGET_OBJECTS:common_objects>
$<TARGET_OBJECTS:crypto_aes128_objects>
$<TARGET_OBJECTS:crypto_blake2s_objects>
$<TARGET_OBJECTS:crypto_blake3s_objects>
$<TARGET_OBJECTS:crypto_ecdsa_objects>
$<TARGET_OBJECTS:crypto_keccak_objects>
$<TARGET_OBJECTS:crypto_pedersen_commitment_objects>
$<TARGET_OBJECTS:crypto_pedersen_hash_objects>
$<TARGET_OBJECTS:crypto_schnorr_objects>
$<TARGET_OBJECTS:crypto_sha256_objects>
$<TARGET_OBJECTS:dsl_objects>
$<TARGET_OBJECTS:ecc_objects>
$<TARGET_OBJECTS:examples_objects>
$<TARGET_OBJECTS:honk_objects>
$<TARGET_OBJECTS:numeric_objects>
$<TARGET_OBJECTS:plonk_objects>
$<TARGET_OBJECTS:polynomials_objects>
$<TARGET_OBJECTS:proof_system_objects>
$<TARGET_OBJECTS:srs_objects>
$<TARGET_OBJECTS:stdlib_aes128_objects>
$<TARGET_OBJECTS:stdlib_blake2s_objects>
$<TARGET_OBJECTS:stdlib_blake3s_objects>
$<TARGET_OBJECTS:stdlib_keccak_objects>
$<TARGET_OBJECTS:stdlib_merkle_tree_objects>
$<TARGET_OBJECTS:stdlib_pedersen_commitment_objects>
$<TARGET_OBJECTS:stdlib_pedersen_hash_objects>
$<TARGET_OBJECTS:stdlib_primitives_objects>
$<TARGET_OBJECTS:stdlib_schnorr_objects>
$<TARGET_OBJECTS:stdlib_sha256_objects>
$<TARGET_OBJECTS:transcript_objects>
${BARRETENBERG_TARGET_OBJECTS}
$<TARGET_OBJECTS:wasi_objects>
)

Expand All @@ -194,12 +179,12 @@ if(WASM)
target_link_options(
barretenberg.wasm
PRIVATE
-nostartfiles -Wl,--no-entry,--export-dynamic,--allow-undefined
-nostartfiles -Wl,--no-entry,--export-dynamic
)

target_link_options(
acvm_backend.wasm
PRIVATE
-nostartfiles -Wl,--no-entry,--export-dynamic,--allow-undefined
-nostartfiles -Wl,--no-entry,--export-dynamic
)
endif()
2 changes: 2 additions & 0 deletions barretenberg/cpp/src/barretenberg/bb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ if (NOT(FUZZING))
add_executable(
bb
main.cpp
get_bn254_crs.cpp
get_grumpkin_crs.cpp
)

target_link_libraries(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,27 @@
#pragma once
#include "exec_pipe.hpp"
#include "file_io.hpp"
#include "log.hpp"
#include <barretenberg/ecc/curves/bn254/g1.hpp>
#include <barretenberg/srs/io.hpp>
#include <filesystem>
#include <fstream>
#include <ios>
#include "get_bn254_crs.hpp"

// Gets the transcript URL from the BARRETENBERG_TRANSCRIPT_URL environment variable, if set.
// Otherwise returns the default URL.
inline std::string getTranscriptURL()
namespace {
std::string get_bn254_transcript_url()
{
const char* ENV_VAR_NAME = "BARRETENBERG_TRANSCRIPT_URL";
const std::string DEFAULT_URL = "https://aztec-ignition.s3.amazonaws.com/MAIN%20IGNITION/monomial/transcript00.dat";

const char* env_url = std::getenv(ENV_VAR_NAME);

auto environment_variable_exists = (env_url && *env_url);
auto environment_variable_exists = ((env_url != nullptr) && *env_url);

return environment_variable_exists ? std::string(env_url) : DEFAULT_URL;
}
} // namespace

inline std::vector<uint8_t> download_g1_data(size_t num_points)
std::vector<uint8_t> download_bn254_g1_data(size_t num_points)
{
size_t g1_start = 28;
size_t g1_end = g1_start + num_points * 64 - 1;

std::string url = getTranscriptURL();
std::string url = get_bn254_transcript_url();

std::string command =
"curl -s -H \"Range: bytes=" + std::to_string(g1_start) + "-" + std::to_string(g1_end) + "\" '" + url + "'";
Expand All @@ -38,23 +32,23 @@ inline std::vector<uint8_t> download_g1_data(size_t num_points)
throw std::runtime_error("Failed to download g1 data.");
}

return exec_pipe(command);
return data;
}

inline std::vector<uint8_t> download_g2_data()
std::vector<uint8_t> download_bn254_g2_data()
{
size_t g2_start = 28 + 5040001 * 64;
size_t g2_end = g2_start + 128 - 1;

std::string url = getTranscriptURL();
std::string url = get_bn254_transcript_url();

std::string command =
"curl -s -H \"Range: bytes=" + std::to_string(g2_start) + "-" + std::to_string(g2_end) + "\" '" + url + "'";

return exec_pipe(command);
}

inline std::vector<barretenberg::g1::affine_element> get_g1_data(const std::filesystem::path& path, size_t num_points)
std::vector<barretenberg::g1::affine_element> get_bn254_g1_data(const std::filesystem::path& path, size_t num_points)
{
std::filesystem::create_directories(path);
std::ifstream size_file(path / "size");
Expand All @@ -74,7 +68,7 @@ inline std::vector<barretenberg::g1::affine_element> get_g1_data(const std::file
}

vinfo("downloading crs...");
auto data = download_g1_data(num_points);
auto data = download_bn254_g1_data(num_points);
write_file(path / "g1.dat", data);

std::ofstream new_size_file(path / "size");
Expand All @@ -90,7 +84,7 @@ inline std::vector<barretenberg::g1::affine_element> get_g1_data(const std::file
return points;
}

inline barretenberg::g2::affine_element get_g2_data(const std::filesystem::path& path)
barretenberg::g2::affine_element get_bn254_g2_data(const std::filesystem::path& path)
{
std::filesystem::create_directories(path);

Expand All @@ -100,7 +94,7 @@ inline barretenberg::g2::affine_element get_g2_data(const std::filesystem::path&
barretenberg::srs::IO<curve::BN254>::read_affine_elements_from_buffer(&g2_point, (char*)data.data(), 128);
return g2_point;
} catch (std::exception&) {
auto data = download_g2_data();
auto data = download_bn254_g2_data();
write_file(path / "g2.dat", data);
barretenberg::g2::affine_element g2_point;
barretenberg::srs::IO<curve::BN254>::read_affine_elements_from_buffer(&g2_point, (char*)data.data(), 128);
Expand Down
12 changes: 12 additions & 0 deletions barretenberg/cpp/src/barretenberg/bb/get_bn254_crs.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once
#include "exec_pipe.hpp"
#include "file_io.hpp"
#include "log.hpp"
#include <barretenberg/ecc/curves/bn254/g1.hpp>
#include <barretenberg/srs/io.hpp>
#include <filesystem>
#include <fstream>
#include <ios>

std::vector<barretenberg::g1::affine_element> get_bn254_g1_data(const std::filesystem::path& path, size_t num_points);
barretenberg::g2::affine_element get_bn254_g2_data(const std::filesystem::path& path);
72 changes: 72 additions & 0 deletions barretenberg/cpp/src/barretenberg/bb/get_grumpkin_crs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include "get_grumpkin_crs.hpp"

// Gets the transcript URL from the BARRETENBERG_GRUMPKIN_TRANSCRIPT_URL environment variable, if set.
// Otherwise returns the default URL.
namespace {
std::string get_grumpkin_transcript_url()
{
const char* ENV_VAR_NAME = "BARRETENBERG_GRUMPKIN_TRANSCRIPT_URL";
const std::string DEFAULT_URL = "https://aztec-ignition.s3.amazonaws.com/TEST%20GRUMPKIN/monomial/transcript00.dat";

const char* env_url = std::getenv(ENV_VAR_NAME);

auto environment_variable_exists = ((env_url != nullptr) && *env_url);

return environment_variable_exists ? env_url : DEFAULT_URL;
}
} // namespace

std::vector<uint8_t> download_grumpkin_g1_data(size_t num_points)
{
size_t g1_start = 28;
size_t g1_end = g1_start + num_points * 64 - 1;

std::string url = get_grumpkin_transcript_url();

std::string command =
"curl -s -H \"Range: bytes=" + std::to_string(g1_start) + "-" + std::to_string(g1_end) + "\" '" + url + "'";

auto data = exec_pipe(command);
// Header + num_points * sizeof point.
if (data.size() < g1_end - g1_start) {
throw std::runtime_error("Failed to download grumpkin g1 data.");
}

return data;
}

std::vector<curve::Grumpkin::AffineElement> get_grumpkin_g1_data(const std::filesystem::path& path, size_t num_points)
{
std::filesystem::create_directories(path);
std::ifstream size_file(path / "grumpkin_size");
size_t size = 0;
if (size_file) {
size_file >> size;
size_file.close();
}
if (size >= num_points) {
vinfo("using cached crs at: ", path);
auto data = read_file(path / "grumpkin_g1.dat", 28 + num_points * 64);
auto points = std::vector<curve::Grumpkin::AffineElement>(num_points);
auto size_of_points_in_bytes = num_points * 64;
barretenberg::srs::IO<curve::Grumpkin>::read_affine_elements_from_buffer(
points.data(), (char*)data.data(), size_of_points_in_bytes);
return points;
}

vinfo("downloading grumpkin crs...");
auto data = download_grumpkin_g1_data(num_points);
write_file(path / "grumpkin_g1.dat", data);

std::ofstream new_size_file(path / "grumpkin_size");
if (!new_size_file) {
throw std::runtime_error("Failed to open size file for writing");
}
new_size_file << num_points;
new_size_file.close();

auto points = std::vector<curve::Grumpkin::AffineElement>(num_points);
barretenberg::srs::IO<curve::Grumpkin>::read_affine_elements_from_buffer(
points.data(), (char*)data.data(), data.size());
return points;
}
11 changes: 11 additions & 0 deletions barretenberg/cpp/src/barretenberg/bb/get_grumpkin_crs.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once
#include "exec_pipe.hpp"
#include "file_io.hpp"
#include "log.hpp"
#include <barretenberg/ecc/curves/bn254/g1.hpp>
#include <barretenberg/srs/io.hpp>
#include <filesystem>
#include <fstream>
#include <ios>

std::vector<curve::Grumpkin::AffineElement> get_grumpkin_g1_data(const std::filesystem::path& path, size_t num_points);
Loading