Skip to content

Commit

Permalink
Merge 357490f into ee23415
Browse files Browse the repository at this point in the history
  • Loading branch information
sklppy88 authored Apr 9, 2024
2 parents ee23415 + 357490f commit a8308cd
Show file tree
Hide file tree
Showing 258 changed files with 1,770 additions and 1,330 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class TokenContract extends ContractBase {
* Creates a tx to deploy a new instance of this contract.
*/
public static deploy(pxe: PXE, admin: AztecAddressLike) {
return new DeployMethod<TokenContract>(Point.ZERO, pxe, TokenContractArtifact, Array.from(arguments).slice(1));
return new DeployMethod<TokenContract>(Point.default(), pxe, TokenContractArtifact, Array.from(arguments).slice(1));
}

/**
Expand Down
12 changes: 12 additions & 0 deletions docs/docs/misc/migration_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ It is not possible to call `simulate` on any call to get the return values!
However, beware that it currently always returns a Field array of size 4 for private and public.
This will change to become similar to the return values of the `unconstrained` functions with proper return types.

### [Aztec.nr] [Aztec.js] IsEmpty / IsZero have been unified and renamed to IsDefault

N.B: Fields and Addresses have not been changed

```diff
- Point.ZERO;
+ Point.default();

- Header::empty();
+ Header::default();
```

```diff
- #[aztec(private)]
- fn get_shared_immutable_constrained_private() -> pub Leader {
Expand Down
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/address-note/src/address_note.nr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use dep::aztec::log::emit_encrypted_log;
// docs:end:encrypted_import
use dep::aztec::{
protocol_types::{address::AztecAddress, traits::Empty},
protocol_types::address::AztecAddress,
note::{note_header::NoteHeader, note_interface::NoteInterface, utils::compute_note_hash_for_consumption},
oracle::{unsafe_rand::unsafe_rand, nullifier_key::get_nullifier_secret_key, get_public_key::get_public_key},
hash::pedersen_hash, context::PrivateContext
Expand Down Expand Up @@ -62,7 +62,7 @@ impl NoteInterface<ADDRESS_NOTE_LEN> for AddressNote {
impl AddressNote {
pub fn new(address: AztecAddress, owner: AztecAddress) -> Self {
let randomness = unsafe_rand();
AddressNote { address, owner, randomness, header: NoteHeader::empty() }
AddressNote { address, owner, randomness, header: NoteHeader::default() }
}
// docs:end:address_note_def
}
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/authwit/src/entrypoint/app.nr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use dep::aztec::prelude::PrivateContext;
use dep::aztec::protocol_types::{constants::GENERATOR_INDEX__SIGNATURE_PAYLOAD, hash::pedersen_hash, traits::{Hash, Serialize}};
use dep::aztec::protocol_types::{constants::GENERATOR_INDEX__SIGNATURE_PAYLOAD, hash::pedersen_hash, traits::{Hash, Serialize, is_zero}};

use crate::entrypoint::function_call::{FunctionCall, FUNCTION_CALL_SIZE_IN_BYTES};

Expand Down Expand Up @@ -56,7 +56,7 @@ impl AppPayload {
// docs:start:entrypoint-execute-calls
fn execute_calls(self, context: &mut PrivateContext) {
for call in self.function_calls {
if !call.target_address.is_zero() {
if !is_zero(call.target_address) {
if call.is_public {
context.call_public_function_with_packed_args(
call.target_address,
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,5 +1,5 @@
use dep::aztec::prelude::PrivateContext;
use dep::aztec::protocol_types::{constants::GENERATOR_INDEX__FEE_PAYLOAD, hash::pedersen_hash, traits::{Hash, Serialize}};
use dep::aztec::protocol_types::{constants::GENERATOR_INDEX__FEE_PAYLOAD, hash::pedersen_hash, traits::{Hash, Serialize, is_zero}};
use crate::entrypoint::function_call::FunctionCall;

// 2 * 4 (function call) + 1
Expand Down Expand Up @@ -52,7 +52,7 @@ impl FeePayload {

fn execute_calls(self, context: &mut PrivateContext) {
for call in self.function_calls {
if !call.target_address.is_zero() {
if !is_zero(call.target_address) {
if call.is_public {
context.call_public_function_with_packed_args(
call.target_address,
Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/context/avm_context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ impl ContextInterface for AvmContext {
}
fn get_header(self) -> Header {
assert(false, "'get_header' not implemented!");
Header::empty()
Header::default()
}
fn get_args_hash(self) -> Field {
self.inputs.args_hash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ struct PrivateGlobalVariables {
}
// docs:end:private-global-variables

impl Default for PrivateGlobalVariables {
fn default() -> Self {
PrivateGlobalVariables {
chain_id: 0,
version: 0,
}
}
}

// Note: public global vars are equal to the private ones
impl Serialize<PRIVATE_GLOBAL_VARIABLES_LENGTH> for PrivateGlobalVariables {
fn serialize(self) -> [Field; PRIVATE_GLOBAL_VARIABLES_LENGTH] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,14 @@ struct PrivateContextInputs {
start_side_effect_counter: u32,
}
// docs:end:private-context-inputs

impl Default for PrivateContextInputs {
fn default() -> Self {
PrivateContextInputs {
call_context : CallContext::default(),
historical_header: Header::default(),
private_global_variables: PrivateGlobalVariables::default(),
start_side_effect_counter: 0 as u32,
}
}
}
43 changes: 33 additions & 10 deletions noir-projects/aztec-nr/aztec/src/context/private_context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use dep::protocol_types::{
},
contrakt::{storage_read::StorageRead, storage_update_request::StorageUpdateRequest},
grumpkin_private_key::GrumpkinPrivateKey, header::Header,
messaging::l2_to_l1_message::L2ToL1Message, utils::reader::Reader, traits::is_empty
messaging::l2_to_l1_message::L2ToL1Message, utils::reader::Reader, traits::is_zero
};

// TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)
Expand Down Expand Up @@ -70,6 +70,29 @@ struct PrivateContext {
nullifier_key: Option<NullifierKeyPair>,
}

impl Default for PrivateContext {
fn default() -> Self {
PrivateContext {
inputs: PrivateContextInputs::default(),
side_effect_counter: 0 as u32,
min_revertible_side_effect_counter: 0 as u32,
args_hash : 0,
return_values : BoundedVec::new(),
max_block_number: MaxBlockNumber::default(),
note_hash_read_requests: BoundedVec::new(),
nullifier_read_requests: BoundedVec::new(),
nullifier_key_validation_requests: BoundedVec::new(),
new_note_hashes: BoundedVec::new(),
new_nullifiers: BoundedVec::new(),
private_call_stack_hashes : BoundedVec::new(),
public_call_stack_hashes : BoundedVec::new(),
new_l2_to_l1_msgs : BoundedVec::new(),
historical_header: Header::default(),
nullifier_key: Option::none(),
}
}
}

impl ContextInterface for PrivateContext {
fn msg_sender(self) -> AztecAddress {
self.inputs.call_context.msg_sender
Expand Down Expand Up @@ -122,7 +145,7 @@ impl PrivateContext {
pub fn new(inputs: PrivateContextInputs, args_hash: Field) -> PrivateContext {
let side_effect_counter = inputs.start_side_effect_counter;
let mut min_revertible_side_effect_counter = 0;
if is_empty(inputs.call_context.msg_sender) {
if is_zero(inputs.call_context.msg_sender) {
min_revertible_side_effect_counter = side_effect_counter;
}
PrivateContext {
Expand Down Expand Up @@ -461,19 +484,19 @@ impl PrivateContext {
call_context: reader.read_struct(CallContext::deserialize),
args_hash: reader.read(),
return_values: [0; RETURN_VALUES_LENGTH],
nullifier_read_requests: [ReadRequest::empty(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL],
nullifier_non_existent_read_requests: [ReadRequest::empty(); MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL],
contract_storage_update_requests: [StorageUpdateRequest::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL],
contract_storage_reads: [StorageRead::empty(); MAX_PUBLIC_DATA_READS_PER_CALL],
nullifier_read_requests: [ReadRequest::default(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL],
nullifier_non_existent_read_requests: [ReadRequest::default(); MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL],
contract_storage_update_requests: [StorageUpdateRequest::default(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL],
contract_storage_reads: [StorageRead::default(); MAX_PUBLIC_DATA_READS_PER_CALL],
public_call_stack_hashes: [0; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL],
new_note_hashes: [SideEffect::empty(); MAX_NEW_NOTE_HASHES_PER_CALL],
new_nullifiers: [SideEffectLinkedToNoteHash::empty(); MAX_NEW_NULLIFIERS_PER_CALL],
new_l2_to_l1_msgs: [L2ToL1Message::empty(); MAX_NEW_L2_TO_L1_MSGS_PER_CALL],
new_note_hashes: [SideEffect::default(); MAX_NEW_NOTE_HASHES_PER_CALL],
new_nullifiers: [SideEffectLinkedToNoteHash::default(); MAX_NEW_NULLIFIERS_PER_CALL],
new_l2_to_l1_msgs: [L2ToL1Message::default(); MAX_NEW_L2_TO_L1_MSGS_PER_CALL],
start_side_effect_counter: 0,
end_side_effect_counter: 0,
unencrypted_logs_hash: 0,
unencrypted_log_preimages_length: 0,
historical_header: Header::empty(),
historical_header: Header::default(),
prover_address: AztecAddress::zero(),
revert_code: 0
},
Expand Down
3 changes: 2 additions & 1 deletion noir-projects/aztec-nr/aztec/src/context/public_context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ impl PublicContext {
unencrypted_logs_hash: 0,
unencrypted_logs_preimages_length: 0,
historical_header: inputs.historical_header,
prover_address: AztecAddress::zero() // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)
prover_address: AztecAddress::zero()
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)
// encrypted_logs_preimages: Vec::new(),
// unencrypted_logs_preimages: Vec::new(),
}
Expand Down
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/aztec/src/deploy.nr
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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, traits::is_zero};

// 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 universal_deploy = instance.deployer.is_zero();
let universal_deploy = is_zero(instance.deployer);
if !universal_deploy {
assert(
instance.deployer == context.this_address(), "Deployer address does not match current address"
Expand Down
8 changes: 3 additions & 5 deletions noir-projects/aztec-nr/aztec/src/initializer.nr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dep::protocol_types::{
address::AztecAddress, hash::{silo_nullifier, pedersen_hash},
constants::GENERATOR_INDEX__CONSTRUCTOR, abis::function_selector::FunctionSelector
constants::GENERATOR_INDEX__CONSTRUCTOR, abis::function_selector::FunctionSelector, traits::is_zero
};

use crate::{
Expand Down Expand Up @@ -65,7 +65,7 @@ pub fn assert_initialization_matches_address_preimage_avm(context: AvmContext) {
let expected_init = compute_initialization_hash(context.selector(), context.get_args_hash());
assert(instance.initialization_hash == expected_init, "Initialization hash does not match");
assert(
(instance.deployer.is_zero()) | (instance.deployer == context.msg_sender()), "Initializer address is not the contract deployer"
is_zero(instance.deployer) | (instance.deployer == context.msg_sender()), "Initializer address is not the contract deployer"
);
}

Expand All @@ -78,9 +78,7 @@ fn assert_initialization_matches_address_preimage<TContext>(context: TContext) w
let instance = get_contract_instance(address);
let expected_init = compute_initialization_hash(context.selector(), context.get_args_hash());
assert(instance.initialization_hash == expected_init, "Initialization hash does not match");
assert(
(instance.deployer.is_zero()) | (instance.deployer == context.msg_sender()), "Initializer address is not the contract deployer"
);
assert(is_zero(instance.deployer) | (instance.deployer == context.msg_sender()), "Initializer address is not the contract deployer");
}

pub fn compute_initialization_hash(init_selector: FunctionSelector, init_args_hash: Field) -> Field {
Expand Down
7 changes: 4 additions & 3 deletions noir-projects/aztec-nr/aztec/src/note/note_header.nr
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use dep::protocol_types::address::AztecAddress;
use dep::protocol_types::traits::{Empty, Serialize};
use dep::protocol_types::traits::Serialize;
use dep::std::default::Default;

struct NoteHeader {
contract_address: AztecAddress,
Expand All @@ -10,8 +11,8 @@ struct NoteHeader {
is_transient: bool,
}

impl Empty for NoteHeader {
fn empty() -> Self {
impl Default for NoteHeader {
fn default() -> Self {
NoteHeader { contract_address: AztecAddress::zero(), nonce: 0, storage_slot: 0, is_transient: false }
}
}
Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/field-note/src/field_note.nr
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl NoteInterface<FIELD_NOTE_LEN> for FieldNote {

impl FieldNote {
pub fn new(value: Field) -> Self {
FieldNote { value, header: NoteHeader::empty() }
FieldNote { value, header: NoteHeader::default() }
}
}

4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/tests/src/mock/test_note.nr
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl NoteInterface<TEST_NOTE_LENGTH> for TestNote {
fn deserialize_content(fields: [Field; TEST_NOTE_LENGTH]) -> Self {
Self {
value: fields[0],
header: NoteHeader::empty(),
header: NoteHeader::default(),
}
}

Expand Down Expand Up @@ -56,6 +56,6 @@ impl NoteInterface<TEST_NOTE_LENGTH> for TestNote {

impl TestNote {
pub fn new(value: Field) -> Self {
TestNote { value, header: NoteHeader::empty() }
TestNote { value, header: NoteHeader::default() }
}
}
14 changes: 7 additions & 7 deletions noir-projects/aztec-nr/tests/src/note_getter_test.nr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::mock::test_note::TestNote;

#[test]
fn sets_note_manually_and_fetches_it() {
let mut context: PrivateContext = dep::std::unsafe::zeroed();
let mut context = PrivateContext::default();
context.inputs.call_context.storage_contract_address = AztecAddress::from_field(69);

let mut test_note = TestNote::new(1337);
Expand All @@ -28,7 +28,7 @@ fn sets_note_manually_and_fetches_it() {

#[test(should_fail)]
fn cannot_return_zero_notes() {
let mut context: PrivateContext = dep::std::unsafe::zeroed();
let mut context = PrivateContext::default();
let storage_slot: Field = 0;
let mut opt_notes: [Option<TestNote>; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL] = [Option::none(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL];

Expand All @@ -38,7 +38,7 @@ fn cannot_return_zero_notes() {

#[test(should_fail)]
fn mismatched_address() {
let mut context: PrivateContext = dep::std::unsafe::zeroed();
let mut context = PrivateContext::default();
context.inputs.call_context.storage_contract_address = AztecAddress::from_field(1);

let storage_slot: Field = 0;
Expand All @@ -51,7 +51,7 @@ fn mismatched_address() {

#[test(should_fail)]
fn mismatched_storage_slot() {
let mut context: PrivateContext = dep::std::unsafe::zeroed();
let mut context = PrivateContext::default();
context.inputs.call_context.storage_contract_address = AztecAddress::from_field(1);

let mut test_note = TestNote::new(1);
Expand All @@ -68,7 +68,7 @@ fn mismatched_storage_slot() {

#[test(should_fail)]
fn invalid_selector() {
let mut context: PrivateContext = dep::std::unsafe::zeroed();
let mut context = PrivateContext::default();
context.inputs.call_context.storage_contract_address = AztecAddress::from_field(1);

let mut test_note = TestNote::new(1);
Expand All @@ -90,7 +90,7 @@ fn invalid_selector() {

#[test(should_fail)]
fn invalid_note_order() {
let mut context: PrivateContext = dep::std::unsafe::zeroed();
let mut context = PrivateContext::default();

let mut opt_notes: [Option<TestNote>; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL] = [Option::none(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL];
opt_notes[0] = Option::some(TestNote::new(1));
Expand All @@ -108,7 +108,7 @@ fn invalid_note_order() {

#[test]
fn sparse_notes_array() {
let mut context: PrivateContext = dep::std::unsafe::zeroed();
let mut context = PrivateContext::default();

let mut opt_notes: [Option<TestNote>; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL] = [Option::none(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL];
opt_notes[1] = Option::some(TestNote::new(0));
Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/value-note/src/value_note.nr
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl NoteInterface<VALUE_NOTE_LEN> for ValueNote {
impl ValueNote {
pub fn new(value: Field, owner: AztecAddress) -> Self {
let randomness = unsafe_rand();
let header = NoteHeader::empty();
let header = NoteHeader::default();
ValueNote { value, owner, randomness, header }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ contract AppSubscription {
SharedImmutable
};

use dep::aztec::protocol_types::traits::is_empty;

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};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ impl NoteInterface<SUBSCRIPTION_NOTE_LEN> for SubscriptionNote {

impl SubscriptionNote {
pub fn new(owner: AztecAddress, expiry_block_number: Field, remaining_txs: Field) -> Self {
SubscriptionNote { owner, expiry_block_number, remaining_txs, header: NoteHeader::empty() }
SubscriptionNote { owner, expiry_block_number, remaining_txs, header: NoteHeader::default() }
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use dep::aztec::protocol_types::{address::AztecAddress, traits::{Serialize, Deserialize}};
use dep::aztec::protocol_types::{address::AztecAddress, traits::{Serialize, Deserialize, is_zero}};
use crate::cards::Card;

global NUMBER_OF_PLAYERS: u64 = 2;
Expand All @@ -12,7 +12,7 @@ struct PlayerEntry {

impl PlayerEntry {
pub fn is_initialized(self) -> bool {
!self.address.is_zero()
!is_zero(self.address)
}
}

Expand Down
Loading

0 comments on commit a8308cd

Please sign in to comment.