Skip to content

Commit

Permalink
chore: run nargo fmt on each nargo project (#5102)
Browse files Browse the repository at this point in the history
Quickly wrote and ran https://github.com/just-mitch/format_all_nargo
over the project root.
  • Loading branch information
just-mitch authored Mar 9, 2024
1 parent 4668597 commit b327254
Show file tree
Hide file tree
Showing 20 changed files with 71 additions and 81 deletions.
8 changes: 2 additions & 6 deletions noir-projects/aztec-nr/aztec/src/context/interface.nr
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
use dep::protocol_types::{
abis::function_selector::FunctionSelector,
address::{AztecAddress, EthAddress},
header::Header,
};
use dep::protocol_types::{abis::function_selector::FunctionSelector, address::{AztecAddress, EthAddress}, header::Header};

trait ContextInterface {
fn push_new_note_hash(&mut self, note_hash: Field);
Expand All @@ -14,4 +10,4 @@ trait ContextInterface {
fn version(self) -> Field;
fn selector(self) -> FunctionSelector;
fn get_header(self) -> Header;
}
}
27 changes: 11 additions & 16 deletions noir-projects/aztec-nr/aztec/src/deploy.nr
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
use crate::{
context::PrivateContext,
oracle::get_contract_instance::get_contract_instance,
};
use crate::{context::PrivateContext, oracle::get_contract_instance::get_contract_instance};

use dep::protocol_types::{
address::AztecAddress,
abis::function_selector::FunctionSelector,
constants::DEPLOYER_CONTRACT_ADDRESS,
};
use dep::protocol_types::{address::AztecAddress, abis::function_selector::FunctionSelector, constants::DEPLOYER_CONTRACT_ADDRESS};

// Calls `deploy` on the deployer contract to deploy a new instance.
pub fn deploy_contract(context: &mut PrivateContext, target: AztecAddress) {
let instance = get_contract_instance(target);

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

Expand All @@ -31,8 +26,8 @@ pub fn deploy_contract(context: &mut PrivateContext, target: AztecAddress) {
serialized_args[5] = universal_deploy as Field;

let _call_result = context.call_private_function(
AztecAddress::from_field(DEPLOYER_CONTRACT_ADDRESS),
FunctionSelector::from_field(0x883355ab),
serialized_args
AztecAddress::from_field(DEPLOYER_CONTRACT_ADDRESS),
FunctionSelector::from_field(0x883355ab),
serialized_args
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use dep::std::merkle::compute_merkle_root;
use dep::protocol_types::header::Header;

use crate::{
context::{PrivateContext, ContextInterface}, oracle::get_nullifier_membership_witness::get_nullifier_membership_witness,
context::{PrivateContext, ContextInterface},
oracle::get_nullifier_membership_witness::get_nullifier_membership_witness,
note::{utils::compute_siloed_nullifier, note_interface::NoteInterface}
};

Expand All @@ -25,7 +26,10 @@ fn _nullifier_inclusion(nullifier: Field, header: Header) {
// was included in the nullifier tree.
}

pub fn prove_nullifier_inclusion<TContext>(nullifier: Field, context: TContext) where TContext: ContextInterface {
pub fn prove_nullifier_inclusion<TContext>(
nullifier: Field,
context: TContext
) where TContext: ContextInterface {
_nullifier_inclusion(nullifier, context.get_header());
}

Expand Down
23 changes: 13 additions & 10 deletions noir-projects/aztec-nr/aztec/src/initializer.nr
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,31 @@ use crate::context::{PrivateContext, PublicContext, ContextInterface};
use crate::history::nullifier_inclusion::prove_nullifier_inclusion;

pub fn mark_as_initialized(context: &mut PrivateContext) {
let init_nullifier = compute_unsiloed_contract_initialization_nullifier(*context);
context.push_new_nullifier(init_nullifier, 0);
let init_nullifier = compute_unsiloed_contract_initialization_nullifier(*context);
context.push_new_nullifier(init_nullifier, 0);
}

// TODO(@spalladino): Using the trait here fails with "No matching impl found for `&mut TContext: ContextInterface`"
// on the `push_new_nullifier` call. Remove this method in favor of a single method that uses the trait (and update
// the noir compiler macro accordingly) once we sort it out.
pub fn mark_as_initialized_public(context: &mut PublicContext) {
let init_nullifier = compute_unsiloed_contract_initialization_nullifier(*context);
context.push_new_nullifier(init_nullifier, 0);
let init_nullifier = compute_unsiloed_contract_initialization_nullifier(*context);
context.push_new_nullifier(init_nullifier, 0);
}

pub fn assert_is_initialized<TContext>(context: &mut TContext) where TContext: ContextInterface {
let init_nullifier = compute_contract_initialization_nullifier(*context);
prove_nullifier_inclusion(init_nullifier, *context);
let init_nullifier = compute_contract_initialization_nullifier(*context);
prove_nullifier_inclusion(init_nullifier, *context);
}

pub fn compute_contract_initialization_nullifier<TContext>(context: TContext) -> Field where TContext: ContextInterface {
let address = context.this_address();
silo_nullifier(address, compute_unsiloed_contract_initialization_nullifier(context))
let address = context.this_address();
silo_nullifier(
address,
compute_unsiloed_contract_initialization_nullifier(context)
)
}

pub fn compute_unsiloed_contract_initialization_nullifier<TContext>(context: TContext) -> Field where TContext: ContextInterface{
context.this_address().to_field()
pub fn compute_unsiloed_contract_initialization_nullifier<TContext>(context: TContext) -> Field where TContext: ContextInterface {
context.this_address().to_field()
}
16 changes: 8 additions & 8 deletions noir-projects/aztec-nr/aztec/src/prelude.nr
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
use dep::protocol_types::{address::{AztecAddress, EthAddress}, abis::function_selector::FunctionSelector};
use crate::{
state_vars::{
map::Map, private_immutable::PrivateImmutable, private_mutable::PrivateMutable,
public_immutable::PublicImmutable, public_mutable::PublicMutable, private_set::PrivateSet,
shared_immutable::SharedImmutable
},
map::Map, private_immutable::PrivateImmutable, private_mutable::PrivateMutable,
public_immutable::PublicImmutable, public_mutable::PublicMutable, private_set::PrivateSet,
shared_immutable::SharedImmutable
},
log::{emit_unencrypted_log, emit_encrypted_log}, context::PrivateContext,
note::{
note_header::NoteHeader, note_interface::NoteInterface, note_getter_options::NoteGetterOptions,
note_viewer_options::NoteViewerOptions,
utils::compute_note_hash_and_nullifier as utils_compute_note_hash_and_nullifier
}
note_header::NoteHeader, note_interface::NoteInterface, note_getter_options::NoteGetterOptions,
note_viewer_options::NoteViewerOptions,
utils::compute_note_hash_and_nullifier as utils_compute_note_hash_and_nullifier
}
};
// docs:end:prelude
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dep::aztec::{
protocol_types::{abis::function_selector::FunctionSelector, address::AztecAddress},
context::PrivateContext,
context::PrivateContext
};

struct Token {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ contract Claim {

use dep::aztec::{
history::note_inclusion::prove_note_inclusion,
protocol_types::{
abis::function_selector::FunctionSelector,
address::AztecAddress,
},
state_vars::SharedImmutable,
protocol_types::{abis::function_selector::FunctionSelector, address::AztecAddress},
state_vars::SharedImmutable
};
use dep::value_note::value_note::ValueNote;
use interfaces::Token;
Expand Down Expand Up @@ -41,7 +38,9 @@ contract Claim {
fn claim(proof_note: ValueNote) {
// 1) Check that the note corresponds to the target contract
let target_address = storage.target_contract.read_private();
assert(target_address == proof_note.header.contract_address, "Note does not correspond to the target contract");
assert(
target_address == proof_note.header.contract_address, "Note does not correspond to the target contract"
);

// 2) Prove that the note hash exists in the note hash tree
prove_note_inclusion(proof_note, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@ contract Crowdfunding {

use dep::aztec::{
log::emit_unencrypted_log_from_private,
protocol_types::{
abis::function_selector::FunctionSelector,
address::AztecAddress,
traits::Serialize
},
state_vars::{PrivateSet, PublicImmutable, SharedImmutable},
protocol_types::{abis::function_selector::FunctionSelector, address::AztecAddress, traits::Serialize},
state_vars::{PrivateSet, PublicImmutable, SharedImmutable}
};
use dep::value_note::value_note::ValueNote;
use interfaces::Token;
Expand Down Expand Up @@ -99,7 +95,13 @@ contract Crowdfunding {

// 2) Transfer the donation tokens from this contract to the operator
let donation_token = Token::at(storage.donation_token.read_private());
donation_token.transfer(&mut context, context.this_address(), operator_address, amount as Field, 0);
donation_token.transfer(
&mut context,
context.this_address(),
operator_address,
amount as Field,
0
);

// 3) Emit an unencrypted event so that anyone can audit how much the operator has withdrawn
let event = WithdrawalProcessed { amount, who: operator_address };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ use root_rollup_inputs::RootRollupInputs;
use root_rollup_public_inputs::RootRollupPublicInputs;

// TODO: Move all the following code to different files
use dep::types::{
constants::{NUM_FIELDS_PER_SHA256, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP},
utils::uint256::U256
};
use dep::types::{constants::{NUM_FIELDS_PER_SHA256, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP}, utils::uint256::U256};

// See `test_message_input_flattened_length` on keeping this in sync,
// why its here and how this constant was computed.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
use crate::{
abis::{
previous_rollup_data::PreviousRollupData,
constant_rollup_data::ConstantRollupData,
},
components,
root::{
compute_messages_hash,
root_rollup_public_inputs::RootRollupPublicInputs,
}
abis::{previous_rollup_data::PreviousRollupData, constant_rollup_data::ConstantRollupData},
components, root::{compute_messages_hash, root_rollup_public_inputs::RootRollupPublicInputs}
};
use dep::types::{
abis::{append_only_tree_snapshot::AppendOnlyTreeSnapshot, nullifier_leaf_preimage::NullifierLeafPreimage},
constants::{NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, L1_TO_L2_MSG_SUBTREE_HEIGHT, L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH, ARCHIVE_HEIGHT},
constants::{
NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, L1_TO_L2_MSG_SUBTREE_HEIGHT,
L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH, ARCHIVE_HEIGHT
},
header::Header, content_commitment::ContentCommitment,
merkle_tree::{append_only_tree, calculate_subtree, calculate_empty_tree_root},
state_reference::StateReference
Expand Down Expand Up @@ -96,4 +92,4 @@ impl RootRollupInputs {
l1_to_l2_messages_hash: compute_messages_hash(self.new_l1_to_l2_messages)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mod module;
mod module;
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mod foo;
mod foo;
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub fn bar(param: Field) -> Field {
dep::std::hash::pedersen_hash([param])
dep::std::hash::pedersen_hash([param])
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ contract TestContract {
open fn openFunction() -> pub Field {
42
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ fn main(x: Field, y: pub Field) {
let z = x + y;
assert(z != y, f"Expected z != y, but got both equal {z}");
assert_eq(x, y, f"Expected x == y, but x is {x} and y is {y}");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ unconstrained fn conditional(x: Field) -> Field {
assert_eq(z, 25, f"Expected 25 but got {z}");
assert(x == 10, f"Expected x to equal 10, but got {x}");
1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ unconstrained fn mut_ref_identity(value: &mut Field) -> Field {
fn main(mut x: Field, y: pub Field) {
let returned_x = mut_ref_identity(&mut x);
assert(returned_x == x);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ contract Foo {
struct T { x: [Field] }

impl T {
fn t(self){}
fn t(self) {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ contract Foo {
}
// Regression for issue #3344
#[contract_library_method]
fn foo(x : u8) -> u8 {
fn foo(x: u8) -> u8 {
x
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

struct MyStruct {
inner: Field
}
Expand Down

0 comments on commit b327254

Please sign in to comment.