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
8 changes: 0 additions & 8 deletions .test_patterns.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ tests:
error_regex: "field_t::range_constraint"
owners:
- *luke
- regex: "barretenberg/acir_tests/scripts/run_test_browser.sh"
owners:
- *luke
- regex: "barretenberg/acir_tests/scripts/run_test_browser.sh"
error_regex: "Failed to fetch"
owners:
Expand Down Expand Up @@ -198,11 +195,6 @@ tests:
owners:
- *grego

- regex: "boxes/scripts/run_test.sh"
error_regex: "expect(locator).toBeVisible()"
owners:
- *esau

# kind tests
- regex: "spartan/bootstrap.sh"
# Will skip all kind tests for now. Too unstable, blocking merge queue.
Expand Down
2 changes: 1 addition & 1 deletion barretenberg/acir_tests/bbjs-test/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ program
.option("-w, --witness-path <path>", "witness path")
.option("-o, --output-directory <path>", "output directory")
.option("-h, --oracle-hash <hash>", "oracle hash")
.option("-multi-threaded", "multi-threaded")
.option("--multi-threaded", "multi-threaded")
.action((args) => generateProof(args));

program
Expand Down
10 changes: 5 additions & 5 deletions barretenberg/acir_tests/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ function test_cmds_internal {

# barretenberg-acir-tests-bb.js:
# Browser tests.
echo BROWSER=chrome THREAD_MODEL=mt $run_test_browser verify_honk_proof
echo BROWSER=chrome THREAD_MODEL=st $run_test_browser 1_mul
echo BROWSER=webkit THREAD_MODEL=mt $run_test_browser verify_honk_proof
echo BROWSER=webkit THREAD_MODEL=st $run_test_browser 1_mul
echo BROWSER=chrome $run_test_browser verify_honk_proof
echo BROWSER=chrome $run_test_browser 1_mul
echo BROWSER=webkit $run_test_browser verify_honk_proof
echo BROWSER=webkit $run_test_browser 1_mul
# echo ecdsa_secp256r1_3x through bb.js on node to check 256k support.
echo BIN=$bbjs_bin FLOW=prove_then_verify $run_test ecdsa_secp256r1_3x
# echo the prove then verify flow for UltraHonk. This makes sure we have the same circuit for different witness inputs.
Expand Down Expand Up @@ -187,7 +187,7 @@ function test_cmds_internal {

# prove and verify using bb.js classes
echo SYS=ultra_honk FLOW=bbjs_prove_verify $run_test 1_mul
echo SYS=ultra_honk FLOW=bbjs_prove_verify THREAD_MODEL=mt $run_test assert_statement
echo SYS=ultra_honk FLOW=bbjs_prove_verify $run_test assert_statement

# prove with bb.js and verify with solidity verifier
echo SYS=ultra_honk FLOW=bbjs_prove_sol_verify $run_test 1_mul
Expand Down
4 changes: 1 addition & 3 deletions barretenberg/acir_tests/browser-test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@
"type": "module",
"scripts": {
"build": "rm -rf dest && webpack",
"serve:dest:st": "serve -n -L -p ${PORT:-8080} -c ../serve.json dest",
"serve:dest:mt": "serve -n -L -p ${PORT:-8080} -c ../serve.json dest"
"serve": "serve -n -L -p ${PORT:-8080} -c ../serve.json dest"
},
"devDependencies": {
"@aztec/bb.js": "portal:../../ts",
"@types/debug": "^4.1.12",
"@types/pako": "^2.0.3",
"debug": "^4.3.4",
"html-webpack-plugin": "^5.6.0",
"ignore-loader": "^0.1.2",
"pako": "^2.1.0",
"serve": "^14.2.1",
"ts-loader": "^9.5.1",
Expand Down
12 changes: 12 additions & 0 deletions barretenberg/acir_tests/browser-test-app/serve.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@
{
"key": "Cross-Origin-Opener-Policy",
"value": "same-origin"
},
{
"key": "Access-Control-Allow-Origin",
"value": "*"
},
{
"key": "Access-Control-Allow-Methods",
"value": "GET, POST, PUT, DELETE, OPTIONS"
},
{
"key": "Access-Control-Allow-Headers",
"value": "Content-Type, Authorization"
}
]
}
Expand Down
36 changes: 23 additions & 13 deletions barretenberg/acir_tests/browser-test-app/src/index.ts

Large diffs are not rendered by default.

20 changes: 7 additions & 13 deletions barretenberg/acir_tests/browser-test-app/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,24 @@ export default {
{
test: /\.tsx?$/,
loader: 'ts-loader',
exclude: /node_modules|\.d\.ts(.map)?$/
},
{
test: /\.d\.ts(.map)?$/,
loader: 'ignore-loader'
},
],
},
output: {
path: resolve(dirname(fileURLToPath(import.meta.url)), "./dest"),
publicPath: "/",
filename: "[name].js",
library: {
type: 'module',
},
chunkFormat: 'module',
},
experiments: {
outputModule: true,
},
optimization: {
splitChunks: {
// Cannot use async due to https://github.com/webpack/webpack/issues/17014
// messing with module workers loaded asynchronously.
chunks: /barretenberg.*.js/,
},
},
plugins: [
new HtmlWebpackPlugin({ inject: false, template: "./src/index.html" }),
new webpack.DefinePlugin({ "process.env.NODE_DEBUG": false }),
Expand All @@ -47,9 +45,5 @@ export default {
logging: "none",
overlay: false,
},
headers: {
"Cross-Origin-Opener-Policy": "same-origin",
"Cross-Origin-Embedder-Policy": "require-corp",
},
},
};
2 changes: 1 addition & 1 deletion barretenberg/acir_tests/flows/bbjs_prove_verify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ node ../../bbjs-test prove \
-b $artifact_dir/program.json \
-w $artifact_dir/witness.gz \
-o $output_dir \
${THREAD_MODEL:-st} = "mt" && echo "--multi-threaded"
--multi-threaded

# Verify the proof by reading the files in ./target
node ../../bbjs-test verify \
Expand Down
66 changes: 57 additions & 9 deletions barretenberg/acir_tests/headless-test/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import fs from "fs";
import { Command } from "commander";
import chalk from "chalk";
import os from "os";
import type { ProofData } from "@aztec/bb.js";

const { BROWSER, PORT = "8080" } = process.env;

Expand Down Expand Up @@ -66,7 +67,7 @@ program
"Specify the path to the gzip encoded ACIR witness",
"./target/witness.gz"
)
.action(async ({ bytecodePath, witnessPath, }) => {
.action(async ({ bytecodePath, witnessPath }) => {
const acir = readBytecodeFile(bytecodePath);
const witness = readWitnessFile(witnessPath);
const threads = Math.min(os.cpus().length, 16);
Expand All @@ -81,28 +82,75 @@ program
const browser = await browserType.launch();

const context = await browser.newContext();
const page = await context.newPage();
const provingPage = await context.newPage();

if (program.opts().verbose) {
page.on("console", (msg) => formatAndPrintLog(msg.text()));
provingPage.on("console", (msg) => formatAndPrintLog(msg.text()));
}

await page.goto(`http://localhost:${PORT}`);

const result: boolean = await page.evaluate(
([acir, witnessData, threads]: [string, number[], number]) => {
await provingPage.goto(`http://localhost:${PORT}`);

const {
publicInputs,
proof,
verificationKey,
}: {
publicInputs: string[];
proof: number[];
verificationKey: number[];
} = await provingPage.evaluate(
async ([acir, witnessData, threads]: [string, number[], number]) => {
// Convert the input data to Uint8Arrays within the browser context
const witnessUint8Array = new Uint8Array(witnessData);

// Call the desired function and return the result
return (window as any).runTest(acir, witnessUint8Array, threads);
const {
proofData,
verificationKey,
}: { proofData: ProofData; verificationKey: Uint8Array } = await (
window as any
).prove(acir, witnessUint8Array, threads);

return {
publicInputs: proofData.publicInputs,
proof: Array.from(proofData.proof),
verificationKey: Array.from(verificationKey),
};
},
[acir, Array.from(witness), threads]
);
await provingPage.close();

// Creating a new page to verify the proof, so this bug is avoided
// https://bugs.webkit.org/show_bug.cgi?id=245346
// Present at least on playwright 1.49.0

const verificationPage = await context.newPage();
await verificationPage.goto(`http://localhost:${PORT}`);

if (program.opts().verbose) {
verificationPage.on("console", (msg) => formatAndPrintLog(msg.text()));
}

const verificationResult: boolean = await verificationPage.evaluate(
([publicInputs, proof, verificationKey]: [
string[],
number[],
number[]
]) => {
const verificationKeyUint8Array = new Uint8Array(verificationKey);
const proofData: ProofData = {
publicInputs,
proof: new Uint8Array(proof),
};
return (window as any).verify(proofData, verificationKeyUint8Array);
},
[publicInputs, proof, verificationKey]
);

await browser.close();

if (!result) {
if (!verificationResult) {
process.exit(1);
}
}
Expand Down
5 changes: 2 additions & 3 deletions barretenberg/acir_tests/scripts/run_test_browser.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -eu

test=$1

name="$BROWSER-$THREAD_MODEL-$test${NAME_POSTFIX:-}"
name="$BROWSER-$test${NAME_POSTFIX:-}"
trap 'docker kill $name &>/dev/null; docker rm $name &>/dev/null' SIGINT SIGTERM

docker run --rm \
Expand All @@ -17,13 +17,12 @@ docker run --rm \
--workdir /root/aztec-packages/barretenberg/acir_tests \
-e NODE_OPTIONS="--no-warnings --experimental-vm-modules" \
-e BROWSER=${BROWSER:-chrome,webkit} \
-e THREAD_MODEL=${THREAD_MODEL:-mt} \
-e TEST=$test \
-e VERBOSE=${VERBOSE:-0} \
aztecprotocol/build:3.0 bash -c '
git config --global --add safe.directory /root/aztec-packages
source /root/aztec-packages/ci3/source
dump_fail "cd browser-test-app && yarn serve:dest:$THREAD_MODEL" > /dev/null &
dump_fail "cd browser-test-app && yarn serve" > /dev/null &
while ! nc -z localhost 8080 &>/dev/null; do sleep 1; done;
BIN=./headless-test/bb.js.browser ./scripts/run_test.sh $TEST
'
8 changes: 0 additions & 8 deletions barretenberg/acir_tests/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,6 @@ __metadata:
"@types/pako": "npm:^2.0.3"
debug: "npm:^4.3.4"
html-webpack-plugin: "npm:^5.6.0"
ignore-loader: "npm:^0.1.2"
pako: "npm:^2.1.0"
serve: "npm:^14.2.1"
ts-loader: "npm:^9.5.1"
Expand Down Expand Up @@ -2734,13 +2733,6 @@ __metadata:
languageName: node
linkType: hard

"ignore-loader@npm:^0.1.2":
version: 0.1.2
resolution: "ignore-loader@npm:0.1.2"
checksum: 10c0/0ba7f0fbcd4d796e68cc05723279b662dea32f229f5912c6ce4fbcc5a50f592d2b6f32baaf047b47b24dccdfdc9faf2db504b48cb6eb886a4969bfc293739cab
languageName: node
linkType: hard

"import-fresh@npm:^3.3.0":
version: 3.3.1
resolution: "import-fresh@npm:3.3.1"
Expand Down
5 changes: 3 additions & 2 deletions barretenberg/ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"homepage": "https://github.com/AztecProtocol/aztec-packages/tree/master/barretenberg/ts",
"license": "MIT",
"type": "module",
"types": "./dest/node-cjs/index.d.ts",
"types": "./dest/node/index.d.ts",
"exports": {
".": {
"require": "./dest/node-cjs/index.js",
Expand All @@ -24,7 +24,7 @@
"clean": "rm -rf ./dest .tsbuildinfo .tsbuildinfo.cjs",
"build": "yarn clean && yarn build:wasm && yarn build:esm && yarn build:cjs && yarn build:browser",
"build:wasm": "./scripts/build_wasm.sh",
"build:esm": "tsc -b && chmod +x ./dest/node/main.js",
"build:esm": "tsc -b tsconfig.esm.json && chmod +x ./dest/node/main.js",
"build:cjs": "tsc -b tsconfig.cjs.json && ./scripts/cjs_postprocess.sh",
"build:browser": "webpack",
"build:bindings": "cd .. && ./scripts/bindgen.sh",
Expand Down Expand Up @@ -89,6 +89,7 @@
"idb-keyval": "^6.2.1",
"jest": "^29.5.0",
"msgpackr": "^1.11.2",
"node-polyfill-webpack-plugin": "^4.1.0",
"prettier": "^2.8.4",
"terser-webpack-plugin": "^5.3.14",
"ts-jest": "^29.1.0",
Expand Down
2 changes: 1 addition & 1 deletion barretenberg/ts/scripts/cjs_postprocess.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ for FILE in $(find "$DIR" -name "*.js"); do
sed -i.bak 's/import\.meta\.url/""/g' "$FILE" && rm "$FILE.bak"
# Use sed to remove any lines postfixed // POSTPROCESS ESM ONLY
sed -i.bak '/\/\/ POSTPROCESS ESM ONLY$/d' "$FILE" && rm "$FILE.bak"
done
done
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { readinessListener } from '../../../helpers/browser/index.js';
export async function createMainWorker() {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const worker = new Worker(new URL('./main.worker.js', import.meta.url), {
const worker = new Worker(new URL(/* webpackIgnore: true */ './main.worker.js', import.meta.url), {
type: 'module',
});
const debugStr = debug.disable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { readinessListener } from '../../../helpers/browser/index.js';
export async function createThreadWorker() {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const worker = new Worker(new URL('./thread.worker.js', import.meta.url), {
const worker = new Worker(new URL(/* webpackIgnore: true */ './thread.worker.js', import.meta.url), {
type: 'module',
});
const debugStr = debug.disable();
Expand Down
5 changes: 4 additions & 1 deletion barretenberg/ts/tsconfig.browser.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{
"extends": ".",
"compilerOptions": {
"composite": false,
"declaration": false,
"declarationMap": false,
"sourceMap": false,
"outDir": "dest/browser",
"tsBuildInfoFile": ".tsbuildinfo.browser"
},
"include": ["!src/main.ts", "src", "src/barretenberg_wasm/barretenberg_wasm_thread/factory/browser/thread.worker.ts", "src/barretenberg_wasm/barretenberg_wasm_main/factory/browser/main.worker.ts"]
}
7 changes: 7 additions & 0 deletions barretenberg/ts/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "dest/node",
"tsBuildInfoFile": "/dev/null",
}
}
2 changes: 0 additions & 2 deletions barretenberg/ts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
"isolatedModules": true,
"skipLibCheck": true,
"composite": true,
"outDir": "dest/node",
"rootDir": "src",
"tsBuildInfoFile": "/dev/null"
},
"include": ["src"]
}
Loading