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

refactor: unify Zero / Empty to Default + refactor away from std::unsafe::zeroed() #5496

Closed
wants to merge 60 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
45d39ab
initial
Mar 27, 2024
ae232cf
fix
Mar 28, 2024
95d2e36
fix
Mar 28, 2024
eef1ae4
Merge branch 'master' into ek/refactor/unify-zero-empty-to-default
Mar 28, 2024
94b50b8
fix build/test
Mar 28, 2024
0fe0c4b
fix
Mar 28, 2024
7d1d27d
fix
Mar 28, 2024
d6c67b6
fix
Mar 28, 2024
a3cd011
fix
Mar 28, 2024
0694acf
Merge branch 'master' into ek/refactor/unify-zero-empty-to-default
sklppy88 Mar 29, 2024
d5426e4
fix
Mar 29, 2024
8472c05
fix
Mar 29, 2024
9d23400
Merge branch 'master' into ek/refactor/unify-zero-empty-to-default
sklppy88 Mar 30, 2024
4ef2fcf
Fix
Mar 30, 2024
9f808e1
isdef ts
Mar 30, 2024
56009a0
fix
Mar 31, 2024
26e225a
Fix
Mar 31, 2024
ab830b4
Merge branch 'master' into ek/refactor/unify-zero-empty-to-default
sklppy88 Mar 31, 2024
97b9180
comment
Apr 1, 2024
dc0d26c
comment
Apr 1, 2024
512249c
comment
Apr 1, 2024
f6cdaa2
fix
Apr 1, 2024
6e536a7
edit
Apr 1, 2024
d738876
fix
Apr 1, 2024
933c73e
fixes
Apr 1, 2024
c9847c1
fixes
Apr 1, 2024
6669380
fix
Apr 1, 2024
34aa68d
Merge branch 'master' into ek/refactor/unify-zero-empty-to-default
Apr 5, 2024
b423c9a
fix
Apr 5, 2024
6e81f94
fix
Apr 5, 2024
1c433ed
fix
Apr 5, 2024
e2b1b53
address comments
Apr 5, 2024
1498c8b
fix
Apr 5, 2024
308b537
fix
Apr 5, 2024
1df2000
fix
Apr 5, 2024
af3a62e
fix msg
Apr 5, 2024
428621a
fix
Apr 5, 2024
57fbcbf
sync
Apr 5, 2024
626ba6a
sync
Apr 5, 2024
bcd67b3
align
Apr 5, 2024
6fd559f
fix
Apr 5, 2024
ac8e980
fix
Apr 5, 2024
5ea8eec
fix
Apr 5, 2024
2657a82
fix
Apr 5, 2024
b668055
fix
Apr 5, 2024
dad29c9
fix
Apr 5, 2024
7ba3c1c
fix
Apr 5, 2024
f1a1ef3
fix
Apr 5, 2024
3aedba2
fix
Apr 5, 2024
b78f9fd
address comments
Apr 5, 2024
34bb1b5
fix
Apr 6, 2024
a7a9bf8
noir
Apr 8, 2024
481d851
Merge branch 'master' into ek/refactor/unify-zero-empty-to-default
Apr 8, 2024
92d2f1f
fix
Apr 8, 2024
4aa05a6
yarn format
Apr 9, 2024
260b286
Merge branch 'master' into ek/refactor/unify-zero-empty-to-default
sklppy88 Apr 9, 2024
d07cd6a
l1 contracts ci
Apr 9, 2024
357490f
Merge branch 'master' into ek/refactor/unify-zero-empty-to-default
sklppy88 Apr 9, 2024
635f899
asdf
Apr 9, 2024
f8fdd28
Merge branch 'master' into ek/refactor/unify-zero-empty-to-default
Apr 10, 2024
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
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_default}};

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_default(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_default}};
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_default(call.target_address) {
if call.is_public {
context.call_public_function_with_packed_args(
call.target_address,
Expand Down
6 changes: 3 additions & 3 deletions noir-projects/aztec-nr/aztec/src/context/avm_context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ impl PublicContextInterface for AvmContext {

fn coinbase(self) -> EthAddress {
assert(false, "'coinbase' not implemented!");
EthAddress::zero()
EthAddress::default()
}

fn fee_recipient(self) -> AztecAddress {
assert(false, "'fee_recipient' not implemented!");
AztecAddress::zero()
AztecAddress::default()
}

fn push_nullifier_read_request(&mut self, nullifier: Field) {
Expand Down Expand Up @@ -196,7 +196,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
22 changes: 11 additions & 11 deletions noir-projects/aztec-nr/aztec/src/context/private_context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use dep::protocol_types::{
},
contrakt::{storage_read::StorageRead, storage_update_request::StorageUpdateRequest},
grumpkin_private_key::GrumpkinPrivateKey, hash::hash_args_array, 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_default
};

// TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)
Expand Down Expand Up @@ -121,7 +121,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_default(inputs.call_context.msg_sender) {
min_revertible_side_effect_counter = side_effect_counter;
}
PrivateContext {
Expand Down Expand Up @@ -460,20 +460,20 @@ 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(),
prover_address: AztecAddress::zero(),
historical_header: Header::default(),
prover_address: AztecAddress::default(),
revert_code: 0
},
is_execution_request: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ 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::default() // 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_default};

// 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_default(instance.deployer);
if !universal_deploy {
assert(
instance.deployer == context.this_address(), "Deployer address does not match current address"
Expand Down
6 changes: 2 additions & 4 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::{
hash::{silo_nullifier, pedersen_hash}, constants::GENERATOR_INDEX__CONSTRUCTOR,
abis::function_selector::FunctionSelector
abis::function_selector::FunctionSelector, traits::is_default,
};

use crate::{
Expand Down Expand Up @@ -36,9 +36,7 @@ pub fn assert_initialization_matches_address_preimage<TContext>(context: TContex
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_default(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
9 changes: 5 additions & 4 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,9 +11,9 @@ struct NoteHeader {
is_transient: bool,
}

impl Empty for NoteHeader {
fn empty() -> Self {
NoteHeader { contract_address: AztecAddress::zero(), nonce: 0, storage_slot: 0, is_transient: false }
impl Default for NoteHeader {
fn default() -> Self {
NoteHeader { contract_address: AztecAddress::default(), 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() }
}
}

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_default}};
use crate::cards::Card;

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ contract ContractInstanceDeployer {
// TODO(@spalladino): assert nullifier_exists silo(contract_class_id, ContractClassRegisterer)

let deployer = if universal_deploy {
AztecAddress::zero()
AztecAddress::default()
} else {
context.msg_sender()
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct CardNote {

impl CardNote {
pub fn new(points: u8, randomness: Field, owner: AztecAddress) -> Self {
CardNote { points, randomness, owner, header: NoteHeader::empty() }
CardNote { points, randomness, owner, header: Noteheader::default() }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl NoteInterface<ECDSA_PUBLIC_KEY_NOTE_LEN> for EcdsaPublicKeyNote {
}
y[31] = serialized_note[3].to_be_bytes(32)[31];

EcdsaPublicKeyNote { x, y, owner: AztecAddress::from_field(serialized_note[4]), header: NoteHeader::empty() }
EcdsaPublicKeyNote { x, y, owner: AztecAddress::from_field(serialized_note[4]), header: Noteheader::default() }
}

fn compute_nullifier(self, context: &mut PrivateContext) -> Field {
Expand Down Expand Up @@ -104,6 +104,6 @@ impl NoteInterface<ECDSA_PUBLIC_KEY_NOTE_LEN> for EcdsaPublicKeyNote {

impl EcdsaPublicKeyNote {
pub fn new(x: [u8; 32], y: [u8; 32], owner: AztecAddress) -> Self {
EcdsaPublicKeyNote { x, y, owner, header: NoteHeader::empty() }
EcdsaPublicKeyNote { x, y, owner, header: Noteheader::default() }
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod interfaces;

contract FPC {
use dep::aztec::protocol_types::{abis::function_selector::FunctionSelector, address::AztecAddress, traits::is_empty};
use dep::aztec::protocol_types::{abis::function_selector::FunctionSelector, address::AztecAddress};
use dep::aztec::state_vars::SharedImmutable;

use crate::interfaces::Token;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ impl NoteInterface<PUBLIC_KEY_NOTE_LEN> for PublicKeyNote {

impl PublicKeyNote {
pub fn new(x: Field, y: Field, owner: AztecAddress) -> Self {
PublicKeyNote { x, y, owner, header: NoteHeader::empty() }
PublicKeyNote { x, y, owner, header: Noteheader::default() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod interfaces;
contract TokenBlacklist {
// Libs

use dep::aztec::protocol_types::{abis::function_selector::FunctionSelector, address::AztecAddress};
use dep::aztec::protocol_types::{abis::function_selector::FunctionSelector, address::AztecAddress, traits::is_default};
use dep::aztec::{
note::{note_getter_options::NoteGetterOptions, note_header::NoteHeader},
hash::compute_secret_hash, state_vars::{Map, PublicMutable, PrivateSet, SharedImmutable}
Expand Down Expand Up @@ -44,7 +44,7 @@ contract TokenBlacklist {
#[aztec(initializer)]
fn constructor(admin: AztecAddress, slow_updates_contract: AztecAddress) {
// docs:end:constructor
assert(!admin.is_zero(), "invalid admin");
assert(!is_default(admin), "invalid admin");
storage.admin.write(admin);
// docs:start:write_slow_update_public
storage.slow_update.initialize(slow_updates_contract);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl OwnedNote for TokenNote {
amount,
owner,
randomness: unsafe_rand(),
header: NoteHeader::empty(),
header: Noteheader::default(),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl NoteInterface<TRANSPARENT_NOTE_LEN> for TransparentNote {
amount: serialized_note[0],
secret_hash: serialized_note[1],
secret: 0,
header: NoteHeader::empty(),
header: Noteheader::default(),
}
}

Expand All @@ -59,13 +59,13 @@ impl TransparentNote {
// CONSTRUCTORS

pub fn new(amount: Field, secret_hash: Field) -> Self {
TransparentNote { amount, secret_hash, secret: 0, header: NoteHeader::empty() }
TransparentNote { amount, secret_hash, secret: 0, header: Noteheader::default() }
}

// new oracle call primitive
// get me the secret corresponding to this hash
pub fn new_from_secret(amount: Field, secret: Field) -> Self {
TransparentNote { amount, secret_hash: compute_secret_hash(secret), secret, header: NoteHeader::empty() }
TransparentNote { amount, secret_hash: compute_secret_hash(secret), secret, header: Noteheader::default() }
}

// CUSTOM FUNCTIONS FOR THIS NOTE TYPE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ contract Token {

use dep::compressed_string::FieldCompressedString;

use dep::aztec::prelude::{
NoteGetterOptions, NoteHeader, Map, PublicMutable, SharedImmutable, PrivateSet,
FunctionSelector, AztecAddress
use dep::aztec::{
prelude::{
NoteGetterOptions, NoteHeader, Map, PublicMutable, SharedImmutable, PrivateSet,
FunctionSelector, AztecAddress
},
hash::compute_secret_hash, protocol_types::traits::is_default
};
use dep::aztec::hash::compute_secret_hash;

// docs:start:import_authwit
use dep::authwit::{auth::{assert_current_call_valid_authwit, assert_current_call_valid_authwit_public}};
Expand Down Expand Up @@ -55,7 +57,7 @@ contract Token {
#[aztec(public)]
#[aztec(initializer)]
fn constructor(admin: AztecAddress, name: str<31>, symbol: str<31>, decimals: u8) {
assert(!admin.is_zero(), "invalid admin");
assert(!is_default(admin), "invalid admin");
storage.admin.write(admin);
storage.minters.at(admin).write(true);
storage.name.initialize(FieldCompressedString::from_string(name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl OwnedNote for TokenNote {
amount,
owner,
randomness: unsafe_rand(),
header: NoteHeader::empty(),
header: Noteheader::default(),
}
}

Expand Down
Loading
Loading