Skip to content

Commit

Permalink
chore: run nargo format for noir-projects (#5483)
Browse files Browse the repository at this point in the history
  • Loading branch information
sklppy88 committed Mar 28, 2024
1 parent 95d2e36 commit 48572dc
Show file tree
Hide file tree
Showing 53 changed files with 180 additions and 180 deletions.
16 changes: 13 additions & 3 deletions noir-projects/aztec-nr/authwit/src/account.nr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dep::aztec::context::{PrivateContext, PublicContext, Context};
use dep::aztec::state_vars::{Map, PublicMutable};
use dep::aztec::protocol_types::{address::AztecAddress, abis::function_selector::FunctionSelector, hash::{pedersen_hash}};
use dep::aztec::protocol_types::{address::AztecAddress, abis::function_selector::FunctionSelector, hash::pedersen_hash};

use crate::entrypoint::{app::AppPayload, fee::FeePayload};
use crate::auth::{IS_VALID_SELECTOR, compute_outer_authwit_hash};
Expand Down Expand Up @@ -76,7 +76,12 @@ impl AccountActions {
// The `inner_hash` is "siloed" with the `msg_sender` to ensure that only it can
// consume the message.
// This ensures that contracts cannot consume messages that are not intended for them.
let message_hash = compute_outer_authwit_hash(context.msg_sender(), context.chain_id(), context.version(), inner_hash);
let message_hash = compute_outer_authwit_hash(
context.msg_sender(),
context.chain_id(),
context.version(),
inner_hash
);
let valid_fn = self.is_valid_impl;
assert(valid_fn(context, message_hash) == true, "Message not authorized by account");
context.push_new_nullifier(message_hash, 0);
Expand All @@ -90,7 +95,12 @@ impl AccountActions {
// The `inner_hash` is "siloed" with the `msg_sender` to ensure that only it can
// consume the message.
// This ensures that contracts cannot consume messages that are not intended for them.
let message_hash = compute_outer_authwit_hash(context.msg_sender(), context.chain_id(), context.version(), inner_hash);
let message_hash = compute_outer_authwit_hash(
context.msg_sender(),
context.chain_id(),
context.version(),
inner_hash
);
let is_valid = self.approved_action.at(message_hash).read();
assert(is_valid == true, "Message not authorized by account");
context.push_new_nullifier(message_hash, 0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use dep::protocol_types::{
abis::call_context::CallContext,
header::Header
};
use dep::protocol_types::{abis::call_context::CallContext, header::Header};
use crate::context::globals::private_global_variables::PrivateGlobalVariables;

// PrivateContextInputs are expected to be provided to each private function
Expand Down
3 changes: 2 additions & 1 deletion noir-projects/aztec-nr/aztec/src/context/public_context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use dep::protocol_types::{
MAX_NEW_NOTE_HASHES_PER_CALL, MAX_NEW_L2_TO_L1_MSGS_PER_CALL, MAX_NEW_NULLIFIERS_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, RETURN_VALUES_LENGTH
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_array, header::Header, messaging::l2_to_l1_message::L2ToL1Message,
Expand Down
4 changes: 3 additions & 1 deletion noir-projects/aztec-nr/aztec/src/deploy.nr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ pub fn deploy_contract(context: &mut PrivateContext, target: AztecAddress) {

let universal_deploy = is_default(instance.deployer);
if !universal_deploy {
assert(instance.deployer == context.this_address(), "Deployer address does not match current address");
assert(
instance.deployer == context.this_address(), "Deployer address does not match current address"
);
}

// Adapted from noir-contracts/contracts/contract_instance_deployer_contract/src/interface/ContractInstanceDeployer.nr
Expand Down
47 changes: 17 additions & 30 deletions noir-projects/aztec-nr/aztec/src/history/contract_inclusion.nr
Original file line number Diff line number Diff line change
@@ -1,61 +1,48 @@
use dep::protocol_types::{
address::{AztecAddress, EthAddress},
contract_class_id::ContractClassId,
grumpkin_point::GrumpkinPoint,
hash::silo_nullifier,
constants::DEPLOYER_CONTRACT_ADDRESS
address::{AztecAddress, EthAddress}, contract_class_id::ContractClassId,
grumpkin_point::GrumpkinPoint, hash::silo_nullifier, constants::DEPLOYER_CONTRACT_ADDRESS
};
use dep::std::merkle::compute_merkle_root;

use crate::{
context::PrivateContext,
history::{
nullifier_inclusion::prove_nullifier_inclusion_at,
nullifier_non_inclusion::prove_nullifier_not_included_at,
}
nullifier_inclusion::prove_nullifier_inclusion_at,
nullifier_non_inclusion::prove_nullifier_not_included_at
}
};

pub fn prove_contract_deployment_at(
contract_address: AztecAddress,
block_number: u32,
context: PrivateContext
) {
pub fn prove_contract_deployment_at(contract_address: AztecAddress, block_number: u32, context: PrivateContext) {
// Compute deployment nullifier
let nullifier = silo_nullifier(AztecAddress::from_field(DEPLOYER_CONTRACT_ADDRESS), contract_address.to_field());
let nullifier = silo_nullifier(
AztecAddress::from_field(DEPLOYER_CONTRACT_ADDRESS),
contract_address.to_field()
);

// Prove its inclusion
prove_nullifier_inclusion_at(nullifier, block_number, context);
}

pub fn prove_contract_non_deployment_at(
contract_address: AztecAddress,
block_number: u32,
context: PrivateContext
) {
pub fn prove_contract_non_deployment_at(contract_address: AztecAddress, block_number: u32, context: PrivateContext) {
// Compute deployment nullifier
let nullifier = silo_nullifier(AztecAddress::from_field(DEPLOYER_CONTRACT_ADDRESS), contract_address.to_field());
let nullifier = silo_nullifier(
AztecAddress::from_field(DEPLOYER_CONTRACT_ADDRESS),
contract_address.to_field()
);

// Prove its non-inclusion
prove_nullifier_not_included_at(nullifier, block_number, context);
}

pub fn prove_contract_initialization_at(
contract_address: AztecAddress,
block_number: u32,
context: PrivateContext
) {
pub fn prove_contract_initialization_at(contract_address: AztecAddress, block_number: u32, context: PrivateContext) {
// Compute initialization nullifier
let nullifier = silo_nullifier(contract_address, contract_address.to_field());

// Prove its inclusion
prove_nullifier_inclusion_at(nullifier, block_number, context);
}

pub fn prove_contract_non_initialization_at(
contract_address: AztecAddress,
block_number: u32,
context: PrivateContext
) {
pub fn prove_contract_non_initialization_at(contract_address: AztecAddress, block_number: u32, context: PrivateContext) {
// Compute initialization nullifier
let nullifier = silo_nullifier(contract_address, contract_address.to_field());

Expand Down
16 changes: 9 additions & 7 deletions noir-projects/aztec-nr/aztec/src/initializer.nr
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use dep::protocol_types::{
hash::{silo_nullifier, pedersen_hash},
constants::GENERATOR_INDEX__CONSTRUCTOR,
hash::{silo_nullifier, pedersen_hash}, constants::GENERATOR_INDEX__CONSTRUCTOR,
abis::function_selector::FunctionSelector,
traits::is_default,
traits::is_default
};

use crate::{
context::{PrivateContext, PublicContext, ContextInterface},
oracle::get_contract_instance::get_contract_instance,
history::nullifier_inclusion::prove_nullifier_inclusion,
history::nullifier_inclusion::prove_nullifier_inclusion
};

pub fn mark_as_initialized<TContext>(context: &mut TContext) where TContext: ContextInterface {
Expand All @@ -34,13 +33,16 @@ pub fn compute_unsiloed_contract_initialization_nullifier<TContext>(context: TCo
}

pub fn assert_initialization_matches_address_preimage<TContext>(context: TContext) where TContext: ContextInterface {
let address = context.this_address();
let address = context.this_address();
let instance = get_contract_instance(address);
let expected_init = compute_initialization_hash(context.selector(), context.get_args_hash());
assert(instance.initialization_hash == expected_init, "Initialization hash does not match");
assert(is_default(instance.deployer) | (instance.deployer == context.msg_sender()), "Initializer address is not the contract deployer");
}

pub fn compute_initialization_hash(init_selector: FunctionSelector, init_args_hash: Field) -> Field {
pedersen_hash([init_selector.to_field(), init_args_hash], GENERATOR_INDEX__CONSTRUCTOR)
}
pedersen_hash(
[init_selector.to_field(), init_args_hash],
GENERATOR_INDEX__CONSTRUCTOR
)
}
9 changes: 8 additions & 1 deletion noir-projects/aztec-nr/aztec/src/messaging.nr
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ pub fn process_l1_to_l2_message(
secret: Field
) -> Field {
let secret_hash = compute_secret_hash(secret);
let message_hash = compute_message_hash(portal_contract_address, chain_id, storage_contract_address, version, content, secret_hash);
let message_hash = compute_message_hash(
portal_contract_address,
chain_id,
storage_contract_address,
version,
content,
secret_hash
);

let returned_message = get_l1_to_l2_membership_witness(storage_contract_address, message_hash, secret);
let leaf_index = returned_message[0];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use dep::protocol_types::{
abis::function_selector::FunctionSelector,
address::AztecAddress,
abis::function_selector::FunctionSelector, address::AztecAddress,
constants::ENQUEUE_PUBLIC_FUNCTION_CALL_RETURN_LENGTH
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
use dep::protocol_types::{
address::AztecAddress,
constants::L1_TO_L2_MESSAGE_ORACLE_CALL_LENGTH,
};
use dep::protocol_types::{address::AztecAddress, constants::L1_TO_L2_MESSAGE_ORACLE_CALL_LENGTH};

// Obtains membership witness (index and sibling path) for a message in the L1 to L2 message tree.
#[oracle(getL1ToL2MembershipWitness)]
fn get_l1_to_l2_membership_witness_oracle(_contract_address: AztecAddress, _message_hash: Field, _secret: Field) -> [Field; L1_TO_L2_MESSAGE_ORACLE_CALL_LENGTH] {}
fn get_l1_to_l2_membership_witness_oracle(
_contract_address: AztecAddress,
_message_hash: Field,
_secret: Field
) -> [Field; L1_TO_L2_MESSAGE_ORACLE_CALL_LENGTH] {}

unconstrained pub fn get_l1_to_l2_membership_witness(contract_address: AztecAddress, message_hash: Field, secret: Field) -> [Field; L1_TO_L2_MESSAGE_ORACLE_CALL_LENGTH] {
unconstrained pub fn get_l1_to_l2_membership_witness(
contract_address: AztecAddress,
message_hash: Field,
secret: Field
) -> [Field; L1_TO_L2_MESSAGE_ORACLE_CALL_LENGTH] {
get_l1_to_l2_membership_witness_oracle(contract_address, message_hash, secret)
}
14 changes: 7 additions & 7 deletions noir-projects/aztec-nr/aztec/src/oracle/logs.nr
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ unconstrained pub fn emit_encrypted_log<N>(
encryption_pub_key: GrumpkinPoint,
preimage: [Field; N]
) -> Field {
emit_encrypted_log_oracle(
contract_address,
storage_slot,
note_type_id,
encryption_pub_key,
preimage
)
emit_encrypted_log_oracle(
contract_address,
storage_slot,
note_type_id,
encryption_pub_key,
preimage
)
}

#[oracle(emitUnencryptedLog)]
Expand Down
1 change: 0 additions & 1 deletion noir-projects/aztec-nr/aztec/src/oracle/unsafe_rand.nr
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#[oracle(getRandomField)]
fn rand_oracle() -> Field {}


// Called `unsafe_rand` because we do not constrain in circuit that we are dealing with an actual random value.
// Instead we just trust our PXE.
unconstrained pub fn unsafe_rand() -> Field {
Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/state_vars/map.nr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::context::{PrivateContext, PublicContext, Context};
use dep::protocol_types::{hash::pedersen_hash, traits::{ToField}};
use dep::protocol_types::{hash::pedersen_hash, traits::ToField};
use crate::state_vars::storage::Storage;

// docs:start:map
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use dep::protocol_types::{address::AztecAddress, constants::{GENERATOR_INDEX__INITIALIZATION_NULLIFIER}, hash::pedersen_hash};
use dep::protocol_types::{address::AztecAddress, constants::GENERATOR_INDEX__INITIALIZATION_NULLIFIER, hash::pedersen_hash};

use crate::context::{PrivateContext, Context};
use crate::note::{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use dep::protocol_types::{address::AztecAddress, constants::{GENERATOR_INDEX__INITIALIZATION_NULLIFIER}, hash::pedersen_hash};
use dep::protocol_types::{address::AztecAddress, constants::GENERATOR_INDEX__INITIALIZATION_NULLIFIER, hash::pedersen_hash};

use crate::context::{PrivateContext, PublicContext, Context};
use crate::note::{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::context::{Context};
use crate::context::Context;
use crate::oracle::storage::storage_read;
use crate::oracle::storage::storage_write;
use dep::protocol_types::traits::{Deserialize, Serialize};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ contract Benchmarking {
};
use dep::value_note::{utils::{increment, decrement}, value_note::ValueNote};

use dep::aztec::{context::{Context}};
use dep::aztec::{context::Context};

struct Storage {
notes: Map<AztecAddress, PrivateSet<ValueNote>>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use dep::aztec::protocol_types::{
contract_class_id::ContractClassId,
constants::{MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS, REGISTERER_CONTRACT_CLASS_REGISTERED_MAGIC_VALUE},
traits::{Serialize}
traits::Serialize
};

// #[event]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use dep::aztec::protocol_types::{
contract_class_id::ContractClassId,
address::{AztecAddress, EthAddress, PublicKeysHash, PartialAddress},
constants::{DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE}, traits::{Serialize}
constants::DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE, traits::Serialize
};

// #[event]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ mod events;
contract ContractInstanceDeployer {
use dep::aztec::protocol_types::{
address::{AztecAddress, EthAddress, PublicKeysHash, PartialAddress},
contract_class_id::ContractClassId,
constants::{DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE}, traits::{Serialize}
contract_class_id::ContractClassId, constants::DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE,
traits::Serialize
};

use dep::aztec::log::{emit_unencrypted_log, emit_unencrypted_log_from_private};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod lib;

contract GasToken {
use dep::aztec::protocol_types::{abis::function_selector::FunctionSelector, address::{AztecAddress, EthAddress}};
use dep::aztec::{hash::{compute_secret_hash}, state_vars::{PublicMutable, Map}};
use dep::aztec::{hash::compute_secret_hash, state_vars::{PublicMutable, Map}};

use crate::lib::{calculate_fee, get_bridge_gas_msg_hash};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ contract StatefulTest {
use dep::aztec::prelude::{PrivateContext, NoteHeader, Map, PublicMutable, PrivateSet, AztecAddress, FunctionSelector};
use dep::value_note::{balance_utils, utils::{increment, decrement}, value_note::{VALUE_NOTE_LEN, ValueNote}};
use dep::aztec::{
deploy::{deploy_contract as aztec_deploy_contract}, context::{PublicContext, Context},
oracle::get_contract_instance::get_contract_instance,
initializer::assert_is_initialized,
deploy::deploy_contract as aztec_deploy_contract, context::{PublicContext, Context},
oracle::get_contract_instance::get_contract_instance, initializer::assert_is_initialized
};

struct Storage {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ contract Test {
note_getter_options::NoteStatus
},
deploy::deploy_contract as aztec_deploy_contract,
oracle::{get_public_key::get_public_key as get_public_key_oracle, context::get_portal_address, unsafe_rand::unsafe_rand},
oracle::{
get_public_key::get_public_key as get_public_key_oracle, context::get_portal_address,
unsafe_rand::unsafe_rand
},
log::emit_unencrypted_log_from_private
};
use dep::token_portal_content_hash_lib::{get_mint_private_content_hash, get_mint_public_content_hash};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,12 @@ contract Uniswap {
// if valid, it returns the IS_VALID selector which is expected by token contract
#[aztec(public)]
fn spend_public_authwit(inner_hash: Field) -> Field {
let message_hash = compute_outer_authwit_hash(context.msg_sender(), context.chain_id(), context.version(), inner_hash);
let message_hash = compute_outer_authwit_hash(
context.msg_sender(),
context.chain_id(),
context.version(),
inner_hash
);
let value = storage.approved_action.at(message_hash).read();
if (value) {
context.push_new_nullifier(message_hash, 0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mod base_parity_inputs;
mod base_parity_inputs;
Loading

0 comments on commit 48572dc

Please sign in to comment.