Skip to content

Commit

Permalink
Do not insert init check if contract has no initializer
Browse files Browse the repository at this point in the history
  • Loading branch information
spalladino committed Feb 28, 2024
1 parent 65306c5 commit e231cb7
Show file tree
Hide file tree
Showing 19 changed files with 9 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ contract AvmTest {
use dep::aztec::avm::hash::{keccak256, poseidon, sha256};

#[aztec(private)]
#[aztec(initializer)]
fn constructor() {}

// Public-vm macro will prefix avm to the function name for transpilation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ contract Benchmarking {
}

#[aztec(private)]
#[aztec(initializer)]
fn constructor() {}

// Creates a new value note for the target owner. Use this method to seed an initial set of notes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ contract CardGame {
}

#[aztec(private)]
#[aztec(initializer)]
fn constructor() {}

#[aztec(private)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ contract Child {
}

#[aztec(private)]
#[aztec(initializer)]
fn constructor() {}

// Returns a sum of the input and the chain id and version of the contract in private circuit public input's return_values.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ contract ContractClassRegisterer {
use crate::capsule::pop_capsule;

#[aztec(private)]
#[aztec(initializer)]
fn constructor() {}

#[aztec(private)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ contract ContractInstanceDeployer {
use crate::events::{instance_deployed::ContractInstanceDeployed};

#[aztec(private)]
#[aztec(initializer)]
fn constructor() {}

#[aztec(private)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ contract DelegatedOn {
}

#[aztec(private)]
#[aztec(initializer)]
fn constructor() {}

#[aztec(private)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ contract Delegator {
}

#[aztec(private)]
#[aztec(initializer)]
fn constructor() {}

#[aztec(private)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ contract DocsExample {
}

#[aztec(private)]
#[aztec(initializer)]
fn constructor() {}

#[aztec(public)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ contract GasToken {
}

#[aztec(private)]
#[aztec(initializer)]
fn constructor() {}

#[aztec(public)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ contract Parent {
use dep::aztec::protocol_types::{address::AztecAddress, abis::function_selector::FunctionSelector};

#[aztec(private)]
#[aztec(initializer)]
fn constructor() {}

// Private function to call another private function in the targetContract using the provided selector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ contract PendingCommitments {
// (once Noir's support for this is more robust)

#[aztec(private)]
#[aztec(initializer)]
fn constructor() {}

// Confirm can access pending note hashes by creating / inserting a note and then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ contract PriceFeed {
}

#[aztec(private)]
#[aztec(initializer)]
fn constructor() {}

#[aztec(public)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ contract Reader {
use dep::compressed_string::FieldCompressedString;

#[aztec(private)]
#[aztec(initializer)]
fn constructor() {}

#[aztec(public)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ contract SchnorrHardcodedAccount {
global ACCOUNT_ACTIONS_STORAGE_SLOT = 1;

#[aztec(private)]
#[aztec(initializer)]
fn constructor() {}

// Note: If you globally change the entrypoint signature don't forget to update default_entrypoint.ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ contract SchnorrSingleKeyAccount {
global ACCOUNT_ACTIONS_STORAGE_SLOT = 1;

#[aztec(private)]
#[aztec(initializer)]
fn constructor() {}

// Note: If you globally change the entrypoint signature don't forget to update default_entrypoint.ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ contract SlowTree {
// docs:end:constants_and_storage

#[aztec(private)]
#[aztec(initializer)]
fn constructor() {}
// docs:start:initialize
#[aztec(public)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ contract Uniswap {
}

#[aztec(private)]
#[aztec(initializer)]
fn constructor() {}
// docs:end:uniswap_setup

Expand Down
15 changes: 9 additions & 6 deletions noir/aztec_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,23 +435,26 @@ fn transform_module(
}
}

let has_initializer = module.functions.iter().any(|func| func.def.attributes.secondary.iter().any(|attr| is_custom_attribute(&attr, "aztec(initializer)")));

for func in module.functions.iter_mut() {
let mut is_private = false;
let mut is_public = false;
let mut is_public_vm = false;
let mut is_initializer = false;
let mut skip_init_check = false;
let mut insert_init_check = has_initializer;

for secondary_attribute in func.def.attributes.secondary.clone() {
if is_custom_attribute(&secondary_attribute, "aztec(private)") {
is_private = true;
} else if is_custom_attribute(&secondary_attribute, "aztec(initializer)") {
is_initializer = true;
insert_init_check = false;
} else if is_custom_attribute(&secondary_attribute, "aztec(noinitcheck)") {
skip_init_check = true;
insert_init_check = false;
} else if is_custom_attribute(&secondary_attribute, "aztec(public)") {
is_public = true;
skip_init_check = true;
insert_init_check = false;
} else if is_custom_attribute(&secondary_attribute, "aztec(public-vm)") {
is_public_vm = true;
}
Expand All @@ -464,7 +467,7 @@ fn transform_module(
func,
storage_defined,
is_initializer,
skip_init_check,
insert_init_check,
)
.map_err(|err| (err, crate_graph.root_file_id))?;
has_transformed_module = true;
Expand Down Expand Up @@ -656,14 +659,14 @@ fn transform_function(
func: &mut NoirFunction,
storage_defined: bool,
is_initializer: bool,
skip_init_check: bool,
insert_init_check: bool,
) -> Result<(), AztecMacroError> {
let context_name = format!("{}Context", ty);
let inputs_name = format!("{}ContextInputs", ty);
let return_type_name = format!("{}CircuitPublicInputs", ty);

// Add initialization check
if !skip_init_check {
if insert_init_check {
if ty == "Public" {
let error = AztecMacroError::UnsupportedAttributes {
span: func.def.name.span(),
Expand Down

0 comments on commit e231cb7

Please sign in to comment.