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

feat: Sync from noir #8466

Merged
merged 6 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .noir-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3dab4dd771b7d8b9242ce3a9aeff5770f4d85cf6
d6f60d70dc41640ad84f7a968927b20818bcaf2a
19 changes: 16 additions & 3 deletions noir-projects/aztec-nr/authwit/src/auth.nr
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,11 @@ pub fn assert_current_call_valid_authwit(context: &mut PrivateContext, on_behalf
* @param on_behalf_of The address that have authorized the current call
* @param inner_hash The hash of the message to authorize
*/
pub fn assert_inner_hash_valid_authwit(context: &mut PrivateContext, on_behalf_of: AztecAddress, inner_hash: Field) {
pub fn assert_inner_hash_valid_authwit(
context: &mut PrivateContext,
on_behalf_of: AztecAddress,
inner_hash: Field
) {
// We perform a static call here and not a standard one to ensure that the account contract cannot re-enter.
let result: Field = context.static_call_private_function(
on_behalf_of,
Expand Down Expand Up @@ -262,7 +266,11 @@ pub fn assert_current_call_valid_authwit_public(context: &mut PublicContext, on_
*
* @param on_behalf_of The address that have authorized the `inner_hash`
*/
pub fn assert_inner_hash_valid_authwit_public(context: &mut PublicContext, on_behalf_of: AztecAddress, inner_hash: Field) {
pub fn assert_inner_hash_valid_authwit_public(
context: &mut PublicContext,
on_behalf_of: AztecAddress,
inner_hash: Field
) {
let result: Field = context.call_public_function(
CANONICAL_AUTH_REGISTRY_ADDRESS,
comptime {
Expand Down Expand Up @@ -338,7 +346,12 @@ pub fn compute_authwit_nullifier(on_behalf_of: AztecAddress, inner_hash: Field)
* @param version The version of the chain that the message is being consumed on
* @param inner_hash The hash of the "inner" message that is being consumed
*/
pub fn compute_authwit_message_hash(consumer: AztecAddress, chain_id: Field, version: Field, inner_hash: Field) -> Field {
pub fn compute_authwit_message_hash(
consumer: AztecAddress,
chain_id: Field,
version: Field,
inner_hash: Field
) -> Field {
poseidon2_hash_with_separator(
[
consumer.to_field(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ mod test {
}
};

/// 1. `EncryptedLogIncomingBody::from_note` calls `note.to_be_bytes(storage_slot)` function which serializes
/// the note to bytes - note that in the case of `AddressNote` the `to_be_bytes` function was automatically
/// implemented by Aztec macros.
// 1. `EncryptedLogIncomingBody::from_note` calls `note.to_be_bytes(storage_slot)` function which serializes
// the note to bytes - note that in the case of `AddressNote` the `to_be_bytes` function was automatically
// implemented by Aztec macros.
let body = EncryptedLogIncomingBody::from_note(note, storage_slot);

/// 2. `body.compute_ciphertext(...)` function then derives symmetric key from `eph_sk` and `ivpk` and encrypts
// 2. `body.compute_ciphertext(...)` function then derives symmetric key from `eph_sk` and `ivpk` and encrypts
// the note plaintext using AES-128.
let ciphertext = body.compute_ciphertext(eph_sk, ivpk);

Expand Down
108 changes: 50 additions & 58 deletions noir-projects/noir-protocol-circuits/crates/blob/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -344,28 +344,24 @@ fn barycentric_evaluate_blob_at_z(z: F, ys: [F; FIELDS_PER_BLOB]) -> F {
// Making a call to this function causes a "stack too deep" error, so I've put the body of that function here, instead:
// let fracs = __compute_fracs(z, ys); // { y_i / (z - ω^i) }

/**
*
* Note: it's more efficient (saving 30k constraints) to compute:
* ___d-1
* \ / y_i \
* / | --------- | . ω^i
* /____ \ z - ω^i /
* i=0
* ^^^^^^^^^
* frac
*
* ... than to compute:
*
* ___d-1
* \ / ω^i \
* / y_i . | --------- |
* /____ \ z - ω^i /
* i=0
*
* perhaps because all the ω^i terms are constant witnesses?
*
*/
// Note: it's more efficient (saving 30k constraints) to compute:
// ___d-1
// \ / y_i \
// / | --------- | . ω^i
// /____ \ z - ω^i /
// i=0
// ^^^^^^^^^
// frac
//
// ... than to compute:
//
// ___d-1
// \ / ω^i \
// / y_i . | --------- |
// /____ \ z - ω^i /
// i=0
//
// perhaps because all the ω^i terms are constant witnesses?

//*****************************************************************
// This section is only needed because `__compute_fracs` isn't working (stack too deep error).
Expand Down Expand Up @@ -415,28 +411,25 @@ fn barycentric_evaluate_blob_at_z(z: F, ys: [F; FIELDS_PER_BLOB]) -> F {
// which implies...we can accomodate up to EIGHT additions of product terms before we risk overflowing
// (this is really messy! I never considered the case of giant linear sequences of products)
let mut sum: F = BigNum::new();
/**
* Seeking:
* ___d-1
* \ ω^i
* sum = / y_i . ---------
* /____ z - ω^i
* i=0
*/

// Seeking:
// ___d-1
// \ ω^i
// sum = / y_i . ---------
// /____ z - ω^i
// i=0
let NUM_PARTIAL_SUMS = FIELDS_PER_BLOB / 8;
for i in 0..NUM_PARTIAL_SUMS {
let mut partial_sum: F = BigNum::new();
let mut lhs: [F; 8] = [BigNum::new(); 8];
let mut rhs = lhs;

/**
* Seeking:
* ___i*8 + 7
* \ ω^k
* partial_sum = / y_k . ---------
* /____ z - ω^k
* k=i*8 + 0
*/
// Seeking:
// ___i*8 + 7
// \ ω^k
// partial_sum = / y_k . ---------
// /____ z - ω^k
// k=i*8 + 0

for j in 0..8 {
let k = i * 8 + j;
Expand All @@ -459,26 +452,25 @@ fn barycentric_evaluate_blob_at_z(z: F, ys: [F; FIELDS_PER_BLOB]) -> F {
std::as_witness(partial_sum.limbs[2]);
}

/**
* Seeking:
* ___i*8 - 1 ___i*8 + 7
* \ ω^i \ / y_k \
* sum_out = / y_i . --------- + / ω^k . | --------- |
* /____ z - ω^i /____ \ z - ω^k /
* 0 k = i*8
* ^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
* sum partial_sum
*
* ... that is:
*
* ___i*8 - 1 ___ 7
* \ ω^i \
* sum_out = / y_i . --------- + / lhs[j] . rhs[j]
* /____ z - ω^i /____
* 0 j = 0
* ^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^
* sum partial_sum
*/
// Seeking:
// ___i*8 - 1 ___i*8 + 7
// \ ω^i \ / y_k \
// sum_out = / y_i . --------- + / ω^k . | --------- |
// /____ z - ω^i /____ \ z - ω^k /
// 0 k = i*8
// ^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// sum partial_sum
//
// ... that is:
//
// ___i*8 - 1 ___ 7
// \ ω^i \
// sum_out = / y_i . --------- + / lhs[j] . rhs[j]
// /____ z - ω^i /____
// 0 j = 0
// ^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^
// sum partial_sum
//

let mut sum_out = sum.__add(partial_sum);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,7 @@ fn validate_propagated_from_private_call_note_hash_read_requests_output_extra_no
* With previous kernel.
*/

fn append_note_hash_read_requests_to_previous_kernel(
builder: &mut PrivateKernelCircuitOutputValidatorBuilder,
num_requests: u32
) {
fn append_note_hash_read_requests_to_previous_kernel(builder: &mut PrivateKernelCircuitOutputValidatorBuilder, num_requests: u32) {
builder.previous_kernel.append_note_hash_read_requests(num_requests);
builder.output.append_note_hash_read_requests(num_requests);
builder.offset_values(num_requests as Field);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -900,10 +900,6 @@ mod tests {

#[test]
unconstrained fn new_nullifier_tree_empty() {
/**
* DESCRIPTION
*/

// This test checks for insertions of all 0 values
// In this special case we will not need to provide sibling paths to check insertion of the nullifier values
// This is because 0 values are not actually inserted into the tree, rather the inserted subtree is left
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ use dep::types::{
* Asserts that the tree formed by rollup circuits is filled greedily from L to R
*
*/
pub fn assert_txs_filled_from_left(left: BaseOrMergeRollupPublicInputs, right: BaseOrMergeRollupPublicInputs) {
pub fn assert_txs_filled_from_left(
left: BaseOrMergeRollupPublicInputs,
right: BaseOrMergeRollupPublicInputs
) {
// assert that the left rollup is either a base (1 tx) or a balanced tree (num txs = power of 2)
if (left.rollup_type == 1) {
let left_txs = left.num_txs;
Expand All @@ -47,7 +50,10 @@ pub fn assert_txs_filled_from_left(left: BaseOrMergeRollupPublicInputs, right: B
* Asserts that the constants used in the left and right child are identical
*
*/
pub fn assert_equal_constants(left: BaseOrMergeRollupPublicInputs, right: BaseOrMergeRollupPublicInputs) {
pub fn assert_equal_constants(
left: BaseOrMergeRollupPublicInputs,
right: BaseOrMergeRollupPublicInputs
) {
assert(left.constants.eq(right.constants), "input proofs have different constants");
}

Expand Down
Loading
Loading