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

fix: remove unnecessary ivpk's from aztec-nr #9460

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 5 additions & 7 deletions boxes/boxes/react/src/contracts/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use dep::aztec::macros::aztec;
#[aztec]
contract BoxReact {
use dep::aztec::{
protocol_types::public_keys::{IvpkM, OvpkM},
protocol_types::public_keys::OvpkM,
prelude::{AztecAddress, PrivateMutable, Map, NoteInterface, NoteHeader, Point},
encrypted_logs::encrypted_note_emission::encode_and_encrypt_note,
macros::{storage::storage, functions::{private, public, initializer}}
Expand All @@ -21,25 +21,23 @@ contract BoxReact {
number: Field,
owner: AztecAddress,
owner_npk_m_hash: Field,
owner_ovpk_m: OvpkM,
owner_ivpk_m: IvpkM
owner_ovpk_m: OvpkM
) {
let numbers = storage.numbers;
let mut new_number = ValueNote::new(number, owner_npk_m_hash);
numbers.at(owner).initialize(&mut new_number).emit(encode_and_encrypt_note(&mut context, owner_ovpk_m, owner_ivpk_m, owner));
numbers.at(owner).initialize(&mut new_number).emit(encode_and_encrypt_note(&mut context, owner_ovpk_m, owner));
}

#[private]
fn setNumber(
number: Field,
owner: AztecAddress,
owner_npk_m_hash: Field,
owner_ovpk_m: OvpkM,
owner_ivpk_m: IvpkM
owner_ovpk_m: OvpkM
) {
let numbers = storage.numbers;
let mut new_number = ValueNote::new(number, owner_npk_m_hash);
numbers.at(owner).replace(&mut new_number).emit(encode_and_encrypt_note(&mut context, owner_ovpk_m, owner_ivpk_m, owner));
numbers.at(owner).replace(&mut new_number).emit(encode_and_encrypt_note(&mut context, owner_ovpk_m, owner));
}

unconstrained fn getNumber(owner: AztecAddress) -> pub ValueNote {
Expand Down
3 changes: 1 addition & 2 deletions boxes/boxes/react/src/hooks/useContract.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ export function useContract() {
setWait(true);
const wallet = await deployerEnv.getWallet();
const salt = Fr.random();
const { masterNullifierPublicKey, masterIncomingViewingPublicKey, masterOutgoingViewingPublicKey } =
const { masterNullifierPublicKey, masterOutgoingViewingPublicKey } =
wallet.getCompleteAddress().publicKeys;
const tx = await BoxReactContract.deploy(
wallet,
Fr.random(),
wallet.getCompleteAddress().address,
masterNullifierPublicKey.hash(),
masterOutgoingViewingPublicKey.toWrappedNoirStruct(),
masterIncomingViewingPublicKey.toWrappedNoirStruct(),
).send({
contractAddressSalt: salt,
});
Expand Down
3 changes: 1 addition & 2 deletions boxes/boxes/react/src/hooks/useNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function useNumber({ contract }: { contract: Contract }) {

const value = BigInt(el.value);
const deployerWallet = await deployerEnv.getWallet();
const { masterNullifierPublicKey, masterIncomingViewingPublicKey, masterOutgoingViewingPublicKey } =
const { masterNullifierPublicKey, masterOutgoingViewingPublicKey } =
deployerWallet.getCompleteAddress().publicKeys;
await toast.promise(
contract!.methods
Expand All @@ -34,7 +34,6 @@ export function useNumber({ contract }: { contract: Contract }) {
deployerWallet.getCompleteAddress().address,
masterNullifierPublicKey.hash(),
masterOutgoingViewingPublicKey.toWrappedNoirStruct(),
masterIncomingViewingPublicKey.toWrappedNoirStruct(),
)
.send()
.wait(),
Expand Down
8 changes: 3 additions & 5 deletions boxes/boxes/react/tests/node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ describe('BoxReact Contract Tests', () => {
wallet = await deployerEnv.getWallet();
accountCompleteAddress = wallet.getCompleteAddress();
const salt = Fr.random();
const { masterNullifierPublicKey, masterIncomingViewingPublicKey, masterOutgoingViewingPublicKey } =
const { masterNullifierPublicKey, masterOutgoingViewingPublicKey } =
accountCompleteAddress.publicKeys;
contract = await BoxReactContract.deploy(
wallet,
Fr.random(),
accountCompleteAddress.address,
masterNullifierPublicKey.hash(),
masterOutgoingViewingPublicKey.toWrappedNoirStruct(),
masterIncomingViewingPublicKey.toWrappedNoirStruct(),
masterOutgoingViewingPublicKey.toWrappedNoirStruct()
)
.send({ contractAddressSalt: salt })
.deployed();
Expand All @@ -32,15 +31,14 @@ describe('BoxReact Contract Tests', () => {

test('Can set a number', async () => {
logger.info(`${await wallet.getRegisteredAccounts()}`);
const { masterNullifierPublicKey, masterIncomingViewingPublicKey, masterOutgoingViewingPublicKey } =
const { masterNullifierPublicKey, masterOutgoingViewingPublicKey } =
accountCompleteAddress.publicKeys;
await contract.methods
.setNumber(
numberToSet,
accountCompleteAddress.address,
masterNullifierPublicKey.hash(),
masterOutgoingViewingPublicKey.toWrappedNoirStruct(),
masterIncomingViewingPublicKey.toWrappedNoirStruct(),
)
.send()
.wait();
Expand Down
12 changes: 5 additions & 7 deletions boxes/boxes/vanilla/src/contracts/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use dep::aztec::macros::aztec;
#[aztec]
contract Vanilla {
use dep::aztec::{
protocol_types::public_keys::{IvpkM, OvpkM},
protocol_types::public_keys::OvpkM,
prelude::{AztecAddress, PrivateMutable, Map, NoteInterface, NoteHeader, Point},
encrypted_logs::encrypted_note_emission::encode_and_encrypt_note,
macros::{storage::storage, functions::{private, public, initializer}}
Expand All @@ -21,25 +21,23 @@ contract Vanilla {
number: Field,
owner: AztecAddress,
owner_npk_m_hash: Field,
owner_ovpk_m: OvpkM,
owner_ivpk_m: IvpkM
owner_ovpk_m: OvpkM
) {
let numbers = storage.numbers;
let mut new_number = ValueNote::new(number, owner_npk_m_hash);
numbers.at(owner).initialize(&mut new_number).emit(encode_and_encrypt_note(&mut context, owner_ovpk_m, owner_ivpk_m, owner));
numbers.at(owner).initialize(&mut new_number).emit(encode_and_encrypt_note(&mut context, owner_ovpk_m, owner));
}

#[private]
fn setNumber(
number: Field,
owner: AztecAddress,
owner_npk_m_hash: Field,
owner_ovpk_m: OvpkM,
owner_ivpk_m: IvpkM
owner_ovpk_m: OvpkM
) {
let numbers = storage.numbers;
let mut new_number = ValueNote::new(number, owner_npk_m_hash);
numbers.at(owner).replace(&mut new_number).emit(encode_and_encrypt_note(&mut context, owner_ovpk_m, owner_ivpk_m, owner));
numbers.at(owner).replace(&mut new_number).emit(encode_and_encrypt_note(&mut context, owner_ovpk_m, owner));
}

unconstrained fn getNumber(owner: AztecAddress) -> pub ValueNote {
Expand Down
6 changes: 2 additions & 4 deletions boxes/boxes/vanilla/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ const setWait = (state: boolean): void =>
document.querySelector('#deploy').addEventListener('click', async ({ target }: any) => {
setWait(true);
wallet = await account.register();
const { masterNullifierPublicKey, masterIncomingViewingPublicKey, masterOutgoingViewingPublicKey } =
const { masterNullifierPublicKey, masterOutgoingViewingPublicKey } =
wallet.getCompleteAddress().publicKeys;
contract = await VanillaContract.deploy(
wallet,
Fr.random(),
wallet.getCompleteAddress().address,
masterNullifierPublicKey.hash(),
masterOutgoingViewingPublicKey.toWrappedNoirStruct(),
masterIncomingViewingPublicKey.toWrappedNoirStruct(),
)
.send({ contractAddressSalt: Fr.random() })
.deployed();
Expand All @@ -45,14 +44,13 @@ document.querySelector('#set').addEventListener('submit', async (e: Event) => {

const { value } = document.querySelector('#number') as HTMLInputElement;
const { address: owner, publicKeys } = wallet.getCompleteAddress();
const { masterNullifierPublicKey, masterIncomingViewingPublicKey, masterOutgoingViewingPublicKey } = publicKeys;
const { masterNullifierPublicKey, masterOutgoingViewingPublicKey } = publicKeys;
await contract.methods
.setNumber(
parseInt(value),
owner,
masterNullifierPublicKey.hash(),
masterOutgoingViewingPublicKey.toWrappedNoirStruct(),
masterIncomingViewingPublicKey.toWrappedNoirStruct(),
)
.send()
.wait();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ use crate::{
context::PrivateContext, encrypted_logs::payload::compute_private_log_payload,
event::event_interface::EventInterface, keys::getters::get_ovsk_app, oracle::random::random,
};
use dep::protocol_types::{
address::AztecAddress,
hash::sha256_to_field,
public_keys::{IvpkM, OvpkM},
};
use dep::protocol_types::{address::AztecAddress, hash::sha256_to_field, public_keys::OvpkM};

/// Computes private event log payload and a log hash
fn compute_payload_and_hash<Event, let N: u32>(
Expand All @@ -15,7 +11,6 @@ fn compute_payload_and_hash<Event, let N: u32>(
randomness: Field,
ovsk_app: Field,
ovpk: OvpkM,
ivpk: IvpkM,
recipient: AztecAddress,
) -> ([u8; 416 + N * 32], Field)
where
Expand All @@ -42,22 +37,20 @@ unconstrained fn compute_payload_and_hash_unconstrained<Event, let N: u32>(
event: Event,
randomness: Field,
ovpk: OvpkM,
ivpk: IvpkM,
recipient: AztecAddress,
) -> ([u8; 416 + N * 32], Field)
where
Event: EventInterface<N>,
{
let ovsk_app = get_ovsk_app(ovpk.hash());
compute_payload_and_hash(context, event, randomness, ovsk_app, ovpk, ivpk, recipient)
compute_payload_and_hash(context, event, randomness, ovsk_app, ovpk, recipient)
}

pub fn encode_and_encrypt_event<Event, let N: u32>(
context: &mut PrivateContext,
ovpk: OvpkM,
ivpk: IvpkM,
recipient: AztecAddress,
) -> fn[(&mut PrivateContext, OvpkM, IvpkM, AztecAddress)](Event) -> ()
) -> fn[(&mut PrivateContext, OvpkM, AztecAddress)](Event) -> ()
where
Event: EventInterface<N>,
{
Expand All @@ -69,17 +62,16 @@ where
let randomness = unsafe { random() };
let ovsk_app: Field = context.request_ovsk_app(ovpk.hash());
let (encrypted_log, log_hash) =
compute_payload_and_hash(*context, e, randomness, ovsk_app, ovpk, ivpk, recipient);
compute_payload_and_hash(*context, e, randomness, ovsk_app, ovpk, recipient);
context.emit_raw_event_log_with_masked_address(randomness, encrypted_log, log_hash);
}
}

pub fn encode_and_encrypt_event_unconstrained<Event, let N: u32>(
context: &mut PrivateContext,
ovpk: OvpkM,
ivpk: IvpkM,
recipient: AztecAddress,
) -> fn[(&mut PrivateContext, OvpkM, IvpkM, AztecAddress)](Event) -> ()
) -> fn[(&mut PrivateContext, OvpkM, AztecAddress)](Event) -> ()
where
Event: EventInterface<N>,
{
Expand All @@ -90,7 +82,7 @@ where
// value generation.
let randomness = unsafe { random() };
let (encrypted_log, log_hash) = unsafe {
compute_payload_and_hash_unconstrained(*context, e, randomness, ovpk, ivpk, recipient)
compute_payload_and_hash_unconstrained(*context, e, randomness, ovpk, recipient)
};
context.emit_raw_event_log_with_masked_address(randomness, encrypted_log, log_hash);
}
Expand All @@ -103,16 +95,15 @@ pub fn encode_and_encrypt_event_with_randomness<Event, let N: u32>(
context: &mut PrivateContext,
randomness: Field,
ovpk: OvpkM,
ivpk: IvpkM,
recipient: AztecAddress,
) -> fn[(&mut PrivateContext, OvpkM, Field, IvpkM, AztecAddress)](Event) -> ()
) -> fn[(&mut PrivateContext, OvpkM, Field, AztecAddress)](Event) -> ()
where
Event: EventInterface<N>,
{
|e: Event| {
let ovsk_app: Field = context.request_ovsk_app(ovpk.hash());
let (encrypted_log, log_hash) =
compute_payload_and_hash(*context, e, randomness, ovsk_app, ovpk, ivpk, recipient);
compute_payload_and_hash(*context, e, randomness, ovsk_app, ovpk, recipient);
context.emit_raw_event_log_with_masked_address(randomness, encrypted_log, log_hash);
}
}
Expand All @@ -121,9 +112,8 @@ pub fn encode_and_encrypt_event_with_randomness_unconstrained<Event, let N: u32>
context: &mut PrivateContext,
randomness: Field,
ovpk: OvpkM,
ivpk: IvpkM,
recipient: AztecAddress,
) -> fn[(&mut PrivateContext, Field, OvpkM, IvpkM, AztecAddress)](Event) -> ()
) -> fn[(&mut PrivateContext, Field, OvpkM, AztecAddress)](Event) -> ()
where
Event: EventInterface<N>,
{
Expand All @@ -143,7 +133,7 @@ where
// return the log from this function to the app, otherwise it could try to do stuff with it and then that might
// be wrong.
let (encrypted_log, log_hash) = unsafe {
compute_payload_and_hash_unconstrained(*context, e, randomness, ovpk, ivpk, recipient)
compute_payload_and_hash_unconstrained(*context, e, randomness, ovpk, recipient)
};
context.emit_raw_event_log_with_masked_address(randomness, encrypted_log, log_hash);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use dep::protocol_types::{
abis::note_hash::NoteHash,
address::AztecAddress,
hash::sha256_to_field,
public_keys::{IvpkM, OvpkM, PublicKeys},
public_keys::{OvpkM, PublicKeys},
};

/// Computes private note log payload and a log hash
Expand All @@ -17,7 +17,6 @@ fn compute_payload_and_hash<Note, let N: u32>(
note: Note,
ovsk_app: Field,
ovpk: OvpkM,
ivpk: IvpkM,
recipient: AztecAddress,
) -> (u32, [u8; 417 + N * 32], Field)
where
Expand Down Expand Up @@ -47,14 +46,13 @@ unconstrained fn compute_payload_and_hash_unconstrained<Note, let N: u32>(
context: PrivateContext,
note: Note,
ovpk: OvpkM,
ivpk: IvpkM,
recipient: AztecAddress,
) -> (u32, [u8; 417 + N * 32], Field)
where
Note: NoteInterface<N>,
{
let ovsk_app = get_ovsk_app(ovpk.hash());
compute_payload_and_hash(context, note, ovsk_app, ovpk, ivpk, recipient)
compute_payload_and_hash(context, note, ovsk_app, ovpk, recipient)
}

// This function seems to be affected by the following Noir bug:
Expand All @@ -63,27 +61,25 @@ where
pub fn encode_and_encrypt_note<Note, let N: u32>(
context: &mut PrivateContext,
ovpk: OvpkM,
ivpk: IvpkM,
recipient: AztecAddress,
) -> fn[(&mut PrivateContext, OvpkM, IvpkM, AztecAddress)](NoteEmission<Note>) -> ()
) -> fn[(&mut PrivateContext, OvpkM, AztecAddress)](NoteEmission<Note>) -> ()
where
Note: NoteInterface<N>,
{
|e: NoteEmission<Note>| {
let ovsk_app: Field = context.request_ovsk_app(ovpk.hash());

let (note_hash_counter, encrypted_log, log_hash) =
compute_payload_and_hash(*context, e.note, ovsk_app, ovpk, ivpk, recipient);
compute_payload_and_hash(*context, e.note, ovsk_app, ovpk, recipient);
context.emit_raw_note_log(note_hash_counter, encrypted_log, log_hash);
}
}

pub fn encode_and_encrypt_note_unconstrained<Note, let N: u32>(
context: &mut PrivateContext,
ovpk: OvpkM,
ivpk: IvpkM,
recipient: AztecAddress,
) -> fn[(&mut PrivateContext, OvpkM, IvpkM, AztecAddress)](NoteEmission<Note>) -> ()
) -> fn[(&mut PrivateContext, OvpkM, AztecAddress)](NoteEmission<Note>) -> ()
where
Note: NoteInterface<N>,
{
Expand All @@ -107,9 +103,8 @@ where
// for the log to be deleted when it shouldn't have (which is fine - they can already make the content be
// whatever), or cause for the log to not be deleted when it should have (which is also fine - it'll be a log
// for a note that doesn't exist).
let (note_hash_counter, encrypted_log, log_hash) = unsafe {
compute_payload_and_hash_unconstrained(*context, e.note, ovpk, ivpk, recipient)
};
let (note_hash_counter, encrypted_log, log_hash) =
unsafe { compute_payload_and_hash_unconstrained(*context, e.note, ovpk, recipient) };
context.emit_raw_note_log(note_hash_counter, encrypted_log, log_hash);
}
}
Loading
Loading