Skip to content

Commit

Permalink
feat: PXE browser proving (#10704)
Browse files Browse the repository at this point in the history
Closes: #10587

- Imports `bb.js` as a prover for PXE, both in the browser and in the
`cli-wallet` (if PXE_PROVER_ENABLED=1 but BB_WORKING_DIRECTORY and
BB_BINARY_PATH are unset)
- Splits `noir-protocol-circuits-types` so a `/client` bundle can be
imported without all the public artifacts
- Reenables vite box with proving since it doesn't run out of memory
anymore

---------

Co-authored-by: Cody <[email protected]>
Co-authored-by: ledwards2225 <[email protected]>
Co-authored-by: ludamad <[email protected]>
  • Loading branch information
4 people authored Dec 17, 2024
1 parent 309b5f7 commit 46da3cc
Show file tree
Hide file tree
Showing 77 changed files with 2,097 additions and 1,494 deletions.
2 changes: 1 addition & 1 deletion barretenberg/ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
},
"dependencies": {
"comlink": "^4.4.1",
"commander": "^10.0.1",
"commander": "^12.1.0",
"debug": "^4.3.4",
"fflate": "^0.8.0",
"pako": "^2.1.0",
Expand Down
2 changes: 1 addition & 1 deletion barretenberg/ts/src/barretenberg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class Barretenberg extends BarretenbergApi {
async initSRSClientIVC(): Promise<void> {
// crsPath can be undefined
const crs = await Crs.new(2 ** 20 + 1, this.options.crsPath);
const grumpkinCrs = await GrumpkinCrs.new(2 ** 14 + 1, this.options.crsPath);
const grumpkinCrs = await GrumpkinCrs.new(2 ** 15 + 1, this.options.crsPath);

// Load CRS into wasm global CRS state.
// TODO: Make RawBuffer be default behavior, and have a specific Vector type for when wanting length prefixed.
Expand Down
9 changes: 8 additions & 1 deletion barretenberg/ts/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ __metadata:
"@typescript-eslint/parser": ^5.54.1
buffer: ^6.0.3
comlink: ^4.4.1
commander: ^10.0.1
commander: ^12.1.0
copy-webpack-plugin: ^11.0.0
debug: ^4.3.4
eslint: ^8.35.0
Expand Down Expand Up @@ -2434,6 +2434,13 @@ __metadata:
languageName: node
linkType: hard

"commander@npm:^12.1.0":
version: 12.1.0
resolution: "commander@npm:12.1.0"
checksum: 68e9818b00fc1ed9cdab9eb16905551c2b768a317ae69a5e3c43924c2b20ac9bb65b27e1cab36aeda7b6496376d4da908996ba2c0b5d79463e0fb1e77935d514
languageName: node
linkType: hard

"commander@npm:^2.20.0":
version: 2.20.3
resolution: "commander@npm:2.20.3"
Expand Down
1 change: 1 addition & 0 deletions boxes/boxes/vite/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_AZTEC_NODE_URL=http://localhost:8080
15 changes: 7 additions & 8 deletions boxes/boxes/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"dependencies": {
"@aztec/accounts": "portal:../../../yarn-project/accounts",
"@aztec/aztec.js": "portal:../../../yarn-project/aztec.js",
"@aztec/bb-prover": "link:../../../yarn-project/bb-prover",
"@aztec/circuit-types": "portal:../../../yarn-project/circuit-types",
"@aztec/key-store": "link:../../../yarn-project/key-store",
"@aztec/kv-store": "portal:../../../yarn-project/kv-store",
Expand All @@ -31,18 +32,16 @@
"@eslint/js": "^9.13.0",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@vitejs/plugin-react-swc": "^3.5.0",
"@vitejs/plugin-react-swc": "^3.7.2",
"eslint": "^9.13.0",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-refresh": "^0.4.14",
"eslint-plugin-react-hooks": "^5.1.0",
"eslint-plugin-react-refresh": "^0.4.16",
"globals": "^15.11.0",
"memfs": "^4.14.0",
"node-stdlib-browser": "^1.3.0",
"typescript": "~5.6.2",
"typescript-eslint": "^8.11.0",
"vite": "^5.4.10",
"vite-plugin-externalize-deps": "^0.8.0",
"vite": "^6.0.3",
"vite-plugin-node-polyfills": "^0.22.0",
"vite-plugin-strip-block": "^1.0.1",
"vite-plugin-top-level-await": "^1.4.4"
}
}
}
17 changes: 11 additions & 6 deletions boxes/boxes/vite/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@ import {
} from "@aztec/aztec.js";
import { BoxReactContractArtifact } from "../artifacts/BoxReact";
import { AccountManager } from "@aztec/aztec.js/account";
import { SingleKeyAccountContract } from "@aztec/accounts/single_key";
import { SchnorrAccountContract } from "@aztec/accounts/schnorr";
import { createAztecNodeClient } from "@aztec/aztec.js";
import { PXEService } from "@aztec/pxe/service";
import { PXEServiceConfig, getPXEServiceConfig } from "@aztec/pxe/config";
import { KVPxeDatabase } from "@aztec/pxe/database";
import { TestPrivateKernelProver } from "@aztec/pxe/kernel_prover";
import { KeyStore } from "@aztec/key-store";
import { PrivateKernelProver } from "@aztec/circuit-types";
import { L2TipsStore } from "@aztec/kv-store/stores";
import { createStore } from "@aztec/kv-store/indexeddb";
import { BBWasmPrivateKernelProver } from "@aztec/bb-prover/wasm";

process.env = Object.keys(import.meta.env).reduce((acc, key) => {
acc[key.replace("VITE_", "")] = import.meta.env[key];
return acc;
}, {});

const SECRET_KEY = Fr.random();

Expand All @@ -33,17 +38,18 @@ export class PrivateEnv {
const config = getPXEServiceConfig();
config.dataDirectory = "pxe";
const aztecNode = await createAztecNodeClient(this.nodeURL);
const proofCreator = new TestPrivateKernelProver();
const proofCreator = new BBWasmPrivateKernelProver(16);
this.pxe = await this.createPXEService(aztecNode, config, proofCreator);
const encryptionPrivateKey = deriveMasterIncomingViewingSecretKey(
this.secretKey,
);
this.accountContract = new SingleKeyAccountContract(encryptionPrivateKey);
this.accountContract = new SchnorrAccountContract(encryptionPrivateKey);
this.account = new AccountManager(
this.pxe,
this.secretKey,
this.accountContract,
);
await this.account.deploy().wait();
}

async createPXEService(
Expand Down Expand Up @@ -81,14 +87,13 @@ export class PrivateEnv {
}

async getWallet() {
// taking advantage that register is no-op if already registered
return await this.account.register();
}
}

export const deployerEnv = new PrivateEnv(
SECRET_KEY,
process.env.PXE_URL || "http://localhost:8080",
process.env.AZTEC_NODE_URL,
);

const IGNORE_FUNCTIONS = [
Expand Down
30 changes: 14 additions & 16 deletions boxes/boxes/vite/src/contracts/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ use dep::aztec::macros::aztec;
#[aztec]
contract BoxReact {
use dep::aztec::{
protocol_types::public_keys::OvpkM,
keys::getters::get_public_keys,
prelude::{AztecAddress, PrivateMutable, Map, NoteInterface, NoteHeader, Point},
encrypted_logs::encrypted_note_emission::encode_and_encrypt_note,
macros::{storage::storage, functions::{private, public, initializer}}
macros::{functions::{initializer, private}, storage::storage},
prelude::{AztecAddress, Map, PrivateMutable},
};
use dep::value_note::value_note::ValueNote;

Expand All @@ -18,27 +16,27 @@ contract BoxReact {

#[private]
#[initializer]
fn constructor(
number: Field,
owner: AztecAddress
) {
fn constructor(number: Field, owner: AztecAddress) {
let numbers = storage.numbers;
let mut new_number = ValueNote::new(number, owner);

let owner_ovpk_m = get_public_keys(owner).ovpk_m;
numbers.at(owner).initialize(&mut new_number).emit(encode_and_encrypt_note(&mut context, owner_ovpk_m, owner, context.msg_sender()));
numbers.at(owner).initialize(&mut new_number).emit(encode_and_encrypt_note(
&mut context,
owner,
context.msg_sender(),
));
}

#[private]
fn setNumber(
number: Field,
owner: AztecAddress
) {
fn setNumber(number: Field, owner: AztecAddress) {
let numbers = storage.numbers;
let mut new_number = ValueNote::new(number, owner);

let owner_ovpk_m = get_public_keys(owner).ovpk_m;
numbers.at(owner).replace(&mut new_number).emit(encode_and_encrypt_note(&mut context, owner_ovpk_m, owner, context.msg_sender()));
numbers.at(owner).replace(&mut new_number).emit(encode_and_encrypt_note(
&mut context,
owner,
context.msg_sender(),
));
}

unconstrained fn getNumber(owner: AztecAddress) -> pub ValueNote {
Expand Down
17 changes: 10 additions & 7 deletions boxes/boxes/vite/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { defineConfig } from "vite";
import react from "@vitejs/plugin-react-swc";
import { PolyfillOptions, nodePolyfills } from "vite-plugin-node-polyfills";
import topLevelAwait from "vite-plugin-top-level-await";
import stripBlock from "vite-plugin-strip-block";

// Unfortunate, but needed due to https://github.com/davidmyersdev/vite-plugin-node-polyfills/issues/81
// Suspected to be because of the yarn workspace setup, but not sure
Expand All @@ -23,17 +24,19 @@ const nodePolyfillsFix = (options?: PolyfillOptions | undefined): Plugin => {

// https://vite.dev/config/
export default defineConfig({
server: {
headers: {
"Cross-Origin-Opener-Policy": "same-origin",
"Cross-Origin-Embedder-Policy": "require-corp",
},
},
plugins: [
stripBlock({ start: "testing-only-start", end: "testing-only-end" }),
react(),
nodePolyfillsFix({
overrides: {
fs: "memfs",
buffer: "buffer/",
},
}),
nodePolyfillsFix({ include: ["buffer", "process", "path"] }),
topLevelAwait(),
],
optimizeDeps: {
exclude: ["@noir-lang/acvm_js", "@noir-lang/noirc_abi"],
exclude: ["@noir-lang/acvm_js", "@noir-lang/noirc_abi", "@aztec/bb-prover"],
},
});
6 changes: 3 additions & 3 deletions boxes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"version": "0.5.0",
"type": "module",
"scripts": {
"compile": "yarn workspaces foreach --exclude vite -A -v run compile",
"build": "yarn workspaces foreach --exclude vite -A -v run build",
"compile": "yarn workspaces foreach -A -v run compile",
"build": "yarn workspaces foreach -A -v run build",
"install-browsers": "playwright install --with-deps",
"publish": "yarn npm publish",
"test": "vitest bin.test.js",
Expand Down Expand Up @@ -43,4 +43,4 @@
"devDependencies": {
"@playwright/test": "1.46.1"
}
}
}
Loading

0 comments on commit 46da3cc

Please sign in to comment.