Skip to content

Commit 080485a

Browse files
Thunkarnventuro
andauthored
fix: more worker fixes (#13759)
Of course webpack wasn't going to cooperate. * Ignore webpack's web-worker loader and do it ourselves. * Fix the web build since it doesn't make sense for it to include TS stuff * Ensure all the downstream projects work with new bundling Cleaned up flakes: * `bb` browser test seems to have a nice regexp for the flake, the "catchall" version only hid real errors * Only timeouts on boxes may be flakes, the locator.toBeVisible() hides real errors Also noticed the THREAD_MODEL in `acir_tests` was not being honored, we were always running in multithreaded mode (which is what makes sense for proving/verifying), so got rid of it. Also, the requisites for single threaded bb.js are strictly a subset of the ones for multithreading, so we're fine. Edit: Had to split the test due to running into this webkit bug: https://bugs.webkit.org/show_bug.cgi?id=245346 --------- Co-authored-by: Nicolás Venturo <[email protected]>
1 parent e96e5bf commit 080485a

File tree

28 files changed

+1078
-124
lines changed

28 files changed

+1078
-124
lines changed

.test_patterns.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ tests:
4141
error_regex: "field_t::range_constraint"
4242
owners:
4343
- *luke
44-
- regex: "barretenberg/acir_tests/scripts/run_test_browser.sh"
45-
owners:
46-
- *luke
4744
- regex: "barretenberg/acir_tests/scripts/run_test_browser.sh"
4845
error_regex: "Failed to fetch"
4946
owners:
@@ -198,11 +195,6 @@ tests:
198195
owners:
199196
- *grego
200197

201-
- regex: "boxes/scripts/run_test.sh"
202-
error_regex: "expect(locator).toBeVisible()"
203-
owners:
204-
- *esau
205-
206198
# kind tests
207199
- regex: "spartan/bootstrap.sh"
208200
# Will skip all kind tests for now. Too unstable, blocking merge queue.

barretenberg/acir_tests/bbjs-test/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ program
111111
.option("-w, --witness-path <path>", "witness path")
112112
.option("-o, --output-directory <path>", "output directory")
113113
.option("-h, --oracle-hash <hash>", "oracle hash")
114-
.option("-multi-threaded", "multi-threaded")
114+
.option("--multi-threaded", "multi-threaded")
115115
.action((args) => generateProof(args));
116116

117117
program

barretenberg/acir_tests/bootstrap.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,10 @@ function test_cmds_internal {
149149

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

188188
# prove and verify using bb.js classes
189189
echo SYS=ultra_honk FLOW=bbjs_prove_verify $run_test 1_mul
190-
echo SYS=ultra_honk FLOW=bbjs_prove_verify THREAD_MODEL=mt $run_test assert_statement
190+
echo SYS=ultra_honk FLOW=bbjs_prove_verify $run_test assert_statement
191191

192192
# prove with bb.js and verify with solidity verifier
193193
echo SYS=ultra_honk FLOW=bbjs_prove_sol_verify $run_test 1_mul

barretenberg/acir_tests/browser-test-app/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@
66
"type": "module",
77
"scripts": {
88
"build": "rm -rf dest && webpack",
9-
"serve:dest:st": "serve -n -L -p ${PORT:-8080} -c ../serve.json dest",
10-
"serve:dest:mt": "serve -n -L -p ${PORT:-8080} -c ../serve.json dest"
9+
"serve": "serve -n -L -p ${PORT:-8080} -c ../serve.json dest"
1110
},
1211
"devDependencies": {
1312
"@aztec/bb.js": "portal:../../ts",
1413
"@types/debug": "^4.1.12",
1514
"@types/pako": "^2.0.3",
1615
"debug": "^4.3.4",
1716
"html-webpack-plugin": "^5.6.0",
18-
"ignore-loader": "^0.1.2",
1917
"pako": "^2.1.0",
2018
"serve": "^14.2.1",
2119
"ts-loader": "^9.5.1",

barretenberg/acir_tests/browser-test-app/serve.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@
1010
{
1111
"key": "Cross-Origin-Opener-Policy",
1212
"value": "same-origin"
13+
},
14+
{
15+
"key": "Access-Control-Allow-Origin",
16+
"value": "*"
17+
},
18+
{
19+
"key": "Access-Control-Allow-Methods",
20+
"value": "GET, POST, PUT, DELETE, OPTIONS"
21+
},
22+
{
23+
"key": "Access-Control-Allow-Headers",
24+
"value": "Content-Type, Authorization"
1325
}
1426
]
1527
}

barretenberg/acir_tests/browser-test-app/src/index.ts

Lines changed: 23 additions & 13 deletions
Large diffs are not rendered by default.

barretenberg/acir_tests/browser-test-app/webpack.config.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,24 @@ export default {
1414
{
1515
test: /\.tsx?$/,
1616
loader: 'ts-loader',
17-
exclude: /node_modules|\.d\.ts(.map)?$/
18-
},
19-
{
20-
test: /\.d\.ts(.map)?$/,
21-
loader: 'ignore-loader'
2217
},
2318
],
2419
},
2520
output: {
2621
path: resolve(dirname(fileURLToPath(import.meta.url)), "./dest"),
27-
publicPath: "/",
2822
filename: "[name].js",
29-
library: {
30-
type: 'module',
31-
},
3223
chunkFormat: 'module',
3324
},
3425
experiments: {
3526
outputModule: true,
3627
},
28+
optimization: {
29+
splitChunks: {
30+
// Cannot use async due to https://github.com/webpack/webpack/issues/17014
31+
// messing with module workers loaded asynchronously.
32+
chunks: /barretenberg.*.js/,
33+
},
34+
},
3735
plugins: [
3836
new HtmlWebpackPlugin({ inject: false, template: "./src/index.html" }),
3937
new webpack.DefinePlugin({ "process.env.NODE_DEBUG": false }),
@@ -47,9 +45,5 @@ export default {
4745
logging: "none",
4846
overlay: false,
4947
},
50-
headers: {
51-
"Cross-Origin-Opener-Policy": "same-origin",
52-
"Cross-Origin-Embedder-Policy": "require-corp",
53-
},
5448
},
5549
};

barretenberg/acir_tests/flows/bbjs_prove_verify.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ node ../../bbjs-test prove \
2020
-b $artifact_dir/program.json \
2121
-w $artifact_dir/witness.gz \
2222
-o $output_dir \
23-
${THREAD_MODEL:-st} = "mt" && echo "--multi-threaded"
23+
--multi-threaded
2424

2525
# Verify the proof by reading the files in ./target
2626
node ../../bbjs-test verify \

barretenberg/acir_tests/headless-test/src/index.ts

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import fs from "fs";
33
import { Command } from "commander";
44
import chalk from "chalk";
55
import os from "os";
6+
import type { ProofData } from "@aztec/bb.js";
67

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

@@ -66,7 +67,7 @@ program
6667
"Specify the path to the gzip encoded ACIR witness",
6768
"./target/witness.gz"
6869
)
69-
.action(async ({ bytecodePath, witnessPath, }) => {
70+
.action(async ({ bytecodePath, witnessPath }) => {
7071
const acir = readBytecodeFile(bytecodePath);
7172
const witness = readWitnessFile(witnessPath);
7273
const threads = Math.min(os.cpus().length, 16);
@@ -81,28 +82,75 @@ program
8182
const browser = await browserType.launch();
8283

8384
const context = await browser.newContext();
84-
const page = await context.newPage();
85+
const provingPage = await context.newPage();
8586

8687
if (program.opts().verbose) {
87-
page.on("console", (msg) => formatAndPrintLog(msg.text()));
88+
provingPage.on("console", (msg) => formatAndPrintLog(msg.text()));
8889
}
8990

90-
await page.goto(`http://localhost:${PORT}`);
91-
92-
const result: boolean = await page.evaluate(
93-
([acir, witnessData, threads]: [string, number[], number]) => {
91+
await provingPage.goto(`http://localhost:${PORT}`);
92+
93+
const {
94+
publicInputs,
95+
proof,
96+
verificationKey,
97+
}: {
98+
publicInputs: string[];
99+
proof: number[];
100+
verificationKey: number[];
101+
} = await provingPage.evaluate(
102+
async ([acir, witnessData, threads]: [string, number[], number]) => {
94103
// Convert the input data to Uint8Arrays within the browser context
95104
const witnessUint8Array = new Uint8Array(witnessData);
96105

97106
// Call the desired function and return the result
98-
return (window as any).runTest(acir, witnessUint8Array, threads);
107+
const {
108+
proofData,
109+
verificationKey,
110+
}: { proofData: ProofData; verificationKey: Uint8Array } = await (
111+
window as any
112+
).prove(acir, witnessUint8Array, threads);
113+
114+
return {
115+
publicInputs: proofData.publicInputs,
116+
proof: Array.from(proofData.proof),
117+
verificationKey: Array.from(verificationKey),
118+
};
99119
},
100120
[acir, Array.from(witness), threads]
101121
);
122+
await provingPage.close();
123+
124+
// Creating a new page to verify the proof, so this bug is avoided
125+
// https://bugs.webkit.org/show_bug.cgi?id=245346
126+
// Present at least on playwright 1.49.0
127+
128+
const verificationPage = await context.newPage();
129+
await verificationPage.goto(`http://localhost:${PORT}`);
130+
131+
if (program.opts().verbose) {
132+
verificationPage.on("console", (msg) => formatAndPrintLog(msg.text()));
133+
}
134+
135+
const verificationResult: boolean = await verificationPage.evaluate(
136+
([publicInputs, proof, verificationKey]: [
137+
string[],
138+
number[],
139+
number[]
140+
]) => {
141+
const verificationKeyUint8Array = new Uint8Array(verificationKey);
142+
const proofData: ProofData = {
143+
publicInputs,
144+
proof: new Uint8Array(proof),
145+
};
146+
return (window as any).verify(proofData, verificationKeyUint8Array);
147+
},
148+
[publicInputs, proof, verificationKey]
149+
);
102150

103151
await browser.close();
104152

105-
if (!result) {
153+
if (!verificationResult) {
106154
process.exit(1);
107155
}
108156
}

barretenberg/acir_tests/scripts/run_test_browser.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -eu
44

55
test=$1
66

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

1010
docker run --rm \
@@ -17,13 +17,12 @@ docker run --rm \
1717
--workdir /root/aztec-packages/barretenberg/acir_tests \
1818
-e NODE_OPTIONS="--no-warnings --experimental-vm-modules" \
1919
-e BROWSER=${BROWSER:-chrome,webkit} \
20-
-e THREAD_MODEL=${THREAD_MODEL:-mt} \
2120
-e TEST=$test \
2221
-e VERBOSE=${VERBOSE:-0} \
2322
aztecprotocol/build:3.0 bash -c '
2423
git config --global --add safe.directory /root/aztec-packages
2524
source /root/aztec-packages/ci3/source
26-
dump_fail "cd browser-test-app && yarn serve:dest:$THREAD_MODEL" > /dev/null &
25+
dump_fail "cd browser-test-app && yarn serve" > /dev/null &
2726
while ! nc -z localhost 8080 &>/dev/null; do sleep 1; done;
2827
BIN=./headless-test/bb.js.browser ./scripts/run_test.sh $TEST
2928
'

barretenberg/acir_tests/yarn.lock

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,6 @@ __metadata:
11801180
"@types/pako": "npm:^2.0.3"
11811181
debug: "npm:^4.3.4"
11821182
html-webpack-plugin: "npm:^5.6.0"
1183-
ignore-loader: "npm:^0.1.2"
11841183
pako: "npm:^2.1.0"
11851184
serve: "npm:^14.2.1"
11861185
ts-loader: "npm:^9.5.1"
@@ -2734,13 +2733,6 @@ __metadata:
27342733
languageName: node
27352734
linkType: hard
27362735

2737-
"ignore-loader@npm:^0.1.2":
2738-
version: 0.1.2
2739-
resolution: "ignore-loader@npm:0.1.2"
2740-
checksum: 10c0/0ba7f0fbcd4d796e68cc05723279b662dea32f229f5912c6ce4fbcc5a50f592d2b6f32baaf047b47b24dccdfdc9faf2db504b48cb6eb886a4969bfc293739cab
2741-
languageName: node
2742-
linkType: hard
2743-
27442736
"import-fresh@npm:^3.3.0":
27452737
version: 3.3.1
27462738
resolution: "import-fresh@npm:3.3.1"

barretenberg/ts/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"homepage": "https://github.com/AztecProtocol/aztec-packages/tree/master/barretenberg/ts",
66
"license": "MIT",
77
"type": "module",
8-
"types": "./dest/node-cjs/index.d.ts",
8+
"types": "./dest/node/index.d.ts",
99
"exports": {
1010
".": {
1111
"require": "./dest/node-cjs/index.js",
@@ -24,7 +24,7 @@
2424
"clean": "rm -rf ./dest .tsbuildinfo .tsbuildinfo.cjs",
2525
"build": "yarn clean && yarn build:wasm && yarn build:esm && yarn build:cjs && yarn build:browser",
2626
"build:wasm": "./scripts/build_wasm.sh",
27-
"build:esm": "tsc -b && chmod +x ./dest/node/main.js",
27+
"build:esm": "tsc -b tsconfig.esm.json && chmod +x ./dest/node/main.js",
2828
"build:cjs": "tsc -b tsconfig.cjs.json && ./scripts/cjs_postprocess.sh",
2929
"build:browser": "webpack",
3030
"build:bindings": "cd .. && ./scripts/bindgen.sh",
@@ -89,6 +89,7 @@
8989
"idb-keyval": "^6.2.1",
9090
"jest": "^29.5.0",
9191
"msgpackr": "^1.11.2",
92+
"node-polyfill-webpack-plugin": "^4.1.0",
9293
"prettier": "^2.8.4",
9394
"terser-webpack-plugin": "^5.3.14",
9495
"ts-jest": "^29.1.0",

barretenberg/ts/scripts/cjs_postprocess.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ for FILE in $(find "$DIR" -name "*.js"); do
1313
sed -i.bak 's/import\.meta\.url/""/g' "$FILE" && rm "$FILE.bak"
1414
# Use sed to remove any lines postfixed // POSTPROCESS ESM ONLY
1515
sed -i.bak '/\/\/ POSTPROCESS ESM ONLY$/d' "$FILE" && rm "$FILE.bak"
16-
done
16+
done

barretenberg/ts/src/barretenberg_wasm/barretenberg_wasm_main/factory/browser/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { readinessListener } from '../../../helpers/browser/index.js';
44
export async function createMainWorker() {
55
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
66
// @ts-ignore
7-
const worker = new Worker(new URL('./main.worker.js', import.meta.url), {
7+
const worker = new Worker(new URL(/* webpackIgnore: true */ './main.worker.js', import.meta.url), {
88
type: 'module',
99
});
1010
const debugStr = debug.disable();

barretenberg/ts/src/barretenberg_wasm/barretenberg_wasm_thread/factory/browser/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { readinessListener } from '../../../helpers/browser/index.js';
44
export async function createThreadWorker() {
55
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
66
// @ts-ignore
7-
const worker = new Worker(new URL('./thread.worker.js', import.meta.url), {
7+
const worker = new Worker(new URL(/* webpackIgnore: true */ './thread.worker.js', import.meta.url), {
88
type: 'module',
99
});
1010
const debugStr = debug.disable();

barretenberg/ts/tsconfig.browser.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
{
22
"extends": ".",
33
"compilerOptions": {
4+
"composite": false,
5+
"declaration": false,
6+
"declarationMap": false,
7+
"sourceMap": false,
48
"outDir": "dest/browser",
5-
"tsBuildInfoFile": ".tsbuildinfo.browser"
69
},
710
"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"]
811
}

barretenberg/ts/tsconfig.esm.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "dest/node",
5+
"tsBuildInfoFile": "/dev/null",
6+
}
7+
}

barretenberg/ts/tsconfig.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
"isolatedModules": true,
1616
"skipLibCheck": true,
1717
"composite": true,
18-
"outDir": "dest/node",
1918
"rootDir": "src",
20-
"tsBuildInfoFile": "/dev/null"
2119
},
2220
"include": ["src"]
2321
}

0 commit comments

Comments
 (0)