From bd26f5588cd55fd795087ba678ff19c5564422ad Mon Sep 17 00:00:00 2001 From: benesjan Date: Mon, 8 Jul 2024 10:32:36 +0000 Subject: [PATCH] refactor: replace usage of GrumpkinPrivateKey with EmbeddedCurveScalar --- .../aztec/src/encrypted_logs/header.nr | 6 +-- .../aztec/src/encrypted_logs/incoming_body.nr | 10 ++--- .../aztec/src/encrypted_logs/outgoing_body.nr | 16 +++---- .../aztec/src/encrypted_logs/payload.nr | 10 ++--- .../aztec/src/keys/point_to_symmetric_key.nr | 6 +-- .../contracts/test_contract/src/main.nr | 10 ++--- .../contracts/test_log_contract/src/main.nr | 4 +- .../src/private_kernel_reset.nr | 2 +- .../src/private_kernel_tail.nr | 2 +- .../private_validation_request_processor.nr | 2 +- .../src/reset/key_validation_hint.nr | 8 ++-- .../crates/types/src/embedded_curve_scalar.nr | 8 ++++ .../crates/types/src/grumpkin_private_key.nr | 44 ------------------- .../crates/types/src/lib.nr | 2 +- .../noir_stdlib/src/embedded_curve_ops.nr | 15 +++++++ yarn-project/accounts/README.md | 6 +-- .../accounts/src/schnorr/account_contract.ts | 6 +-- yarn-project/accounts/src/schnorr/index.ts | 6 +-- .../src/single_key/account_contract.ts | 6 +-- yarn-project/accounts/src/single_key/index.ts | 4 +- yarn-project/aztec.js/src/index.ts | 2 +- yarn-project/aztec.js/src/utils/pub_key.ts | 4 +- yarn-project/circuit-types/src/index.ts | 2 +- .../src/logs/l1_payload/encrypt_buffer.ts | 6 +-- .../logs/l1_payload/encrypted_log_header.ts | 6 +-- .../encrypted_event_log_incoming_body.ts | 4 +- .../encrypted_log_incoming_body.ts | 6 +-- .../encrypted_note_log_incoming_body.ts | 4 +- .../l1_payload/encrypted_log_outgoing_body.ts | 12 ++--- .../src/logs/l1_payload/encryption_utils.ts | 4 +- .../src/logs/l1_payload/l1_event_payload.ts | 8 ++-- .../src/logs/l1_payload/l1_note_payload.ts | 8 ++-- .../src/logs/l1_payload/l1_payload.ts | 14 +++--- .../src/logs/l1_payload/tagged_log.ts | 16 +++---- .../src/barretenberg/crypto/schnorr/index.ts | 6 +-- .../circuits.js/src/keys/derivation.ts | 12 ++--- .../src/structs/key_validation_request.ts | 12 ++--- .../read_request_hints/key_validation_hint.ts | 8 ++-- .../circuits.js/src/tests/factories.ts | 6 +-- .../src/types/grumpkin_private_key.ts | 4 +- .../src/e2e_account_contracts.test.ts | 6 +-- .../src/fixtures/snapshot_manager.ts | 6 +-- .../writing_an_account_contract.test.ts | 4 +- yarn-project/key-store/src/key_store.ts | 6 +-- .../src/type_conversion.ts | 22 +++++----- yarn-project/pxe/src/kernel_oracle/index.ts | 4 +- .../src/kernel_prover/proving_data_oracle.ts | 4 +- .../src/note_processor/note_processor.test.ts | 6 +-- .../src/client/private_execution.test.ts | 10 ++--- 49 files changed, 182 insertions(+), 203 deletions(-) create mode 100644 noir-projects/noir-protocol-circuits/crates/types/src/embedded_curve_scalar.nr delete mode 100644 noir-projects/noir-protocol-circuits/crates/types/src/grumpkin_private_key.nr diff --git a/noir-projects/aztec-nr/aztec/src/encrypted_logs/header.nr b/noir-projects/aztec-nr/aztec/src/encrypted_logs/header.nr index 4158e6423658..8d36fdb57d58 100644 --- a/noir-projects/aztec-nr/aztec/src/encrypted_logs/header.nr +++ b/noir-projects/aztec-nr/aztec/src/encrypted_logs/header.nr @@ -1,4 +1,4 @@ -use dep::protocol_types::{address::AztecAddress, grumpkin_private_key::GrumpkinPrivateKey, point::Point}; +use dep::protocol_types::{address::AztecAddress, embedded_curve_scalar::EmbeddedCurveScalar, point::Point}; use crate::keys::point_to_symmetric_key::point_to_symmetric_key; @@ -13,7 +13,7 @@ impl EncryptedLogHeader { EncryptedLogHeader { address } } - fn compute_ciphertext(self, secret: GrumpkinPrivateKey, point: Point) -> [u8; 48] { + fn compute_ciphertext(self, secret: EmbeddedCurveScalar, point: Point) -> [u8; 48] { let full_key = point_to_symmetric_key(secret, point); let mut sym_key = [0; 16]; let mut iv = [0; 16]; @@ -32,7 +32,7 @@ impl EncryptedLogHeader { fn test_encrypted_log_header() { let address = AztecAddress::from_field(0xdeadbeef); let header = EncryptedLogHeader::new(address); - let secret = GrumpkinPrivateKey::new( + let secret = EmbeddedCurveScalar::new( 0x0000000000000000000000000000000023b3127c127b1f29a7adff5cccf8fb06, 0x00000000000000000000000000000000649e7ca01d9de27b21624098b897babd ); diff --git a/noir-projects/aztec-nr/aztec/src/encrypted_logs/incoming_body.nr b/noir-projects/aztec-nr/aztec/src/encrypted_logs/incoming_body.nr index f5690db6af80..80de101495e8 100644 --- a/noir-projects/aztec-nr/aztec/src/encrypted_logs/incoming_body.nr +++ b/noir-projects/aztec-nr/aztec/src/encrypted_logs/incoming_body.nr @@ -1,6 +1,6 @@ use crate::note::note_interface::NoteInterface; use crate::event::event_interface::EventInterface; -use dep::protocol_types::{grumpkin_private_key::GrumpkinPrivateKey, point::Point}; +use dep::protocol_types::{embedded_curve_scalar::EmbeddedCurveScalar, point::Point}; use std::aes128::aes128_encrypt; use crate::keys::point_to_symmetric_key::point_to_symmetric_key; @@ -20,7 +20,7 @@ impl EncryptedLogIncomingBody { EncryptedLogIncomingBody { plaintext } } - pub fn compute_ciphertext(self, eph_sk: GrumpkinPrivateKey, ivpk_app: Point) -> [u8] { + pub fn compute_ciphertext(self, eph_sk: EmbeddedCurveScalar, ivpk_app: Point) -> [u8] { let full_key = point_to_symmetric_key(eph_sk, ivpk_app); let mut sym_key = [0; 16]; let mut iv = [0; 16]; @@ -37,7 +37,7 @@ 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, point::Point, traits::Serialize, + embedded_curve_scalar::EmbeddedCurveScalar, point::Point, traits::Serialize, abis::event_selector::EventSelector }; @@ -119,7 +119,7 @@ mod test { let storage_slot = 2; - let eph_sk = GrumpkinPrivateKey::new( + let eph_sk = EmbeddedCurveScalar::new( 0x0000000000000000000000000000000023b3127c127b1f29a7adff5cccf8fb06, 0x00000000000000000000000000000000649e7ca01d9de27b21624098b897babd ); @@ -218,7 +218,7 @@ mod test { fn test_encrypted_log_event_incoming_body() { let test_event = TestEvent { value0: 1, value1: 2, value2: 3 }; - let eph_sk = GrumpkinPrivateKey::new( + let eph_sk = EmbeddedCurveScalar::new( 0x0000000000000000000000000000000023b3127c127b1f29a7adff5cccf8fb06, 0x00000000000000000000000000000000649e7ca01d9de27b21624098b897babd ); diff --git a/noir-projects/aztec-nr/aztec/src/encrypted_logs/outgoing_body.nr b/noir-projects/aztec-nr/aztec/src/encrypted_logs/outgoing_body.nr index 3962f27b5be9..a068fb500ccc 100644 --- a/noir-projects/aztec-nr/aztec/src/encrypted_logs/outgoing_body.nr +++ b/noir-projects/aztec-nr/aztec/src/encrypted_logs/outgoing_body.nr @@ -1,5 +1,5 @@ use dep::protocol_types::{ - address::AztecAddress, grumpkin_private_key::GrumpkinPrivateKey, point::Point, + address::AztecAddress, embedded_curve_scalar::EmbeddedCurveScalar, point::Point, constants::GENERATOR_INDEX__SYMMETRIC_KEY, hash::poseidon2_hash }; @@ -8,17 +8,17 @@ use std::aes128::aes128_encrypt; use crate::keys::point_to_symmetric_key::point_to_symmetric_key; struct EncryptedLogOutgoingBody { - eph_sk: GrumpkinPrivateKey, + eph_sk: EmbeddedCurveScalar, recipient: AztecAddress, recipient_ivpk_app: Point, } impl EncryptedLogOutgoingBody { - pub fn new(eph_sk: GrumpkinPrivateKey, recipient: AztecAddress, recipient_ivpk_app: Point) -> Self { + pub fn new(eph_sk: EmbeddedCurveScalar, recipient: AztecAddress, recipient_ivpk_app: Point) -> Self { Self { eph_sk, recipient, recipient_ivpk_app } } - pub fn compute_ciphertext(self, ovsk_app: GrumpkinPrivateKey, eph_pk: Point) -> [u8; 176] { + pub fn compute_ciphertext(self, ovsk_app: EmbeddedCurveScalar, eph_pk: Point) -> [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 @@ -64,22 +64,22 @@ 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, point::Point, hash::poseidon2_hash + embedded_curve_scalar::EmbeddedCurveScalar, point::Point, hash::poseidon2_hash }; use crate::context::PrivateContext; #[test] fn test_encrypted_log_outgoing_body() { - let eph_sk = GrumpkinPrivateKey::new( + let eph_sk = EmbeddedCurveScalar::new( 0x000000000000000000000000000000000f096b423017226a18461115fa8d34bb, 0x00000000000000000000000000000000d0d302ee245dfaf2807e604eec4715fe ); - let recipient_ivsk_app = GrumpkinPrivateKey::new( + let recipient_ivsk_app = EmbeddedCurveScalar::new( 0x000000000000000000000000000000000f4d97c25d578f9348251a71ca17ae31, 0x000000000000000000000000000000004828f8f95676ebb481df163f87fd4022 ); - let sender_ovsk_app = GrumpkinPrivateKey::new( + let sender_ovsk_app = EmbeddedCurveScalar::new( 0x00000000000000000000000000000000089c6887cb1446d86c64e81afc78048b, 0x0000000000000000000000000000000074d2e28c6bc5176ac02cf7c7d36a444e ); diff --git a/noir-projects/aztec-nr/aztec/src/encrypted_logs/payload.nr b/noir-projects/aztec-nr/aztec/src/encrypted_logs/payload.nr index 4ef42e78960b..a7190786ef23 100644 --- a/noir-projects/aztec-nr/aztec/src/encrypted_logs/payload.nr +++ b/noir-projects/aztec-nr/aztec/src/encrypted_logs/payload.nr @@ -1,5 +1,5 @@ use dep::protocol_types::{ - address::AztecAddress, grumpkin_private_key::GrumpkinPrivateKey, point::{Point, pub_key_to_bytes}, + address::AztecAddress, embedded_curve_scalar::EmbeddedCurveScalar, point::{Point, pub_key_to_bytes}, constants::{GENERATOR_INDEX__IVSK_M, GENERATOR_INDEX__OVSK_M}, hash::poseidon2_hash }; @@ -24,7 +24,7 @@ pub fn compute_encrypted_event_log( event: Event ) -> [u8; OB] where Event: EventInterface { // @todo Need to draw randomness from the full domain of Fq not only Fr - let eph_sk: GrumpkinPrivateKey = fr_to_private_key(unsafe_rand()); + let eph_sk: EmbeddedCurveScalar = fr_to_private_key(unsafe_rand()); let eph_pk = eph_sk.derive_public_key(); // TODO: (#7177) This value needs to be populated! @@ -81,7 +81,7 @@ pub fn compute_encrypted_note_log( note: Note ) -> [u8; M] where Note: NoteInterface { // @todo Need to draw randomness from the full domain of Fq not only Fr - let eph_sk: GrumpkinPrivateKey = fr_to_private_key(unsafe_rand()); + let eph_sk: EmbeddedCurveScalar = fr_to_private_key(unsafe_rand()); let eph_pk = eph_sk.derive_public_key(); // TODO: (#7177) This value needs to be populated! @@ -129,7 +129,7 @@ pub fn compute_encrypted_note_log( encrypted_bytes } -fn fr_to_private_key(r: Field) -> GrumpkinPrivateKey { +fn fr_to_private_key(r: Field) -> EmbeddedCurveScalar { let r_bytes = r.to_be_bytes(32); let mut high_bytes = [0; 32]; @@ -143,7 +143,7 @@ fn fr_to_private_key(r: Field) -> GrumpkinPrivateKey { let low = bytes32_to_field(low_bytes); let high = bytes32_to_field(high_bytes); - GrumpkinPrivateKey::new(high, low) + EmbeddedCurveScalar::new(high, low) } fn compute_ivpk_app(ivpk: Point, contract_address: AztecAddress) -> Point { diff --git a/noir-projects/aztec-nr/aztec/src/keys/point_to_symmetric_key.nr b/noir-projects/aztec-nr/aztec/src/keys/point_to_symmetric_key.nr index 1e98630343d9..74bc74571935 100644 --- a/noir-projects/aztec-nr/aztec/src/keys/point_to_symmetric_key.nr +++ b/noir-projects/aztec-nr/aztec/src/keys/point_to_symmetric_key.nr @@ -1,12 +1,12 @@ use dep::protocol_types::{ - constants::GENERATOR_INDEX__SYMMETRIC_KEY, grumpkin_private_key::GrumpkinPrivateKey, + constants::GENERATOR_INDEX__SYMMETRIC_KEY, embedded_curve_scalar::EmbeddedCurveScalar, point::{Point, pub_key_to_bytes}, utils::arr_copy_slice }; use std::{hash::sha256, embedded_curve_ops::{EmbeddedCurveScalar, multi_scalar_mul}}; // TODO(#5726): This function is called deriveAESSecret in TS. I don't like point_to_symmetric_key name much since // point is not the only input of the function. Unify naming with TS once we have a better name. -pub fn point_to_symmetric_key(secret: GrumpkinPrivateKey, point: Point) -> [u8; 32] { +pub fn point_to_symmetric_key(secret: EmbeddedCurveScalar, point: Point) -> [u8; 32] { let shared_secret_fields = multi_scalar_mul( [Point { x: point.x, y: point.y, is_infinite: false }], [EmbeddedCurveScalar { lo: secret.low, hi: secret.high }] @@ -22,7 +22,7 @@ pub fn point_to_symmetric_key(secret: GrumpkinPrivateKey, point: Point) -> [u8; #[test] fn check_point_to_symmetric_key() { // Value taken from "derive shared secret" test in encrypt_buffer.test.ts - let secret = GrumpkinPrivateKey::new( + let secret = EmbeddedCurveScalar::new( 0x0000000000000000000000000000000023b3127c127b1f29a7adff5cccf8fb06, 0x00000000000000000000000000000000649e7ca01d9de27b21624098b897babd ); diff --git a/noir-projects/noir-contracts/contracts/test_contract/src/main.nr b/noir-projects/noir-contracts/contracts/test_contract/src/main.nr index 2a39996b02bc..678261018dba 100644 --- a/noir-projects/noir-contracts/contracts/test_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/test_contract/src/main.nr @@ -13,7 +13,7 @@ contract Test { use dep::aztec::protocol_types::{ abis::private_circuit_public_inputs::PrivateCircuitPublicInputs, constants::{MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, CANONICAL_KEY_REGISTRY_ADDRESS}, - traits::{Serialize, ToField, FromField}, point::Point, grumpkin_private_key::GrumpkinPrivateKey, + traits::{Serialize, ToField, FromField}, point::Point, embedded_curve_scalar::EmbeddedCurveScalar, storage::map::derive_storage_slot_in_map }; @@ -404,14 +404,14 @@ contract Test { } #[aztec(private)] - fn compute_note_header_ciphertext(secret: GrumpkinPrivateKey, point: Point) -> [u8; 48] { + fn compute_note_header_ciphertext(secret: EmbeddedCurveScalar, point: Point) -> [u8; 48] { EncryptedLogHeader::new(context.this_address()).compute_ciphertext(secret, point) } // 64 bytes + 32 * #fields + 16 = 112 bytes #[aztec(private)] fn compute_incoming_log_body_ciphertext( - secret: GrumpkinPrivateKey, + secret: EmbeddedCurveScalar, point: Point, storage_slot: Field, value: Field @@ -422,10 +422,10 @@ contract Test { #[aztec(private)] fn compute_outgoing_log_body_ciphertext( - eph_sk: GrumpkinPrivateKey, + eph_sk: EmbeddedCurveScalar, recipient: AztecAddress, recipient_ivpk_app: Point, - ovsk_app: GrumpkinPrivateKey + ovsk_app: EmbeddedCurveScalar ) -> [u8; 176] { let eph_pk = eph_sk.derive_public_key(); EncryptedLogOutgoingBody::new(eph_sk, recipient, recipient_ivpk_app).compute_ciphertext(ovsk_app, eph_pk) diff --git a/noir-projects/noir-contracts/contracts/test_log_contract/src/main.nr b/noir-projects/noir-contracts/contracts/test_log_contract/src/main.nr index fb0bef304c91..168c9a3692ba 100644 --- a/noir-projects/noir-contracts/contracts/test_log_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/test_log_contract/src/main.nr @@ -1,6 +1,6 @@ contract TestLog { use dep::aztec::prelude::PrivateSet; - use dep::aztec::protocol_types::{traits::Serialize, point::Point, grumpkin_private_key::GrumpkinPrivateKey, address::AztecAddress}; + use dep::aztec::protocol_types::{traits::Serialize, point::Point, embedded_curve_scalar::EmbeddedCurveScalar, address::AztecAddress}; use dep::value_note::value_note::ValueNote; use dep::aztec::encrypted_logs::incoming_body::EncryptedLogIncomingBody; use dep::aztec::event::event_interface::EventInterface; @@ -29,7 +29,7 @@ contract TestLog { #[aztec(private)] fn compute_incoming_log_body_ciphertext( - secret: GrumpkinPrivateKey, + secret: EmbeddedCurveScalar, point: Point, randomness: Field, event_type_id: Field, diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_reset.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_reset.nr index 93bf2ab22e72..2bca8d9265b0 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_reset.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_reset.nr @@ -113,7 +113,7 @@ mod tests { max_block_number::MaxBlockNumber, note_hash::{NoteHash, ScopedNoteHash}, nullifier::{Nullifier, ScopedNullifier}, log_hash::NoteLogHash, read_request::ScopedReadRequest }, - address::AztecAddress, grumpkin_private_key::GrumpkinPrivateKey, + address::AztecAddress, embedded_curve_scalar::EmbeddedCurveScalar, tests::{fixture_builder::FixtureBuilder}, utils::{arrays::{array_eq, array_length}}, traits::{Empty, is_empty, is_empty_array}, point::Point }; diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail.nr index 01bd8a0e14ef..b5147b3c6830 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail.nr @@ -61,7 +61,7 @@ mod tests { kernel_circuit_public_inputs::KernelCircuitPublicInputs, max_block_number::MaxBlockNumber, note_hash::{NoteHash, ScopedNoteHash}, nullifier::{Nullifier, ScopedNullifier}, gas::Gas }, - address::{AztecAddress, EthAddress}, grumpkin_private_key::GrumpkinPrivateKey, + address::{AztecAddress, EthAddress}, embedded_curve_scalar::EmbeddedCurveScalar, hash::{ sha256_to_field, silo_note_hash, silo_nullifier, compute_siloed_encrypted_log_hash, compute_siloed_unencrypted_log_hash diff --git a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/private_validation_request_processor.nr b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/private_validation_request_processor.nr index 94500890172d..e120ef8773d0 100644 --- a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/private_validation_request_processor.nr +++ b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/private_validation_request_processor.nr @@ -13,7 +13,7 @@ use dep::types::{ MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, MAX_KEY_VALIDATION_REQUESTS_PER_TX, GENERATOR_INDEX__NSK_M, MAX_NOTE_HASH_READ_REQUESTS_PER_TX, MAX_NULLIFIER_READ_REQUESTS_PER_TX }, - grumpkin_private_key::GrumpkinPrivateKey, hash::poseidon2_hash, traits::is_empty, + embedded_curve_scalar::EmbeddedCurveScalar, hash::poseidon2_hash, traits::is_empty, utils::arrays::filter_array_to_bounded_vec }; diff --git a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/reset/key_validation_hint.nr b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/reset/key_validation_hint.nr index d64b0816dded..403efefda12f 100644 --- a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/reset/key_validation_hint.nr +++ b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/reset/key_validation_hint.nr @@ -1,18 +1,18 @@ use dep::types::{ traits::{Empty, is_empty}, abis::{validation_requests::ScopedKeyValidationRequestAndGenerator}, - constants::MAX_KEY_VALIDATION_REQUESTS_PER_TX, grumpkin_private_key::GrumpkinPrivateKey, + constants::MAX_KEY_VALIDATION_REQUESTS_PER_TX, embedded_curve_scalar::EmbeddedCurveScalar, hash::poseidon2_hash, utils::arrays::filter_array_to_bounded_vec }; struct KeyValidationHint { - sk_m: GrumpkinPrivateKey, + sk_m: EmbeddedCurveScalar, request_index: u64, } impl Empty for KeyValidationHint { fn empty() -> Self { KeyValidationHint { - sk_m: GrumpkinPrivateKey::empty(), + sk_m: EmbeddedCurveScalar::empty(), request_index: 0, } } @@ -51,7 +51,7 @@ pub fn reset_key_validation_requests( // Then we check that siloing the master secret key with the contract address gives the app secret key - let sk_app = poseidon2_hash([sk_m.high, sk_m.low, contract_address.to_field(), sk_app_generator]); + let sk_app = poseidon2_hash([sk_m.hi, sk_m.lo, contract_address.to_field(), sk_app_generator]); assert( sk_app.eq(request.sk_app), "Failed to derive matching app secret key from the secret key." ); diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/embedded_curve_scalar.nr b/noir-projects/noir-protocol-circuits/crates/types/src/embedded_curve_scalar.nr new file mode 100644 index 000000000000..ca639b5d9a11 --- /dev/null +++ b/noir-projects/noir-protocol-circuits/crates/types/src/embedded_curve_scalar.nr @@ -0,0 +1,8 @@ +use dep::std::embedded_curve_ops::EmbeddedCurveScalar; +use crate::{embedded_curve_point::EmbeddedCurvePoint, traits::Empty}; + +impl Empty for EmbeddedCurveScalar { + fn empty() -> Self { + Self { hi: 0, lo: 0 } + } +} \ No newline at end of file diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/grumpkin_private_key.nr b/noir-projects/noir-protocol-circuits/crates/types/src/grumpkin_private_key.nr deleted file mode 100644 index 03db72a48040..000000000000 --- a/noir-projects/noir-protocol-circuits/crates/types/src/grumpkin_private_key.nr +++ /dev/null @@ -1,44 +0,0 @@ -use std::{cmp::Eq, embedded_curve_ops::fixed_base_scalar_mul}; -use crate::{point::Point, traits::Empty}; - -global GRUMPKIN_PRIVATE_KEY_SERIALIZED_LEN: Field = 2; - -struct GrumpkinPrivateKey { - high: Field, - low: Field, -} - -impl Eq for GrumpkinPrivateKey { - fn eq(self, key: GrumpkinPrivateKey) -> bool { - (key.high == self.high) & (key.low == self.low) - } -} - -impl Empty for GrumpkinPrivateKey { - fn empty() -> Self { - Self { high: 0, low: 0 } - } -} - -impl GrumpkinPrivateKey { - pub fn new(high: Field, low: Field) -> Self { - GrumpkinPrivateKey { high, low } - } - - pub fn zero() -> Self { - Self { high: 0, low: 0 } - } - - pub fn is_zero(self) -> bool { - (self.high == 0) & (self.low == 0) - } - - pub fn serialize(self) -> [Field; GRUMPKIN_PRIVATE_KEY_SERIALIZED_LEN] { - [self.high, self.low] - } - - pub fn derive_public_key(self) -> Point { - let public_key = fixed_base_scalar_mul(self.low, self.high); - Point { x: public_key[0], y: public_key[1], is_infinite: public_key[2] as bool } - } -} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/lib.nr b/noir-projects/noir-protocol-circuits/crates/types/src/lib.nr index f602d0b6abdc..4f76655f4acc 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/lib.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/lib.nr @@ -2,7 +2,7 @@ mod utils; mod address; mod debug_log; mod point; -mod grumpkin_private_key; +mod embedded_curve_scalar; // This is intentionally spelled like this // since contract is a reserved keyword, so it cannot // be used as an ident. diff --git a/noir/noir-repo/noir_stdlib/src/embedded_curve_ops.nr b/noir/noir-repo/noir_stdlib/src/embedded_curve_ops.nr index cef2088fe108..e43f82760a3c 100644 --- a/noir/noir-repo/noir_stdlib/src/embedded_curve_ops.nr +++ b/noir/noir-repo/noir_stdlib/src/embedded_curve_ops.nr @@ -56,6 +56,15 @@ struct EmbeddedCurveScalar { } impl EmbeddedCurveScalar { + pub fn new(hi: Field, lo: Field) -> Self { + EmbeddedCurveScalar { hi, lo } + } + + pub fn derive_public_key(self) -> EmbeddedCurvePoint { + let public_key = fixed_base_scalar_mul(self.lo, self.hi); + EmbeddedCurvePoint { x: public_key[0], y: public_key[1], is_infinite: false } + } + #[field(bn254)] fn from_field(scalar: Field) -> EmbeddedCurveScalar { let (a,b) = crate::field::bn254::decompose(scalar); @@ -63,6 +72,12 @@ impl EmbeddedCurveScalar { } } +impl Eq for EmbeddedCurveScalar { + fn eq(self, key: EmbeddedCurveScalar) -> bool { + (key.hi == self.hi) & (key.lo == self.lo) + } +} + // Computes a multi scalar multiplication over the embedded curve. // For bn254, We have Grumpkin and Baby JubJub. // For bls12-381, we have JubJub and Bandersnatch. diff --git a/yarn-project/accounts/README.md b/yarn-project/accounts/README.md index 96afcdc10d54..9a4c2d159726 100644 --- a/yarn-project/accounts/README.md +++ b/yarn-project/accounts/README.md @@ -20,10 +20,10 @@ npm install @aztec/accounts ```typescript import { getSchnorrAccount } from '@aztec/accounts/schnorr'; -import { GrumpkinPrivateKey } from '@aztec/circuit-types'; +import { EmbeddedCurveScalar } from '@aztec/circuit-types'; -const encryptionPrivateKey = GrumpkinPrivateKey.random(); -const signingPrivateKey = GrumpkinPrivateKey.random(); +const encryptionPrivateKey = EmbeddedCurveScalar.random(); +const signingPrivateKey = EmbeddedCurveScalar.random(); const wallet = getSchnorrAccount(pxe, encryptionPrivateKey, signingPrivateKey).waitDeploy(); console.log(`New account deployed at ${wallet.getAddress()}`); ``` diff --git a/yarn-project/accounts/src/schnorr/account_contract.ts b/yarn-project/accounts/src/schnorr/account_contract.ts index cac79664b28d..9f1f0b921498 100644 --- a/yarn-project/accounts/src/schnorr/account_contract.ts +++ b/yarn-project/accounts/src/schnorr/account_contract.ts @@ -1,5 +1,5 @@ import { type AuthWitnessProvider } from '@aztec/aztec.js/account'; -import { AuthWitness, type CompleteAddress, type GrumpkinPrivateKey } from '@aztec/circuit-types'; +import { AuthWitness, type CompleteAddress, type EmbeddedCurveScalar } from '@aztec/circuit-types'; import { Schnorr } from '@aztec/circuits.js/barretenberg'; import { type ContractArtifact } from '@aztec/foundation/abi'; import { type Fr } from '@aztec/foundation/fields'; @@ -12,7 +12,7 @@ import { SchnorrAccountContractArtifact } from './artifact.js'; * verified against a Grumpkin public key stored in an immutable encrypted note. */ export class SchnorrAccountContract extends DefaultAccountContract { - constructor(private signingPrivateKey: GrumpkinPrivateKey) { + constructor(private signingPrivateKey: EmbeddedCurveScalar) { super(SchnorrAccountContractArtifact as ContractArtifact); } @@ -28,7 +28,7 @@ export class SchnorrAccountContract extends DefaultAccountContract { /** Creates auth witnesses using Schnorr signatures. */ class SchnorrAuthWitnessProvider implements AuthWitnessProvider { - constructor(private signingPrivateKey: GrumpkinPrivateKey) {} + constructor(private signingPrivateKey: EmbeddedCurveScalar) {} createAuthWit(messageHash: Fr): Promise { const schnorr = new Schnorr(); diff --git a/yarn-project/accounts/src/schnorr/index.ts b/yarn-project/accounts/src/schnorr/index.ts index 1053606041bf..de8fb49b2f7f 100644 --- a/yarn-project/accounts/src/schnorr/index.ts +++ b/yarn-project/accounts/src/schnorr/index.ts @@ -6,7 +6,7 @@ */ import { AccountManager, type Salt } from '@aztec/aztec.js/account'; import { type AccountWallet, getWallet } from '@aztec/aztec.js/wallet'; -import { type GrumpkinPrivateKey, type PXE } from '@aztec/circuit-types'; +import { type EmbeddedCurveScalar, type PXE } from '@aztec/circuit-types'; import { type AztecAddress, type Fr } from '@aztec/circuits.js'; import { SchnorrAccountContract } from './account_contract.js'; @@ -25,7 +25,7 @@ export { SchnorrAccountContractArtifact } from './artifact.js'; export function getSchnorrAccount( pxe: PXE, secretKey: Fr, - signingPrivateKey: GrumpkinPrivateKey, + signingPrivateKey: EmbeddedCurveScalar, salt?: Salt, ): AccountManager { return new AccountManager(pxe, secretKey, new SchnorrAccountContract(signingPrivateKey), salt); @@ -41,7 +41,7 @@ export function getSchnorrAccount( export function getSchnorrWallet( pxe: PXE, address: AztecAddress, - signingPrivateKey: GrumpkinPrivateKey, + signingPrivateKey: EmbeddedCurveScalar, ): Promise { return getWallet(pxe, address, new SchnorrAccountContract(signingPrivateKey)); } diff --git a/yarn-project/accounts/src/single_key/account_contract.ts b/yarn-project/accounts/src/single_key/account_contract.ts index 1e0443a7724b..68f282a8cf81 100644 --- a/yarn-project/accounts/src/single_key/account_contract.ts +++ b/yarn-project/accounts/src/single_key/account_contract.ts @@ -1,5 +1,5 @@ import { type AuthWitnessProvider } from '@aztec/aztec.js/account'; -import { AuthWitness, type CompleteAddress, type GrumpkinPrivateKey } from '@aztec/circuit-types'; +import { AuthWitness, type CompleteAddress, type EmbeddedCurveScalar } from '@aztec/circuit-types'; import { Schnorr } from '@aztec/circuits.js/barretenberg'; import { type ContractArtifact } from '@aztec/foundation/abi'; import { type Fr } from '@aztec/foundation/fields'; @@ -12,7 +12,7 @@ import { SchnorrSingleKeyAccountContractArtifact } from './artifact.js'; * the note encryption key, relying on a single private key for both encryption and authentication. */ export class SingleKeyAccountContract extends DefaultAccountContract { - constructor(private encryptionPrivateKey: GrumpkinPrivateKey) { + constructor(private encryptionPrivateKey: EmbeddedCurveScalar) { super(SchnorrSingleKeyAccountContractArtifact as ContractArtifact); } @@ -31,7 +31,7 @@ export class SingleKeyAccountContract extends DefaultAccountContract { * by reconstructing the current address. */ class SingleKeyAuthWitnessProvider implements AuthWitnessProvider { - constructor(private privateKey: GrumpkinPrivateKey, private account: CompleteAddress) {} + constructor(private privateKey: EmbeddedCurveScalar, private account: CompleteAddress) {} createAuthWit(messageHash: Fr): Promise { const schnorr = new Schnorr(); diff --git a/yarn-project/accounts/src/single_key/index.ts b/yarn-project/accounts/src/single_key/index.ts index 72bb8d7c1de2..11584f94878b 100644 --- a/yarn-project/accounts/src/single_key/index.ts +++ b/yarn-project/accounts/src/single_key/index.ts @@ -6,7 +6,7 @@ */ import { AccountManager, type Salt } from '@aztec/aztec.js/account'; import { type AccountWallet, getWallet } from '@aztec/aztec.js/wallet'; -import { type GrumpkinPrivateKey, type PXE } from '@aztec/circuit-types'; +import { type EmbeddedCurveScalar, type PXE } from '@aztec/circuit-types'; import { type AztecAddress, type Fr, deriveMasterIncomingViewingSecretKey } from '@aztec/circuits.js'; import { SingleKeyAccountContract } from './account_contract.js'; @@ -36,7 +36,7 @@ export function getSingleKeyAccount(pxe: PXE, secretKey: Fr, salt?: Salt): Accou export function getSingleKeyWallet( pxe: PXE, address: AztecAddress, - signingKey: GrumpkinPrivateKey, + signingKey: EmbeddedCurveScalar, ): Promise { return getWallet(pxe, address, new SingleKeyAccountContract(signingKey)); } diff --git a/yarn-project/aztec.js/src/index.ts b/yarn-project/aztec.js/src/index.ts index 38cf7e986bce..22d56dacc6bc 100644 --- a/yarn-project/aztec.js/src/index.ts +++ b/yarn-project/aztec.js/src/index.ts @@ -102,7 +102,7 @@ export { EventType, ExtendedNote, FunctionCall, - GrumpkinPrivateKey, + EmbeddedCurveScalar, L1Actor, L1ToL2Message, L2Actor, diff --git a/yarn-project/aztec.js/src/utils/pub_key.ts b/yarn-project/aztec.js/src/utils/pub_key.ts index 85009e302d3a..4a05fa3e364a 100644 --- a/yarn-project/aztec.js/src/utils/pub_key.ts +++ b/yarn-project/aztec.js/src/utils/pub_key.ts @@ -1,4 +1,4 @@ -import { type GrumpkinPrivateKey, type PublicKey } from '@aztec/circuits.js'; +import { type EmbeddedCurveScalar, type PublicKey } from '@aztec/circuits.js'; import { Grumpkin } from '@aztec/circuits.js/barretenberg'; /** @@ -6,7 +6,7 @@ import { Grumpkin } from '@aztec/circuits.js/barretenberg'; * @param privateKey - The private key. * @returns The generated public key. */ -export function generatePublicKey(privateKey: GrumpkinPrivateKey): PublicKey { +export function generatePublicKey(privateKey: EmbeddedCurveScalar): PublicKey { const grumpkin = new Grumpkin(); return grumpkin.mul(grumpkin.generator(), privateKey); } diff --git a/yarn-project/circuit-types/src/index.ts b/yarn-project/circuit-types/src/index.ts index 43672170f4da..b8ecd004c818 100644 --- a/yarn-project/circuit-types/src/index.ts +++ b/yarn-project/circuit-types/src/index.ts @@ -1,4 +1,4 @@ -export { CompleteAddress, GrumpkinPrivateKey, type PartialAddress, type PublicKey } from '@aztec/circuits.js'; +export { CompleteAddress, EmbeddedCurveScalar, type PartialAddress, type PublicKey } from '@aztec/circuits.js'; export * from './auth_witness.js'; export * from './aztec_node/rpc/index.js'; export * from './body.js'; diff --git a/yarn-project/circuit-types/src/logs/l1_payload/encrypt_buffer.ts b/yarn-project/circuit-types/src/logs/l1_payload/encrypt_buffer.ts index 738c9efff9bf..b3a87d96841c 100644 --- a/yarn-project/circuit-types/src/logs/l1_payload/encrypt_buffer.ts +++ b/yarn-project/circuit-types/src/logs/l1_payload/encrypt_buffer.ts @@ -1,4 +1,4 @@ -import { type GrumpkinPrivateKey, type PublicKey } from '@aztec/circuits.js'; +import { type EmbeddedCurveScalar, type PublicKey } from '@aztec/circuits.js'; import { Grumpkin } from '@aztec/circuits.js/barretenberg'; import { Point } from '@aztec/foundation/fields'; @@ -19,7 +19,7 @@ import { deriveAESSecret } from './encryption_utils.js'; */ export function encryptBuffer( data: Buffer, - ephSecretKey: GrumpkinPrivateKey, + ephSecretKey: EmbeddedCurveScalar, incomingViewingPublicKey: PublicKey, ): Buffer { const aesSecret = deriveAESSecret(ephSecretKey, incomingViewingPublicKey); @@ -40,7 +40,7 @@ export function encryptBuffer( * @param incomingViewingSecretKey - The secret key used for decryption. * @returns The decrypted plaintext as a Buffer or undefined if decryption fails. */ -export function decryptBuffer(data: Buffer, incomingViewingSecretKey: GrumpkinPrivateKey): Buffer | undefined { +export function decryptBuffer(data: Buffer, incomingViewingSecretKey: EmbeddedCurveScalar): Buffer | undefined { // Extract the ephemeral public key from the end of the data const ephPubKey = Point.fromBuffer(data.subarray(-Point.SIZE_IN_BYTES)); // Derive the AES secret key using the secret key and the ephemeral public key diff --git a/yarn-project/circuit-types/src/logs/l1_payload/encrypted_log_header.ts b/yarn-project/circuit-types/src/logs/l1_payload/encrypted_log_header.ts index ac19b40cc3c8..1fcd2008964f 100644 --- a/yarn-project/circuit-types/src/logs/l1_payload/encrypted_log_header.ts +++ b/yarn-project/circuit-types/src/logs/l1_payload/encrypted_log_header.ts @@ -1,4 +1,4 @@ -import { AztecAddress, type GrumpkinPrivateKey, type PublicKey } from '@aztec/circuits.js'; +import { AztecAddress, type EmbeddedCurveScalar, type PublicKey } from '@aztec/circuits.js'; import { Aes128 } from '@aztec/circuits.js/barretenberg'; import { deriveAESSecret } from './encryption_utils.js'; @@ -34,7 +34,7 @@ export class EncryptedLogHeader { * @param publicKey - The incoming or outgoing viewing key of the "recipient" of this log * @returns The ciphertext of the encrypted log header */ - public computeCiphertext(secret: GrumpkinPrivateKey, publicKey: PublicKey) { + public computeCiphertext(secret: EmbeddedCurveScalar, publicKey: PublicKey) { const aesSecret = deriveAESSecret(secret, publicKey); const key = aesSecret.subarray(0, 16); const iv = aesSecret.subarray(16, 32); @@ -54,7 +54,7 @@ export class EncryptedLogHeader { */ public static fromCiphertext( ciphertext: Buffer | bigint[], - secret: GrumpkinPrivateKey, + secret: EmbeddedCurveScalar, publicKey: PublicKey, ): EncryptedLogHeader { const input = Buffer.isBuffer(ciphertext) ? ciphertext : Buffer.from(ciphertext.map((x: bigint) => Number(x))); diff --git a/yarn-project/circuit-types/src/logs/l1_payload/encrypted_log_incoming_body/encrypted_event_log_incoming_body.ts b/yarn-project/circuit-types/src/logs/l1_payload/encrypted_log_incoming_body/encrypted_event_log_incoming_body.ts index 077e56490b04..18d04350800a 100644 --- a/yarn-project/circuit-types/src/logs/l1_payload/encrypted_log_incoming_body/encrypted_event_log_incoming_body.ts +++ b/yarn-project/circuit-types/src/logs/l1_payload/encrypted_log_incoming_body/encrypted_event_log_incoming_body.ts @@ -1,4 +1,4 @@ -import { Fr, type GrumpkinPrivateKey, type PublicKey } from '@aztec/circuits.js'; +import { Fr, type EmbeddedCurveScalar, type PublicKey } from '@aztec/circuits.js'; import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize'; import { Event } from '../payload.js'; @@ -51,7 +51,7 @@ export class EncryptedEventLogIncomingBody extends EncryptedLogIncomingBody { */ public static fromCiphertext( ciphertext: Buffer | bigint[], - ivskAppOrEphSk: GrumpkinPrivateKey, + ivskAppOrEphSk: EmbeddedCurveScalar, ephPkOrIvpkApp: PublicKey, ): EncryptedEventLogIncomingBody { const buffer = super.fromCiphertextToBuffer(ciphertext, ivskAppOrEphSk, ephPkOrIvpkApp); diff --git a/yarn-project/circuit-types/src/logs/l1_payload/encrypted_log_incoming_body/encrypted_log_incoming_body.ts b/yarn-project/circuit-types/src/logs/l1_payload/encrypted_log_incoming_body/encrypted_log_incoming_body.ts index 6a8b5566e4f1..488dcdecf424 100644 --- a/yarn-project/circuit-types/src/logs/l1_payload/encrypted_log_incoming_body/encrypted_log_incoming_body.ts +++ b/yarn-project/circuit-types/src/logs/l1_payload/encrypted_log_incoming_body/encrypted_log_incoming_body.ts @@ -1,4 +1,4 @@ -import { type GrumpkinPrivateKey, type PublicKey } from '@aztec/circuits.js'; +import { type EmbeddedCurveScalar, type PublicKey } from '@aztec/circuits.js'; import { Aes128 } from '@aztec/circuits.js/barretenberg'; import { deriveAESSecret } from '../encryption_utils.js'; @@ -20,7 +20,7 @@ export abstract class EncryptedLogIncomingBody { */ protected static fromCiphertextToBuffer( ciphertext: Buffer | bigint[], - ivskAppOrEphSk: GrumpkinPrivateKey, + ivskAppOrEphSk: EmbeddedCurveScalar, ephPkOrIvpkApp: PublicKey, ): Buffer { const input = Buffer.isBuffer(ciphertext) ? ciphertext : Buffer.from(ciphertext.map((x: bigint) => Number(x))); @@ -41,7 +41,7 @@ export abstract class EncryptedLogIncomingBody { * * @returns The ciphertext of the encrypted log body */ - public computeCiphertext(ephSk: GrumpkinPrivateKey, ivpkApp: PublicKey) { + public computeCiphertext(ephSk: EmbeddedCurveScalar, ivpkApp: PublicKey) { const aesSecret = deriveAESSecret(ephSk, ivpkApp); const key = aesSecret.subarray(0, 16); const iv = aesSecret.subarray(16, 32); diff --git a/yarn-project/circuit-types/src/logs/l1_payload/encrypted_log_incoming_body/encrypted_note_log_incoming_body.ts b/yarn-project/circuit-types/src/logs/l1_payload/encrypted_log_incoming_body/encrypted_note_log_incoming_body.ts index 2edaba57db46..6e991bb21a8b 100644 --- a/yarn-project/circuit-types/src/logs/l1_payload/encrypted_log_incoming_body/encrypted_note_log_incoming_body.ts +++ b/yarn-project/circuit-types/src/logs/l1_payload/encrypted_log_incoming_body/encrypted_note_log_incoming_body.ts @@ -1,4 +1,4 @@ -import { Fr, type GrumpkinPrivateKey, type PublicKey } from '@aztec/circuits.js'; +import { Fr, type EmbeddedCurveScalar, type PublicKey } from '@aztec/circuits.js'; import { NoteSelector } from '@aztec/foundation/abi'; import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize'; @@ -53,7 +53,7 @@ export class EncryptedNoteLogIncomingBody extends EncryptedLogIncomingBody { */ public static fromCiphertext( ciphertext: Buffer | bigint[], - ivskAppOrEphSk: GrumpkinPrivateKey, + ivskAppOrEphSk: EmbeddedCurveScalar, ephPkOrIvpkApp: PublicKey, ): EncryptedNoteLogIncomingBody { const buffer = super.fromCiphertextToBuffer(ciphertext, ivskAppOrEphSk, ephPkOrIvpkApp); diff --git a/yarn-project/circuit-types/src/logs/l1_payload/encrypted_log_outgoing_body.ts b/yarn-project/circuit-types/src/logs/l1_payload/encrypted_log_outgoing_body.ts index bba788dfe52d..402e64d0b469 100644 --- a/yarn-project/circuit-types/src/logs/l1_payload/encrypted_log_outgoing_body.ts +++ b/yarn-project/circuit-types/src/logs/l1_payload/encrypted_log_outgoing_body.ts @@ -1,10 +1,10 @@ -import { AztecAddress, Fr, GeneratorIndex, GrumpkinPrivateKey, Point, type PublicKey } from '@aztec/circuits.js'; +import { AztecAddress, Fr, GeneratorIndex, EmbeddedCurveScalar, Point, type PublicKey } from '@aztec/circuits.js'; import { Aes128 } from '@aztec/circuits.js/barretenberg'; import { poseidon2Hash } from '@aztec/foundation/crypto'; import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize'; export class EncryptedLogOutgoingBody { - constructor(public ephSk: GrumpkinPrivateKey, public recipient: AztecAddress, public recipientIvpkApp: PublicKey) {} + constructor(public ephSk: EmbeddedCurveScalar, public recipient: AztecAddress, public recipientIvpkApp: PublicKey) {} /** * Serializes the log body @@ -27,7 +27,7 @@ export class EncryptedLogOutgoingBody { const reader = BufferReader.asReader(buf); const high = reader.readObject(Fr); const low = reader.readObject(Fr); - const ephSk = GrumpkinPrivateKey.fromHighLow(high, low); + const ephSk = EmbeddedCurveScalar.fromHighLow(high, low); const recipient = reader.readObject(AztecAddress); const recipientIvpkApp = reader.readObject(Point); // PublicKey = Point @@ -42,7 +42,7 @@ export class EncryptedLogOutgoingBody { * * @returns The ciphertext of the encrypted log body */ - public computeCiphertext(ovskApp: GrumpkinPrivateKey, ephPk: PublicKey) { + public computeCiphertext(ovskApp: EmbeddedCurveScalar, ephPk: PublicKey) { // We could use `ephSk` and compute `ephPk` from it. // We mainly provide it to keep the same api and potentially slight optimization as we can reuse it. @@ -68,7 +68,7 @@ export class EncryptedLogOutgoingBody { */ public static fromCiphertext( ciphertext: Buffer | bigint[], - ovskApp: GrumpkinPrivateKey, + ovskApp: EmbeddedCurveScalar, ephPk: PublicKey, ): EncryptedLogOutgoingBody { const input = Buffer.isBuffer(ciphertext) ? ciphertext : Buffer.from(ciphertext.map((x: bigint) => Number(x))); @@ -91,7 +91,7 @@ export class EncryptedLogOutgoingBody { * @param ephPk - The ephemeral public key * @returns The derived AES symmetric key */ - private static derivePoseidonAESSecret(ovskApp: GrumpkinPrivateKey, ephPk: PublicKey) { + private static derivePoseidonAESSecret(ovskApp: EmbeddedCurveScalar, ephPk: PublicKey) { // For performance reasons, we do NOT use the usual `deriveAESSecret` function here and instead we compute it using // poseidon. Note that we can afford to use poseidon here instead of deriving shared secret using Diffie-Hellman // because for outgoing we are encrypting for ourselves and hence we don't need to perform a key exchange. diff --git a/yarn-project/circuit-types/src/logs/l1_payload/encryption_utils.ts b/yarn-project/circuit-types/src/logs/l1_payload/encryption_utils.ts index 202c7e22e922..6d0b5f085a64 100644 --- a/yarn-project/circuit-types/src/logs/l1_payload/encryption_utils.ts +++ b/yarn-project/circuit-types/src/logs/l1_payload/encryption_utils.ts @@ -1,4 +1,4 @@ -import { GeneratorIndex, type GrumpkinPrivateKey, type PublicKey } from '@aztec/circuits.js'; +import { GeneratorIndex, type EmbeddedCurveScalar, type PublicKey } from '@aztec/circuits.js'; import { Grumpkin } from '@aztec/circuits.js/barretenberg'; import { sha256 } from '@aztec/foundation/crypto'; import { numToUInt8 } from '@aztec/foundation/serialize'; @@ -16,7 +16,7 @@ import { numToUInt8 } from '@aztec/foundation/serialize'; * TODO(#5726): This function is called point_to_symmetric_key in Noir. I don't like that name much since point is not * the only input of the function. Unify naming once we have a better name. */ -export function deriveAESSecret(secretKey: GrumpkinPrivateKey, publicKey: PublicKey): Buffer { +export function deriveAESSecret(secretKey: EmbeddedCurveScalar, publicKey: PublicKey): Buffer { if (publicKey.isZero()) { throw new Error( `Attempting to derive AES secret with a zero public key. You have probably passed a zero public key in your Noir code somewhere thinking that the note won't broadcasted... but it was.`, diff --git a/yarn-project/circuit-types/src/logs/l1_payload/l1_event_payload.ts b/yarn-project/circuit-types/src/logs/l1_payload/l1_event_payload.ts index 741a0128475d..4a5e475f0342 100644 --- a/yarn-project/circuit-types/src/logs/l1_payload/l1_event_payload.ts +++ b/yarn-project/circuit-types/src/logs/l1_payload/l1_event_payload.ts @@ -1,4 +1,4 @@ -import { AztecAddress, type GrumpkinPrivateKey, type KeyValidationRequest, type PublicKey } from '@aztec/circuits.js'; +import { AztecAddress, type EmbeddedCurveScalar, type KeyValidationRequest, type PublicKey } from '@aztec/circuits.js'; import { EventSelector } from '@aztec/foundation/abi'; import { Fr } from '@aztec/foundation/fields'; import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize'; @@ -64,7 +64,7 @@ export class L1EventPayload extends L1Payload { return new L1EventPayload(Event.random(), AztecAddress.random(), Fr.random(), EventSelector.random()); } - public encrypt(ephSk: GrumpkinPrivateKey, recipient: AztecAddress, ivpk: PublicKey, ovKeys: KeyValidationRequest) { + public encrypt(ephSk: EmbeddedCurveScalar, recipient: AztecAddress, ivpk: PublicKey, ovKeys: KeyValidationRequest) { return super._encrypt( this.contractAddress, ephSk, @@ -88,7 +88,7 @@ export class L1EventPayload extends L1Payload { * @returns The decrypted log payload * @remarks The encrypted log is assumed to always have tags. */ - public static decryptAsIncoming(encryptedLog: EncryptedL2Log, ivsk: GrumpkinPrivateKey) { + public static decryptAsIncoming(encryptedLog: EncryptedL2Log, ivsk: EmbeddedCurveScalar) { const reader = BufferReader.asReader(encryptedLog.data); // We skip the tags @@ -123,7 +123,7 @@ export class L1EventPayload extends L1Payload { * @param ovsk - The outgoing viewing secret key, used to decrypt the logs * @returns The decrypted log payload */ - public static decryptAsOutgoing(encryptedLog: EncryptedL2Log, ovsk: GrumpkinPrivateKey) { + public static decryptAsOutgoing(encryptedLog: EncryptedL2Log, ovsk: EmbeddedCurveScalar) { const reader = BufferReader.asReader(encryptedLog.data); // Skip the tags diff --git a/yarn-project/circuit-types/src/logs/l1_payload/l1_note_payload.ts b/yarn-project/circuit-types/src/logs/l1_payload/l1_note_payload.ts index b0dadca6ffe2..cf981ac28443 100644 --- a/yarn-project/circuit-types/src/logs/l1_payload/l1_note_payload.ts +++ b/yarn-project/circuit-types/src/logs/l1_payload/l1_note_payload.ts @@ -1,4 +1,4 @@ -import { AztecAddress, type GrumpkinPrivateKey, type KeyValidationRequest, type PublicKey } from '@aztec/circuits.js'; +import { AztecAddress, type EmbeddedCurveScalar, type KeyValidationRequest, type PublicKey } from '@aztec/circuits.js'; import { NoteSelector } from '@aztec/foundation/abi'; import { Fr } from '@aztec/foundation/fields'; import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize'; @@ -66,7 +66,7 @@ export class L1NotePayload extends L1Payload { return new L1NotePayload(Note.random(), contract, Fr.random(), NoteSelector.random()); } - public encrypt(ephSk: GrumpkinPrivateKey, recipient: AztecAddress, ivpk: PublicKey, ovKeys: KeyValidationRequest) { + public encrypt(ephSk: EmbeddedCurveScalar, recipient: AztecAddress, ivpk: PublicKey, ovKeys: KeyValidationRequest) { return super._encrypt( this.contractAddress, ephSk, @@ -89,7 +89,7 @@ export class L1NotePayload extends L1Payload { * @param ivsk - The incoming viewing secret key, used to decrypt the logs * @returns The decrypted log payload */ - public static decryptAsIncoming(ciphertext: Buffer | bigint[], ivsk: GrumpkinPrivateKey) { + public static decryptAsIncoming(ciphertext: Buffer | bigint[], ivsk: EmbeddedCurveScalar) { const input = Buffer.isBuffer(ciphertext) ? ciphertext : Buffer.from(ciphertext.map((x: bigint) => Number(x))); const reader = BufferReader.asReader(input); @@ -115,7 +115,7 @@ export class L1NotePayload extends L1Payload { * @param ovsk - The outgoing viewing secret key, used to decrypt the logs * @returns The decrypted log payload */ - public static decryptAsOutgoing(ciphertext: Buffer | bigint[], ovsk: GrumpkinPrivateKey) { + public static decryptAsOutgoing(ciphertext: Buffer | bigint[], ovsk: EmbeddedCurveScalar) { const input = Buffer.isBuffer(ciphertext) ? ciphertext : Buffer.from(ciphertext.map((x: bigint) => Number(x))); const reader = BufferReader.asReader(input); diff --git a/yarn-project/circuit-types/src/logs/l1_payload/l1_payload.ts b/yarn-project/circuit-types/src/logs/l1_payload/l1_payload.ts index 4e6b026840a1..045b8cf59e46 100644 --- a/yarn-project/circuit-types/src/logs/l1_payload/l1_payload.ts +++ b/yarn-project/circuit-types/src/logs/l1_payload/l1_payload.ts @@ -1,6 +1,6 @@ import { type AztecAddress, - type GrumpkinPrivateKey, + type EmbeddedCurveScalar, type KeyValidationRequest, type PublicKey, computeIvpkApp, @@ -47,7 +47,7 @@ export abstract class L1Payload { */ protected _encrypt( contractAddress: AztecAddress, - ephSk: GrumpkinPrivateKey, + ephSk: EmbeddedCurveScalar, recipient: AztecAddress, ivpk: PublicKey, ovKeys: KeyValidationRequest, @@ -69,7 +69,7 @@ export abstract class L1Payload { const incomingBodyCiphertext = incomingBody.computeCiphertext(ephSk, ivpkApp); const outgoingBodyCiphertext = new EncryptedLogOutgoingBody(ephSk, recipient, ivpkApp).computeCiphertext( - ovKeys.skAppAsGrumpkinPrivateKey, + ovKeys.skAppAsEmbeddedCurveScalar, ephPk, ); @@ -96,8 +96,8 @@ export abstract class L1Payload { */ protected static _decryptAsIncoming( data: Buffer, - ivsk: GrumpkinPrivateKey, - fromCiphertext: (incomingBodySlice: Buffer, ivskApp: GrumpkinPrivateKey, ephPk: Point) => T, + ivsk: EmbeddedCurveScalar, + fromCiphertext: (incomingBodySlice: Buffer, ivskApp: EmbeddedCurveScalar, ephPk: Point) => T, ): [AztecAddress, T] { const reader = BufferReader.asReader(data); @@ -133,8 +133,8 @@ export abstract class L1Payload { */ protected static _decryptAsOutgoing( data: Buffer, - ovsk: GrumpkinPrivateKey, - fromCiphertext: (incomingBodySlice: Buffer, ivskApp: GrumpkinPrivateKey, ephPk: Point) => T, + ovsk: EmbeddedCurveScalar, + fromCiphertext: (incomingBodySlice: Buffer, ivskApp: EmbeddedCurveScalar, ephPk: Point) => T, ): [AztecAddress, T] { const reader = BufferReader.asReader(data); diff --git a/yarn-project/circuit-types/src/logs/l1_payload/tagged_log.ts b/yarn-project/circuit-types/src/logs/l1_payload/tagged_log.ts index c4d2ec5fe73f..26102e78cc7e 100644 --- a/yarn-project/circuit-types/src/logs/l1_payload/tagged_log.ts +++ b/yarn-project/circuit-types/src/logs/l1_payload/tagged_log.ts @@ -1,4 +1,4 @@ -import { AztecAddress, type GrumpkinPrivateKey, type KeyValidationRequest, type PublicKey } from '@aztec/circuits.js'; +import { AztecAddress, type EmbeddedCurveScalar, type KeyValidationRequest, type PublicKey } from '@aztec/circuits.js'; import { Fr } from '@aztec/foundation/fields'; import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize'; @@ -55,7 +55,7 @@ export class TaggedLog { } public encrypt( - ephSk: GrumpkinPrivateKey, + ephSk: EmbeddedCurveScalar, recipient: AztecAddress, ivpk: PublicKey, ovKeys: KeyValidationRequest, @@ -65,17 +65,17 @@ export class TaggedLog { static decryptAsIncoming( encryptedLog: EncryptedL2Log, - ivsk: GrumpkinPrivateKey, + ivsk: EmbeddedCurveScalar, payloadType: typeof L1EventPayload, ): TaggedLog | undefined; static decryptAsIncoming( data: Buffer | bigint[], - ivsk: GrumpkinPrivateKey, + ivsk: EmbeddedCurveScalar, payloadType?: typeof L1NotePayload, ): TaggedLog | undefined; static decryptAsIncoming( data: Buffer | bigint[] | EncryptedL2Log, - ivsk: GrumpkinPrivateKey, + ivsk: EmbeddedCurveScalar, payloadType: typeof L1NotePayload | typeof L1EventPayload = L1NotePayload, ): TaggedLog | undefined { try { @@ -111,17 +111,17 @@ export class TaggedLog { static decryptAsOutgoing( encryptedLog: EncryptedL2Log, - ivsk: GrumpkinPrivateKey, + ivsk: EmbeddedCurveScalar, payloadType: typeof L1EventPayload, ): TaggedLog | undefined; static decryptAsOutgoing( data: Buffer | bigint[], - ivsk: GrumpkinPrivateKey, + ivsk: EmbeddedCurveScalar, payloadType?: typeof L1NotePayload, ): TaggedLog | undefined; static decryptAsOutgoing( data: Buffer | bigint[] | EncryptedL2Log, - ovsk: GrumpkinPrivateKey, + ovsk: EmbeddedCurveScalar, payloadType: typeof L1NotePayload | typeof L1EventPayload = L1NotePayload, ) { try { diff --git a/yarn-project/circuits.js/src/barretenberg/crypto/schnorr/index.ts b/yarn-project/circuits.js/src/barretenberg/crypto/schnorr/index.ts index c0a3ccd0c3e5..1d5ea03c039f 100644 --- a/yarn-project/circuits.js/src/barretenberg/crypto/schnorr/index.ts +++ b/yarn-project/circuits.js/src/barretenberg/crypto/schnorr/index.ts @@ -2,7 +2,7 @@ import { BarretenbergSync } from '@aztec/bb.js'; import { Point } from '@aztec/foundation/fields'; import { numToUInt32BE } from '@aztec/foundation/serialize'; -import { type GrumpkinPrivateKey } from '../../../types/grumpkin_private_key.js'; +import { type EmbeddedCurveScalar } from '../../../types/grumpkin_private_key.js'; import { type PublicKey } from '../../../types/public_key.js'; import { SchnorrSignature } from './signature.js'; @@ -19,7 +19,7 @@ export class Schnorr { * @param privateKey - The private key. * @returns A grumpkin public key. */ - public computePublicKey(privateKey: GrumpkinPrivateKey): PublicKey { + public computePublicKey(privateKey: EmbeddedCurveScalar): PublicKey { this.wasm.writeMemory(0, privateKey.toBuffer()); this.wasm.call('schnorr_compute_public_key', 0, 32); return Point.fromBuffer(Buffer.from(this.wasm.getMemorySlice(32, 96))); @@ -31,7 +31,7 @@ export class Schnorr { * @param privateKey - The private key of the signer. * @returns A Schnorr signature of the form (s, e). */ - public constructSignature(msg: Uint8Array, privateKey: GrumpkinPrivateKey) { + public constructSignature(msg: Uint8Array, privateKey: EmbeddedCurveScalar) { const mem = this.wasm.call('bbmalloc', msg.length + 4); this.wasm.writeMemory(0, privateKey.toBuffer()); this.wasm.writeMemory(mem, Buffer.concat([numToUInt32BE(msg.length), msg])); diff --git a/yarn-project/circuits.js/src/keys/derivation.ts b/yarn-project/circuits.js/src/keys/derivation.ts index 326940d65cb1..6f6af52669bf 100644 --- a/yarn-project/circuits.js/src/keys/derivation.ts +++ b/yarn-project/circuits.js/src/keys/derivation.ts @@ -4,7 +4,7 @@ import { Fq, type Fr, type GrumpkinScalar } from '@aztec/foundation/fields'; import { Grumpkin } from '../barretenberg/crypto/grumpkin/index.js'; import { GeneratorIndex } from '../constants.gen.js'; -import { GrumpkinPrivateKey } from '../types/grumpkin_private_key.js'; +import { EmbeddedCurveScalar } from '../types/grumpkin_private_key.js'; import { type PublicKey } from '../types/public_key.js'; import { PublicKeys } from '../types/public_keys.js'; import { type KeyPrefix } from './key_types.js'; @@ -12,11 +12,11 @@ import { getKeyGenerator } from './utils.js'; const curve = new Grumpkin(); -export function computeAppNullifierSecretKey(masterNullifierSecretKey: GrumpkinPrivateKey, app: AztecAddress): Fr { +export function computeAppNullifierSecretKey(masterNullifierSecretKey: EmbeddedCurveScalar, app: AztecAddress): Fr { return computeAppSecretKey(masterNullifierSecretKey, app, 'n'); // 'n' is the key prefix for nullifier secret key } -export function computeAppSecretKey(skM: GrumpkinPrivateKey, app: AztecAddress, keyPrefix: KeyPrefix): Fr { +export function computeAppSecretKey(skM: EmbeddedCurveScalar, app: AztecAddress, keyPrefix: KeyPrefix): Fr { const generator = getKeyGenerator(keyPrefix); return poseidon2Hash([skM.high, skM.low, app, generator]); } @@ -29,7 +29,7 @@ export function computeIvpkApp(ivpk: PublicKey, address: AztecAddress) { return curve.add(curve.mul(Grumpkin.generator, I), ivpk); } -export function computeIvskApp(ivsk: GrumpkinPrivateKey, address: AztecAddress) { +export function computeIvskApp(ivsk: EmbeddedCurveScalar, address: AztecAddress) { return ivsk; // Computing the siloed key is actually useless because we can derive the master key from it // Issue(#6955) @@ -40,11 +40,11 @@ export function computeIvskApp(ivsk: GrumpkinPrivateKey, address: AztecAddress) return new Fq((I.toBigInt() + ivsk.toBigInt()) % Fq.MODULUS); } -export function computeOvskApp(ovsk: GrumpkinPrivateKey, app: AztecAddress) { +export function computeOvskApp(ovsk: EmbeddedCurveScalar, app: AztecAddress) { const ovskAppFr = computeAppSecretKey(ovsk, app, 'ov'); // 'ov' is the key prefix for outgoing viewing key // Here we are intentionally converting Fr (output of poseidon) to Fq. This is fine even though a distribution of // P = s * G will not be uniform because 2 * (q - r) / q is small. - return GrumpkinPrivateKey.fromBuffer(ovskAppFr.toBuffer()); + return EmbeddedCurveScalar.fromBuffer(ovskAppFr.toBuffer()); } export function deriveMasterNullifierSecretKey(secretKey: Fr): GrumpkinScalar { diff --git a/yarn-project/circuits.js/src/structs/key_validation_request.ts b/yarn-project/circuits.js/src/structs/key_validation_request.ts index 2386dc382066..90aa245ebf6a 100644 --- a/yarn-project/circuits.js/src/structs/key_validation_request.ts +++ b/yarn-project/circuits.js/src/structs/key_validation_request.ts @@ -2,7 +2,7 @@ import { Fr, Point } from '@aztec/foundation/fields'; import { BufferReader, FieldReader, serializeToBuffer } from '@aztec/foundation/serialize'; import { KEY_VALIDATION_REQUEST_LENGTH } from '../constants.gen.js'; -import { GrumpkinPrivateKey } from '../types/grumpkin_private_key.js'; +import { EmbeddedCurveScalar } from '../types/grumpkin_private_key.js'; /** * Request for validating keys used in the app. @@ -14,11 +14,11 @@ export class KeyValidationRequest { constructor( /** Master public key corresponding to the same underlying secret as app secret key below. */ public readonly pkM: Point, - skApp: Fr | GrumpkinPrivateKey, + skApp: Fr | EmbeddedCurveScalar, ) { - // I am doing this conversion here because in some places skApp is represented as GrumpkinPrivateKey (Fq). + // I am doing this conversion here because in some places skApp is represented as EmbeddedCurveScalar (Fq). // I can do this conversion even though Fq.MODULUS is larger than Fr.MODULUS because when we pass in - // the skApp as GrumpkinPrivateKey it was converted to that form from Fr. So, it is safe to convert it back + // the skApp as EmbeddedCurveScalar it was converted to that form from Fr. So, it is safe to convert it back // to Fr. If this would change in the future the code below will throw an error so it should be easy to debug. this.skApp = skApp instanceof Fr ? skApp : new Fr(skApp.toBigInt()); } @@ -27,8 +27,8 @@ export class KeyValidationRequest { return serializeToBuffer(this.pkM, this.skApp); } - get skAppAsGrumpkinPrivateKey() { - return new GrumpkinPrivateKey(this.skApp.toBigInt()); + get skAppAsEmbeddedCurveScalar() { + return new EmbeddedCurveScalar(this.skApp.toBigInt()); } static fromBuffer(buffer: Buffer | BufferReader) { diff --git a/yarn-project/circuits.js/src/structs/read_request_hints/key_validation_hint.ts b/yarn-project/circuits.js/src/structs/read_request_hints/key_validation_hint.ts index 1ef0e4ed6de2..991e5736d461 100644 --- a/yarn-project/circuits.js/src/structs/read_request_hints/key_validation_hint.ts +++ b/yarn-project/circuits.js/src/structs/read_request_hints/key_validation_hint.ts @@ -1,18 +1,18 @@ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize'; -import { GrumpkinPrivateKey } from '../../types/grumpkin_private_key.js'; +import { EmbeddedCurveScalar } from '../../types/grumpkin_private_key.js'; export class KeyValidationHint { constructor( /** Master secret key used to derive sk_app and pk_m. */ - public skM: GrumpkinPrivateKey, + public skM: EmbeddedCurveScalar, /** Index of the request in the array of hints. */ public requestIndex: number, ) {} static fromBuffer(buffer: Buffer | BufferReader) { const reader = BufferReader.asReader(buffer); - return new KeyValidationHint(reader.readObject(GrumpkinPrivateKey), reader.readNumber()); + return new KeyValidationHint(reader.readObject(EmbeddedCurveScalar), reader.readNumber()); } toBuffer() { @@ -20,6 +20,6 @@ export class KeyValidationHint { } static empty() { - return new KeyValidationHint(GrumpkinPrivateKey.zero(), 0); + return new KeyValidationHint(EmbeddedCurveScalar.zero(), 0); } } diff --git a/yarn-project/circuits.js/src/tests/factories.ts b/yarn-project/circuits.js/src/tests/factories.ts index d25a74bbc2ff..7f6e1b9c113f 100644 --- a/yarn-project/circuits.js/src/tests/factories.ts +++ b/yarn-project/circuits.js/src/tests/factories.ts @@ -37,7 +37,7 @@ import { Fr, FunctionData, FunctionSelector, - type GrumpkinPrivateKey, + type EmbeddedCurveScalar, GrumpkinScalar, KeyValidationRequest, KeyValidationRequestAndGenerator, @@ -578,9 +578,9 @@ export function makePoint(seed = 1): Point { /** * Creates an arbitrary grumpkin private key. * @param seed - Seed to generate the values. - * @returns A GrumpkinPrivateKey. + * @returns A EmbeddedCurveScalar. */ -export function makeGrumpkinPrivateKey(seed = 1): GrumpkinPrivateKey { +export function makeEmbeddedCurveScalar(seed = 1): EmbeddedCurveScalar { return GrumpkinScalar.fromHighLow(fr(seed), fr(seed + 1)); } diff --git a/yarn-project/circuits.js/src/types/grumpkin_private_key.ts b/yarn-project/circuits.js/src/types/grumpkin_private_key.ts index fa2e53e3b9d0..b17262060369 100644 --- a/yarn-project/circuits.js/src/types/grumpkin_private_key.ts +++ b/yarn-project/circuits.js/src/types/grumpkin_private_key.ts @@ -1,5 +1,5 @@ import { GrumpkinScalar } from '@aztec/foundation/fields'; /** A type alias for private key which belongs to the scalar field of Grumpkin curve. */ -export type GrumpkinPrivateKey = GrumpkinScalar; -export const GrumpkinPrivateKey = GrumpkinScalar; +export type EmbeddedCurveScalar = GrumpkinScalar; +export const EmbeddedCurveScalar = GrumpkinScalar; diff --git a/yarn-project/end-to-end/src/e2e_account_contracts.test.ts b/yarn-project/end-to-end/src/e2e_account_contracts.test.ts index 06d3e6e85d0d..9a5b75bae4f1 100644 --- a/yarn-project/end-to-end/src/e2e_account_contracts.test.ts +++ b/yarn-project/end-to-end/src/e2e_account_contracts.test.ts @@ -8,7 +8,7 @@ import { type CompleteAddress, type DebugLogger, Fr, - type GrumpkinPrivateKey, + type EmbeddedCurveScalar, GrumpkinScalar, type PXE, type Wallet, @@ -20,7 +20,7 @@ import { ChildContract } from '@aztec/noir-contracts.js/Child'; import { setup } from './fixtures/utils.js'; function itShouldBehaveLikeAnAccountContract( - getAccountContract: (encryptionKey: GrumpkinPrivateKey) => AccountContract, + getAccountContract: (encryptionKey: EmbeddedCurveScalar) => AccountContract, walletSetup: (pxe: PXE, secretKey: Fr, accountContract: AccountContract) => Promise, walletAt: (pxe: PXE, accountContract: AccountContract, address: CompleteAddress) => Promise, ) { @@ -79,7 +79,7 @@ describe('e2e_account_contracts', () => { describe('schnorr single-key account', () => { itShouldBehaveLikeAnAccountContract( - (encryptionKey: GrumpkinPrivateKey) => new SingleKeyAccountContract(encryptionKey), + (encryptionKey: EmbeddedCurveScalar) => new SingleKeyAccountContract(encryptionKey), walletSetup, walletAt, ); diff --git a/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts b/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts index fc985e66290c..371d9c88789d 100644 --- a/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts +++ b/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts @@ -8,7 +8,7 @@ import { type DeployL1Contracts, EthCheatCodes, Fr, - GrumpkinPrivateKey, + EmbeddedCurveScalar, SignerlessWallet, type Wallet, } from '@aztec/aztec.js'; @@ -376,9 +376,9 @@ export const addAccounts = (numberOfAccounts: number, logger: DebugLogger) => async ({ pxe }: SubsystemsContext) => { // Generate account keys. - const accountKeys: [Fr, GrumpkinPrivateKey][] = Array.from({ length: numberOfAccounts }).map(_ => [ + const accountKeys: [Fr, EmbeddedCurveScalar][] = Array.from({ length: numberOfAccounts }).map(_ => [ Fr.random(), - GrumpkinPrivateKey.random(), + EmbeddedCurveScalar.random(), ]); logger.verbose('Simulating account deployment...'); diff --git a/yarn-project/end-to-end/src/guides/writing_an_account_contract.test.ts b/yarn-project/end-to-end/src/guides/writing_an_account_contract.test.ts index c5a56d197f27..2ae8bfe12d82 100644 --- a/yarn-project/end-to-end/src/guides/writing_an_account_contract.test.ts +++ b/yarn-project/end-to-end/src/guides/writing_an_account_contract.test.ts @@ -6,7 +6,7 @@ import { type CompleteAddress, ExtendedNote, Fr, - type GrumpkinPrivateKey, + type EmbeddedCurveScalar, GrumpkinScalar, Note, Schnorr, @@ -22,7 +22,7 @@ const PRIVATE_KEY = GrumpkinScalar.fromString('0xd35d743ac0dfe3d6dbe6be8c877cb52 /** Account contract implementation that authenticates txs using Schnorr signatures. */ class SchnorrHardcodedKeyAccountContract extends DefaultAccountContract { - constructor(private privateKey: GrumpkinPrivateKey = PRIVATE_KEY) { + constructor(private privateKey: EmbeddedCurveScalar = PRIVATE_KEY) { super(SchnorrHardcodedAccountContractArtifact); } diff --git a/yarn-project/key-store/src/key_store.ts b/yarn-project/key-store/src/key_store.ts index f3705a92425f..a872e169f9ea 100644 --- a/yarn-project/key-store/src/key_store.ts +++ b/yarn-project/key-store/src/key_store.ts @@ -5,7 +5,7 @@ import { Fq, Fr, GeneratorIndex, - type GrumpkinPrivateKey, + type EmbeddedCurveScalar, GrumpkinScalar, KEY_PREFIXES, type KeyPrefix, @@ -139,7 +139,7 @@ export class KeyStore { } // Now we find the secret key for the public key - let skM: GrumpkinPrivateKey | undefined; + let skM: EmbeddedCurveScalar | undefined; { const skMsBuffer = this.#keys.get(`${account.toString()}-${keyPrefix}sk_m`); if (!skMsBuffer) { @@ -274,7 +274,7 @@ export class KeyStore { * @returns A Promise that resolves to sk_m. * @dev Used when feeding the sk_m to the kernel circuit for keys verification. */ - public getMasterSecretKey(pkM: PublicKey): Promise { + public getMasterSecretKey(pkM: PublicKey): Promise { const [keyPrefix, account] = this.#getKeyPrefixAndAccount(pkM); // We get the secret keys buffer and iterate over the values in the buffer to find the one that matches pkM diff --git a/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts b/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts index a4a65090d22a..17bb71ea43a6 100644 --- a/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts +++ b/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts @@ -24,7 +24,7 @@ import { GasFees, GasSettings, GlobalVariables, - type GrumpkinPrivateKey, + type EmbeddedCurveScalar, GrumpkinScalar, Header, KernelCircuitPublicInputs, @@ -152,7 +152,7 @@ import type { Gas as GasNoir, GasSettings as GasSettingsNoir, GlobalVariables as GlobalVariablesNoir, - GrumpkinPrivateKey as GrumpkinPrivateKeyNoir, + EmbeddedCurveScalar as EmbeddedCurveScalarNoir, Header as HeaderNoir, KernelCircuitPublicInputs as KernelCircuitPublicInputsNoir, KernelData as KernelDataNoir, @@ -303,11 +303,11 @@ export function mapPointFromNoir(point: NoirPoint): Point { } /** - * Maps a GrumpkinPrivateKey to a noir GrumpkinPrivateKey. - * @param privateKey - The GrumpkinPrivateKey. - * @returns The noir GrumpkinPrivateKey. + * Maps a EmbeddedCurveScalar to a noir EmbeddedCurveScalar. + * @param privateKey - The EmbeddedCurveScalar. + * @returns The noir EmbeddedCurveScalar. */ -export function mapGrumpkinPrivateKeyToNoir(privateKey: GrumpkinPrivateKey): GrumpkinPrivateKeyNoir { +export function mapEmbeddedCurveScalarToNoir(privateKey: EmbeddedCurveScalar): EmbeddedCurveScalarNoir { return { high: mapFieldToNoir(privateKey.high), low: mapFieldToNoir(privateKey.low), @@ -321,17 +321,17 @@ export function mapGrumpkinPrivateKeyToNoir(privateKey: GrumpkinPrivateKey): Gru */ export function mapKeyValidationHintToNoir(hint: KeyValidationHint): KeyValidationHintNoir { return { - sk_m: mapGrumpkinPrivateKeyToNoir(hint.skM), + sk_m: mapEmbeddedCurveScalarToNoir(hint.skM), request_index: mapNumberToNoir(hint.requestIndex), }; } /** - * Maps a noir GrumpkinPrivateKey to a GrumpkinPrivateKey. - * @param privateKey - The noir GrumpkinPrivateKey. - * @returns The GrumpkinPrivateKey. + * Maps a noir EmbeddedCurveScalar to a EmbeddedCurveScalar. + * @param privateKey - The noir EmbeddedCurveScalar. + * @returns The EmbeddedCurveScalar. */ -export function mapGrumpkinPrivateKeyFromNoir(privateKey: GrumpkinPrivateKeyNoir): GrumpkinPrivateKey { +export function mapEmbeddedCurveScalarFromNoir(privateKey: EmbeddedCurveScalarNoir): EmbeddedCurveScalar { return GrumpkinScalar.fromHighLow(mapFieldFromNoir(privateKey.high), mapFieldFromNoir(privateKey.low)); } diff --git a/yarn-project/pxe/src/kernel_oracle/index.ts b/yarn-project/pxe/src/kernel_oracle/index.ts index c7f55240771f..23ecee44a0fb 100644 --- a/yarn-project/pxe/src/kernel_oracle/index.ts +++ b/yarn-project/pxe/src/kernel_oracle/index.ts @@ -3,7 +3,7 @@ import { type AztecAddress, type Fr, type FunctionSelector, - type GrumpkinPrivateKey, + type EmbeddedCurveScalar, MembershipWitness, type NOTE_HASH_TREE_HEIGHT, type Point, @@ -73,7 +73,7 @@ export class KernelOracle implements ProvingDataOracle { return header.state.partial.noteHashTree.root; } - public getMasterSecretKey(masterPublicKey: Point): Promise { + public getMasterSecretKey(masterPublicKey: Point): Promise { return this.keyStore.getMasterSecretKey(masterPublicKey); } diff --git a/yarn-project/pxe/src/kernel_prover/proving_data_oracle.ts b/yarn-project/pxe/src/kernel_prover/proving_data_oracle.ts index 1607cb7136e0..d2c4db478d6d 100644 --- a/yarn-project/pxe/src/kernel_prover/proving_data_oracle.ts +++ b/yarn-project/pxe/src/kernel_prover/proving_data_oracle.ts @@ -3,7 +3,7 @@ import { type FUNCTION_TREE_HEIGHT, type Fr, type FunctionSelector, - type GrumpkinPrivateKey, + type EmbeddedCurveScalar, type MembershipWitness, type NOTE_HASH_TREE_HEIGHT, type Point, @@ -76,7 +76,7 @@ export interface ProvingDataOracle { * @returns A Promise that resolves to sk_m. * @dev Used when feeding the sk_m to the kernel circuit for keys verification. */ - getMasterSecretKey(masterPublicKey: Point): Promise; + getMasterSecretKey(masterPublicKey: Point): Promise; getDebugFunctionName(contractAddress: AztecAddress, selector: FunctionSelector): Promise; } diff --git a/yarn-project/pxe/src/note_processor/note_processor.test.ts b/yarn-project/pxe/src/note_processor/note_processor.test.ts index 7904fd9efc09..b94c450ea64a 100644 --- a/yarn-project/pxe/src/note_processor/note_processor.test.ts +++ b/yarn-project/pxe/src/note_processor/note_processor.test.ts @@ -3,7 +3,7 @@ import { AztecAddress, CompleteAddress, Fr, - type GrumpkinPrivateKey, + type EmbeddedCurveScalar, INITIAL_L2_BLOCK_NUM, KeyValidationRequest, MAX_NOTE_HASHES_PER_TX, @@ -80,9 +80,9 @@ describe('Note Processor', () => { const app = AztecAddress.random(); - let ownerIvskM: GrumpkinPrivateKey; + let ownerIvskM: EmbeddedCurveScalar; let ownerIvpkM: PublicKey; - let ownerOvskM: GrumpkinPrivateKey; + let ownerOvskM: EmbeddedCurveScalar; let ownerOvKeys: KeyValidationRequest; let account: CompleteAddress; diff --git a/yarn-project/simulator/src/client/private_execution.test.ts b/yarn-project/simulator/src/client/private_execution.test.ts index 1b5c4c42b3f8..1a434eac2f14 100644 --- a/yarn-project/simulator/src/client/private_execution.test.ts +++ b/yarn-project/simulator/src/client/private_execution.test.ts @@ -15,7 +15,7 @@ import { CompleteAddress, GasSettings, GeneratorIndex, - type GrumpkinPrivateKey, + type EmbeddedCurveScalar, Header, KeyValidationRequest, L1_TO_L2_MSG_TREE_HEIGHT, @@ -90,10 +90,10 @@ describe('Private Execution test suite', () => { let ownerCompleteAddress: CompleteAddress; let recipientCompleteAddress: CompleteAddress; - let ownerNskM: GrumpkinPrivateKey; - let ownerOvskM: GrumpkinPrivateKey; - let recipientNskM: GrumpkinPrivateKey; - let recipientOvskM: GrumpkinPrivateKey; + let ownerNskM: EmbeddedCurveScalar; + let ownerOvskM: EmbeddedCurveScalar; + let recipientNskM: EmbeddedCurveScalar; + let recipientOvskM: EmbeddedCurveScalar; const treeHeights: { [name: string]: number } = { noteHash: NOTE_HASH_TREE_HEIGHT,