Skip to content

Commit

Permalink
feat: Sync from noir (#8466)
Browse files Browse the repository at this point in the history
Automated pull of development from the
[noir](https://github.com/noir-lang/noir) programming language, a
dependency of Aztec.
BEGIN_COMMIT_OVERRIDE
fix: suggest trait attributes in LSP
(noir-lang/noir#5972)
fix: Error when `quote` is used in runtime code
(noir-lang/noir#5978)
chore: document HashMap (noir-lang/noir#5984)
fix: Restrict keccak256_injective test input to 8 bits
(noir-lang/noir#5977)
fix: Error when comptime functions are used in runtime code
(noir-lang/noir#5976)
chore: document BoundedVec (noir-lang/noir#5974)
feat: add `Expr::as_let` (noir-lang/noir#5964)
chore: remove 3 unused functions warnings in the stdlib
(noir-lang/noir#5973)
feat: let `nargo` and LSP work well in the stdlib
(noir-lang/noir#5969)
feat: show doc comments in LSP
(noir-lang/noir#5968)
feat: add a `panic` method to the stdlib
(noir-lang/noir#5966)
fix: LSP document symbol didn't work for primitive impls
(noir-lang/noir#5970)
fix(mem2reg): Handle aliases in function last store cleanup and
additional alias unit test (noir-lang/noir#5967)
fix: let `derive(Eq)` work for empty structs
(noir-lang/noir#5965)
feat: add `FunctionDefinition` methods `is_unconstrained` and
`set_unconstrained` (noir-lang/noir#5962)
feat: LSP autocompletion for attributes
(noir-lang/noir#5963)
feat: `Module::add_item` (noir-lang/noir#5947)
feat: Add `StructDefinition::add_generic`
(noir-lang/noir#5961)
feat: Add `StructDefinition::name`
(noir-lang/noir#5960)
fix(mem2reg): Handle aliases better when setting a known value for a
load (noir-lang/noir#5959)
feat: Arithmetic Generics (noir-lang/noir#5950)
feat: add `FunctionDefinition::module` and `StructDefinition::module`
(noir-lang/noir#5956)
feat: LSP now suggests self fields and methods
(noir-lang/noir#5955)
END_COMMIT_OVERRIDE

---------

Co-authored-by: Tom French <tom@tomfren.ch>
  • Loading branch information
AztecBot and TomAFrench authored Sep 10, 2024
1 parent d5b2397 commit 8ac81b1
Show file tree
Hide file tree
Showing 100 changed files with 2,151 additions and 1,077 deletions.
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

0 comments on commit 8ac81b1

Please sign in to comment.