Skip to content

Commit

Permalink
refactor: replacing old pub key oracle with get_ivpk_m
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed May 6, 2024
1 parent e85dde9 commit a9aeba3
Show file tree
Hide file tree
Showing 19 changed files with 46 additions and 61 deletions.
7 changes: 4 additions & 3 deletions noir-projects/aztec-nr/address-note/src/address_note.nr
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use dep::aztec::{
keys::getters::get_ivpk_m,
protocol_types::{address::AztecAddress, traits::Empty, constants::GENERATOR_INDEX__NOTE_NULLIFIER},
note::{note_header::NoteHeader, note_interface::NoteInterface, utils::compute_note_hash_for_consumption},
oracle::{unsafe_rand::unsafe_rand, nullifier_key::get_app_nullifier_secret_key, get_public_key::get_public_key},
oracle::{unsafe_rand::unsafe_rand, nullifier_key::get_app_nullifier_secret_key},
context::PrivateContext, hash::poseidon2_hash
};

Expand Down Expand Up @@ -40,13 +41,13 @@ impl NoteInterface<ADDRESS_NOTE_LEN> for AddressNote {

// Broadcasts the note as an encrypted log on L1.
fn broadcast(self, context: &mut PrivateContext, slot: Field) {
let encryption_pub_key = get_public_key(self.owner);
let ivpk_m = get_ivpk_m(context, self.owner);
// docs:start:encrypted
context.emit_encrypted_log(
(*context).this_address(),
slot,
Self::get_note_type_id(),
encryption_pub_key,
ivpk_m,
self.serialize_content(),
);
// docs:end:encrypted
Expand Down
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/aztec/src/context/private_context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ impl PrivateContext {
contract_address: AztecAddress,
storage_slot: Field,
note_type_id: Field,
encryption_pub_key: GrumpkinPoint,
ivpk_m: GrumpkinPoint,
preimage: [Field; N]
) where [Field; N]: LensForEncryptedLog<N, M, L> {
// TODO(1139): perform encryption in the circuit
Expand All @@ -300,7 +300,7 @@ impl PrivateContext {
contract_address,
storage_slot,
note_type_id,
encryption_pub_key,
ivpk_m,
preimage,
self.side_effect_counter
);
Expand Down
1 change: 0 additions & 1 deletion noir-projects/aztec-nr/aztec/src/oracle.nr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ mod get_l1_to_l2_membership_witness;
mod get_nullifier_membership_witness;
mod get_public_data_witness;
mod get_membership_witness;
mod get_public_key;
mod keys;
mod nullifier_key;
mod get_sibling_path;
Expand Down
20 changes: 0 additions & 20 deletions noir-projects/aztec-nr/aztec/src/oracle/get_public_key.nr

This file was deleted.

2 changes: 0 additions & 2 deletions noir-projects/aztec-nr/aztec/src/oracle/keys.nr
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ use dep::protocol_types::{
grumpkin_point::GrumpkinPoint,
};

use crate::hash::poseidon2_hash;

#[oracle(getPublicKeysAndPartialAddress)]
fn get_public_keys_and_partial_address_oracle(_address: AztecAddress) -> [Field; 9] {}

Expand Down
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/aztec/src/oracle/logs.nr
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ unconstrained pub fn emit_encrypted_log<N, M>(
contract_address: AztecAddress,
storage_slot: Field,
note_type_id: Field,
encryption_pub_key: GrumpkinPoint,
ivpk_m: GrumpkinPoint,
preimage: [Field; N],
counter: u32
) -> [Field; M] {
emit_encrypted_log_oracle(
contract_address,
storage_slot,
note_type_id,
encryption_pub_key,
ivpk_m,
preimage,
counter
)
Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/value-note/src/utils.nr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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::keys::getters::get_ivpk_m;
use crate::{filter::filter_notes_min_sum, value_note::{ValueNote, VALUE_NOTE_LEN}};

// Sort the note values (0th field) in descending order.
Expand Down
7 changes: 4 additions & 3 deletions noir-projects/aztec-nr/value-note/src/value_note.nr
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use dep::aztec::{
keys::getters::get_ivpk_m,
protocol_types::{
address::AztecAddress, traits::{Deserialize, Serialize},
constants::GENERATOR_INDEX__NOTE_NULLIFIER
},
note::{note_header::NoteHeader, note_interface::NoteInterface, utils::compute_note_hash_for_consumption},
oracle::{unsafe_rand::unsafe_rand, nullifier_key::get_app_nullifier_secret_key, get_public_key::get_public_key},
oracle::{unsafe_rand::unsafe_rand, nullifier_key::get_app_nullifier_secret_key},
hash::poseidon2_hash, context::PrivateContext
};

Expand Down Expand Up @@ -46,12 +47,12 @@ impl NoteInterface<VALUE_NOTE_LEN> for ValueNote {

// Broadcasts the note as an encrypted log on L1.
fn broadcast(self, context: &mut PrivateContext, slot: Field) {
let encryption_pub_key = get_public_key(self.owner);
let ivpk_m = get_ivpk_m(context, self.owner);
context.emit_encrypted_log(
(*context).this_address(),
slot,
Self::get_note_type_id(),
encryption_pub_key,
ivpk_m,
self.serialize_content(),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ contract AppSubscription {

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

use dep::aztec::{context::Context, oracle::get_public_key::get_public_key};
use dep::aztec::{context::Context, keys::getters::get_ivpk_m};
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,9 @@
use dep::aztec::prelude::{AztecAddress, PrivateContext, NoteHeader, NoteInterface};
use dep::aztec::{
keys::getters::get_ivpk_m,
protocol_types::constants::GENERATOR_INDEX__NOTE_NULLIFIER, note::utils::compute_note_hash_for_consumption,
hash::poseidon2_hash,
oracle::{nullifier_key::get_app_nullifier_secret_key, get_public_key::get_public_key}
oracle::{nullifier_key::get_app_nullifier_secret_key}
};

global SUBSCRIPTION_NOTE_LEN: Field = 3;
Expand Down Expand Up @@ -39,12 +40,12 @@ impl NoteInterface<SUBSCRIPTION_NOTE_LEN> for SubscriptionNote {

// Broadcasts the note as an encrypted log on L1.
fn broadcast(self, context: &mut PrivateContext, slot: Field) {
let encryption_pub_key = get_public_key(self.owner);
let ivpk_m = get_ivpk_m(context, self.owner);
context.emit_encrypted_log(
(*context).this_address(),
slot,
Self::get_note_type_id(),
encryption_pub_key,
ivpk_m,
self.serialize_content(),
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use dep::aztec::prelude::{AztecAddress, NoteInterface, NoteHeader, PrivateContext};
use dep::aztec::{
keys::getters::get_ivpk_m,
note::{utils::compute_note_hash_for_consumption},
oracle::{nullifier_key::get_app_nullifier_secret_key, get_public_key::get_public_key},
oracle::nullifier_key::get_app_nullifier_secret_key,
hash::poseidon2_hash, protocol_types::{traits::Empty, constants::GENERATOR_INDEX__NOTE_NULLIFIER},
};

Expand Down Expand Up @@ -47,12 +48,12 @@ impl NoteInterface<CARD_NOTE_LEN> for CardNote {

// Broadcasts the note as an encrypted log on L1.
fn broadcast(self, context: &mut PrivateContext, slot: Field) {
let encryption_pub_key = get_public_key(self.owner);
let ivpk_m = get_ivpk_m(context, self.owner);
context.emit_encrypted_log(
(*context).this_address(),
slot,
Self::get_note_type_id(),
encryption_pub_key,
ivpk_m,
self.serialize_content(),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use dep::aztec::prelude::{
};

use dep::aztec::{
keys::getters::get_ivpk_m,
note::utils::compute_note_hash_for_consumption,
oracle::{nullifier_key::get_app_nullifier_secret_key, get_public_key::get_public_key},
oracle::nullifier_key::get_app_nullifier_secret_key,
hash::poseidon2_hash, protocol_types::constants::GENERATOR_INDEX__NOTE_NULLIFIER,
};

Expand Down Expand Up @@ -87,12 +88,12 @@ impl NoteInterface<ECDSA_PUBLIC_KEY_NOTE_LEN> for EcdsaPublicKeyNote {

// Broadcasts the note as an encrypted log on L1.
fn broadcast(self, context: &mut PrivateContext, slot: Field) {
let encryption_pub_key = get_public_key(self.owner);
let ivpk_m = get_ivpk_m(context, self.owner);
context.emit_encrypted_log(
(*context).this_address(),
slot,
Self::get_note_type_id(),
encryption_pub_key,
ivpk_m,
self.serialize_content(),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ contract EcdsaAccount {
use dep::aztec::protocol_types::abis::call_context::CallContext;
use dep::std;

use dep::aztec::{context::{PublicContext, Context}, oracle::get_public_key::get_public_key};
use dep::aztec::context::Context;
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
Expand Up @@ -2,7 +2,7 @@
contract Escrow {
use dep::aztec::prelude::{AztecAddress, EthAddress, FunctionSelector, NoteHeader, PrivateContext, PrivateImmutable};

use dep::aztec::{context::{PublicContext, Context}, oracle::get_public_key::get_public_key};
use dep::aztec::context::{PublicContext, Context};

use dep::address_note::address_note::AddressNote;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ contract SchnorrAccount {

use dep::aztec::prelude::{AztecAddress, FunctionSelector, NoteHeader, PrivateContext, PrivateImmutable};
use dep::aztec::state_vars::{Map, PublicMutable};
use dep::aztec::{context::Context, oracle::get_public_key::get_public_key};
use dep::aztec::context::Context;
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,7 +1,8 @@
use dep::aztec::prelude::{AztecAddress, NoteHeader, NoteInterface, PrivateContext};
use dep::aztec::{
keys::getters::get_ivpk_m,
note::utils::compute_note_hash_for_consumption, hash::poseidon2_hash,
oracle::{nullifier_key::get_app_nullifier_secret_key, get_public_key::get_public_key},
oracle::{nullifier_key::get_app_nullifier_secret_key},
protocol_types::constants::GENERATOR_INDEX__NOTE_NULLIFIER,
};

Expand Down Expand Up @@ -39,12 +40,12 @@ impl NoteInterface<PUBLIC_KEY_NOTE_LEN> for PublicKeyNote {

// Broadcasts the note as an encrypted log on L1.
fn broadcast(self, context: &mut PrivateContext, slot: Field) {
let encryption_pub_key = get_public_key(self.owner);
let ivpk_m = get_ivpk_m(context, self.owner);
context.emit_encrypted_log(
(*context).this_address(),
slot,
Self::get_note_type_id(),
encryption_pub_key,
ivpk_m,
self.serialize_content(),
);
}
Expand Down
10 changes: 5 additions & 5 deletions noir-projects/noir-contracts/contracts/test_contract/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ contract Test {
use dep::aztec::state_vars::{shared_mutable::SharedMutablePrivateGetter, map::derive_storage_slot_in_map};

use dep::aztec::{
keys::getters::get_npk_m,
keys::getters::{get_npk_m, get_ivpk_m},
context::{Context, inputs::private_context_inputs::PrivateContextInputs},
hash::{pedersen_hash, poseidon2_hash, compute_secret_hash, ArgsHasher},
hash::{pedersen_hash, compute_secret_hash, ArgsHasher},
note::{
lifecycle::{create_note, destroy_note}, note_getter::{get_notes, view_notes},
note_getter_options::NoteStatus
},
deploy::deploy_contract as aztec_deploy_contract,
oracle::{
encryption::aes128_encrypt, get_public_key::get_public_key as get_public_key_oracle,
encryption::aes128_encrypt,
unsafe_rand::unsafe_rand
}
};
Expand All @@ -49,8 +49,8 @@ contract Test {
}

#[aztec(private)]
fn get_public_key(address: AztecAddress) -> [Field; 2] {
let pub_key = get_public_key_oracle(address);
fn get_master_incoming_viewing_public_key(address: AztecAddress) -> [Field; 2] {
let pub_key = get_ivpk_m(&mut context, address);

[pub_key.x, pub_key.y]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use dep::aztec::{
keys::getters::get_ivpk_m,
prelude::{AztecAddress, NoteHeader, NoteInterface, PrivateContext},
protocol_types::constants::GENERATOR_INDEX__NOTE_NULLIFIER,
note::utils::compute_note_hash_for_consumption, hash::poseidon2_hash,
oracle::{unsafe_rand::unsafe_rand, nullifier_key::get_app_nullifier_secret_key, get_public_key::get_public_key}
oracle::{unsafe_rand::unsafe_rand, nullifier_key::get_app_nullifier_secret_key}
};

trait OwnedNote {
Expand Down Expand Up @@ -52,12 +53,12 @@ impl NoteInterface<TOKEN_NOTE_LEN> for TokenNote {
fn broadcast(self, context: &mut PrivateContext, slot: Field) {
// We only bother inserting the note if non-empty to save funds on gas.
if !(self.amount == U128::from_integer(0)) {
let encryption_pub_key = get_public_key(self.owner);
let ivpk_m = get_ivpk_m(context, self.owner);
context.emit_encrypted_log(
(*context).this_address(),
slot,
Self::get_note_type_id(),
encryption_pub_key,
ivpk_m,
self.serialize_content(),
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use dep::aztec::{
keys::getters::get_ivpk_m,
prelude::{AztecAddress, NoteHeader, NoteInterface, PrivateContext},
protocol_types::constants::GENERATOR_INDEX__NOTE_NULLIFIER,
note::utils::compute_note_hash_for_consumption, hash::poseidon2_hash,
oracle::{unsafe_rand::unsafe_rand, nullifier_key::get_app_nullifier_secret_key, get_public_key::get_public_key}
oracle::{unsafe_rand::unsafe_rand, nullifier_key::get_app_nullifier_secret_key}
};

trait OwnedNote {
Expand Down Expand Up @@ -52,12 +53,12 @@ impl NoteInterface<TOKEN_NOTE_LEN> for TokenNote {
fn broadcast(self, context: &mut PrivateContext, slot: Field) {
// We only bother inserting the note if non-empty to save funds on gas.
if !(self.amount == U128::from_integer(0)) {
let encryption_pub_key = get_public_key(self.owner);
let ivpk_m = get_ivpk_m(context, self.owner);
context.emit_encrypted_log(
(*context).this_address(),
slot,
Self::get_note_type_id(),
encryption_pub_key,
ivpk_m,
self.serialize_content(),
);
}
Expand Down

0 comments on commit a9aeba3

Please sign in to comment.