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

do not merge test(ci3): feat(perf): speed up construction of bbjs Frs & cache zero hashes in ephemeral trees (redo) #11931

Closed
wants to merge 12 commits into from
Closed
6 changes: 5 additions & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
".": "0.76.1"
".": "0.76.2",
"yarn-project/cli": "0.35.1",
"yarn-project/aztec": "0.76.2",
"barretenberg": "0.76.2",
"barretenberg/ts": "0.76.2"
}
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
# Changelog

## [0.76.2](https://github.com/AztecProtocol/aztec-packages/compare/aztec-packages-v0.76.1...aztec-packages-v0.76.2) (2025-02-11)


### Features

* Batch writes to the proving broker database ([#11900](https://github.com/AztecProtocol/aztec-packages/issues/11900)) ([608f887](https://github.com/AztecProtocol/aztec-packages/commit/608f8876a0f4209970ea27679dff6029aab0600c))


### Bug Fixes

* Cleanup also post test_kind.sh ([#11886](https://github.com/AztecProtocol/aztec-packages/issues/11886)) ([50cdb15](https://github.com/AztecProtocol/aztec-packages/commit/50cdb15c2664a8786336654be402cf8b7b56117b))
* Contracts with public keys txe ([#11910](https://github.com/AztecProtocol/aztec-packages/issues/11910)) ([2e84bdb](https://github.com/AztecProtocol/aztec-packages/commit/2e84bdb1bb8bc815dfc5fb65b5a6e68e12b7efa9))
* Dont skip wasm civc tests ([#11909](https://github.com/AztecProtocol/aztec-packages/issues/11909)) ([0395e0b](https://github.com/AztecProtocol/aztec-packages/commit/0395e0bf0c7a82e4506657f508e8f3324bdc56ab))
* Note hash collision ([#11869](https://github.com/AztecProtocol/aztec-packages/issues/11869)) ([f289b7c](https://github.com/AztecProtocol/aztec-packages/commit/f289b7c038d399c30e17bc27a620860792416b9f))
* Orchestrator test ([#11901](https://github.com/AztecProtocol/aztec-packages/issues/11901)) ([f1bb51c](https://github.com/AztecProtocol/aztec-packages/commit/f1bb51c9bb6063d52bfd2dafe5faf9476b4bbff0))
* Smt_verification: negative bitvecs, changed gates indicies. acir_formal_proofs: noir-style signed division ([#11649](https://github.com/AztecProtocol/aztec-packages/issues/11649)) ([4146496](https://github.com/AztecProtocol/aztec-packages/commit/41464968895be2ae0bfc9a0a554a3b6824252fd4))
* Update path of stern logs ([#11906](https://github.com/AztecProtocol/aztec-packages/issues/11906)) ([05afb5b](https://github.com/AztecProtocol/aztec-packages/commit/05afb5bc763a26b41ce4e8c6253ffba5d20bc1fa))


### Miscellaneous

* Arm runner start fix ([#11903](https://github.com/AztecProtocol/aztec-packages/issues/11903)) ([6c83c40](https://github.com/AztecProtocol/aztec-packages/commit/6c83c40f09dd9550af426047c300c9f19469409d))
* Fixing the sizes of VMs in CIVC ([#11793](https://github.com/AztecProtocol/aztec-packages/issues/11793)) ([1afddbd](https://github.com/AztecProtocol/aztec-packages/commit/1afddbd0712ad268bcc82931cf91bbb067766cbe))
* **logging:** Support explicit FORCE_COLOR parameter ([#11902](https://github.com/AztecProtocol/aztec-packages/issues/11902)) ([3b3f859](https://github.com/AztecProtocol/aztec-packages/commit/3b3f859f53bba6aa5cabf9f79dd210d326045e70))
* Misc fixes to devnet deploy flow ([#11738](https://github.com/AztecProtocol/aztec-packages/issues/11738)) ([bc4cca7](https://github.com/AztecProtocol/aztec-packages/commit/bc4cca7fe87afc72c38f6a7bf9af5e11149b6d84))
* Remove warnings from noir protocol circuits ([#11803](https://github.com/AztecProtocol/aztec-packages/issues/11803)) ([c6cc3d3](https://github.com/AztecProtocol/aztec-packages/commit/c6cc3d381253f79d3532c2940f73a9304665f4d4))
* Replace relative paths to noir-protocol-circuits ([74d6e6a](https://github.com/AztecProtocol/aztec-packages/commit/74d6e6a14b13dbc3cb9f691c1ec40be5e898a6fb))
* Replacing use of capsules 1.0 with pxe_db + nuking capsules 1.0 ([#11885](https://github.com/AztecProtocol/aztec-packages/issues/11885)) ([72be678](https://github.com/AztecProtocol/aztec-packages/commit/72be67811ebe3b4db0cc245352e5e8e975828578))

## [0.76.1](https://github.com/AztecProtocol/aztec-packages/compare/aztec-packages-v0.76.0...aztec-packages-v0.76.1) (2025-02-10)


Expand Down
13 changes: 13 additions & 0 deletions barretenberg/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog

## [0.76.2](https://github.com/AztecProtocol/aztec-packages/compare/barretenberg-v0.76.1...barretenberg-v0.76.2) (2025-02-11)


### Bug Fixes

* Note hash collision ([#11869](https://github.com/AztecProtocol/aztec-packages/issues/11869)) ([f289b7c](https://github.com/AztecProtocol/aztec-packages/commit/f289b7c038d399c30e17bc27a620860792416b9f))
* Smt_verification: negative bitvecs, changed gates indicies. acir_formal_proofs: noir-style signed division ([#11649](https://github.com/AztecProtocol/aztec-packages/issues/11649)) ([4146496](https://github.com/AztecProtocol/aztec-packages/commit/41464968895be2ae0bfc9a0a554a3b6824252fd4))


### Miscellaneous

* Fixing the sizes of VMs in CIVC ([#11793](https://github.com/AztecProtocol/aztec-packages/issues/11793)) ([1afddbd](https://github.com/AztecProtocol/aztec-packages/commit/1afddbd0712ad268bcc82931cf91bbb067766cbe))

## [0.76.1](https://github.com/AztecProtocol/aztec-packages/compare/barretenberg-v0.76.0...barretenberg-v0.76.1) (2025-02-10)


Expand Down
1 change: 0 additions & 1 deletion barretenberg/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ cmake_minimum_required(VERSION 3.24 FATAL_ERROR)
project(
Barretenberg
DESCRIPTION "BN254 elliptic curve library, and PLONK SNARK prover"
# Placeholder version.
VERSION 00000000.00000000.00000000
LANGUAGES CXX C
)
Expand Down
7 changes: 7 additions & 0 deletions barretenberg/ts/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [0.76.2](https://github.com/AztecProtocol/aztec-packages/compare/barretenberg.js-v0.76.1...barretenberg.js-v0.76.2) (2025-02-11)


### Miscellaneous

* **barretenberg.js:** Synchronize aztec-packages versions

## [0.76.1](https://github.com/AztecProtocol/aztec-packages/compare/barretenberg.js-v0.76.0...barretenberg.js-v0.76.1) (2025-02-10)


Expand Down
2 changes: 1 addition & 1 deletion barretenberg/ts/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@aztec/bb.js",
"packageManager": "yarn@4.5.2",
"version": "0.76.1",
"version": "0.76.2",
"homepage": "https://github.com/AztecProtocol/aztec-packages/tree/master/barretenberg/ts",
"license": "MIT",
"type": "module",
Expand Down
56 changes: 39 additions & 17 deletions barretenberg/ts/src/bigint-array/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,43 @@
export function toBigIntBE(bytes: Uint8Array) {
// A Buffer in node, *is* a Uint8Array. We can't refuse it's type.
// However the algo below only works on an actual Uint8Array, hence we make a new one to be safe.
bytes = new Uint8Array(bytes);
let bigint = BigInt(0);
const view = new DataView(bytes.buffer);
for (let i = 0; i < bytes.byteLength; i++) {
bigint = (bigint << BigInt(8)) + BigInt(view.getUint8(i));
}
return bigint;
/**
* Convert a 32-byte BE Buffer to a BigInt.
*/
export function buffer32BytesToBigIntBE(buf: Buffer): bigint {
return (
(buf.readBigUInt64BE(0) << 192n) +
(buf.readBigUInt64BE(8) << 128n) +
(buf.readBigUInt64BE(16) << 64n) +
buf.readBigUInt64BE(24)
);
}

/**
* Convert a BE Uint8Array to a BigInt.
*/
export function uint8ArrayToBigIntBE(bytes: Uint8Array): bigint {
const buffer = Buffer.from(bytes);
return buffer32BytesToBigIntBE(buffer);
}

export function toBufferBE(value: bigint, byteLength = 32) {
const bytes = new Uint8Array(byteLength);
const view = new DataView(bytes.buffer);
for (let i = 0; i < byteLength; i++) {
view.setUint8(byteLength - i - 1, Number(value & BigInt(0xff)));
value >>= BigInt(8);
/**
* Convert a BigInt to a 32-byte BE Buffer.
*/
export function bigIntToBufferBE(value: bigint, byteLength = 32): Buffer {
if (byteLength != 32) {
throw new Error(
`Only 32 bytes supported for conversion from bigint to buffer, attempted byte length: ${byteLength}`,
);
}
return bytes;
const buf = Buffer.alloc(byteLength);
buf.writeBigUInt64BE(value >> 192n, 0);
buf.writeBigUInt64BE((value >> 128n) & 0xffffffffffffffffn, 8);
buf.writeBigUInt64BE((value >> 64n) & 0xffffffffffffffffn, 16);
buf.writeBigUInt64BE(value & 0xffffffffffffffffn, 24);
return buf;
}

/**
* Convert a BigInt to a 32-byte BE Uint8Array.
*/
export function bigIntToUint8ArrayBE(value: bigint, byteLength = 32): Uint8Array {
return new Uint8Array(bigIntToBufferBE(value, byteLength));
}
37 changes: 24 additions & 13 deletions barretenberg/ts/src/types/fields.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { randomBytes } from '../random/index.js';
import { toBigIntBE, toBufferBE } from '../bigint-array/index.js';
import {
buffer32BytesToBigIntBE,
uint8ArrayToBigIntBE,
bigIntToBufferBE,
bigIntToUint8ArrayBE,
} from '../bigint-array/index.js';
import { BufferReader, uint8ArrayToHexString } from '../serialize/index.js';

// TODO(#4189): Replace with implementation in yarn-project/foundation/src/fields/fields.ts
Expand All @@ -15,30 +20,36 @@ export class Fr {
static SIZE_IN_BYTES = 32;
value: Uint8Array;

constructor(value: Uint8Array | bigint) {
constructor(value: Uint8Array | Buffer | bigint) {
// We convert buffer value to bigint to be able to check it fits within modulus
const valueBigInt = typeof value === 'bigint' ? value : toBigIntBE(value);
const valueBigInt =
typeof value === 'bigint'
? value
: value instanceof Buffer
? buffer32BytesToBigIntBE(value)
: uint8ArrayToBigIntBE(value);

if (valueBigInt > Fr.MAX_VALUE) {
throw new Error(`Value 0x${valueBigInt.toString(16)} is greater or equal to field modulus.`);
}

this.value = typeof value === 'bigint' ? toBufferBE(value) : value;
this.value =
typeof value === 'bigint' ? bigIntToUint8ArrayBE(value) : value instanceof Buffer ? new Uint8Array(value) : value;
}

static random() {
const r = toBigIntBE(randomBytes(64)) % Fr.MODULUS;
const r = uint8ArrayToBigIntBE(randomBytes(64)) % Fr.MODULUS;
return new this(r);
}

static fromBuffer(buffer: Uint8Array | BufferReader) {
static fromBuffer(buffer: Uint8Array | Buffer | BufferReader) {
const reader = BufferReader.asReader(buffer);
return new this(reader.readBytes(this.SIZE_IN_BYTES));
}

static fromBufferReduce(buffer: Uint8Array | BufferReader) {
const reader = BufferReader.asReader(buffer);
return new this(toBigIntBE(reader.readBytes(this.SIZE_IN_BYTES)) % Fr.MODULUS);
return new this(uint8ArrayToBigIntBE(reader.readBytes(this.SIZE_IN_BYTES)) % Fr.MODULUS);
}

static fromString(str: string) {
Expand Down Expand Up @@ -79,26 +90,26 @@ export class Fq {
}

static random() {
const r = toBigIntBE(randomBytes(64)) % Fq.MODULUS;
const r = uint8ArrayToBigIntBE(randomBytes(64)) % Fq.MODULUS;
return new this(r);
}

static fromBuffer(buffer: Uint8Array | BufferReader) {
static fromBuffer(buffer: Uint8Array | Buffer | BufferReader) {
const reader = BufferReader.asReader(buffer);
return new this(toBigIntBE(reader.readBytes(this.SIZE_IN_BYTES)));
return new this(uint8ArrayToBigIntBE(reader.readBytes(this.SIZE_IN_BYTES)));
}

static fromBufferReduce(buffer: Uint8Array | BufferReader) {
static fromBufferReduce(buffer: Uint8Array | Buffer | BufferReader) {
const reader = BufferReader.asReader(buffer);
return new this(toBigIntBE(reader.readBytes(this.SIZE_IN_BYTES)) % Fr.MODULUS);
return new this(uint8ArrayToBigIntBE(reader.readBytes(this.SIZE_IN_BYTES)) % Fr.MODULUS);
}

static fromString(str: string) {
return this.fromBuffer(Buffer.from(str.replace(/^0x/i, ''), 'hex'));
}

toBuffer() {
return toBufferBE(this.value, Fq.SIZE_IN_BYTES);
return bigIntToBufferBE(this.value, Fq.SIZE_IN_BYTES);
}

toString() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Sample escrow contract that stores a balance of a private token on behalf of an owner.
use dep::aztec::macros::aztec;

mod test;

#[aztec]
pub contract Escrow {
use dep::aztec::{
Expand Down
120 changes: 120 additions & 0 deletions noir-projects/noir-contracts/contracts/escrow_contract/src/test.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// TODO(ek): Clean up this test
use crate::Escrow;
use dep::token::Token;

use aztec::{
oracle::{execution::{get_block_number, get_contract_address}, storage::storage_read},
prelude::AztecAddress,
protocol_types::storage::map::derive_storage_slot_in_map,
test::helpers::{cheatcodes, test_environment::TestEnvironment},
};

pub unconstrained fn get_public_balance(
token_contract_address: AztecAddress,
address: AztecAddress,
) -> U128 {
let current_contract_address = get_contract_address();
cheatcodes::set_contract_address(token_contract_address);
let block_number = get_block_number();

let balances_slot = Token::storage_layout().public_balances.slot;
let address_slot = derive_storage_slot_in_map(balances_slot, address);
let amount: U128 = storage_read(token_contract_address, address_slot, block_number);
cheatcodes::set_contract_address(current_contract_address);
amount
}

pub unconstrained fn get_private_balance(
token_contract_address: AztecAddress,
address: AztecAddress,
) -> U128 {
let current_contract_address = get_contract_address();
cheatcodes::set_contract_address(token_contract_address);
// Direct call to unconstrained
let amt = Token::balance_of_private(address);
cheatcodes::set_contract_address(current_contract_address);
amt
}

global MINT_AMOUNT: U128 = U128::from_integer(200000);

unconstrained fn deploy_contracts(
env: &mut TestEnvironment,
admin_and_owner: AztecAddress,
) -> (AztecAddress, AztecAddress) {
env.impersonate(admin_and_owner);

// Deploy token contract
let donation_token_initializer_call_interface = Token::interface().constructor(
admin_and_owner,
"Token00000000000000000000000000",
"TKN0000000000000000000000000000",
18,
);
let donation_token_contract = env
.deploy("./@token_contract", "Token")
.with_public_void_initializer(donation_token_initializer_call_interface);
let token_contract_address = donation_token_contract.to_address();
env.advance_block_by(1);

// Deploy Escrow contract with public keys
let escrow_contract_initializer_call_interface =
Escrow::interface().constructor(admin_and_owner);
let escrow_contract = env
.deploy_with_public_keys("./@escrow_contract", "Escrow", 6969)
.with_private_initializer(escrow_contract_initializer_call_interface);
let escrow_contract_address = escrow_contract.to_address();

env.advance_block_by(1);

Token::at(token_contract_address)
.mint_to_private(admin_and_owner, admin_and_owner, MINT_AMOUNT)
.call(&mut env.private());

env.advance_block_by(1);

let private_balance_after_mint = get_private_balance(token_contract_address, admin_and_owner);
assert(private_balance_after_mint == MINT_AMOUNT);

(token_contract_address, escrow_contract_address)
}

#[test]
unconstrained fn main() {
let mut env = TestEnvironment::new();

let (account_1, account_2) = (env.create_account_contract(1), env.create_account_contract(2));

let (token_contract_address, escrow_contract_address) = deploy_contracts(&mut env, account_1);

// We transfer tokens to the escrow contract
let TRANSFER_AMOUNT = U128::from_integer(20000);
Token::at(token_contract_address).transfer(escrow_contract_address, TRANSFER_AMOUNT).call(
&mut env.private(),
);
env.advance_block_by(1);

let balance_of_escrow_after_transfer =
get_private_balance(token_contract_address, escrow_contract_address);

assert_eq(balance_of_escrow_after_transfer, TRANSFER_AMOUNT);

// We then withdraw some escrowed funds to account_2
let balance_of_account_2_before_withdrawal =
get_private_balance(token_contract_address, account_2);
assert(balance_of_account_2_before_withdrawal == U128::zero());

let WITHDRAWAL_AMOUNT = U128::from_integer(69);
Escrow::at(escrow_contract_address)
.withdraw(token_contract_address, WITHDRAWAL_AMOUNT, account_2)
.call(&mut env.private());
env.advance_block_by(1);

let balance_of_account_2_after_withdrawal =
get_private_balance(token_contract_address, account_2);
assert(balance_of_account_2_after_withdrawal == WITHDRAWAL_AMOUNT);

let balance_of_escrow_after_withdrawal =
get_private_balance(token_contract_address, escrow_contract_address);
assert(balance_of_escrow_after_withdrawal == TRANSFER_AMOUNT - WITHDRAWAL_AMOUNT);
}
2 changes: 1 addition & 1 deletion spartan/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ case "$cmd" in
# Ensure our context exists in kubectl
retry "kind delete cluster || true; timeout -v 2m kind create cluster"
fi
kubectl config use-context kind-kind >/dev/null || true
kubectl config use-context kind-kind || true
docker update --restart=no kind-control-plane >/dev/null
;;
"chaos-mesh")
Expand Down
7 changes: 7 additions & 0 deletions yarn-project/aztec/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [0.76.2](https://github.com/AztecProtocol/aztec-packages/compare/aztec-package-v0.76.1...aztec-package-v0.76.2) (2025-02-11)


### Miscellaneous

* **logging:** Support explicit FORCE_COLOR parameter ([#11902](https://github.com/AztecProtocol/aztec-packages/issues/11902)) ([3b3f859](https://github.com/AztecProtocol/aztec-packages/commit/3b3f859f53bba6aa5cabf9f79dd210d326045e70))

## [0.76.1](https://github.com/AztecProtocol/aztec-packages/compare/aztec-package-v0.76.0...aztec-package-v0.76.1) (2025-02-10)


Expand Down
Loading
Loading