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: define Aztec prelude #4929

Merged
merged 16 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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: 2 additions & 4 deletions boxes/react/src/contracts/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
contract BoxReact {
use dep::aztec::{
protocol_types::address::AztecAddress, state_vars::{PrivateMutable, Map},
note::{utils as note_utils, note_interface::NoteInterface, note_header::NoteHeader}
};
use dep::aztec::prelude::{AztecAddress, PrivateMutable, Map, NoteInterface, NoteHeader};
use dep::aztec::note::utils as note_utils;

use dep::value_note::value_note::{ValueNote, VALUE_NOTE_LEN};

Expand Down
6 changes: 2 additions & 4 deletions boxes/vanilla-js/src/contracts/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
contract Vanilla {
use dep::aztec::{
protocol_types::address::AztecAddress, state_vars::{PrivateMutable, Map},
note::{utils as note_utils, note_interface::NoteInterface, note_header::NoteHeader}
};
use dep::aztec::prelude::{AztecAddress, PrivateMutable, Map, NoteInterface, NoteHeader};
use dep::aztec::note::utils as note_utils;

use dep::value_note::value_note::{ValueNote, VALUE_NOTE_LEN};

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
@@ -1,4 +1,4 @@
use dep::aztec::context::PrivateContext;
use dep::aztec::prelude::PrivateContext;
use dep::aztec::protocol_types::{constants::GENERATOR_INDEX__SIGNATURE_PAYLOAD, hash::pedersen_hash, traits::{Hash, Serialize}};

use crate::entrypoint::function_call::{FunctionCall, FUNCTION_CALL_SIZE_IN_BYTES};
Expand Down
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/authwit/src/entrypoint/fee.nr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dep::aztec::context::PrivateContext;
use dep::aztec::prelude::PrivateContext;
use dep::aztec::protocol_types::{constants::GENERATOR_INDEX__FEE_PAYLOAD, hash::pedersen_hash, traits::{Hash, Serialize}};
use crate::entrypoint::function_call::{FunctionCall};
use crate::entrypoint::function_call::FunctionCall;

// 2 * 4 (function call) + 1
global FEE_PAYLOAD_SIZE: Field = 9;
Expand Down
1 change: 1 addition & 0 deletions noir-projects/aztec-nr/aztec/src/lib.nr
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ mod messaging;
mod note;
mod oracle;
mod state_vars;
mod prelude;
use dep::protocol_types;
14 changes: 14 additions & 0 deletions noir-projects/aztec-nr/aztec/src/prelude.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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
},
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
}
};
7 changes: 2 additions & 5 deletions noir-projects/aztec-nr/value-note/src/utils.nr
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use dep::std::option::Option;
use dep::aztec::context::PrivateContext;
use dep::aztec::note::note_getter_options::{NoteGetterOptions, SortOrder};
use dep::aztec::prelude::{AztecAddress, PrivateContext, PrivateSet, NoteGetterOptions};
use dep::aztec::note::note_getter_options::SortOrder;
use dep::aztec::oracle::get_public_key::get_public_key;
use dep::aztec::state_vars::PrivateSet;
use crate::{filter::filter_notes_min_sum, value_note::{ValueNote, VALUE_NOTE_LEN}};
use dep::aztec::protocol_types::address::AztecAddress;

// Sort the note values (0th field) in descending order.
// Pick the fewest notes whose sum is equal to or greater than `amount`.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use dep::aztec::context::PrivateContext;
use dep::aztec::protocol_types::{
constants::GENERATOR_INDEX__SIGNATURE_PAYLOAD, hash::pedersen_hash, traits::{Hash, Serialize},
address::AztecAddress
};
use dep::aztec::prelude::{PrivateContext, AztecAddress};
use dep::aztec::protocol_types::{constants::GENERATOR_INDEX__SIGNATURE_PAYLOAD, hash::pedersen_hash, traits::{Hash, Serialize}};

use dep::authwit::entrypoint::function_call::{FunctionCall, FUNCTION_CALL_SIZE_IN_BYTES};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ contract AppSubscription {
use dep::std::option::Option;
use crate::dapp_payload::DAppPayload;

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

use dep::aztec::{
context::{PrivateContext, Context}, note::{note_header::NoteHeader, utils as note_utils},
oracle::get_public_key::get_public_key,
state_vars::{Map, PrivateMutable, PublicMutable, SharedImmutable}
use dep::aztec::prelude::{
AztecAddress, FunctionSelector, PrivateContext, NoteHeader, Map, PrivateMutable, PublicMutable,
SharedImmutable
};

use dep::aztec::{context::Context, note::utils as note_utils, oracle::get_public_key::get_public_key};
use dep::authwit::{account::AccountActions, auth_witness::get_auth_witness, auth::assert_current_call_valid_authwit};

use crate::subscription_note::{SubscriptionNote, SUBSCRIPTION_NOTE_LEN};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use dep::aztec::prelude::{AztecAddress, PrivateContext, NoteHeader, emit_encrypted_log, NoteInterface};
use dep::aztec::{
note::{note_header::NoteHeader, note_interface::NoteInterface, utils::compute_note_hash_for_consumption},
hash::pedersen_hash,
oracle::{nullifier_key::get_nullifier_secret_key, get_public_key::get_public_key},
log::emit_encrypted_log, context::PrivateContext, protocol_types::{address::AztecAddress}
note::utils::compute_note_hash_for_consumption, hash::pedersen_hash,
oracle::{nullifier_key::get_nullifier_secret_key, get_public_key::get_public_key}
};

global SUBSCRIPTION_NOTE_LEN: Field = 3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
// arise from code changes.

contract Benchmarking {
use dep::aztec::prelude::{
AztecAddress, FunctionSelector, NoteHeader, NoteGetterOptions, emit_unencrypted_log, Map,
PublicMutable, PrivateSet
};
use dep::value_note::{utils::{increment, decrement}, value_note::ValueNote};

use dep::aztec::{
protocol_types::{abis::function_selector::FunctionSelector, address::AztecAddress},
context::{Context},
note::{utils as note_utils, note_getter_options::NoteGetterOptions, note_header::NoteHeader},
log::emit_unencrypted_log, state_vars::{Map, PublicMutable, PrivateSet}
};
use dep::aztec::{context::{Context}, note::utils as note_utils};

struct Storage {
notes: Map<AztecAddress, PrivateSet<ValueNote>>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
use dep::aztec::prelude::{AztecAddress, FunctionSelector, PrivateContext, NoteHeader, NoteGetterOptions, NoteViewerOptions};

use dep::aztec::{
protocol_types::{address::AztecAddress, constants::{MAX_NOTES_PER_PAGE, MAX_NOTE_HASH_READ_REQUESTS_PER_CALL}},
context::{PrivateContext, PublicContext, Context},
note::{
note_getter_options::NoteGetterOptions, note_viewer_options::NoteViewerOptions,
note_getter::view_notes
},
state_vars::PrivateSet
protocol_types::constants::{MAX_NOTES_PER_PAGE, MAX_NOTE_HASH_READ_REQUESTS_PER_CALL},
context::{PublicContext, Context}, note::note_getter::view_notes, state_vars::PrivateSet
};
use dep::std;
use dep::std::{option::Option};
Expand Down Expand Up @@ -161,7 +158,11 @@ impl Deck {

global PACK_CARDS = 3; // Limited by number of write requests (max 4)

pub fn get_pack_cards(seed: Field, owner: AztecAddress, context: &mut PrivateContext) -> [Card; PACK_CARDS] {
pub fn get_pack_cards(
seed: Field,
owner: AztecAddress,
context: &mut PrivateContext
) -> [Card; 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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// A contract used along with `Parent` contract to test nested calls.
contract Child {
use dep::std::option::Option;
use dep::aztec::prelude::{AztecAddress, FunctionSelector, PublicMutable, PrivateSet, PrivateContext, emit_unencrypted_log};

use dep::aztec::{
context::{PrivateContext, PublicContext, Context}, log::emit_unencrypted_log,
state_vars::{PublicMutable, PrivateSet},
protocol_types::{abis::{function_selector::FunctionSelector, call_context::CallContext}, address::AztecAddress},
context::{PublicContext, Context}, protocol_types::{abis::{call_context::CallContext}},
note::{note_getter_options::NoteGetterOptions, note_header::NoteHeader, utils as note_utils}
};
use dep::value_note::value_note::{ValueNote, VALUE_NOTE_LEN};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use dep::aztec::prelude::FunctionSelector;
use dep::aztec::protocol_types;
use dep::aztec::protocol_types::{
contract_class_id::ContractClassId, abis::function_selector::FunctionSelector,
contract_class_id::ContractClassId,
constants::{
FUNCTION_TREE_HEIGHT, ARTIFACT_FUNCTION_TREE_MAX_HEIGHT,
MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use dep::aztec::prelude::FunctionSelector;
use dep::aztec::protocol_types;
use dep::aztec::protocol_types::{
contract_class_id::ContractClassId, abis::function_selector::FunctionSelector,
contract_class_id::ContractClassId,
constants::{
ARTIFACT_FUNCTION_TREE_MAX_HEIGHT, MAX_PACKED_BYTECODE_SIZE_PER_UNCONSTRAINED_FUNCTION_IN_FIELDS,
REGISTERER_UNCONSTRAINED_FUNCTION_BROADCASTED_MAGIC_VALUE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ mod events;
mod capsule;

contract ContractClassRegisterer {
use dep::std::option::Option;
use dep::aztec::prelude::{AztecAddress, EthAddress, FunctionSelector, emit_unencrypted_log};
use dep::aztec::protocol_types::{
address::{AztecAddress, EthAddress}, contract_class_id::ContractClassId,
contract_class_id::ContractClassId,
constants::{
ARTIFACT_FUNCTION_TREE_MAX_HEIGHT, FUNCTION_TREE_HEIGHT,
MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS, REGISTERER_CONTRACT_CLASS_REGISTERED_MAGIC_VALUE
},
traits::{Serialize}
};

use dep::aztec::log::{emit_unencrypted_log, emit_unencrypted_log_from_private};
use dep::aztec::log::{emit_unencrypted_log_from_private};

use crate::events::{
class_registered::ContractClassRegistered,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
contract Counter {
// docs:start:imports
use dep::aztec::protocol_types::address::AztecAddress;
use dep::aztec::{
context::{PrivateContext, Context}, note::{note_header::NoteHeader, utils as note_utils},
state_vars::Map
};
use dep::aztec::prelude::{AztecAddress, Map};
use dep::aztec::{context::Context, note::utils as note_utils};
use dep::value_note::{balance_utils, value_note::{ValueNote, VALUE_NOTE_LEN}};
use dep::easy_private_state::EasyPrivateUint;
// docs:end:imports
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
// A contract used along with `Parent` contract to test nested calls.
contract DelegatedOn {
use dep::std::option::Option;
use dep::aztec::prelude::{
AztecAddress, FunctionSelector, NoteHeader, NoteGetterOptions, NoteViewerOptions,
emit_unencrypted_log, PublicMutable, PrivateSet, PrivateContext
};

use dep::aztec::{
context::{PrivateContext, PublicContext, Context}, log::emit_unencrypted_log,
state_vars::{PublicMutable, PrivateSet},
protocol_types::{abis::{function_selector::FunctionSelector, call_context::CallContext}, address::AztecAddress},
note::{
note_getter_options::NoteGetterOptions, note_viewer_options::NoteViewerOptions,
utils as note_utils, note_header::NoteHeader
}
context::{PublicContext, Context}, protocol_types::abis::call_context::CallContext,
note::utils as note_utils
};
use dep::value_note::value_note::{ValueNote, VALUE_NOTE_LEN};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// A contract used along with `Parent` contract to test nested calls.
contract Delegator {
use dep::std::option::Option;

use dep::aztec::{
log::emit_unencrypted_log, state_vars::{PublicMutable, PrivateSet},
protocol_types::{abis::{function_selector::FunctionSelector}, address::AztecAddress},
note::{note_viewer_options::NoteViewerOptions, utils as note_utils, note_header::NoteHeader}
use dep::aztec::prelude::{
AztecAddress, FunctionSelector, NoteHeader, NoteViewerOptions, emit_unencrypted_log,
PublicMutable, PrivateSet
};

use dep::aztec::note::utils as note_utils;
use dep::value_note::value_note::{ValueNote, VALUE_NOTE_LEN};

struct Storage {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ mod types;

contract DocsExample {
// how to import dependencies defined in your workspace
use dep::aztec::protocol_types::{abis::function_selector::FunctionSelector, address::AztecAddress};
use dep::aztec::prelude::{
AztecAddress, FunctionSelector, NoteHeader, NoteGetterOptions, PrivateContext, Map,
PublicMutable, PublicImmutable, PrivateMutable, PrivateImmutable, PrivateSet, SharedImmutable
};
use dep::aztec::{
note::{
note_header::NoteHeader, note_getter_options::{NoteGetterOptions, Comparator},
note_viewer_options::{NoteViewerOptions}, utils as note_utils
},
context::{PrivateContext, PublicContext, Context},
state_vars::{Map, PublicMutable, PublicImmutable, PrivateMutable, PrivateImmutable, PrivateSet, SharedImmutable}
note::{note_getter_options::Comparator, note_viewer_options::NoteViewerOptions, utils as note_utils},
context::{PublicContext, Context}
};
// how to import methods from other files/folders within your workspace
use crate::options::create_account_card_getter_options;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::types::card_note::{CardNote, CARD_NOTE_LEN};
use dep::aztec::protocol_types::{address::AztecAddress, constants::MAX_NOTE_HASH_READ_REQUESTS_PER_CALL};
use dep::aztec::note::note_getter_options::{NoteGetterOptions, Sort, SortOrder};
use dep::std::option::Option;
use dep::aztec::prelude::{AztecAddress, NoteGetterOptions};

use dep::aztec::protocol_types::constants::MAX_NOTE_HASH_READ_REQUESTS_PER_CALL;
use dep::aztec::note::note_getter_options::{Sort, SortOrder};

// Shows how to use NoteGetterOptions and query for notes.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use dep::aztec::prelude::{AztecAddress, NoteInterface, NoteHeader, PrivateContext, emit_encrypted_log};
use dep::aztec::{
note::{note_header::NoteHeader, note_interface::NoteInterface, utils::compute_note_hash_for_consumption},
note::{utils::compute_note_hash_for_consumption},
oracle::{nullifier_key::get_nullifier_secret_key, get_public_key::get_public_key},
log::emit_encrypted_log, hash::pedersen_hash, context::PrivateContext,
protocol_types::{address::AztecAddress, traits::Empty}
hash::pedersen_hash, protocol_types::traits::Empty
};

// Shows how to create a custom note
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// docs:start:easy_private_token_contract
contract EasyPrivateToken {
use dep::aztec::protocol_types::address::AztecAddress;
use dep::aztec::{note::{note_header::NoteHeader, utils as note_utils}, state_vars::Map};
use dep::aztec::prelude::{AztecAddress, NoteHeader, Map};
use dep::aztec::note::utils as note_utils;
use dep::value_note::{balance_utils, value_note::ValueNote};
use dep::easy_private_state::EasyPrivateUint;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
contract EasyPrivateVoting {
// docs:start:imports
use dep::aztec::{
protocol_types::{abis::function_selector::FunctionSelector, address::AztecAddress},
context::{PrivateContext, Context}, state_vars::{Map, PublicMutable}
use dep::aztec::prelude::{
AztecAddress, FunctionSelector, NoteHeader, NoteInterface, NoteGetterOptions, PrivateContext,
Map, PublicMutable
};
use dep::aztec::context::Context;
// docs:end:imports
// docs:start:storage_struct
struct Storage {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
use dep::aztec::protocol_types::address::AztecAddress;
use dep::aztec::prelude::{
AztecAddress, FunctionSelector, NoteHeader, NoteInterface, NoteGetterOptions, PrivateContext,
emit_encrypted_log
};

use dep::aztec::{
note::{note_header::NoteHeader, note_interface::NoteInterface, utils::compute_note_hash_for_consumption},
note::utils::compute_note_hash_for_consumption,
oracle::{nullifier_key::get_nullifier_secret_key, get_public_key::get_public_key},
log::emit_encrypted_log, hash::pedersen_hash, context::PrivateContext
hash::pedersen_hash
};

global ECDSA_PUBLIC_KEY_NOTE_LEN: Field = 5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ mod ecdsa_public_key_note;
// Account contract that uses ECDSA signatures for authentication on the same curve as Ethereum.
// The signing key is stored in an immutable private note and should be different from the signing key.
contract EcdsaAccount {
use dep::aztec::protocol_types::{abis::{call_context::CallContext, function_selector::FunctionSelector}, address::AztecAddress};
use dep::aztec::prelude::{AztecAddress, FunctionSelector, NoteHeader, NoteGetterOptions, PrivateContext, PrivateImmutable};

use dep::aztec::protocol_types::abis::call_context::CallContext;
use dep::std;
use dep::std::option::Option;
use dep::aztec::{
context::{PrivateContext, PublicContext, Context},
note::{note_header::NoteHeader, utils as note_utils}, oracle::get_public_key::get_public_key,
state_vars::PrivateImmutable
};

use dep::aztec::{context::{PublicContext, Context}, note::utils as note_utils, oracle::get_public_key::get_public_key};
use dep::authwit::{
entrypoint::{app::AppPayload, fee::FeePayload}, account::AccountActions,
auth_witness::get_auth_witness
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
// Sample escrow contract that stores a balance of a private token on behalf of an owner.
contract Escrow {
use dep::std::option::Option;
use dep::aztec::prelude::{AztecAddress, EthAddress, FunctionSelector, NoteHeader, NoteGetterOptions, PrivateContext, PrivateSet};

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

use dep::aztec::{
context::{PrivateContext, PublicContext, Context},
note::{note_getter_options::NoteGetterOptions, note_header::NoteHeader, utils as note_utils},
oracle::get_public_key::get_public_key, state_vars::PrivateSet
};
use dep::aztec::{context::{PublicContext, Context}, note::{utils as note_utils}, oracle::get_public_key::get_public_key};

use dep::address_note::address_note::{AddressNote, ADDRESS_NOTE_LEN};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use dep::aztec::context::{PrivateContext, PublicContext};
use dep::aztec::prelude::{AztecAddress, EthAddress, FunctionSelector, PrivateContext};
use dep::aztec::context::PublicContext;

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

struct Token {
address: AztecAddress,
Expand Down
Loading
Loading