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 all 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
5 changes: 1 addition & 4 deletions boxes/react/src/contracts/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
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::value_note::value_note::{ValueNote, VALUE_NOTE_LEN};

Expand Down
5 changes: 1 addition & 4 deletions boxes/vanilla-js/src/contracts/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
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::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
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ use dep::protocol_types::{
grumpkin_private_key::GrumpkinPrivateKey, hash::hash_args, header::Header,
messaging::l2_to_l1_message::L2ToL1Message, utils::reader::Reader, traits::is_empty
};
use dep::std::option::Option;

// TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)
// use dep::std::collections::vec::Vec;
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;
7 changes: 1 addition & 6 deletions noir-projects/aztec-nr/aztec/src/note/note_getter.nr
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use dep::std::option::Option;
use dep::protocol_types::{
constants::{
MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, GET_NOTE_ORACLE_RETURN_LENGTH, GET_NOTES_ORACLE_RETURN_LENGTH,
Expand All @@ -13,11 +12,7 @@ use crate::note::{
};
use crate::oracle;

fn check_note_header<Note, N>(
context: PrivateContext,
storage_slot: Field,
note: Note
) where Note: NoteInterface<N> {
fn check_note_header<Note, N>(context: PrivateContext, storage_slot: Field, note: Note) where Note: NoteInterface<N> {
let header = note.get_header();
let contract_address = context.this_address();
assert(header.contract_address.eq(contract_address));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use dep::std::option::Option;
use dep::protocol_types::{constants::MAX_NOTE_HASH_READ_REQUESTS_PER_CALL};
use crate::note::note_interface::NoteInterface;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use dep::std::option::Option;
use crate::note::note_getter_options::{Select, Sort, Comparator, NoteStatus};
use dep::protocol_types::{constants::MAX_NOTES_PER_PAGE};
use crate::note::note_interface::NoteInterface;
Expand Down
1 change: 0 additions & 1 deletion noir-projects/aztec-nr/aztec/src/oracle/notes.nr
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use dep::std::option::Option;
use crate::note::{note_header::NoteHeader, note_interface::NoteInterface};

use dep::protocol_types::{address::AztecAddress, utils::arr_copy_slice};
Expand Down
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
}
};
1 change: 0 additions & 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,4 @@
use crate::context::{PrivateContext, PublicContext, Context};
use dep::std::option::Option;
use dep::protocol_types::{hash::pedersen_hash, traits::{ToField}};
use crate::state_vars::storage::Storage;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use dep::std::option::Option;
use dep::protocol_types::{address::AztecAddress, constants::{GENERATOR_INDEX__INITIALIZATION_NULLIFIER}, hash::pedersen_hash};

use crate::context::{PrivateContext, Context};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use dep::std::option::Option;

use dep::protocol_types::{address::AztecAddress, constants::{GENERATOR_INDEX__INITIALIZATION_NULLIFIER}, hash::pedersen_hash};

use crate::context::{PrivateContext, PublicContext, Context};
Expand Down
1 change: 0 additions & 1 deletion noir-projects/aztec-nr/aztec/src/state_vars/private_set.nr
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use dep::std::option::Option;
use dep::protocol_types::{
constants::{MAX_NOTES_PER_PAGE, MAX_NOTE_HASH_READ_REQUESTS_PER_CALL},
abis::side_effect::{SideEffect, SideEffectLinkedToNoteHash}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::context::{Context};
use crate::oracle::storage::storage_read;
use crate::oracle::storage::storage_write;
use dep::std::option::Option;
use dep::protocol_types::traits::{Deserialize, Serialize};
use crate::state_vars::storage::Storage;

Expand Down
1 change: 0 additions & 1 deletion noir-projects/aztec-nr/value-note/src/filter.nr
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use dep::std::option::Option;
use dep::aztec::protocol_types::constants::MAX_NOTE_HASH_READ_REQUESTS_PER_CALL;
use crate::value_note::ValueNote;

Expand Down
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 @@ -3,16 +3,14 @@ mod dapp_payload;

contract AppSubscription {
use dep::std;
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, 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}};

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
Expand Up @@ -5,10 +5,9 @@ contract CardGame {
use dep::aztec::protocol_types::{abis::function_selector::FunctionSelector, address::AztecAddress, constants::MAX_NOTES_PER_PAGE};
use dep::aztec::{context::Context, hash::pedersen_hash, state_vars::{Map, PublicMutable}};

use dep::std::option::Option;
use dep::value_note::{balance_utils, value_note::{ValueNote, VALUE_NOTE_LEN}};

use dep::aztec::note::{note_header::NoteHeader, utils as note_utils};
use dep::aztec::note::note_header::NoteHeader;

use crate::cards::{PACK_CARDS, Deck, Card, get_pack_cards, compute_deck_strength};
use crate::game::{NUMBER_OF_PLAYERS, NUMBER_OF_CARDS_DECK, PLAYABLE_CARDS, PlayerEntry, Game, GAME_SERIALIZED_LEN};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// 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},
note::{note_getter_options::NoteGetterOptions, note_header::NoteHeader, utils as note_utils}
context::{PublicContext, Context}, protocol_types::{abis::{call_context::CallContext}},
note::{note_getter_options::NoteGetterOptions, note_header::NoteHeader}
};
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,7 +1,6 @@
mod events;

contract ContractInstanceDeployer {
use dep::std::option::Option;
use dep::aztec::protocol_types::{
address::{AztecAddress, EthAddress, PublicKeysHash, PartialAddress},
contract_class_id::ContractClassId,
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;
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,16 +1,11 @@
// A contract used along with `Parent` contract to test nested calls.
contract DelegatedOn {
use dep::std::option::Option;

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
}
use dep::aztec::prelude::{
AztecAddress, FunctionSelector, NoteHeader, NoteGetterOptions, NoteViewerOptions,
emit_unencrypted_log, PublicMutable, PrivateSet, PrivateContext
};

use dep::aztec::{context::{PublicContext, Context}, protocol_types::abis::call_context::CallContext};
use dep::value_note::value_note::{ValueNote, VALUE_NOTE_LEN};

struct Storage {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// 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::value_note::value_note::{ValueNote, VALUE_NOTE_LEN};

struct Storage {
Expand Down Expand Up @@ -66,6 +64,6 @@ contract Delegator {
serialized_note: [Field; VALUE_NOTE_LEN]
) -> pub [Field; 4] {
let note_header = NoteHeader::new(contract_address, nonce, storage_slot);
note_utils::compute_note_hash_and_nullifier(ValueNote::deserialize_content, note_header, serialized_note)
dep::aztec::note::utils::compute_note_hash_and_nullifier(ValueNote::deserialize_content, note_header, serialized_note)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,12 @@ 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::{
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}
use dep::aztec::prelude::{
AztecAddress, FunctionSelector, NoteHeader, NoteGetterOptions, NoteViewerOptions,
PrivateContext, Map, PublicMutable, PublicImmutable, PrivateMutable, PrivateImmutable,
PrivateSet, SharedImmutable
};
use dep::aztec::{note::note_getter_options::Comparator, context::{PublicContext, Context}};
// how to import methods from other files/folders within your workspace
use crate::options::create_account_card_getter_options;
use crate::types::{card_note::{CardNote, CARD_NOTE_LEN}, leader::Leader};
Expand Down
Loading
Loading