Skip to content

Commit

Permalink
Merge branch 'master' into sync-noir
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench authored Jan 7, 2025
2 parents 0091c7c + cd5a615 commit 051613b
Show file tree
Hide file tree
Showing 29 changed files with 314 additions and 367 deletions.
16 changes: 9 additions & 7 deletions barretenberg/acir_tests/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ function prepare_tests {
# TODO(https://github.com/AztecProtocol/barretenberg/issues/1108): problem regardless the proof system used
rm -rf acir_tests/regression_5045

# Regenerate verify_honk_proof and verify_rollup_honk_proof recursive input.
echo "Regenerating verify_honk_proof and verify_rollup_honk_proof recursive inputs."
COMPILE=2 ./run_test.sh assert_statement
local bb=$(realpath ../cpp/build/bin/bb)
(cd ./acir_tests/assert_statement && \
$bb write_recursion_inputs_ultra_honk -b ./target/program.json -o ../../../../noir/noir-repo/test_programs/execution_success/verify_honk_proof --recursive && \
$bb write_recursion_inputs_rollup_honk -b ./target/program.json -o ../../../../noir/noir-repo/test_programs/execution_success/verify_rollup_honk_proof --recursive && \
cp -R ../../../../noir/noir-repo/test_programs/execution_success/verify_honk_proof .. && cp -R ../../../../noir/noir-repo/test_programs/execution_success/verify_rollup_honk_proof ..)

# COMPILE=2 only compiles the test.
denoise "parallel --joblog joblog.txt --line-buffered 'COMPILE=2 ./run_test.sh \$(basename {})' ::: ./acir_tests/*"

Expand All @@ -29,13 +38,6 @@ function build_tests {

prepare_tests


# TODO: This actually breaks things, but shouldn't. We want to do it here and not maintain manually.
# Regenerate verify_honk_proof recursive input.
# local bb=$(realpath ../cpp/build/bin/bb)
# (cd ./acir_tests/assert_statement && \
# $bb write_recursion_inputs_honk -b ./target/program.json -o ../verify_honk_proof --recursive)

# Update yarn.lock so it can be committed.
# Be lenient about bb.js hash changing, even if we try to minimize the occurrences.
denoise "cd browser-test-app && yarn add --dev @aztec/bb.js@../../ts && yarn"
Expand Down
51 changes: 0 additions & 51 deletions barretenberg/acir_tests/regenerate_verify_honk_proof_inputs.sh

This file was deleted.

176 changes: 82 additions & 94 deletions noir-projects/noir-protocol-circuits/crates/blob/src/blob.nr
Original file line number Diff line number Diff line change
Expand Up @@ -227,67 +227,69 @@ fn barycentric_evaluate_blob_at_z(z: F, ys: [F; FIELDS_PER_BLOB]) -> F {
__compute_partial_sums(fracs, ROOTS)
};

// We split off the first term to check the initial sum

// partial_sums[0] <- (lhs[0] * rhs[0] + ... + lhs[7] * rhs[7])
// => (lhs[0] * rhs[0] + ... + lhs[7] * rhs[7]) - partial_sums[0] == 0
let lhs = [
[ROOTS[0]], [ROOTS[1]], [ROOTS[2]], [ROOTS[3]], [ROOTS[4]], [ROOTS[5]], [ROOTS[6]],
[ROOTS[7]],
];
let rhs = [
[fracs[0]], [fracs[1]], [fracs[2]], [fracs[3]], [fracs[4]], [fracs[5]], [fracs[6]],
[fracs[7]],
];
BigNum::evaluate_quadratic_expression(
lhs,
[[false], [false], [false], [false], [false], [false], [false], [false]],
rhs,
[[false], [false], [false], [false], [false], [false], [false], [false]],
[partial_sums[0]],
[true],
);
for i in 1..NUM_PARTIAL_SUMS {
// Seeking:
// ___i*8 - 1 ___i*8 + 7
// \ omega^i \ / y_k \
// sum_out = / y_i . --------- + / omega^k . | --------- |
// /____ z - omega^i /____ \ z - omega^k /
// 0 k = i*8
// ^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// sum partial_sum
//
// ... that is:
//
// ___i*8 - 1 ___ 7
// \ omega^i \
// sum_out = / y_i . --------- + / lhs[j] . rhs[j]
// /____ z - omega^i /____
// 0 j = 0
// ^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^
// sum partial_sum
//

let mut lhs: [[F; 1]; 8] = [std::mem::zeroed(); 8];
let mut rhs: [[F; 1]; 8] = [std::mem::zeroed(); 8];
for j in 0..8 {
let k = i * 8 + j;
lhs[j] = [ROOTS[k]]; // omega^k
rhs[j] = [fracs[k]]; // y_k / (z - omega^k)
}

let linear_terms = [partial_sums[i - 1], partial_sums[i]];

// partial_sums[i] <- partial_sums[i-1] + (lhs[8*i] * rhs[8*i] + ... + lhs[8*i + 7] * rhs[8*i + 7])
// => (lhs[8*i] * rhs[8*i] + ... + lhs[8*i + 7] * rhs[8*i + 7]) + partial_sums[i-1] - partial_sums[i] == 0
if !std::runtime::is_unconstrained() {
// We split off the first term to check the initial sum

// partial_sums[0] <- (lhs[0] * rhs[0] + ... + lhs[7] * rhs[7])
// => (lhs[0] * rhs[0] + ... + lhs[7] * rhs[7]) - partial_sums[0] == 0
let lhs = [
[ROOTS[0]], [ROOTS[1]], [ROOTS[2]], [ROOTS[3]], [ROOTS[4]], [ROOTS[5]], [ROOTS[6]],
[ROOTS[7]],
];
let rhs = [
[fracs[0]], [fracs[1]], [fracs[2]], [fracs[3]], [fracs[4]], [fracs[5]], [fracs[6]],
[fracs[7]],
];
BigNum::evaluate_quadratic_expression(
lhs,
[[false], [false], [false], [false], [false], [false], [false], [false]],
rhs,
[[false], [false], [false], [false], [false], [false], [false], [false]],
linear_terms,
[false, true],
[partial_sums[0]],
[true],
);
for i in 1..NUM_PARTIAL_SUMS {
// Seeking:
// ___i*8 - 1 ___i*8 + 7
// \ omega^i \ / y_k \
// sum_out = / y_i . --------- + / omega^k . | --------- |
// /____ z - omega^i /____ \ z - omega^k /
// 0 k = i*8
// ^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// sum partial_sum
//
// ... that is:
//
// ___i*8 - 1 ___ 7
// \ omega^i \
// sum_out = / y_i . --------- + / lhs[j] . rhs[j]
// /____ z - omega^i /____
// 0 j = 0
// ^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^
// sum partial_sum
//

// partial_sums[i] <- partial_sums[i-1] + (lhs[8*i] * rhs[8*i] + ... + lhs[8*i + 7] * rhs[8*i + 7])
// => (lhs[8*i] * rhs[8*i] + ... + lhs[8*i + 7] * rhs[8*i + 7]) + partial_sums[i-1] - partial_sums[i] == 0
let mut lhs: [[F; 1]; 8] = [std::mem::zeroed(); 8];
let mut rhs: [[F; 1]; 8] = [std::mem::zeroed(); 8];
for j in 0..8 {
let k = i * 8 + j;
lhs[j] = [ROOTS[k]]; // omega^k
rhs[j] = [fracs[k]]; // y_k / (z - omega^k)
}

let linear_terms = [partial_sums[i - 1], partial_sums[i]];

BigNum::evaluate_quadratic_expression(
lhs,
[[false], [false], [false], [false], [false], [false], [false], [false]],
rhs,
[[false], [false], [false], [false], [false], [false], [false], [false]],
linear_terms,
[false, true],
);
}
}

let factor = compute_factor(z);
Expand Down Expand Up @@ -317,14 +319,16 @@ fn compute_factor(z: F) -> F {

// (z_pow_d - one) * (D_INV) - factor = 0
// z_pow_d * D_INV - D_INV - factor = 0
BigNum::evaluate_quadratic_expression(
[[z_pow_d]],
[[false]],
[[D_INV]],
[[false]],
[factor, D_INV],
[true, true],
);
if !std::runtime::is_unconstrained() {
BigNum::evaluate_quadratic_expression(
[[z_pow_d]],
[[false]],
[[D_INV]],
[[false]],
[factor, D_INV],
[true, true],
);
}

// This version doesn't work:
// BigNum::evaluate_quadratic_expression(
Expand Down Expand Up @@ -371,17 +375,19 @@ fn compute_fracs(
__compute_fracs(z, ys, ROOTS)
};

for i in 0..FIELDS_PER_BLOB {
// frac <-- ys[i] / (z + neg_roots[i])
// frac * (z + neg_roots[i]) - ys[i] = 0
BigNum::evaluate_quadratic_expression(
[[fracs[i]]],
[[false]],
[[z, ROOTS[i].neg()]],
[[false, false]],
[ys[i]],
[true],
);
if !std::runtime::is_unconstrained() {
for i in 0..FIELDS_PER_BLOB {
// frac <-- ys[i] / (z + neg_roots[i])
// frac * (z + neg_roots[i]) - ys[i] = 0
BigNum::evaluate_quadratic_expression(
[[fracs[i]]],
[[false]],
[[z, ROOTS[i].neg()]],
[[false, false]],
[ys[i]],
[true],
);
}
}

fracs
Expand Down Expand Up @@ -442,7 +448,7 @@ mod tests {
field_to_bignum,
},
blob_public_inputs::BlobCommitment,
unconstrained_config::{D, D_INV, F, LOG_FIELDS_PER_BLOB},
unconstrained_config::{D, D_INV, F},
};
use bigint::{BigNum, fields::bls12_381Fr::BLS12_381_Fr_Params};
use types::{
Expand All @@ -451,24 +457,6 @@ mod tests {
tests::{fixture_builder::FixtureBuilder, utils::pad_end},
};

// Helper to return (z^d - 1)/d (unsafe - test only)
fn z_d_helper(challenge_z: F) -> F {
let mut t1 = unsafe { challenge_z.__mul(challenge_z) };
let mut t2: F = BigNum::new();
for _i in 0..LOG_FIELDS_PER_BLOB - 1 {
t2 = unsafe { t1.__mul(t1) };
t1 = t2;
}

let z_pow_d = t1;

let one: F = BigNum::one();

t1 = unsafe { z_pow_d.__sub(one) };
let factor = unsafe { t1.__mul(D_INV) };
factor
}

#[test]
unconstrained fn test_one_note() {
let mut tx_data = FixtureBuilder::new();
Expand Down Expand Up @@ -500,7 +488,7 @@ mod tests {
//* p(z).(z - 1) = ---------
//* d
//
let rhs = z_d_helper(challenge_z);
let rhs = super::compute_factor(challenge_z);
let z_minus_1 = unsafe { challenge_z.__sub(BigNum::one()) };
let lhs = y.__mul(z_minus_1);
assert_eq(lhs, rhs);
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion yarn-project/aztec.js/src/utils/cheat_codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ export class AztecCheatCodes {
* @returns The notes stored at the given slot
*/
public async loadPrivate(owner: AztecAddress, contract: AztecAddress, slot: Fr | bigint): Promise<Note[]> {
const extendedNotes = await this.pxe.getIncomingNotes({
const extendedNotes = await this.pxe.getNotes({
owner,
contractAddress: contract,
storageSlot: new Fr(slot),
Expand Down
6 changes: 3 additions & 3 deletions yarn-project/aztec.js/src/wallet/base_wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {
type EventMetadataDefinition,
type ExtendedNote,
type GetUnencryptedLogsResponse,
type IncomingNotesFilter,
type L2Block,
type LogFilter,
type NotesFilter,
type PXE,
type PXEInfo,
type PrivateExecutionResult,
Expand Down Expand Up @@ -134,8 +134,8 @@ export abstract class BaseWallet implements Wallet {
getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
return this.pxe.getTxReceipt(txHash);
}
getIncomingNotes(filter: IncomingNotesFilter): Promise<UniqueNote[]> {
return this.pxe.getIncomingNotes(filter);
getNotes(filter: NotesFilter): Promise<UniqueNote[]> {
return this.pxe.getNotes(filter);
}
getPublicStorageAt(contract: AztecAddress, storageSlot: Fr): Promise<any> {
return this.pxe.getPublicStorageAt(contract, storageSlot);
Expand Down
8 changes: 4 additions & 4 deletions yarn-project/circuit-types/src/interfaces/pxe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ import { AuthWitness } from '../auth_witness.js';
import { type InBlock } from '../in_block.js';
import { L2Block } from '../l2_block.js';
import { ExtendedUnencryptedL2Log, type GetUnencryptedLogsResponse, type LogFilter } from '../logs/index.js';
import { type IncomingNotesFilter } from '../notes/incoming_notes_filter.js';
import { ExtendedNote, UniqueNote } from '../notes/index.js';
import { type NotesFilter } from '../notes/notes_filter.js';
import { PrivateExecutionResult } from '../private_execution_result.js';
import { type EpochProofQuote } from '../prover_coordination/epoch_proof_quote.js';
import { SiblingPath } from '../sibling_path/sibling_path.js';
Expand Down Expand Up @@ -190,8 +190,8 @@ describe('PXESchema', () => {
expect(result).toBeInstanceOf(Fr);
});

it('getIncomingNotes', async () => {
const result = await context.client.getIncomingNotes({ contractAddress: address });
it('getNotes', async () => {
const result = await context.client.getNotes({ contractAddress: address });
expect(result).toEqual([expect.any(UniqueNote)]);
});

Expand Down Expand Up @@ -409,7 +409,7 @@ class MockPXE implements PXE {
expect(slot).toBeInstanceOf(Fr);
return Promise.resolve(Fr.random());
}
getIncomingNotes(filter: IncomingNotesFilter): Promise<UniqueNote[]> {
getNotes(filter: NotesFilter): Promise<UniqueNote[]> {
expect(filter.contractAddress).toEqual(this.address);
return Promise.resolve([UniqueNote.random()]);
}
Expand Down
8 changes: 4 additions & 4 deletions yarn-project/circuit-types/src/interfaces/pxe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ import {
type LogFilter,
LogFilterSchema,
} from '../logs/index.js';
import { type IncomingNotesFilter, IncomingNotesFilterSchema } from '../notes/incoming_notes_filter.js';
import { ExtendedNote, UniqueNote } from '../notes/index.js';
import { type NotesFilter, NotesFilterSchema } from '../notes/notes_filter.js';
import { PrivateExecutionResult } from '../private_execution_result.js';
import { SiblingPath } from '../sibling_path/sibling_path.js';
import { Tx, TxHash, TxProvingResult, TxReceipt, TxSimulationResult } from '../tx/index.js';
Expand Down Expand Up @@ -232,11 +232,11 @@ export interface PXE {
getPublicStorageAt(contract: AztecAddress, slot: Fr): Promise<Fr>;

/**
* Gets incoming notes of accounts registered in this PXE based on the provided filter.
* Gets notes registered in this PXE based on the provided filter.
* @param filter - The filter to apply to the notes.
* @returns The requested notes.
*/
getIncomingNotes(filter: IncomingNotesFilter): Promise<UniqueNote[]>;
getNotes(filter: NotesFilter): Promise<UniqueNote[]>;

/**
* Fetches an L1 to L2 message from the node.
Expand Down Expand Up @@ -483,7 +483,7 @@ export const PXESchema: ApiSchemaFor<PXE> = {
.args(TxHash.schema)
.returns(z.union([inBlockSchemaFor(TxEffect.schema), z.undefined()])),
getPublicStorageAt: z.function().args(schemas.AztecAddress, schemas.Fr).returns(schemas.Fr),
getIncomingNotes: z.function().args(IncomingNotesFilterSchema).returns(z.array(UniqueNote.schema)),
getNotes: z.function().args(NotesFilterSchema).returns(z.array(UniqueNote.schema)),
getL1ToL2MembershipWitness: z
.function()
.args(schemas.AztecAddress, schemas.Fr, schemas.Fr)
Expand Down
Loading

0 comments on commit 051613b

Please sign in to comment.