Skip to content

Commit

Permalink
fix: replace usage of GrumpkinPoint with EmbeddedCurvePoint
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Jul 8, 2024
1 parent 0414eb5 commit 0fb6dbe
Show file tree
Hide file tree
Showing 65 changed files with 309 additions and 288 deletions.
10 changes: 5 additions & 5 deletions boxes/boxes/react/src/contracts/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
contract BoxReact {
use dep::aztec::prelude::{AztecAddress, PrivateMutable, Map, NoteInterface, NoteHeader};
use dep::aztec::protocol_types::grumpkin_point::GrumpkinPoint;
use dep::aztec::protocol_types::embedded_curve_point::EmbeddedCurvePoint;
use dep::aztec::encrypted_logs::encrypted_note_emission::encode_and_encrypt_note_with_keys;
use dep::value_note::value_note::{ValueNote, VALUE_NOTE_LEN};

Expand All @@ -15,8 +15,8 @@ contract BoxReact {
number: Field,
owner: AztecAddress,
owner_npk_m_hash: Field,
owner_ovpk_m: GrumpkinPoint,
owner_ivpk_m: GrumpkinPoint
owner_ovpk_m: EmbeddedCurvePoint,
owner_ivpk_m: EmbeddedCurvePoint
) {
let numbers = storage.numbers;
let mut new_number = ValueNote::new(number, owner_npk_m_hash);
Expand All @@ -28,8 +28,8 @@ contract BoxReact {
number: Field,
owner: AztecAddress,
owner_npk_m_hash: Field,
owner_ovpk_m: GrumpkinPoint,
owner_ivpk_m: GrumpkinPoint
owner_ovpk_m: EmbeddedCurvePoint,
owner_ivpk_m: EmbeddedCurvePoint
) {
let numbers = storage.numbers;
let mut new_number = ValueNote::new(number, owner_npk_m_hash);
Expand Down
10 changes: 5 additions & 5 deletions boxes/boxes/vanilla/src/contracts/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
contract Vanilla {
use dep::aztec::prelude::{AztecAddress, PrivateMutable, Map, NoteInterface, NoteHeader};
use dep::aztec::protocol_types::grumpkin_point::GrumpkinPoint;
use dep::aztec::protocol_types::embedded_curve_point::EmbeddedCurvePoint;
use dep::aztec::encrypted_logs::encrypted_note_emission::encode_and_encrypt_note_with_keys;
use dep::value_note::value_note::{ValueNote, VALUE_NOTE_LEN};

Expand All @@ -15,8 +15,8 @@ contract Vanilla {
number: Field,
owner: AztecAddress,
owner_npk_m_hash: Field,
owner_ovpk_m: GrumpkinPoint,
owner_ivpk_m: GrumpkinPoint
owner_ovpk_m: EmbeddedCurvePoint,
owner_ivpk_m: EmbeddedCurvePoint
) {
let numbers = storage.numbers;
let mut new_number = ValueNote::new(number, owner_npk_m_hash);
Expand All @@ -28,8 +28,8 @@ contract Vanilla {
number: Field,
owner: AztecAddress,
owner_npk_m_hash: Field,
owner_ovpk_m: GrumpkinPoint,
owner_ivpk_m: GrumpkinPoint
owner_ovpk_m: EmbeddedCurvePoint,
owner_ivpk_m: EmbeddedCurvePoint
) {
let numbers = storage.numbers;
let mut new_number = ValueNote::new(number, owner_npk_m_hash);
Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/address-note/src/address_note.nr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use dep::aztec::{
protocol_types::{
address::AztecAddress, traits::Empty, constants::GENERATOR_INDEX__NOTE_NULLIFIER,
grumpkin_point::GrumpkinPoint, hash::poseidon2_hash
embedded_curve_point::EmbeddedCurvePoint, hash::poseidon2_hash
},
note::{note_header::NoteHeader, note_interface::NoteInterface, utils::compute_note_hash_for_consumption},
oracle::unsafe_rand::unsafe_rand, keys::getters::get_nsk_app, context::PrivateContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ use crate::{
encrypted_logs::payload::compute_encrypted_event_log, oracle::logs_traits::LensForEncryptedEvent,
oracle::unsafe_rand::unsafe_rand
};
use dep::protocol_types::{address::AztecAddress, grumpkin_point::GrumpkinPoint, hash::sha256_to_field};
use dep::protocol_types::{address::AztecAddress, embedded_curve_point::EmbeddedCurvePoint, hash::sha256_to_field};

unconstrained fn compute_unconstrained<Event, NB, MB, OB>(
contract_address: AztecAddress,
randomness: Field,
ovsk_app: Field,
ovpk: GrumpkinPoint,
ivpk: GrumpkinPoint,
ovpk: EmbeddedCurvePoint,
ivpk: EmbeddedCurvePoint,
event: Event
) -> ([u8; OB], Field) where Event: EventInterface<NB, MB>, [u8; NB]: LensForEncryptedEvent<NB, OB> {
compute(contract_address, randomness, ovsk_app, ovpk, ivpk, event)
Expand All @@ -20,8 +20,8 @@ fn compute<Event, NB, MB, OB>(
contract_address: AztecAddress,
randomness: Field,
ovsk_app: Field,
ovpk: GrumpkinPoint,
ivpk: GrumpkinPoint,
ovpk: EmbeddedCurvePoint,
ivpk: EmbeddedCurvePoint,
event: Event
) -> ([u8; OB], Field) where Event: EventInterface<NB, MB>, [u8; NB]: LensForEncryptedEvent<NB, OB> {
let encrypted_log: [u8; OB] = compute_encrypted_event_log(contract_address, randomness, ovsk_app, ovpk, ivpk, event);
Expand All @@ -33,9 +33,9 @@ fn emit_with_keys<Event, NB, MB, OB>(
context: &mut PrivateContext,
randomness: Field,
event: Event,
ovpk: GrumpkinPoint,
ivpk: GrumpkinPoint,
inner_compute: fn(AztecAddress, Field, Field, GrumpkinPoint, GrumpkinPoint, Event) -> ([u8; OB], Field)
ovpk: EmbeddedCurvePoint,
ivpk: EmbeddedCurvePoint,
inner_compute: fn(AztecAddress, Field, Field, EmbeddedCurvePoint, EmbeddedCurvePoint, Event) -> ([u8; OB], Field)
) where Event: EventInterface<NB, MB>, [u8; NB]: LensForEncryptedEvent<NB, OB> {
let contract_address: AztecAddress = context.this_address();
let ovsk_app: Field = context.request_ovsk_app(ovpk.hash());
Expand Down Expand Up @@ -101,9 +101,9 @@ pub fn encode_and_encrypt_event_with_randomness_unconstrained<Event, NB, MB, OB>

pub fn encode_and_encrypt_event_with_keys<Event, NB, MB, OB>(
context: &mut PrivateContext,
ovpk: GrumpkinPoint,
ivpk: GrumpkinPoint
) -> fn[(&mut PrivateContext, GrumpkinPoint, GrumpkinPoint)](Event) -> () where Event: EventInterface<NB, MB>, [u8; NB]: LensForEncryptedEvent<NB, OB> {
ovpk: EmbeddedCurvePoint,
ivpk: EmbeddedCurvePoint
) -> fn[(&mut PrivateContext, EmbeddedCurvePoint, EmbeddedCurvePoint)](Event) -> () where Event: EventInterface<NB, MB>, [u8; NB]: LensForEncryptedEvent<NB, OB> {
| e: Event | {
let randomness = unsafe_rand();
emit_with_keys(context, randomness, e, ovpk, ivpk, compute);
Expand All @@ -112,9 +112,9 @@ pub fn encode_and_encrypt_event_with_keys<Event, NB, MB, OB>(

pub fn encode_and_encrypt_event_with_keys_unconstrained<Event, NB, MB, OB>(
context: &mut PrivateContext,
ovpk: GrumpkinPoint,
ivpk: GrumpkinPoint
) -> fn[(&mut PrivateContext, GrumpkinPoint, GrumpkinPoint)](Event) -> () where Event: EventInterface<NB, MB>, [u8; NB]: LensForEncryptedEvent<NB, OB> {
ovpk: EmbeddedCurvePoint,
ivpk: EmbeddedCurvePoint
) -> fn[(&mut PrivateContext, EmbeddedCurvePoint, EmbeddedCurvePoint)](Event) -> () where Event: EventInterface<NB, MB>, [u8; NB]: LensForEncryptedEvent<NB, OB> {
| e: Event | {
let randomness = unsafe_rand();
emit_with_keys(context, randomness, e, ovpk, ivpk, compute_unconstrained);
Expand All @@ -124,9 +124,9 @@ pub fn encode_and_encrypt_event_with_keys_unconstrained<Event, NB, MB, OB>(
pub fn encode_and_encrypt_event_with_keys_with_randomness<Event, NB, MB, OB>(
context: &mut PrivateContext,
randomness: Field,
ovpk: GrumpkinPoint,
ivpk: GrumpkinPoint
) -> fn[(&mut PrivateContext, Field, GrumpkinPoint, GrumpkinPoint)](Event) -> () where Event: EventInterface<NB, MB>, [u8; NB]: LensForEncryptedEvent<NB, OB> {
ovpk: EmbeddedCurvePoint,
ivpk: EmbeddedCurvePoint
) -> fn[(&mut PrivateContext, Field, EmbeddedCurvePoint, EmbeddedCurvePoint)](Event) -> () where Event: EventInterface<NB, MB>, [u8; NB]: LensForEncryptedEvent<NB, OB> {
| e: Event | {
emit_with_keys(context, randomness, e, ovpk, ivpk, compute);
}
Expand All @@ -135,9 +135,9 @@ pub fn encode_and_encrypt_event_with_keys_with_randomness<Event, NB, MB, OB>(
pub fn encode_and_encrypt_event_with_keys_with_randomness_unconstrained<Event, NB, MB, OB>(
context: &mut PrivateContext,
randomness: Field,
ovpk: GrumpkinPoint,
ivpk: GrumpkinPoint
) -> fn[(&mut PrivateContext, Field, GrumpkinPoint, GrumpkinPoint)](Event) -> () where Event: EventInterface<NB, MB>, [u8; NB]: LensForEncryptedEvent<NB, OB> {
ovpk: EmbeddedCurvePoint,
ivpk: EmbeddedCurvePoint
) -> fn[(&mut PrivateContext, Field, EmbeddedCurvePoint, EmbeddedCurvePoint)](Event) -> () where Event: EventInterface<NB, MB>, [u8; NB]: LensForEncryptedEvent<NB, OB> {
| e: Event | {
emit_with_keys(context, randomness, e, ovpk, ivpk, compute_unconstrained);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ use crate::{
encrypted_logs::payload::compute_encrypted_note_log, oracle::logs_traits::LensForEncryptedLog
};
use dep::protocol_types::{
hash::sha256_to_field, address::AztecAddress, grumpkin_point::GrumpkinPoint,
hash::sha256_to_field, address::AztecAddress, embedded_curve_point::EmbeddedCurvePoint,
abis::note_hash::NoteHash, constants::MAX_NOTE_HASHES_PER_CALL, utils::arrays::find_index
};

unconstrained fn compute_unconstrained<Note, N, NB, M>(
contract_address: AztecAddress,
storage_slot: Field,
ovsk_app: Field,
ovpk: GrumpkinPoint,
ivpk: GrumpkinPoint,
ovpk: EmbeddedCurvePoint,
ivpk: EmbeddedCurvePoint,
note: Note
) -> ([u8; M], Field) where Note: NoteInterface<N, NB>, [Field; N]: LensForEncryptedLog<N, M> {
compute(contract_address, storage_slot, ovsk_app, ovpk, ivpk, note)
Expand All @@ -22,8 +22,8 @@ fn compute<Note, N, NB, M>(
contract_address: AztecAddress,
storage_slot: Field,
ovsk_app: Field,
ovpk: GrumpkinPoint,
ivpk: GrumpkinPoint,
ovpk: EmbeddedCurvePoint,
ivpk: EmbeddedCurvePoint,
note: Note
) -> ([u8; M], Field) where Note: NoteInterface<N, NB>, [Field; N]: LensForEncryptedLog<N, M> {
let encrypted_log: [u8; M] = compute_encrypted_note_log(contract_address, storage_slot, ovsk_app, ovpk, ivpk, note);
Expand All @@ -34,9 +34,9 @@ fn compute<Note, N, NB, M>(
fn emit_with_keys<Note, N, NB, M>(
context: &mut PrivateContext,
note: Note,
ovpk: GrumpkinPoint,
ivpk: GrumpkinPoint,
inner_compute: fn(AztecAddress, Field, Field, GrumpkinPoint, GrumpkinPoint, Note) -> ([u8; M], Field)
ovpk: EmbeddedCurvePoint,
ivpk: EmbeddedCurvePoint,
inner_compute: fn(AztecAddress, Field, Field, EmbeddedCurvePoint, EmbeddedCurvePoint, Note) -> ([u8; M], Field)
) where Note: NoteInterface<N, NB>, [Field; N]: LensForEncryptedLog<N, M> {
let note_header = note.get_header();
let note_hash_counter = note_header.note_hash_counter;
Expand Down Expand Up @@ -86,19 +86,19 @@ pub fn encode_and_encrypt_note_unconstrained<Note, N, NB, M>(

pub fn encode_and_encrypt_note_with_keys<Note, N, NB, M>(
context: &mut PrivateContext,
ovpk: GrumpkinPoint,
ivpk: GrumpkinPoint
) -> fn[(&mut PrivateContext, GrumpkinPoint, GrumpkinPoint)](NoteEmission<Note>) -> () where Note: NoteInterface<N, NB>, [Field; N]: LensForEncryptedLog<N, M> {
ovpk: EmbeddedCurvePoint,
ivpk: EmbeddedCurvePoint
) -> fn[(&mut PrivateContext, EmbeddedCurvePoint, EmbeddedCurvePoint)](NoteEmission<Note>) -> () where Note: NoteInterface<N, NB>, [Field; N]: LensForEncryptedLog<N, M> {
| e: NoteEmission<Note> | {
emit_with_keys(context, e.note, ovpk, ivpk, compute);
}
}

pub fn encode_and_encrypt_note_with_keys_unconstrained<Note, N, NB, M>(
context: &mut PrivateContext,
ovpk: GrumpkinPoint,
ivpk: GrumpkinPoint
) -> fn[(&mut PrivateContext, GrumpkinPoint, GrumpkinPoint)](NoteEmission<Note>) -> () where Note: NoteInterface<N, NB>, [Field; N]: LensForEncryptedLog<N, M> {
ovpk: EmbeddedCurvePoint,
ivpk: EmbeddedCurvePoint
) -> fn[(&mut PrivateContext, EmbeddedCurvePoint, EmbeddedCurvePoint)](NoteEmission<Note>) -> () where Note: NoteInterface<N, NB>, [Field; N]: LensForEncryptedLog<N, M> {
| e: NoteEmission<Note> | {
emit_with_keys(context, e.note, ovpk, ivpk, compute_unconstrained);
}
Expand Down
12 changes: 8 additions & 4 deletions noir-projects/aztec-nr/aztec/src/encrypted_logs/header.nr
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use dep::protocol_types::{address::AztecAddress, grumpkin_private_key::GrumpkinPrivateKey, grumpkin_point::GrumpkinPoint};
use dep::protocol_types::{
address::AztecAddress, grumpkin_private_key::GrumpkinPrivateKey,
embedded_curve_point::EmbeddedCurvePoint
};

use crate::keys::point_to_symmetric_key::point_to_symmetric_key;

Expand All @@ -13,7 +16,7 @@ impl EncryptedLogHeader {
EncryptedLogHeader { address }
}

fn compute_ciphertext(self, secret: GrumpkinPrivateKey, point: GrumpkinPoint) -> [u8; 48] {
fn compute_ciphertext(self, secret: GrumpkinPrivateKey, point: EmbeddedCurvePoint) -> [u8; 48] {
let full_key = point_to_symmetric_key(secret, point);
let mut sym_key = [0; 16];
let mut iv = [0; 16];
Expand All @@ -36,9 +39,10 @@ fn test_encrypted_log_header() {
0x0000000000000000000000000000000023b3127c127b1f29a7adff5cccf8fb06,
0x00000000000000000000000000000000649e7ca01d9de27b21624098b897babd
);
let point = GrumpkinPoint::new(
let point = EmbeddedCurvePoint::new(
0x2688431c705a5ff3e6c6f2573c9e3ba1c1026d2251d0dbbf2d810aa53fd1d186,
0x1e96887b117afca01c00468264f4f80b5bb16d94c1808a448595f115556e5c8e
0x1e96887b117afca01c00468264f4f80b5bb16d94c1808a448595f115556e5c8e,
false
);

let ciphertext = header.compute_ciphertext(secret, point);
Expand Down
18 changes: 10 additions & 8 deletions noir-projects/aztec-nr/aztec/src/encrypted_logs/incoming_body.nr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::note::note_interface::NoteInterface;
use crate::event::event_interface::EventInterface;
use dep::protocol_types::{grumpkin_private_key::GrumpkinPrivateKey, grumpkin_point::GrumpkinPoint};
use dep::protocol_types::{grumpkin_private_key::GrumpkinPrivateKey, embedded_curve_point::EmbeddedCurvePoint};

use std::aes128::aes128_encrypt;
use crate::keys::point_to_symmetric_key::point_to_symmetric_key;
Expand All @@ -20,7 +20,7 @@ impl<M> EncryptedLogIncomingBody<M> {
EncryptedLogIncomingBody { plaintext }
}

pub fn compute_ciphertext(self, eph_sk: GrumpkinPrivateKey, ivpk_app: GrumpkinPoint) -> [u8] {
pub fn compute_ciphertext(self, eph_sk: GrumpkinPrivateKey, ivpk_app: EmbeddedCurvePoint) -> [u8] {
let full_key = point_to_symmetric_key(eph_sk, ivpk_app);
let mut sym_key = [0; 16];
let mut iv = [0; 16];
Expand All @@ -37,8 +37,8 @@ mod test {
use crate::encrypted_logs::incoming_body::EncryptedLogIncomingBody;
use dep::protocol_types::{
address::AztecAddress, traits::Empty, constants::GENERATOR_INDEX__NOTE_NULLIFIER,
grumpkin_private_key::GrumpkinPrivateKey, grumpkin_point::GrumpkinPoint, traits::Serialize,
abis::event_selector::EventSelector
grumpkin_private_key::GrumpkinPrivateKey, embedded_curve_point::EmbeddedCurvePoint,
traits::Serialize, abis::event_selector::EventSelector
};

use crate::{
Expand Down Expand Up @@ -123,9 +123,10 @@ mod test {
0x0000000000000000000000000000000023b3127c127b1f29a7adff5cccf8fb06,
0x00000000000000000000000000000000649e7ca01d9de27b21624098b897babd
);
let ivpk_app = GrumpkinPoint::new(
let ivpk_app = EmbeddedCurvePoint::new(
0x2688431c705a5ff3e6c6f2573c9e3ba1c1026d2251d0dbbf2d810aa53fd1d186,
0x1e96887b117afca01c00468264f4f80b5bb16d94c1808a448595f115556e5c8e
0x1e96887b117afca01c00468264f4f80b5bb16d94c1808a448595f115556e5c8e,
false
);

let body = EncryptedLogIncomingBody::from_note(note, storage_slot);
Expand Down Expand Up @@ -222,9 +223,10 @@ mod test {
0x00000000000000000000000000000000649e7ca01d9de27b21624098b897babd
);

let ivpk_app = GrumpkinPoint::new(
let ivpk_app = EmbeddedCurvePoint::new(
0x2688431c705a5ff3e6c6f2573c9e3ba1c1026d2251d0dbbf2d810aa53fd1d186,
0x1e96887b117afca01c00468264f4f80b5bb16d94c1808a448595f115556e5c8e
0x1e96887b117afca01c00468264f4f80b5bb16d94c1808a448595f115556e5c8e,
false
);

let randomness = 2;
Expand Down
18 changes: 12 additions & 6 deletions noir-projects/aztec-nr/aztec/src/encrypted_logs/outgoing_body.nr
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use dep::protocol_types::{
address::AztecAddress, grumpkin_private_key::GrumpkinPrivateKey, grumpkin_point::GrumpkinPoint,
constants::GENERATOR_INDEX__SYMMETRIC_KEY, hash::poseidon2_hash
address::AztecAddress, grumpkin_private_key::GrumpkinPrivateKey,
embedded_curve_point::EmbeddedCurvePoint, constants::GENERATOR_INDEX__SYMMETRIC_KEY,
hash::poseidon2_hash
};

use std::aes128::aes128_encrypt;
Expand All @@ -10,19 +11,23 @@ use crate::keys::point_to_symmetric_key::point_to_symmetric_key;
struct EncryptedLogOutgoingBody {
eph_sk: GrumpkinPrivateKey,
recipient: AztecAddress,
recipient_ivpk_app: GrumpkinPoint,
recipient_ivpk_app: EmbeddedCurvePoint,
}

impl EncryptedLogOutgoingBody {
pub fn new(
eph_sk: GrumpkinPrivateKey,
recipient: AztecAddress,
recipient_ivpk_app: GrumpkinPoint
recipient_ivpk_app: EmbeddedCurvePoint
) -> Self {
Self { eph_sk, recipient, recipient_ivpk_app }
}

pub fn compute_ciphertext(self, ovsk_app: GrumpkinPrivateKey, eph_pk: GrumpkinPoint) -> [u8; 176] {
pub fn compute_ciphertext(
self,
ovsk_app: GrumpkinPrivateKey,
eph_pk: EmbeddedCurvePoint
) -> [u8; 176] {
// Again, we could compute `eph_pk` here, but we keep the interface more similar
// and also make it easier to optimise it later as we just pass it along

Expand Down Expand Up @@ -68,7 +73,8 @@ mod test {
use crate::encrypted_logs::outgoing_body::EncryptedLogOutgoingBody;
use dep::protocol_types::{
address::AztecAddress, traits::Empty, constants::GENERATOR_INDEX__NOTE_NULLIFIER,
grumpkin_private_key::GrumpkinPrivateKey, grumpkin_point::GrumpkinPoint, hash::poseidon2_hash
grumpkin_private_key::GrumpkinPrivateKey, embedded_curve_point::EmbeddedCurvePoint,
hash::poseidon2_hash
};

use crate::context::PrivateContext;
Expand Down
Loading

0 comments on commit 0fb6dbe

Please sign in to comment.