Skip to content

Commit

Permalink
feat: Check initializer by default in private functions
Browse files Browse the repository at this point in the history
  • Loading branch information
spalladino committed Feb 28, 2024
1 parent 6657206 commit 75bc458
Show file tree
Hide file tree
Showing 35 changed files with 40 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ contract AppSubscriptionContract {

// Constructs the contract
#[aztec(private)]
#[aztec(initializer)]
fn constructor(
target_address: AztecAddress,
subscription_recipient_address: AztecAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ 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,6 +20,7 @@ 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,6 +20,7 @@ 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,6 +16,7 @@ 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,6 +23,7 @@ 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,6 +13,7 @@ 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 @@ -17,6 +17,7 @@ contract Counter {

// docs:start:constructor
#[aztec(private)]
#[aztec(initializer)]
fn constructor(headstart: u64, owner: AztecAddress) {
let counters = storage.counters;
counters.at(owner).add(headstart, owner);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ 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,6 +15,7 @@ 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,6 +89,7 @@ contract DocsExample {
}

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

#[aztec(public)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ contract EasyPrivateToken {
* initialize the contract's initial state variables.
*/
#[aztec(private)]
#[aztec(initializer)]
fn constructor(initial_supply: u64, owner: AztecAddress) {
let balances = storage.balances;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ contract EasyPrivateVoting {
// docs:end:storage_struct

// docs:start:constructor
#[aztec(private)] // annotation to mark function as private and expose private context
#[aztec(private)]
#[aztec(initializer)] // annotation to mark function as private and expose private context
fn constructor(admin: AztecAddress) { // called when contract is deployed
context.call_public_function(
// we cannot update public state directly from private function but we can call public function (which queues it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ contract EcdsaAccount {

// Creates a new account out of an ECDSA public key to use for signature verification
#[aztec(private)]
#[aztec(initializer)]
fn constructor(signing_pub_key_x: pub [u8; 32], signing_pub_key_y: pub [u8; 32]) {
let this = context.this_address();
let mut pub_key_note = EcdsaPublicKeyNote::new(signing_pub_key_x, signing_pub_key_y, this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ contract Escrow {
// Creates a new instance
// docs:start:constructor
#[aztec(private)]
#[aztec(initializer)]
fn constructor(owner: pub AztecAddress) {
let this = context.this_address();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ contract FPC {
}

#[aztec(private)]
#[aztec(initializer)]
fn constructor(other_asset: AztecAddress, fee_asset: AztecAddress) {
let selector = FunctionSelector::from_signature("_initialize((Field),(Field))");
context.call_public_function(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ contract GasToken {
}

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ contract InclusionProofs {
}

#[aztec(private)]
#[aztec(initializer)]
fn constructor(public_value: Field) {
let selector = FunctionSelector::from_signature("_initialize(Field)");
context.call_public_function(context.this_address(), selector, [public_value]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ contract Lending {

// Constructs the contract.
#[aztec(private)]
#[aztec(initializer)]
fn constructor(
) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ 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,6 +21,7 @@ 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,6 +12,7 @@ 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,6 +4,7 @@ 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 @@ -29,6 +29,7 @@ contract SchnorrAccount {

// Constructs the contract
#[aztec(private)]
#[aztec(initializer)]
fn constructor(signing_pub_key_x: pub Field, signing_pub_key_y: pub Field) {
let this = context.this_address();
// docs:start:initialize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ 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,6 +12,7 @@ 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,6 +36,7 @@ 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 @@ -25,7 +25,6 @@ contract StatefulTest {
}

#[aztec(private)]
#[aztec(initcheck)]
fn create_note(owner: AztecAddress, value: Field) {
if (value != 0) {
let loc = storage.notes.at(owner);
Expand All @@ -34,6 +33,7 @@ contract StatefulTest {
}

#[aztec(private)]
#[aztec(noinitcheck)]
internal fn internal_create_note(owner: AztecAddress, value: Field) {
if (value != 0) {
let loc = storage.notes.at(owner);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ contract Test {
}

#[aztec(private)]
#[aztec(initializer)]
// docs:start:empty-constructor
fn constructor() {}
// docs:end:empty-constructor
Expand Down Expand Up @@ -225,7 +226,7 @@ contract Test {
}

// Forcefully emits a nullifier (for testing purposes)
#[aztec(private)]
#[aztec(private,noinitcheck)]
fn emit_nullifier(nullifier: Field) {
context.push_new_nullifier(nullifier, 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ contract TokenBlacklist {

// docs:start:constructor
#[aztec(private)]
#[aztec(initializer)]
fn constructor(admin: AztecAddress, slow_updates_contract: AztecAddress) {
let mut slow_note = FieldNote::new(slow_updates_contract.to_field());
storage.slow_update.initialize(&mut slow_note, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ contract TokenBridge {

// Constructs the contract.
#[aztec(private)]
#[aztec(initializer)]
fn constructor(token: AztecAddress) {
let selector = FunctionSelector::from_signature("_initialize((Field))");
context.call_public_function(context.this_address(), selector, [token.to_field()]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ contract Token {

// docs:start:constructor
#[aztec(private)]
#[aztec(initializer)]
fn constructor(admin: AztecAddress, name: str<31>, symbol: str<31>, decimals: u8) {
let selector = FunctionSelector::from_signature("_initialize((Field),(Field),(Field),u8)");
let name_s = FieldCompressedString::from_string(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ contract Uniswap {
}

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

Expand Down
7 changes: 4 additions & 3 deletions noir/aztec_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,17 +440,18 @@ fn transform_module(
let mut is_public = false;
let mut is_public_vm = false;
let mut is_initializer = false;
let mut skip_init_check = true; // Default to true once we're confident that the approach works
let mut skip_init_check = false;

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;
} else if is_custom_attribute(&secondary_attribute, "aztec(initcheck)") {
skip_init_check = false;
} else if is_custom_attribute(&secondary_attribute, "aztec(noinitcheck)") {
skip_init_check = true;
} else if is_custom_attribute(&secondary_attribute, "aztec(public)") {
is_public = true;
skip_init_check = true;
} else if is_custom_attribute(&secondary_attribute, "aztec(public-vm)") {
is_public_vm = true;
}
Expand Down

0 comments on commit 75bc458

Please sign in to comment.