Skip to content

Commit

Permalink
Merge branch 'master' into saleel/flamegraph
Browse files Browse the repository at this point in the history
  • Loading branch information
saleel authored Jan 31, 2025
2 parents 95a49c8 + d421460 commit 02c46a6
Show file tree
Hide file tree
Showing 285 changed files with 10,090 additions and 4,265 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ jobs:
scripts/copy_from_builder ./noir-projects/gates_report.json protocol_circuits_report.json
- name: Compare gates reports
id: gates_diff
uses: noir-lang/noir-gates-diff@7e4ddaa91c69380f15ccba514eac17bc7432a8cc
uses: noir-lang/noir-gates-diff@dbe920a8dcc3370af4be4f702ca9cef29317bec1
continue-on-error: true
timeout-minutes: 1
with:
Expand Down Expand Up @@ -608,7 +608,7 @@ jobs:
scripts/copy_from_builder noir-projects/public_functions_report.json public_functions_report.json
- name: Compare public functions bytecode size reports
id: public_functions_sizes_diff
uses: noir-lang/noir-gates-diff@7e4ddaa91c69380f15ccba514eac17bc7432a8cc
uses: noir-lang/noir-gates-diff@dbe920a8dcc3370af4be4f702ca9cef29317bec1
continue-on-error: true
timeout-minutes: 1
with:
Expand Down
2 changes: 1 addition & 1 deletion .noir-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
c172880ae47ec4906cda662801bd4b7866c9586b
c44b62615f1c8ee657eedd82f2b80e2ec76c9078
4 changes: 2 additions & 2 deletions barretenberg/.gitrepo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[subrepo]
remote = https://github.com/AztecProtocol/barretenberg
branch = master
commit = 2b718dec0624621c81bdc406bed8db0c30ed2a77
parent = 6ce23892c8762ffde6fc3198e1e392cd1a72969b
commit = 37c100901c570b61ca79b46f0fdb0bbc5ce22708
parent = 756b94101345d231b86233921398555512855273
method = merge
cmdver = 0.4.6
3 changes: 0 additions & 3 deletions barretenberg/acir_tests/browser-test-app/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ export default {
index: "./src/index.ts",
},
module: {
parser: {
javascript: { importMeta: false },
},
rules: [
{
test: /\.gz$/,
Expand Down
4 changes: 2 additions & 2 deletions barretenberg/acir_tests/browser-test-app/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ __metadata:

"@aztec/bb.js@file:../../ts::locator=browser-test-app%40workspace%3A.":
version: 0.72.1
resolution: "@aztec/bb.js@file:../../ts#../../ts::hash=2e6237&locator=browser-test-app%40workspace%3A."
resolution: "@aztec/bb.js@file:../../ts#../../ts::hash=90d55d&locator=browser-test-app%40workspace%3A."
dependencies:
comlink: "npm:^4.4.1"
commander: "npm:^12.1.0"
Expand All @@ -17,7 +17,7 @@ __metadata:
tslib: "npm:^2.4.0"
bin:
bb.js: ./dest/node/main.js
checksum: 10c0/174074ea937d9e4888e1aa600717ace0f0c5745d15bdd23730c136d927c2d58eec87ba83cb21fbfb72f7aa00ec128a564d7fa6d822f709e0327e01aa6475e255
checksum: 10c0/6ec39503ec545df13d297134ae28d8be01d02105a8518fa9cc15c54d1f93924956ce5c41913d1f2db31a8e05a5bad1fe7f5a0c1d5f1a6346f4703e307cc3f05a
languageName: node
linkType: hard

Expand Down
2 changes: 1 addition & 1 deletion barretenberg/acir_tests/headless-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"dependencies": {
"chalk": "^5.3.0",
"commander": "^12.1.0",
"playwright": "^1.50.0",
"playwright": "1.49.0",
"puppeteer": "^22.4.1"
},
"devDependencies": {
Expand Down
20 changes: 10 additions & 10 deletions barretenberg/acir_tests/headless-test/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ __metadata:
dependencies:
chalk: "npm:^5.3.0"
commander: "npm:^12.1.0"
playwright: "npm:^1.50.0"
playwright: "npm:1.49.0"
puppeteer: "npm:^22.4.1"
ts-node: "npm:^10.9.2"
typescript: "npm:^5.4.2"
Expand Down Expand Up @@ -1408,27 +1408,27 @@ __metadata:
languageName: node
linkType: hard

"playwright-core@npm:1.50.0":
version: 1.50.0
resolution: "playwright-core@npm:1.50.0"
"playwright-core@npm:1.49.0":
version: 1.49.0
resolution: "playwright-core@npm:1.49.0"
bin:
playwright-core: cli.js
checksum: 10c0/b0cc7fadcb2db68a7b8d730b26c7a7d17baad454a0697c781e08074a619e57779a90be9b57c4c741ff4895390bdfd093d8393a746e8bf68ae57ac452f4c1cdb2
checksum: 10c0/22c1a72fabdcc87bd1cd4d40a032d2c5b94cf94ba7484dc182048c3fa1c8ec26180b559d8cac4ca9870e8fd6bdf5ef9d9f54e7a31fd60d67d098fcffc5e4253b
languageName: node
linkType: hard

"playwright@npm:^1.50.0":
version: 1.50.0
resolution: "playwright@npm:1.50.0"
"playwright@npm:1.49.0":
version: 1.49.0
resolution: "playwright@npm:1.49.0"
dependencies:
fsevents: "npm:2.3.2"
playwright-core: "npm:1.50.0"
playwright-core: "npm:1.49.0"
dependenciesMeta:
fsevents:
optional: true
bin:
playwright: cli.js
checksum: 10c0/0076a536433819b7122066a07c5fcfa56d40d09cbbec0a39061bbfa832c8a1f626df5e4fe206fbeba56b3a61f0e2b26d4ad3c2b402852d6f147a266fd18e4ddf
checksum: 10c0/e94d662747cd147d0573570fec90dadc013c1097595714036fc8934a075c5a82ab04a49111b03b1f762ea86429bdb7c94460901896901e20970b30ce817cc93f
languageName: node
linkType: hard

Expand Down
9 changes: 5 additions & 4 deletions barretenberg/cpp/src/barretenberg/common/fuzzer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,17 +234,16 @@ inline static FF mutateFieldElement(FF e, T& rng)
e = e.to_montgomery_form();
}
if (rng.next() & 1) {
value_data = e + FF(rng.next() & 0xff);
e += FF(rng.next() & 0xff);
} else {
value_data = e - FF(rng.next() & 0xff);
e -= FF(rng.next() & 0xff);
}
if (convert_to_montgomery) {
e = e.from_montgomery_form();
}
} else { // 25% to use special values

// Substitute field element with a special value
MONT_CONVERSION_LOCAL
switch (rng.next() % 8) {
case 0:
e = FF::zero();
Expand Down Expand Up @@ -274,7 +273,9 @@ inline static FF mutateFieldElement(FF e, T& rng)
abort();
break;
}
INV_MONT_CONVERSION_LOCAL
if (convert_to_montgomery) {
e = e.from_montgomery_form();
}
}
// Return instruction
return e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,16 +404,15 @@ template <typename Builder> class BigFieldBase {
e = e.to_montgomery_form();
}
if (rng.next() & 1) {
value_data = e + bb::fq(rng.next() & 0xff);
e += bb::fq(rng.next() & 0xff);
} else {
value_data = e - bb::fq(rng.next() & 0xff);
e -= bb::fq(rng.next() & 0xff);
}
if (convert_to_montgomery) {
e = e.from_montgomery_form();
}
} else {
// Substitute field element with a special value
MONT_CONVERSION
switch (rng.next() % 9) {
case 0:
e = bb::fq::zero();
Expand Down Expand Up @@ -446,7 +445,9 @@ template <typename Builder> class BigFieldBase {
abort();
break;
}
INV_MONT_CONVERSION
if (convert_to_montgomery) {
e = e.from_montgomery_form();
}
}
// Return instruction
return e;
Expand Down Expand Up @@ -740,9 +741,7 @@ template <typename Builder> class BigFieldBase {
instruction_opcode == Instruction::OPCODE::WITNESS ||
instruction_opcode == Instruction::OPCODE::CONSTANT_WITNESS) {
*Data = instruction.id;
memcpy(Data + 1,
&instruction.arguments.element.value.data[0],
sizeof(instruction.arguments.element.value.data));
bb::fq::serialize_to_buffer(instruction.arguments.element.value, Data + 1);
}

if constexpr (instruction_opcode == Instruction::OPCODE::SQR ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,16 +367,15 @@ template <typename Builder> class FieldBase {
e = e.to_montgomery_form();
}
if (rng.next() & 1) {
value_data = e + bb::fr(rng.next() & 0xff);
e += bb::fr(rng.next() & 0xff);
} else {
value_data = e - bb::fr(rng.next() & 0xff);
e -= bb::fr(rng.next() & 0xff);
}
if (convert_to_montgomery) {
e = e.from_montgomery_form();
}
} else {
// Substitute field element with a special value
MONT_CONVERSION
switch (rng.next() % 9) {
case 0:
e = bb::fr::zero();
Expand Down Expand Up @@ -409,7 +408,9 @@ template <typename Builder> class FieldBase {
abort();
break;
}
INV_MONT_CONVERSION
if (convert_to_montgomery) {
e = e.from_montgomery_form();
}
}
// Return instruction
return e;
Expand Down Expand Up @@ -647,7 +648,7 @@ template <typename Builder> class FieldBase {
instruction_opcode == Instruction::OPCODE::WITNESS ||
instruction_opcode == Instruction::OPCODE::CONSTANT_WITNESS) {
*Data = instruction.id;
memcpy(Data + 1, &instruction.arguments.element.data[0], sizeof(instruction.arguments.element.data));
bb::fr::serialize_to_buffer(insturction.arguments.element.data, Data + 1);
}

if constexpr (instruction_opcode == Instruction::OPCODE::ASSERT_ZERO ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,16 +326,15 @@ template <typename Builder> class SafeUintFuzzBase {
e = e.to_montgomery_form();
}
if (rng.next() & 1) {
value_data = e + fr(rng.next() & 0xff);
e += fr(rng.next() & 0xff);
} else {
value_data = e - fr(rng.next() & 0xff);
e -= fr(rng.next() & 0xff);
}
if (convert_to_montgomery) {
e = e.from_montgomery_form();
}
} else {
// Substitute field element with a special value
MONT_CONVERSION
switch (rng.next() % 8) {
case 0:
e = fr::zero();
Expand Down Expand Up @@ -365,7 +364,9 @@ template <typename Builder> class SafeUintFuzzBase {
abort();
break;
}
INV_MONT_CONVERSION
if (convert_to_montgomery) {
e = e.from_montgomery_form();
}
}
// Return instruction
return e;
Expand Down
3 changes: 2 additions & 1 deletion barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,8 @@ void AvmTraceBuilder::pay_fee()
FF current_balance = read_hint.leaf_preimage.value;

const auto updated_balance = current_balance - tx_fee;
if (current_balance < tx_fee) {
// Comparison on Field gives inverted results, so we cast to uint128, which should be enough for fees.
if (static_cast<uint128_t>(current_balance) < static_cast<uint128_t>(tx_fee)) {
info("Not enough balance for fee payer to pay for transaction (got ", current_balance, " needs ", tx_fee);
throw std::runtime_error("Not enough balance for fee payer to pay for transaction");
}
Expand Down
13 changes: 8 additions & 5 deletions barretenberg/ts/src/barretenberg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export type BackendOptions = {

/** @description Path to download CRS files */
crsPath?: string;

/** @description Path to download WASM files */
wasmPath?: string;
};

export type CircuitOptions = {
Expand Down Expand Up @@ -50,7 +53,7 @@ export class Barretenberg extends BarretenbergApi {
static async new(options: BackendOptions = {}) {
const worker = createMainWorker();
const wasm = getRemoteBarretenbergWasm<BarretenbergWasmMainWorker>(worker);
const { module, threads } = await fetchModuleAndThreads(options.threads);
const { module, threads } = await fetchModuleAndThreads(options.threads, options.wasmPath);
await wasm.init(module, threads, proxy(debug), options.memory?.initial, options.memory?.maximum);
return new Barretenberg(worker, wasm, options);
}
Expand Down Expand Up @@ -97,16 +100,16 @@ export class BarretenbergSync extends BarretenbergApiSync {
super(wasm);
}

private static async new() {
private static async new(wasmPath?: string) {
const wasm = new BarretenbergWasmMain();
const { module, threads } = await fetchModuleAndThreads(1);
const { module, threads } = await fetchModuleAndThreads(1, wasmPath);
await wasm.init(module, threads);
return new BarretenbergSync(wasm);
}

static async initSingleton() {
static async initSingleton(wasmPath?: string) {
if (!barrentenbergSyncSingletonPromise) {
barrentenbergSyncSingletonPromise = BarretenbergSync.new();
barrentenbergSyncSingletonPromise = BarretenbergSync.new(wasmPath);
}

barretenbergSyncSingleton = await barrentenbergSyncSingletonPromise;
Expand Down
22 changes: 19 additions & 3 deletions barretenberg/ts/src/barretenberg_wasm/fetch_code/browser/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
import barretenbergModule from '../../barretenberg.wasm.gz';
import barretenbergThreadsModule from '../../barretenberg-threads.wasm.gz';
import pako from 'pako';

// Annoyingly the wasm declares if it's memory is shared or not. So now we need two wasms if we want to be
// able to fallback on "non shared memory" situations.
export async function fetchCode(multithreaded: boolean) {
const res = await fetch(multithreaded ? barretenbergThreadsModule : barretenbergModule);
return res.arrayBuffer();
export async function fetchCode(multithreaded: boolean, wasmPath?: string) {
let url = multithreaded ? barretenbergThreadsModule : barretenbergModule;
url = wasmPath ? `${wasmPath}/${/[^/]+(?=\/$|$)/.exec(url)?.[0]}` : url;
const res = await fetch(url);
const maybeCompressedData = await res.arrayBuffer();
const buffer = new Uint8Array(maybeCompressedData);
const isGzip =
// Check magic number
buffer[0] === 0x1f &&
buffer[1] === 0x8b &&
// Check compression method:
buffer[2] === 0x08;
if (isGzip) {
const decompressedData = pako.ungzip(buffer);
return decompressedData.buffer;
} else {
return buffer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function getCurrentDir() {
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export async function fetchCode(multithreaded: boolean) {
export async function fetchCode(multithreaded: boolean, wasmPath?: string) {
const path = getCurrentDir() + '/../../barretenberg-threads.wasm.gz';
const compressedData = await readFile(path);
const decompressedData = pako.ungzip(new Uint8Array(compressedData));
Expand Down
8 changes: 4 additions & 4 deletions barretenberg/ts/src/barretenberg_wasm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import { fetchCode } from './fetch_code/index.js';

const debug = createDebug('bb.js:wasm');

export async function fetchModuleAndThreads(desiredThreads = 32) {
export async function fetchModuleAndThreads(desiredThreads = 32, wasmPath?: string) {
const shared = getSharedMemoryAvailable();

const availableThreads = shared ? await getAvailableThreads() : 1;
// We limit the number of threads to 32 as we do not benefit from greater numbers.
const limitedThreads = Math.min(desiredThreads, availableThreads, 32);

const code = await fetchCode(shared);
const code = await fetchCode(shared, wasmPath);
const module = await WebAssembly.compile(code);
return { module, threads: limitedThreads };
}
Expand All @@ -38,10 +38,10 @@ export class BarretenbergWasm extends BarretenbergWasmMain {
* Construct and initialize BarretenbergWasm within a Worker. Return both the worker and the wasm proxy.
* Used when running in the browser, because we can't block the main thread.
*/
public static async new(desiredThreads?: number) {
public static async new(desiredThreads?: number, wasmPath?: string) {
const worker = createMainWorker();
const wasm = getRemoteBarretenbergWasm<BarretenbergWasmMainWorker>(worker);
const { module, threads } = await fetchModuleAndThreads(desiredThreads);
const { module, threads } = await fetchModuleAndThreads(desiredThreads, wasmPath);
await wasm.init(module, threads, proxy(debug));
return { worker, wasm };
}
Expand Down
Loading

0 comments on commit 02c46a6

Please sign in to comment.