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

BENCHMARK_CAPTURE(bench_round_ultra, preparation, [](auto& prover) { prover.preparation_round(); })
-> DenseRange(14, 20) -> Unit(kMillisecond);
BENCHMARK_CAPTURE(bench_round_ultra, perturbator, [](auto& prover) { prover.perturbator_round(); })
-> DenseRange(14, 20) -> Unit(kMillisecond);
BENCHMARK_CAPTURE(bench_round_ultra, combiner_quotient, [](auto& prover) { prover.combiner_quotient_round(); })
-> DenseRange(14, 20) -> Unit(kMillisecond);
BENCHMARK_CAPTURE(bench_round_ultra, accumulator_update, [](auto& prover) { prover.accumulator_update_round(); })
-> DenseRange(14, 20) -> Unit(kMillisecond);

BENCHMARK_CAPTURE(bench_round_goblin_ultra, preparation, [](auto& prover) { prover.preparation_round(); })
-> DenseRange(14, 20) -> Unit(kMillisecond);
BENCHMARK_CAPTURE(bench_round_goblin_ultra, perturbator, [](auto& prover) { prover.perturbator_round(); })
-> DenseRange(14, 20) -> Unit(kMillisecond);
BENCHMARK_CAPTURE(bench_round_goblin_ultra, combiner_quotient, [](auto& prover) { prover.combiner_quotient_round(); })
-> DenseRange(14, 20) -> Unit(kMillisecond);
BENCHMARK_CAPTURE(bench_round_goblin_ultra, accumulator_update, [](auto& prover) { prover.accumulator_update_round(); })
-> DenseRange(14, 20) -> Unit(kMillisecond);
BENCHMARK_CAPTURE(bench_round_ultra, preparation, [](auto& prover) {
prover.preparation_round();
}) -> DenseRange(14, 20) -> Unit(kMillisecond);
BENCHMARK_CAPTURE(bench_round_ultra, perturbator, [](auto& prover) {
prover.perturbator_round();
}) -> DenseRange(14, 20) -> Unit(kMillisecond);
BENCHMARK_CAPTURE(bench_round_ultra, combiner_quotient, [](auto& prover) {
prover.combiner_quotient_round();
}) -> DenseRange(14, 20) -> Unit(kMillisecond);
BENCHMARK_CAPTURE(bench_round_ultra, accumulator_update, [](auto& prover) {
prover.accumulator_update_round();
}) -> DenseRange(14, 20) -> Unit(kMillisecond);

BENCHMARK_CAPTURE(bench_round_goblin_ultra, preparation, [](auto& prover) {
prover.preparation_round();
}) -> DenseRange(14, 20) -> Unit(kMillisecond);
BENCHMARK_CAPTURE(bench_round_goblin_ultra, perturbator, [](auto& prover) {
prover.perturbator_round();
}) -> DenseRange(14, 20) -> Unit(kMillisecond);
BENCHMARK_CAPTURE(bench_round_goblin_ultra, combiner_quotient, [](auto& prover) {
prover.combiner_quotient_round();
}) -> DenseRange(14, 20) -> Unit(kMillisecond);
BENCHMARK_CAPTURE(bench_round_goblin_ultra, accumulator_update, [](auto& prover) {
prover.accumulator_update_round();
}) -> DenseRange(14, 20) -> Unit(kMillisecond);

} // namespace bb

Expand Down
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 @@ -476,19 +499,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
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(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gonna be the annoying guy and ask that you add these changes in the migration_notes.md

}
}

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() }
}
}
Loading
Loading