Skip to content

Commit

Permalink
refactor: replace usage of GrumpkinPoint with EmbeddedCurvePoint (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan authored Jul 9, 2024
1 parent 046af9b commit 5279695
Show file tree
Hide file tree
Showing 99 changed files with 497 additions and 468 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::point::Point;
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: Point,
owner_ivpk_m: Point
) {
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: Point,
owner_ivpk_m: Point
) {
let numbers = storage.numbers;
let mut new_number = ValueNote::new(number, owner_npk_m_hash);
Expand Down
4 changes: 2 additions & 2 deletions boxes/boxes/react/src/hooks/useContract.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export function useContract() {
Fr.random(),
wallet.getCompleteAddress().address,
masterNullifierPublicKey.hash(),
masterOutgoingViewingPublicKey,
masterIncomingViewingPublicKey,
masterOutgoingViewingPublicKey.toNoirStruct(),
masterIncomingViewingPublicKey.toNoirStruct(),
).send({
contractAddressSalt: salt,
});
Expand Down
4 changes: 2 additions & 2 deletions boxes/boxes/react/src/hooks/useNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export function useNumber({ contract }: { contract: Contract }) {
value,
deployerWallet.getCompleteAddress().address,
masterNullifierPublicKey.hash(),
masterOutgoingViewingPublicKey,
masterIncomingViewingPublicKey,
masterOutgoingViewingPublicKey.toNoirStruct(),
masterIncomingViewingPublicKey.toNoirStruct(),
)
.send()
.wait(),
Expand Down
8 changes: 4 additions & 4 deletions boxes/boxes/react/tests/node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ describe('BoxReact Contract Tests', () => {
Fr.random(),
accountCompleteAddress.address,
masterNullifierPublicKey.hash(),
masterOutgoingViewingPublicKey,
masterIncomingViewingPublicKey,
masterOutgoingViewingPublicKey.toNoirStruct(),
masterIncomingViewingPublicKey.toNoirStruct(),
)
.send({ contractAddressSalt: salt })
.deployed();
Expand All @@ -39,8 +39,8 @@ describe('BoxReact Contract Tests', () => {
numberToSet,
accountCompleteAddress.address,
masterNullifierPublicKey.hash(),
masterOutgoingViewingPublicKey,
masterIncomingViewingPublicKey,
masterOutgoingViewingPublicKey.toNoirStruct(),
masterIncomingViewingPublicKey.toNoirStruct(),
)
.send()
.wait();
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::point::Point;
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: Point,
owner_ivpk_m: Point
) {
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: Point,
owner_ivpk_m: Point
) {
let numbers = storage.numbers;
let mut new_number = ValueNote::new(number, owner_npk_m_hash);
Expand Down
8 changes: 4 additions & 4 deletions boxes/boxes/vanilla/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ document.querySelector('#deploy').addEventListener('click', async ({ target }: a
Fr.random(),
wallet.getCompleteAddress().address,
masterNullifierPublicKey.hash(),
masterOutgoingViewingPublicKey,
masterIncomingViewingPublicKey,
masterOutgoingViewingPublicKey.toNoirStruct(),
masterIncomingViewingPublicKey.toNoirStruct(),
)
.send({ contractAddressSalt: Fr.random() })
.deployed();
Expand All @@ -51,8 +51,8 @@ document.querySelector('#set').addEventListener('submit', async (e: Event) => {
parseInt(value),
owner,
masterNullifierPublicKey.hash(),
masterOutgoingViewingPublicKey,
masterIncomingViewingPublicKey,
masterOutgoingViewingPublicKey.toNoirStruct(),
masterIncomingViewingPublicKey.toNoirStruct(),
)
.send()
.wait();
Expand Down
16 changes: 8 additions & 8 deletions l1-contracts/src/core/libraries/ConstantsGen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ library Constants {
uint256 internal constant L2_TO_L1_MESSAGE_LENGTH = 3;
uint256 internal constant SCOPED_L2_TO_L1_MESSAGE_LENGTH = 4;
uint256 internal constant MAX_BLOCK_NUMBER_LENGTH = 2;
uint256 internal constant KEY_VALIDATION_REQUEST_LENGTH = 3;
uint256 internal constant KEY_VALIDATION_REQUEST_AND_GENERATOR_LENGTH = 4;
uint256 internal constant SCOPED_KEY_VALIDATION_REQUEST_AND_GENERATOR_LENGTH = 5;
uint256 internal constant KEY_VALIDATION_REQUEST_LENGTH = 4;
uint256 internal constant KEY_VALIDATION_REQUEST_AND_GENERATOR_LENGTH = 5;
uint256 internal constant SCOPED_KEY_VALIDATION_REQUEST_AND_GENERATOR_LENGTH = 6;
uint256 internal constant PARTIAL_STATE_REFERENCE_LENGTH = 6;
uint256 internal constant READ_REQUEST_LENGTH = 2;
uint256 internal constant LOG_HASH_LENGTH = 3;
Expand All @@ -172,23 +172,23 @@ library Constants {
uint256 internal constant TX_REQUEST_LENGTH = 13;
uint256 internal constant TOTAL_FEES_LENGTH = 1;
uint256 internal constant HEADER_LENGTH = 23;
uint256 internal constant PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 428;
uint256 internal constant PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 444;
uint256 internal constant PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = 481;
uint256 internal constant PRIVATE_CALL_STACK_ITEM_LENGTH = 431;
uint256 internal constant PRIVATE_CALL_STACK_ITEM_LENGTH = 447;
uint256 internal constant PUBLIC_CONTEXT_INPUTS_LENGTH = 40;
uint256 internal constant AGGREGATION_OBJECT_LENGTH = 16;
uint256 internal constant SCOPED_READ_REQUEST_LEN = 3;
uint256 internal constant PUBLIC_DATA_READ_LENGTH = 2;
uint256 internal constant VALIDATION_REQUESTS_LENGTH = 1026;
uint256 internal constant VALIDATION_REQUESTS_LENGTH = 1090;
uint256 internal constant PUBLIC_DATA_UPDATE_REQUEST_LENGTH = 3;
uint256 internal constant COMBINED_ACCUMULATED_DATA_LENGTH = 333;
uint256 internal constant COMBINED_CONSTANT_DATA_LENGTH = 41;
uint256 internal constant PUBLIC_CALL_STACK_ITEM_COMPRESSED_LENGTH = 15;
uint256 internal constant CALL_REQUEST_LENGTH = 7;
uint256 internal constant PRIVATE_ACCUMULATED_DATA_LENGTH = 1160;
uint256 internal constant PRIVATE_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 2236;
uint256 internal constant PRIVATE_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 2300;
uint256 internal constant PUBLIC_ACCUMULATED_DATA_LENGTH = 983;
uint256 internal constant PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 3259;
uint256 internal constant PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 3323;
uint256 internal constant KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 384;
uint256 internal constant CONSTANT_ROLLUP_DATA_LENGTH = 11;
uint256 internal constant BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH = 28;
Expand Down
5 changes: 1 addition & 4 deletions noir-projects/aztec-nr/address-note/src/address_note.nr
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use dep::aztec::{
protocol_types::{
address::AztecAddress, traits::Empty, constants::GENERATOR_INDEX__NOTE_NULLIFIER,
grumpkin_point::GrumpkinPoint, hash::poseidon2_hash
},
protocol_types::{address::AztecAddress, traits::Empty, constants::GENERATOR_INDEX__NOTE_NULLIFIER, 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, point::Point, 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: Point,
ivpk: Point,
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: Point,
ivpk: Point,
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: Point,
ivpk: Point,
inner_compute: fn(AztecAddress, Field, Field, Point, Point, 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: Point,
ivpk: Point
) -> fn[(&mut PrivateContext, Point, Point)](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: Point,
ivpk: Point
) -> fn[(&mut PrivateContext, Point, Point)](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: Point,
ivpk: Point
) -> fn[(&mut PrivateContext, Field, Point, Point)](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: Point,
ivpk: Point
) -> fn[(&mut PrivateContext, Field, Point, Point)](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,
abis::note_hash::NoteHash, constants::MAX_NOTE_HASHES_PER_CALL, utils::arrays::find_index
hash::sha256_to_field, address::AztecAddress, point::Point, 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: Point,
ivpk: Point,
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: Point,
ivpk: Point,
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: Point,
ivpk: Point,
inner_compute: fn(AztecAddress, Field, Field, Point, Point, 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: Point,
ivpk: Point
) -> fn[(&mut PrivateContext, Point, Point)](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: Point,
ivpk: Point
) -> fn[(&mut PrivateContext, Point, Point)](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
9 changes: 5 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,4 @@
use dep::protocol_types::{address::AztecAddress, grumpkin_private_key::GrumpkinPrivateKey, grumpkin_point::GrumpkinPoint};
use dep::protocol_types::{address::AztecAddress, grumpkin_private_key::GrumpkinPrivateKey, point::Point};

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

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

fn compute_ciphertext(self, secret: GrumpkinPrivateKey, point: GrumpkinPoint) -> [u8; 48] {
fn compute_ciphertext(self, secret: GrumpkinPrivateKey, point: Point) -> [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 +36,10 @@ fn test_encrypted_log_header() {
0x0000000000000000000000000000000023b3127c127b1f29a7adff5cccf8fb06,
0x00000000000000000000000000000000649e7ca01d9de27b21624098b897babd
);
let point = GrumpkinPoint::new(
let point = Point::new(
0x2688431c705a5ff3e6c6f2573c9e3ba1c1026d2251d0dbbf2d810aa53fd1d186,
0x1e96887b117afca01c00468264f4f80b5bb16d94c1808a448595f115556e5c8e
0x1e96887b117afca01c00468264f4f80b5bb16d94c1808a448595f115556e5c8e,
false
);

let ciphertext = header.compute_ciphertext(secret, point);
Expand Down
Loading

0 comments on commit 5279695

Please sign in to comment.