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

fix(bb.js): (breaking change) bundles bb.js properly so that it works in the browser and in node #1855

Merged
merged 48 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
dcca716
Revert "feat: Modify bb.js to be compatible with next.js (https://git…
charlielye Aug 25, 2023
e7d3696
The work. I accidently did it on barretenberg repo originally 🤦
charlielye Aug 25, 2023
fcef7c1
Simplify bb.js api (remove sync api). Avoids double embedding the wasms.
charlielye Aug 26, 2023
13417bf
Move bin-tests to be part of acir_tests just as another flow.
charlielye Aug 26, 2023
ecf872e
Refactor common code out of barretenberg_wasm.
charlielye Aug 26, 2023
7b77197
Headless chrome runner.
charlielye Aug 26, 2023
50d97c9
Vite example, to be sure. Playwright to test all 3 browsers.
charlielye Aug 28, 2023
2cbe241
Env var to pick browser.
charlielye Aug 31, 2023
fae7bf4
Merge remote-tracking branch 'origin/master' into cl/bb_bundling
charlielye Aug 31, 2023
9d1a993
Let's try just testing bb.js tests at same time as build for simplici…
charlielye Aug 31, 2023
0708c48
Address some review comments.
charlielye Aug 31, 2023
29bd585
Fix a single threaded serialization issue. Improve the test stuff.
charlielye Sep 1, 2023
0ce9de6
Merge remote-tracking branch 'origin/master' into cl/bb_bundling
charlielye Sep 2, 2023
89332ac
Merge remote-tracking branch 'origin/master' into cl/bb_bundling
charlielye Sep 2, 2023
9183444
Build
charlielye Sep 2, 2023
e65b1d8
Mac/Linux base64 can be unified.
charlielye Sep 4, 2023
0830183
Merge remote-tracking branch 'origin/master' into cl/bb_bundling
charlielye Sep 4, 2023
e6db480
Fix
charlielye Sep 4, 2023
7e36672
Run bb.js on spot as cci seems slow. Fix bunch of failing scripts due…
charlielye Sep 4, 2023
13ab8bb
Poke to try and rebuild bb.js
charlielye Sep 4, 2023
1356525
Fix
charlielye Sep 4, 2023
08c3b3a
Fix
charlielye Sep 4, 2023
bfa4e35
[TEST] ci test
ludamad Sep 4, 2023
7fa9fcd
Revert acir test
ludamad Sep 4, 2023
6373c88
Revert acir test
ludamad Sep 4, 2023
f3815dc
Revert acir test
ludamad Sep 4, 2023
f76ce97
Revert acir test
ludamad Sep 4, 2023
e99e01c
Revert acir test
ludamad Sep 4, 2023
563070e
Revert acir test
ludamad Sep 4, 2023
d804fcd
Revert acir test
ludamad Sep 4, 2023
a7e598d
Revert acir test
ludamad Sep 4, 2023
5e51762
Revert acir test
ludamad Sep 4, 2023
f08b783
Revert acir test
ludamad Sep 4, 2023
606d4a8
Revert
ludamad Sep 4, 2023
8102619
Revert
ludamad Sep 4, 2023
688441c
See if git in end-to-end
ludamad Sep 4, 2023
6331ae9
Merge remote-tracking branch 'origin/ludamad-patch-1' into cl/bb_bund…
charlielye Sep 4, 2023
b1d8ac3
Attempt to poke build.
charlielye Sep 4, 2023
17357db
Remove noop in build.
charlielye Sep 4, 2023
ab1f303
Remove framework examples.
charlielye Sep 4, 2023
e81290f
Merge remote-tracking branch 'origin/master' into cl/bb_bundling
charlielye Sep 4, 2023
fa6ede3
Merge remote-tracking branch 'origin/master' into cl/bb_bundling
charlielye Sep 4, 2023
21ede5e
Run double_verify_proof!
charlielye Sep 4, 2023
e0f1f45
Back to master.
charlielye Sep 4, 2023
835e7d7
Don't know st webkit only fails in cci :(
charlielye Sep 4, 2023
d0c6e2f
Add 1_mul to webapp for manual testing.
charlielye Sep 4, 2023
8495e04
Revert "Remove noop in build."
charlielye Sep 4, 2023
abf257c
Merge remote-tracking branch 'origin/master' into cl/bb_bundling
charlielye Sep 4, 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
1 change: 1 addition & 0 deletions barretenberg
2 changes: 2 additions & 0 deletions build_manifest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# commit them, so that the most important build path remains fast and simple.

PROJECTS=(
bb:circuits/cpp/barretenberg/cpp:./dockerfiles/Dockerfile.wasm-linux-clang:barretenberg-wasm-linux-clang
bb.js:circuits/cpp/barretenberg/ts:.Dockerfile:bb.js
circuits:circuits/cpp:./dockerfiles/Dockerfile.wasm-linux-clang:circuits-wasm-linux-clang
l1-contracts:l1-contracts
noir-contracts:yarn-project:DockerFile.build:noir-contracts-build
Expand Down
2 changes: 1 addition & 1 deletion circuits/cpp/barretenberg/acir_tests/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ COPY . .
# Run all native tests.
RUN ./run_acir_tests.sh
# Just run double_verify_proof as a sanity check as bb.js is quite slow.
RUN BB=./run_bb.sh ./run_acir_tests.sh double_verify_proof
RUN BIN=../ts/dest/main.js ./run_acir_tests.sh double_verify_proof
31 changes: 31 additions & 0 deletions circuits/cpp/barretenberg/acir_tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Acir Test Vector Runner

The aim is to verify acir tests verify through a given backend binary. To run:

```
$ ./run_acir_tests.sh
```

This will clone the acir test vectors from the noir repo, and will iterate over each one, running it through the
`../cpp/build/bin/bb` binary (by default) `prove_and_verify` command.

You can substitute the backend binary using the `BIN` environment variable.
You can turn on logging with `VERBOSE` environment variable.
You can specify a specific test to run.

```
$ BIN=bb.js VERBOSE=1 ./run_acir_tests.sh 1_mul
```

You can use a relative path to an executable.

```
$ BIN=../ts/bb.js-dev VERBOSE=1 ./run_acir_tests.sh 1_mul
```

kevaundray marked this conversation as resolved.
Show resolved Hide resolved
You can specify a different testing "flow" with with `FLOW` environment variable. Flows are in the `flows` dir.
The `all_cmds` flow tests (almost) all the supported commands on the binary. Slower, but is there to test the cli.
kevaundray marked this conversation as resolved.
Show resolved Hide resolved

```
$ FLOW=all_cmds ./run_acir_tests.sh 1_mul
```
16 changes: 16 additions & 0 deletions circuits/cpp/barretenberg/acir_tests/flows/all_cmds.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh
set -eu

NAME=$(basename $PWD)

if [ -n "$VERBOSE" ]; then
VFLAG="-v"
fi

BFLAG="-b ./target/${NAME}.bytecode"
FLAGS="-c $CRS_PATH $VFLAG"

$BIN gates $FLAGS $BFLAG
$BIN prove -o proof $FLAGS $BFLAG
$BIN write_vk -o vk $FLAGS $BFLAG
$BIN verify -k vk -p proof $FLAGS
10 changes: 10 additions & 0 deletions circuits/cpp/barretenberg/acir_tests/flows/prove_and_verify.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh
set -eu

NAME=$(basename $PWD)

if [ -n "$VERBOSE" ]; then
$BIN prove_and_verify -v -c $CRS_PATH -b ./target/$NAME.bytecode
else
$BIN prove_and_verify -c $CRS_PATH -b ./target/$NAME.bytecode > /dev/null 2>&1
fi
24 changes: 15 additions & 9 deletions circuits/cpp/barretenberg/acir_tests/run_acir_tests.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
#!/bin/bash
# Env var overrides:
# BB: to specify a different binary to test with (e.g. bb.js or bb.js-dev).
# BIN: to specify a different binary to test with (e.g. bb.js or bb.js-dev).
# VERBOSE: to enable logging for each test.

set -e

BB=$PWD/${BB:-../cpp/build/bin/bb}
BIN=${BIN:-../cpp/build/bin/bb}
FLOW=${FLOW:-prove_and_verify}
CRS_PATH=~/.bb-crs
BRANCH=master
VERBOSE=$VERBOSE

FLOW_SCRIPT=$(realpath ./flows/${FLOW}.sh)

if [[ -f $BIN ]]; then
BIN=$(realpath $BIN)
else
BIN=$(realpath $(which $BIN))
fi

export BIN CRS_PATH VERBOSE

# Pull down the test vectors from the noir repo, if we don't have the folder already.
if [ ! -d acir_tests ]; then
Expand Down Expand Up @@ -48,20 +60,14 @@ function test() {
cd $1

set +e
if [ -n "$VERBOSE" ]; then
$BB prove_and_verify -v -c $CRS_PATH -b ./target/$dir_name.bytecode
else
$BB prove_and_verify -c $CRS_PATH -b ./target/$dir_name.bytecode > /dev/null 2>&1
fi
$FLOW_SCRIPT
result=$?
set -e

if [ $result -eq 0 ]; then
echo -e "\033[32mPASSED\033[0m"
else
echo -e "\033[31mFAILED\033[0m"
# Run again verbose.
$BB prove_and_verify -v -c $CRS_PATH -b ./target/$dir_name.bytecode
exit 1
fi

Expand Down
4 changes: 0 additions & 4 deletions circuits/cpp/barretenberg/acir_tests/run_bb.sh

This file was deleted.

3 changes: 0 additions & 3 deletions circuits/cpp/barretenberg/cpp/bin-test/.gitignore

This file was deleted.

6 changes: 0 additions & 6 deletions circuits/cpp/barretenberg/cpp/bin-test/Nargo.toml

This file was deleted.

6 changes: 0 additions & 6 deletions circuits/cpp/barretenberg/cpp/bin-test/Prover.toml

This file was deleted.

10 changes: 0 additions & 10 deletions circuits/cpp/barretenberg/cpp/bin-test/README.md

This file was deleted.

1 change: 0 additions & 1 deletion circuits/cpp/barretenberg/cpp/bin-test/Verifier.toml

This file was deleted.

12 changes: 0 additions & 12 deletions circuits/cpp/barretenberg/cpp/bin-test/bin-test.sh

This file was deleted.

32 changes: 0 additions & 32 deletions circuits/cpp/barretenberg/cpp/bin-test/src/main.nr

This file was deleted.

1 change: 0 additions & 1 deletion circuits/cpp/barretenberg/cpp/bin-test/target/main.json

This file was deleted.

Binary file not shown.
3 changes: 3 additions & 0 deletions circuits/cpp/barretenberg/cpp/scripts/strip-wasm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
./src/wasi-sdk-20.0/bin/llvm-strip ./build-wasm/bin/barretenberg.wasm
./src/wasi-sdk-20.0/bin/llvm-strip ./build-wasm-threads/bin/barretenberg.wasm
1 change: 1 addition & 0 deletions circuits/cpp/barretenberg/ts-cjs-example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
crs
19 changes: 19 additions & 0 deletions circuits/cpp/barretenberg/ts-cjs-example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "ts-cjs-example",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"start": "ts-node ./src"
},
"dependencies": {
"@aztec/bb.js": "../ts",
"debug": "^4.3.4"
},
"devDependencies": {
"@types/debug": "^4.1.8",
"@types/node": "^20.5.6",
"ts-node": "^10.9.1",
"typescript": "^4"
}
}
40 changes: 40 additions & 0 deletions circuits/cpp/barretenberg/ts-cjs-example/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import createDebug from "debug";

createDebug.enable("simple_test,bb*");
const debug = createDebug("simple_test");

async function main() {
const { loadModule } = await import("@aztec/bb.js");
const { Barretenberg, RawBuffer, Crs } = await loadModule();
const CIRCUIT_SIZE = 2 ** 19;

debug("starting test...");
const api = await Barretenberg.new();

// Important to init slab allocator as first thing, to ensure maximum memory efficiency.
await api.commonInitSlabAllocator(CIRCUIT_SIZE);

// Plus 1 needed!
const crs = await Crs.new(CIRCUIT_SIZE + 1);
await api.srsInitSrs(
new RawBuffer(crs.getG1Data()),
crs.numPoints,
new RawBuffer(crs.getG2Data())
);

const iterations = 1;
let totalTime = 0;
for (let i = 0; i < iterations; ++i) {
const start = new Date().getTime();
debug(`iteration ${i} starting...`);
await api.examplesSimpleCreateAndVerifyProof();
totalTime += new Date().getTime() - start;
}

await api.destroy();

debug(`avg iteration time: ${totalTime / iterations}ms`);
debug("test complete.");
}

main();
17 changes: 17 additions & 0 deletions circuits/cpp/barretenberg/ts-cjs-example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"target": "es2020",
"module": "commonjs",
"moduleResolution": "node",
"esModuleInterop": true, // Allows default imports from modules with no default export
"allowSyntheticDefaultImports": true, // Allow default imports from modules with no default export
"strict": true, // Enable all strict type-checking options
"skipLibCheck": true, // Skip type checking of declaration files
"forceConsistentCasingInFileNames": true, // Disallow inconsistently-cased references to the same file
"outDir": "./dist", // Where to put the compiled JavaScript
"rootDir": "./src", // Where the source TypeScript files are
"declaration": true, // Generate corresponding .d.ts file (useful if you're building a library)
"sourceMap": true, // Generate corresponding .map file for debugging
"noImplicitAny": true
}
}
Loading