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 #5416

Merged
merged 5 commits into from
Mar 25, 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
6 changes: 3 additions & 3 deletions l1-contracts/src/core/libraries/ConstantsGen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ library Constants {
uint256 internal constant L1_TO_L2_MSG_SUBTREE_HEIGHT = 4;
uint256 internal constant L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH = 12;
uint256 internal constant FUNCTION_SELECTOR_NUM_BYTES = 4;
uint256 internal constant ARGS_HASH_CHUNK_LENGTH = 32;
uint256 internal constant ARGS_HASH_CHUNK_COUNT = 32;
uint256 internal constant ARGS_HASH_CHUNK_LENGTH = 64;
uint256 internal constant ARGS_HASH_CHUNK_COUNT = 64;
uint256 internal constant INITIALIZATION_SLOT_SEPARATOR = 1000_000_000;
uint256 internal constant INITIAL_L2_BLOCK_NUM = 1;
uint256 internal constant BLOB_SIZE_IN_BYTES = 126976;
Expand All @@ -91,7 +91,7 @@ library Constants {
uint256 internal constant DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE =
0x85864497636cf755ae7bde03f267ce01a520981c21c3682aaf82a631;
uint256 internal constant DEPLOYER_CONTRACT_ADDRESS =
0x127a8fd1a31888ccd00c88d84b93474449bb6683197083e1727dd02ab6803c6c;
0x2496dd9fa6701d5be6537860bcf258c778c678201d6e481ccc7e827dc62356ac;
uint256 internal constant L1_TO_L2_MESSAGE_ORACLE_CALL_LENGTH = 17;
uint256 internal constant MAX_NOTE_FIELDS_LENGTH = 20;
uint256 internal constant GET_NOTE_ORACLE_RETURN_LENGTH = 23;
Expand Down
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/authwit/src/auth.nr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use dep::aztec::protocol_types::{
abis::function_selector::FunctionSelector, address::AztecAddress,
constants::{GENERATOR_INDEX__AUTHWIT_INNER, GENERATOR_INDEX__AUTHWIT_OUTER},
hash::{hash_args, pedersen_hash}
hash::{hash_args_array, pedersen_hash}
};
use dep::aztec::context::{PrivateContext, PublicContext, Context};

Expand Down Expand Up @@ -37,7 +37,7 @@ pub fn compute_call_authwit_hash<N>(
selector: FunctionSelector,
args: [Field; N]
) -> Field {
let args_hash = hash_args(args);
let args_hash = hash_args_array(args);
let inner_hash = compute_inner_authwit_hash([caller.to_field(), selector.to_field(), args_hash]);
compute_outer_authwit_hash(consumer, chain_id, version, inner_hash)
}
Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/authwit/src/entrypoint/app.nr
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl AppPayload {
for i in 0..ACCOUNT_MAX_CALLS {
bytes.extend_from_array(self.function_calls[i].to_be_bytes());
}
bytes.extend_from_array(self.nonce.to_be_bytes(32));
bytes.extend_from_slice(self.nonce.to_be_bytes(32));

bytes.storage
}
Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/authwit/src/entrypoint/fee.nr
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl FeePayload {
for i in 0..MAX_FEE_FUNCTION_CALLS {
bytes.extend_from_array(self.function_calls[i].to_be_bytes());
}
bytes.extend_from_array(self.nonce.to_be_bytes(32));
bytes.extend_from_slice(self.nonce.to_be_bytes(32));

bytes.storage
}
Expand Down
17 changes: 9 additions & 8 deletions noir-projects/aztec-nr/aztec/src/context/private_context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ use dep::protocol_types::{
MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL, MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL,
MAX_PUBLIC_DATA_READS_PER_CALL, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL,
MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, MAX_NULLIFIER_READ_REQUESTS_PER_CALL,
MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL, MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL, RETURN_VALUES_LENGTH
MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL, MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL,
RETURN_VALUES_LENGTH
},
contrakt::{storage_read::StorageRead, storage_update_request::StorageUpdateRequest},
grumpkin_private_key::GrumpkinPrivateKey, hash::hash_args, header::Header,
grumpkin_private_key::GrumpkinPrivateKey, hash::hash_args_array, header::Header,
messaging::l2_to_l1_message::L2ToL1Message, utils::reader::Reader, traits::is_empty
};

Expand Down Expand Up @@ -273,7 +274,7 @@ impl PrivateContext {
function_selector: FunctionSelector,
args: [Field; ARGS_COUNT]
) -> [Field; RETURN_VALUES_LENGTH] {
let args_hash = hash_args(args);
let args_hash = hash_args_array(args);
assert(args_hash == arguments::pack_arguments(args));
self.call_private_function_with_packed_args(contract_address, function_selector, args_hash, false, false)
}
Expand All @@ -284,7 +285,7 @@ impl PrivateContext {
function_selector: FunctionSelector,
args: [Field; ARGS_COUNT]
) -> [Field; RETURN_VALUES_LENGTH] {
let args_hash = hash_args(args);
let args_hash = hash_args_array(args);
assert(args_hash == arguments::pack_arguments(args));
self.call_private_function_with_packed_args(contract_address, function_selector, args_hash, true, false)
}
Expand All @@ -295,7 +296,7 @@ impl PrivateContext {
function_selector: FunctionSelector,
args: [Field; ARGS_COUNT]
) -> [Field; RETURN_VALUES_LENGTH] {
let args_hash = hash_args(args);
let args_hash = hash_args_array(args);
assert(args_hash == arguments::pack_arguments(args));
self.call_private_function_with_packed_args(contract_address, function_selector, args_hash, false, true)
}
Expand Down Expand Up @@ -380,7 +381,7 @@ impl PrivateContext {
function_selector: FunctionSelector,
args: [Field; ARGS_COUNT]
) {
let args_hash = hash_args(args);
let args_hash = hash_args_array(args);
assert(args_hash == arguments::pack_arguments(args));
self.call_public_function_with_packed_args(contract_address, function_selector, args_hash, false, false)
}
Expand All @@ -391,7 +392,7 @@ impl PrivateContext {
function_selector: FunctionSelector,
args: [Field; ARGS_COUNT]
) {
let args_hash = hash_args(args);
let args_hash = hash_args_array(args);
assert(args_hash == arguments::pack_arguments(args));
self.call_public_function_with_packed_args(contract_address, function_selector, args_hash, true, false)
}
Expand All @@ -402,7 +403,7 @@ impl PrivateContext {
function_selector: FunctionSelector,
args: [Field; ARGS_COUNT]
) {
let args_hash = hash_args(args);
let args_hash = hash_args_array(args);
assert(args_hash == arguments::pack_arguments(args));
self.call_public_function_with_packed_args(contract_address, function_selector, args_hash, false, true)
}
Expand Down
9 changes: 5 additions & 4 deletions noir-projects/aztec-nr/aztec/src/context/public_context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ use dep::protocol_types::{
MAX_NULLIFIER_READ_REQUESTS_PER_CALL, MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL, RETURN_VALUES_LENGTH
},
contrakt::{storage_read::StorageRead, storage_update_request::StorageUpdateRequest},
hash::hash_args, header::Header, messaging::l2_to_l1_message::L2ToL1Message, utils::reader::Reader
hash::hash_args_array, header::Header, messaging::l2_to_l1_message::L2ToL1Message,
utils::reader::Reader
};

struct PublicContext {
Expand Down Expand Up @@ -266,7 +267,7 @@ impl PublicContextInterface for PublicContext {
function_selector: FunctionSelector,
args: [Field; ARGS_COUNT]
) -> [Field; RETURN_VALUES_LENGTH] {
let args_hash = hash_args(args);
let args_hash = hash_args_array(args);
assert(args_hash == arguments::pack_arguments(args));
self.call_public_function_with_packed_args(contract_address, function_selector, args_hash, false, false)
}
Expand All @@ -277,7 +278,7 @@ impl PublicContextInterface for PublicContext {
function_selector: FunctionSelector,
args: [Field; ARGS_COUNT]
) -> [Field; RETURN_VALUES_LENGTH] {
let args_hash = hash_args(args);
let args_hash = hash_args_array(args);
assert(args_hash == arguments::pack_arguments(args));
self.call_public_function_with_packed_args(contract_address, function_selector, args_hash, true, false)
}
Expand All @@ -288,7 +289,7 @@ impl PublicContextInterface for PublicContext {
function_selector: FunctionSelector,
args: [Field; ARGS_COUNT]
) -> [Field; RETURN_VALUES_LENGTH] {
let args_hash = hash_args(args);
let args_hash = hash_args_array(args);
assert(args_hash == arguments::pack_arguments(args));
self.call_public_function_with_packed_args(contract_address, function_selector, args_hash, false, true)
}
Expand Down
2 changes: 2 additions & 0 deletions noir-projects/aztec-nr/aztec/src/hash.nr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use dep::protocol_types::{
constants::GENERATOR_INDEX__L1_TO_L2_MESSAGE_SECRET,
hash::{pedersen_hash, silo_nullifier}};

use dep::protocol_types::hash::{hash_args, hash_args_array};

pub fn compute_secret_hash(secret: Field) -> Field {
// TODO(#1205) This is probably not the right index to use
pedersen_hash([secret], GENERATOR_INDEX__L1_TO_L2_MESSAGE_SECRET)
Expand Down
27 changes: 0 additions & 27 deletions noir-projects/aztec-nr/aztec/src/hasher.nr

This file was deleted.

1 change: 0 additions & 1 deletion noir-projects/aztec-nr/aztec/src/lib.nr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ mod avm;
mod context;
mod deploy;
mod hash;
mod hasher;
mod history;
mod initializer;
mod key;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl DAppPayload {
for i in 0..DAPP_MAX_CALLS {
bytes.extend_from_array(self.function_calls[i].to_be_bytes());
}
bytes.extend_from_array(self.nonce.to_be_bytes(32));
bytes.extend_from_slice(self.nonce.to_be_bytes(32));

bytes.storage
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl Deck {
pub fn add_cards<N>(&mut self, cards: [Card; N], owner: AztecAddress) -> [CardNote] {
let _context = self.set.context.private.unwrap();

let mut inserted_cards = [];
let mut inserted_cards = &[];
for card in cards {
let mut card_note = CardNote::from_card(card, owner);
self.set.insert(&mut card_note.note, true);
Expand Down Expand Up @@ -173,7 +173,7 @@ pub fn get_pack_cards(
// generate pseudo randomness deterministically from 'seed' and user secret
let secret = context.request_nullifier_secret_key(owner);
let mix = secret.high + secret.low + seed;
let random_bytes = std::hash::sha256(mix.to_le_bytes(32));
let random_bytes = std::hash::sha256_slice(mix.to_le_bytes(32));

let mut cards = [Card::from_field(0); PACK_CARDS];
// we generate PACK_CARDS cards
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ contract DocsExample {
}

/// Macro equivalence section
use dep::aztec::hasher::Hasher;
use dep::aztec::hash::hash_args;

use dep::aztec::protocol_types::abis::private_circuit_public_inputs::PrivateCircuitPublicInputs;
use dep::aztec::context::inputs::PrivateContextInputs;
Expand Down Expand Up @@ -281,14 +281,14 @@ contract DocsExample {
// ************************************************************
// The hasher is a structure used to generate a hash of the circuits inputs.
// docs:start:context-example-hasher
let mut hasher = Hasher::new();
hasher.add(a);
hasher.add(b);
let mut serialized_args = BoundedVec::new();
serialized_args.push(a);
serialized_args.push(b);
// docs:end:context-example-hasher

// The context object is created with the inputs and the hash of the inputs
// docs:start:context-example-context
let mut context = PrivateContext::new(inputs, hasher.hash());
let mut context = PrivateContext::new(inputs, hash_args(serialized_args));
// docs:end:context-example-context

// docs:start:storage-example-context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ contract EcdsaAccount {

// Verify payload signature using Ethereum's signing scheme
// Note that noir expects the hash of the message/challenge as input to the ECDSA verification.
let hashed_message: [u8; 32] = std::hash::sha256(outer_hash.to_be_bytes(32));
let hashed_message: [u8; 32] = std::hash::sha256_slice(outer_hash.to_be_bytes(32));
let verification = std::ecdsa_secp256k1::verify_signature(public_key.x, public_key.y, signature, hashed_message);
assert(verification == true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ contract SchnorrAccount {
}

// Verify signature of the payload bytes
let verification = std::schnorr::verify_signature(
let verification = std::schnorr::verify_signature_slice(
public_key.x,
public_key.y,
signature,
Expand Down Expand Up @@ -134,7 +134,7 @@ contract SchnorrAccount {
for i in 0..64 {
signature[i] = witness[i] as u8;
}
std::schnorr::verify_signature(
std::schnorr::verify_signature_slice(
public_key.x,
public_key.y,
signature,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ contract SchnorrHardcodedAccount {
}

// Verify signature using hardcoded public key
let verification = std::schnorr::verify_signature(
let verification = std::schnorr::verify_signature_slice(
public_key_x,
public_key_y,
signature,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use dep::aztec::prelude::AztecAddress;
use dep::aztec::protocol_types::address::PublicKeysHash;
use dep::std::{schnorr::verify_signature};
use crate::auth_oracle::{AuthWitness};
use dep::std::{schnorr::verify_signature_slice};
use crate::auth_oracle::AuthWitness;

pub fn recover_address(message_hash: Field, witness: AuthWitness) -> AztecAddress {
let message_bytes = message_hash.to_be_bytes(32);
let verification = verify_signature(
let verification = verify_signature_slice(
witness.owner.x,
witness.owner.y,
witness.signature,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ contract Test {
a_struct: DummyNote,
a_deep_struct: DeepStruct
) -> distinct pub PrivateCircuitPublicInputs {
let mut args: BoundedVec<Field, 17> = BoundedVec::new();
let mut args = BoundedVec::new();
args.push(a_field);
args.push(a_bool as Field);
args.push(a_number as Field);
Expand All @@ -204,7 +204,7 @@ contract Test {
args.push(note.amount);
args.push(note.secret_hash);
}
let args_hash = hash_args(args.storage);
let args_hash = hash_args(args);
let mut context = PrivateContext::new(inputs, args_hash);
context.return_values.push(args_hash);
context.finish()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ global L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH: u64 = 12;

// MISC CONSTANTS
global FUNCTION_SELECTOR_NUM_BYTES: Field = 4;
global ARGS_HASH_CHUNK_LENGTH: u64 = 32;
global ARGS_HASH_CHUNK_COUNT: u64 = 32;
global ARGS_HASH_CHUNK_LENGTH: u64 = 64;
global ARGS_HASH_CHUNK_COUNT: u64 = 64;
global MAX_ARGS_LENGTH: u64 = ARGS_HASH_CHUNK_COUNT * ARGS_HASH_CHUNK_LENGTH;
// The following is used in immutable state variables to compute an initialization slot whose value is used to
// determine whether a given variable has been initialized (by asserting that the value in the slot is 0).
// The initialization slot is computed by adding the constant bellow to the variable's storage slot. This constant has
Expand Down Expand Up @@ -130,7 +131,7 @@ global REGISTERER_UNCONSTRAINED_FUNCTION_BROADCASTED_MAGIC_VALUE = 0xe7af8166354
// CONTRACT INSTANCE CONSTANTS
// sha224sum 'struct ContractInstanceDeployed'
global DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE = 0x85864497636cf755ae7bde03f267ce01a520981c21c3682aaf82a631;
global DEPLOYER_CONTRACT_ADDRESS = 0x127a8fd1a31888ccd00c88d84b93474449bb6683197083e1727dd02ab6803c6c;
global DEPLOYER_CONTRACT_ADDRESS = 0x2496dd9fa6701d5be6537860bcf258c778c678201d6e481ccc7e827dc62356ac;

// NOIR CONSTANTS - constants used only in yarn-packages/noir-contracts
// Some are defined here because Noir doesn't yet support globals referencing other globals yet.
Expand Down Expand Up @@ -242,6 +243,7 @@ global GENERATOR_INDEX__SIGNATURE_PAYLOAD = 34;
global GENERATOR_INDEX__VK = 41;
global GENERATOR_INDEX__PRIVATE_CIRCUIT_PUBLIC_INPUTS = 42;
global GENERATOR_INDEX__PUBLIC_CIRCUIT_PUBLIC_INPUTS = 43;
// TODO: Function args generator index is being used to hash 64 items
global GENERATOR_INDEX__FUNCTION_ARGS = 44;
global GENERATOR_INDEX__AUTHWIT_INNER = 45;
global GENERATOR_INDEX__AUTHWIT_OUTER = 46;
Loading
Loading