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..7d660e11853f 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, scalar::Scalar, 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: Scalar, 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,9 +32,9 @@ impl EncryptedLogHeader { fn test_encrypted_log_header() { let address = AztecAddress::from_field(0xdeadbeef); let header = EncryptedLogHeader::new(address); - let secret = GrumpkinPrivateKey::new( - 0x0000000000000000000000000000000023b3127c127b1f29a7adff5cccf8fb06, - 0x00000000000000000000000000000000649e7ca01d9de27b21624098b897babd + let secret = Scalar::new( + 0x00000000000000000000000000000000649e7ca01d9de27b21624098b897babd, + 0x0000000000000000000000000000000023b3127c127b1f29a7adff5cccf8fb06 ); let point = Point::new( 0x2688431c705a5ff3e6c6f2573c9e3ba1c1026d2251d0dbbf2d810aa53fd1d186, 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..c7052bbbbe40 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::{scalar::Scalar, 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: Scalar, 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,8 +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, - abis::event_selector::EventSelector + scalar::Scalar, point::Point, traits::Serialize, abis::event_selector::EventSelector }; use crate::{ @@ -119,9 +118,9 @@ mod test { let storage_slot = 2; - let eph_sk = GrumpkinPrivateKey::new( - 0x0000000000000000000000000000000023b3127c127b1f29a7adff5cccf8fb06, - 0x00000000000000000000000000000000649e7ca01d9de27b21624098b897babd + let eph_sk = Scalar::new( + 0x00000000000000000000000000000000649e7ca01d9de27b21624098b897babd, + 0x0000000000000000000000000000000023b3127c127b1f29a7adff5cccf8fb06 ); let ivpk_app = Point::new( 0x2688431c705a5ff3e6c6f2573c9e3ba1c1026d2251d0dbbf2d810aa53fd1d186, @@ -218,9 +217,9 @@ mod test { fn test_encrypted_log_event_incoming_body() { let test_event = TestEvent { value0: 1, value1: 2, value2: 3 }; - let eph_sk = GrumpkinPrivateKey::new( - 0x0000000000000000000000000000000023b3127c127b1f29a7adff5cccf8fb06, - 0x00000000000000000000000000000000649e7ca01d9de27b21624098b897babd + let eph_sk = Scalar::new( + 0x00000000000000000000000000000000649e7ca01d9de27b21624098b897babd, + 0x0000000000000000000000000000000023b3127c127b1f29a7adff5cccf8fb06 ); let ivpk_app = Point::new( 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..c63a54baa6c3 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,6 +1,6 @@ use dep::protocol_types::{ - address::AztecAddress, grumpkin_private_key::GrumpkinPrivateKey, point::Point, - constants::GENERATOR_INDEX__SYMMETRIC_KEY, hash::poseidon2_hash + address::AztecAddress, scalar::Scalar, point::Point, constants::GENERATOR_INDEX__SYMMETRIC_KEY, + hash::poseidon2_hash }; use std::aes128::aes128_encrypt; @@ -8,25 +8,24 @@ use std::aes128::aes128_encrypt; use crate::keys::point_to_symmetric_key::point_to_symmetric_key; struct EncryptedLogOutgoingBody { - eph_sk: GrumpkinPrivateKey, + eph_sk: Scalar, 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: Scalar, 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: Scalar, 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 let mut buffer: [u8; 160] = [0; 160]; - let serialized_eph_sk: [Field; 2] = self.eph_sk.serialize(); - let serialized_eph_sk_high = serialized_eph_sk[0].to_be_bytes(32); - let serialized_eph_sk_low = serialized_eph_sk[1].to_be_bytes(32); + let serialized_eph_sk_high = self.eph_sk.hi.to_be_bytes(32); + let serialized_eph_sk_low = self.eph_sk.lo.to_be_bytes(32); let address_bytes = self.recipient.to_field().to_be_bytes(32); let serialized_recipient_ivpk_app = self.recipient_ivpk_app.serialize(); @@ -44,7 +43,7 @@ impl EncryptedLogOutgoingBody { // We compute the symmetric key using poseidon. let full_key: [u8; 32] = poseidon2_hash( [ - ovsk_app.high, ovsk_app.low, eph_pk.x, eph_pk.y, + ovsk_app.hi, ovsk_app.lo, eph_pk.x, eph_pk.y, GENERATOR_INDEX__SYMMETRIC_KEY as Field ] ).to_be_bytes(32).as_array(); @@ -64,24 +63,24 @@ 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 + scalar::Scalar, point::Point, hash::poseidon2_hash }; use crate::context::PrivateContext; #[test] fn test_encrypted_log_outgoing_body() { - let eph_sk = GrumpkinPrivateKey::new( - 0x000000000000000000000000000000000f096b423017226a18461115fa8d34bb, - 0x00000000000000000000000000000000d0d302ee245dfaf2807e604eec4715fe + let eph_sk = Scalar::new( + 0x00000000000000000000000000000000d0d302ee245dfaf2807e604eec4715fe, + 0x000000000000000000000000000000000f096b423017226a18461115fa8d34bb ); - let recipient_ivsk_app = GrumpkinPrivateKey::new( - 0x000000000000000000000000000000000f4d97c25d578f9348251a71ca17ae31, - 0x000000000000000000000000000000004828f8f95676ebb481df163f87fd4022 + let recipient_ivsk_app = Scalar::new( + 0x000000000000000000000000000000004828f8f95676ebb481df163f87fd4022, + 0x000000000000000000000000000000000f4d97c25d578f9348251a71ca17ae31 ); - let sender_ovsk_app = GrumpkinPrivateKey::new( - 0x00000000000000000000000000000000089c6887cb1446d86c64e81afc78048b, - 0x0000000000000000000000000000000074d2e28c6bc5176ac02cf7c7d36a444e + let sender_ovsk_app = Scalar::new( + 0x0000000000000000000000000000000074d2e28c6bc5176ac02cf7c7d36a444e, + 0x00000000000000000000000000000000089c6887cb1446d86c64e81afc78048b ); let eph_pk = eph_sk.derive_public_key(); 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..d0dbde5450c6 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, scalar::Scalar, 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: Scalar = fr_to_fq(unsafe_rand()); let eph_pk = eph_sk.derive_public_key(); // TODO: (#7177) This value needs to be populated! @@ -37,7 +37,7 @@ pub fn compute_encrypted_event_log( let incoming_header_ciphertext: [u8; 48] = header.compute_ciphertext(eph_sk, ivpk); let outgoing_Header_ciphertext: [u8; 48] = header.compute_ciphertext(eph_sk, ovpk); let incoming_body_ciphertext = EncryptedLogIncomingBody::from_event(event, randomness).compute_ciphertext(eph_sk, ivpk_app); - let outgoing_body_ciphertext: [u8; 176] = EncryptedLogOutgoingBody::new(eph_sk, recipient, ivpk_app).compute_ciphertext(fr_to_private_key(ovsk_app), eph_pk); + let outgoing_body_ciphertext: [u8; 176] = EncryptedLogOutgoingBody::new(eph_sk, recipient, ivpk_app).compute_ciphertext(fr_to_fq(ovsk_app), eph_pk); let mut encrypted_bytes: [u8; OB] = [0; OB]; // @todo We ignore the tags for now @@ -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: Scalar = fr_to_fq(unsafe_rand()); let eph_pk = eph_sk.derive_public_key(); // TODO: (#7177) This value needs to be populated! @@ -94,7 +94,7 @@ pub fn compute_encrypted_note_log( let incoming_header_ciphertext: [u8; 48] = header.compute_ciphertext(eph_sk, ivpk); let outgoing_Header_ciphertext: [u8; 48] = header.compute_ciphertext(eph_sk, ovpk); let incoming_body_ciphertext = EncryptedLogIncomingBody::from_note(note, storage_slot).compute_ciphertext(eph_sk, ivpk_app); - let outgoing_body_ciphertext: [u8; 176] = EncryptedLogOutgoingBody::new(eph_sk, recipient, ivpk_app).compute_ciphertext(fr_to_private_key(ovsk_app), eph_pk); + let outgoing_body_ciphertext: [u8; 176] = EncryptedLogOutgoingBody::new(eph_sk, recipient, ivpk_app).compute_ciphertext(fr_to_fq(ovsk_app), eph_pk); let mut encrypted_bytes: [u8; M] = [0; M]; // @todo We ignore the tags for now @@ -129,7 +129,9 @@ pub fn compute_encrypted_note_log( encrypted_bytes } -fn fr_to_private_key(r: Field) -> GrumpkinPrivateKey { +/// Converts a base field elememt to scalar field element. +/// This is fine because modulus of the base field is smaller than the modulus of the scalar field. +fn fr_to_fq(r: Field) -> Scalar { let r_bytes = r.to_be_bytes(32); let mut high_bytes = [0; 32]; @@ -143,7 +145,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) + Scalar::new(low, high) } fn compute_ivpk_app(ivpk: Point, contract_address: AztecAddress) -> Point { @@ -155,7 +157,7 @@ fn compute_ivpk_app(ivpk: Point, contract_address: AztecAddress) -> Point { // for example user could define ivpk = infinity using the registry assert((ivpk.x != 0) & (ivpk.y != 0), "ivpk is infinite"); - let i = fr_to_private_key(poseidon2_hash([contract_address.to_field(), ivpk.x, ivpk.y, GENERATOR_INDEX__IVSK_M])); + let i = fr_to_fq(poseidon2_hash([contract_address.to_field(), ivpk.x, ivpk.y, GENERATOR_INDEX__IVSK_M])); let I = i.derive_public_key(); let embed_I = Point { x: I.x, y: I.y, is_infinite: false }; 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..6515b2bca382 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,16 +1,13 @@ use dep::protocol_types::{ - constants::GENERATOR_INDEX__SYMMETRIC_KEY, grumpkin_private_key::GrumpkinPrivateKey, - point::{Point, pub_key_to_bytes}, utils::arr_copy_slice + constants::GENERATOR_INDEX__SYMMETRIC_KEY, scalar::Scalar, point::{Point, pub_key_to_bytes}, + utils::arr_copy_slice }; -use std::{hash::sha256, embedded_curve_ops::{EmbeddedCurveScalar, multi_scalar_mul}}; +use std::{hash::sha256, embedded_curve_ops::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] { - let shared_secret_fields = multi_scalar_mul( - [Point { x: point.x, y: point.y, is_infinite: false }], - [EmbeddedCurveScalar { lo: secret.low, hi: secret.high }] - ); +pub fn point_to_symmetric_key(secret: Scalar, point: Point) -> [u8; 32] { + let shared_secret_fields = multi_scalar_mul([point], [secret]); // TODO(https://github.com/AztecProtocol/aztec-packages/issues/6061): make the func return Point struct directly let shared_secret = pub_key_to_bytes(Point::new(shared_secret_fields[0], shared_secret_fields[1], false)); let mut shared_secret_bytes_with_separator = [0 as u8; 65]; @@ -22,9 +19,9 @@ 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( - 0x0000000000000000000000000000000023b3127c127b1f29a7adff5cccf8fb06, - 0x00000000000000000000000000000000649e7ca01d9de27b21624098b897babd + let secret = Scalar::new( + 0x00000000000000000000000000000000649e7ca01d9de27b21624098b897babd, + 0x0000000000000000000000000000000023b3127c127b1f29a7adff5cccf8fb06 ); let point = Point::new( 0x2688431c705a5ff3e6c6f2573c9e3ba1c1026d2251d0dbbf2d810aa53fd1d186, diff --git a/noir-projects/noir-contracts/contracts/avm_test_contract/src/main.nr b/noir-projects/noir-contracts/contracts/avm_test_contract/src/main.nr index 02d2de9fabb9..cb7aef45b53b 100644 --- a/noir-projects/noir-contracts/contracts/avm_test_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/avm_test_contract/src/main.nr @@ -24,11 +24,11 @@ contract AvmTest { global big_field_136_bits: Field = 0x991234567890abcdef1234567890abcdef; // Libs - use std::embedded_curve_ops::{EmbeddedCurveScalar, multi_scalar_mul}; + use std::embedded_curve_ops::multi_scalar_mul; use dep::aztec::protocol_types::constants::CONTRACT_INSTANCE_LENGTH; use dep::aztec::prelude::{Map, Deserialize}; use dep::aztec::state_vars::PublicMutable; - use dep::aztec::protocol_types::{address::{AztecAddress, EthAddress}, constants::L1_TO_L2_MESSAGE_LENGTH, point::Point}; + use dep::aztec::protocol_types::{address::{AztecAddress, EthAddress}, constants::L1_TO_L2_MESSAGE_LENGTH, point::Point, scalar::Scalar}; use dep::aztec::oracle::get_contract_instance::{get_contract_instance_avm, get_contract_instance_internal_avm}; use dep::aztec::protocol_types::abis::function_selector::FunctionSelector; use dep::aztec::context::gas::GasOpts; @@ -147,8 +147,8 @@ contract AvmTest { #[aztec(public)] fn variable_base_msm() -> [Field; 3] { let g = Point { x: 1, y: 17631683881184975370165255887551781615748388533673675138860, is_infinite: false }; - let scalar = EmbeddedCurveScalar { lo: 3, hi: 0 }; - let scalar2 = EmbeddedCurveScalar { lo: 20, hi: 0 }; + let scalar = Scalar { lo: 3, hi: 0 }; + let scalar2 = Scalar { lo: 20, hi: 0 }; let triple_g = multi_scalar_mul([g, g], [scalar, scalar2]); triple_g } diff --git a/noir-projects/noir-contracts/contracts/private_token_contract/src/types/token_note.nr b/noir-projects/noir-contracts/contracts/private_token_contract/src/types/token_note.nr index 21f99a36c40e..0be1dc18f529 100644 --- a/noir-projects/noir-contracts/contracts/private_token_contract/src/types/token_note.nr +++ b/noir-projects/noir-contracts/contracts/private_token_contract/src/types/token_note.nr @@ -1,11 +1,11 @@ use dep::aztec::{ prelude::{AztecAddress, NoteHeader, NoteInterface, PrivateContext}, - protocol_types::{constants::GENERATOR_INDEX__NOTE_NULLIFIER, point::Point, hash::poseidon2_hash}, + protocol_types::{constants::GENERATOR_INDEX__NOTE_NULLIFIER, point::Point, scalar::Scalar, hash::poseidon2_hash}, note::utils::compute_note_hash_for_consumption, oracle::unsafe_rand::unsafe_rand, keys::getters::get_nsk_app, note::note_getter_options::PropertySelector }; use dep::std::field::bn254::decompose; -use dep::std::embedded_curve_ops::{EmbeddedCurveScalar, multi_scalar_mul, fixed_base_scalar_mul}; +use dep::std::embedded_curve_ops::multi_scalar_mul; trait OwnedNote { fn new(amount: U128, owner_npk_m_hash: Field) -> Self; @@ -80,15 +80,15 @@ impl NoteInterface for TokenNote { // by leveraging homomorphism. multi_scalar_mul( [G1, G1, G1], - [EmbeddedCurveScalar { + [Scalar { lo: self.amount.to_integer(), hi: 0 }, - EmbeddedCurveScalar { + Scalar { lo: npk_lo, hi: npk_hi }, - EmbeddedCurveScalar { + Scalar { lo: random_lo, hi: random_hi, }] @@ -204,11 +204,11 @@ impl PrivatelyRefundable for TokenNote { // 2. Now that we have correct representationsn of fee payer and randomness we can compute `G ^ (fee_payer_npk + randomness)` let incomplete_fee_payer_point = multi_scalar_mul( [G1, G1], - [EmbeddedCurveScalar { + [Scalar { lo: fee_payer_npk_m_hash_lo, hi: fee_payer_npk_m_hash_hi }, - EmbeddedCurveScalar { + Scalar { lo: fee_payer_randomness_lo, hi: fee_payer_randomness_hi }] @@ -223,15 +223,15 @@ impl PrivatelyRefundable for TokenNote { // 4. We compute `G ^ (user_npk_m_hash + funded_amount + randomness)` let incomplete_user_point = multi_scalar_mul( [G1, G1, G1], - [EmbeddedCurveScalar { + [Scalar { lo: user_lo, hi: user_hi }, - EmbeddedCurveScalar { + Scalar { lo: funded_amount_lo, hi: funded_amount_hi }, - EmbeddedCurveScalar { + Scalar { lo: user_randomness_lo, hi: user_randomness_hi }] @@ -256,7 +256,7 @@ impl PrivatelyRefundable for TokenNote { // 2. We compute the fee point as `G ^ transaction_fee` let fee_point_raw = multi_scalar_mul( [G1], - [EmbeddedCurveScalar { + [Scalar { lo: transaction_fee_lo, hi: transaction_fee_hi, }] 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..97aaec35ace1 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, scalar::Scalar, 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: Scalar, 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: Scalar, 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: Scalar, recipient: AztecAddress, recipient_ivpk_app: Point, - ovsk_app: GrumpkinPrivateKey + ovsk_app: Scalar ) -> [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..01a65af901b5 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, scalar::Scalar, 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: Scalar, 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..bd442c0eaf40 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,9 +113,9 @@ 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, - tests::{fixture_builder::FixtureBuilder}, utils::{arrays::{array_eq, array_length}}, - traits::{Empty, is_empty, is_empty_array}, point::Point + address::AztecAddress, scalar::Scalar, tests::{fixture_builder::FixtureBuilder}, + utils::{arrays::{array_eq, array_length}}, traits::{Empty, is_empty, is_empty_array}, + point::Point }; struct PrivateKernelResetInputsBuilder { 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..1be641061183 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}, scalar::Scalar, 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..e8ed87e45825 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,8 +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, - utils::arrays::filter_array_to_bounded_vec + scalar::Scalar, hash::poseidon2_hash, traits::is_empty, utils::arrays::filter_array_to_bounded_vec }; struct PrivateValidationRequestProcessor { 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..a682550ccb41 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, - hash::poseidon2_hash, utils::arrays::filter_array_to_bounded_vec + constants::MAX_KEY_VALIDATION_REQUESTS_PER_TX, scalar::Scalar, hash::poseidon2_hash, + utils::arrays::filter_array_to_bounded_vec }; struct KeyValidationHint { - sk_m: GrumpkinPrivateKey, + sk_m: Scalar, request_index: u64, } impl Empty for KeyValidationHint { fn empty() -> Self { KeyValidationHint { - sk_m: GrumpkinPrivateKey::empty(), + sk_m: Scalar::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/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..e70b3103d77a 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 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-projects/noir-protocol-circuits/crates/types/src/scalar.nr b/noir-projects/noir-protocol-circuits/crates/types/src/scalar.nr new file mode 100644 index 000000000000..a108f4f23bb2 --- /dev/null +++ b/noir-projects/noir-protocol-circuits/crates/types/src/scalar.nr @@ -0,0 +1,16 @@ +use dep::std::embedded_curve_ops::EmbeddedCurveScalar as Scalar; +use crate::traits::{Empty, Serialize}; + +global SCALAR_SIZE: Field = 2; + +impl Empty for Scalar { + fn empty() -> Self { + Self { lo: 0, hi: 0 } + } +} + +impl Serialize for Scalar { + fn serialize(self) -> [Field; SCALAR_SIZE] { + [self.lo, self.hi] + } +} 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..c791ac884046 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(lo: Field, hi: Field) -> Self { + EmbeddedCurveScalar { lo, hi } + } + + 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..6fcd9376a6c9 100644 --- a/yarn-project/accounts/README.md +++ b/yarn-project/accounts/README.md @@ -20,11 +20,11 @@ npm install @aztec/accounts ```typescript import { getSchnorrAccount } from '@aztec/accounts/schnorr'; -import { GrumpkinPrivateKey } from '@aztec/circuit-types'; +import { GrumpkinScalar } from '@aztec/circuit-types'; -const encryptionPrivateKey = GrumpkinPrivateKey.random(); -const signingPrivateKey = GrumpkinPrivateKey.random(); -const wallet = getSchnorrAccount(pxe, encryptionPrivateKey, signingPrivateKey).waitDeploy(); +const encryptionSecretKey = GrumpkinScalar.random(); +const signingSecretKey = GrumpkinScalar.random(); +const wallet = getSchnorrAccount(pxe, encryptionSecretKey, signingSecretKey).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..7bb4c6dda1f2 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 GrumpkinScalar } 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: GrumpkinScalar) { 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: GrumpkinScalar) {} 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..b80e306587ed 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 GrumpkinScalar, 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: GrumpkinScalar, 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: GrumpkinScalar, ): 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..ed2de53ebfec 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 GrumpkinScalar } 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: GrumpkinScalar) { 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: GrumpkinScalar, 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..da92a710ac78 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 GrumpkinScalar, 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: GrumpkinScalar, ): 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..ea5fba3f345d 100644 --- a/yarn-project/aztec.js/src/index.ts +++ b/yarn-project/aztec.js/src/index.ts @@ -102,7 +102,6 @@ export { EventType, ExtendedNote, FunctionCall, - GrumpkinPrivateKey, 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..ab7388a5c168 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 GrumpkinScalar, 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: GrumpkinScalar): 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..e9154e4c24a8 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, GrumpkinScalar, 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.test.ts b/yarn-project/circuit-types/src/logs/l1_payload/encrypt_buffer.test.ts index 3db91fe87a0e..6f38c689e992 100644 --- a/yarn-project/circuit-types/src/logs/l1_payload/encrypt_buffer.test.ts +++ b/yarn-project/circuit-types/src/logs/l1_payload/encrypt_buffer.test.ts @@ -15,8 +15,8 @@ describe('encrypt buffer', () => { it('derive shared secret', () => { // The following 2 are arbitrary fixed values - fixed in order to test a match with Noir - const ownerSecretKey: GrumpkinScalar = new Fq(0x23b3127c127b1f29a7adff5cccf8fb06649e7ca01d9de27b21624098b897babdn); - const ephSecretKey: GrumpkinScalar = new Fq(0x1fdd0dd8c99b21af8e00d2d130bdc263b36dadcbea84ac5ec9293a0660deca01n); + const ownerSecretKey = new Fq(0x23b3127c127b1f29a7adff5cccf8fb06649e7ca01d9de27b21624098b897babdn); + const ephSecretKey = new Fq(0x1fdd0dd8c99b21af8e00d2d130bdc263b36dadcbea84ac5ec9293a0660deca01n); const ownerPubKey = grumpkin.mul(Grumpkin.generator, ownerSecretKey); const ephPubKey = grumpkin.mul(Grumpkin.generator, ephSecretKey); 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..d19c2452390e 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 GrumpkinScalar, type PublicKey } from '@aztec/circuits.js'; import { Grumpkin } from '@aztec/circuits.js/barretenberg'; import { Point } from '@aztec/foundation/fields'; @@ -17,11 +17,7 @@ import { deriveAESSecret } from './encryption_utils.js'; * @param incomingViewingPublicKey - The note owner's incoming viewing public key. * @returns A Buffer containing the encrypted data and the ephemeral public key. */ -export function encryptBuffer( - data: Buffer, - ephSecretKey: GrumpkinPrivateKey, - incomingViewingPublicKey: PublicKey, -): Buffer { +export function encryptBuffer(data: Buffer, ephSecretKey: GrumpkinScalar, incomingViewingPublicKey: PublicKey): Buffer { const aesSecret = deriveAESSecret(ephSecretKey, incomingViewingPublicKey); const aesKey = aesSecret.subarray(0, 16); const iv = aesSecret.subarray(16, 32); @@ -40,7 +36,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: GrumpkinScalar): 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.test.ts b/yarn-project/circuit-types/src/logs/l1_payload/encrypted_log_header.test.ts index af5a63c9f810..bf93841caa5e 100644 --- a/yarn-project/circuit-types/src/logs/l1_payload/encrypted_log_header.test.ts +++ b/yarn-project/circuit-types/src/logs/l1_payload/encrypted_log_header.test.ts @@ -29,12 +29,8 @@ describe('encrypt log header', () => { it('encrypt a log header, generate input for noir test', () => { // The following 2 are arbitrary fixed values - fixed in order to test a match with Noir - const viewingSecretKey: GrumpkinScalar = new GrumpkinScalar( - 0x23b3127c127b1f29a7adff5cccf8fb06649e7ca01d9de27b21624098b897babdn, - ); - const ephSecretKey: GrumpkinScalar = new GrumpkinScalar( - 0x1fdd0dd8c99b21af8e00d2d130bdc263b36dadcbea84ac5ec9293a0660deca01n, - ); + const viewingSecretKey = new GrumpkinScalar(0x23b3127c127b1f29a7adff5cccf8fb06649e7ca01d9de27b21624098b897babdn); + const ephSecretKey = new GrumpkinScalar(0x1fdd0dd8c99b21af8e00d2d130bdc263b36dadcbea84ac5ec9293a0660deca01n); const viewingPubKey = grumpkin.mul(Grumpkin.generator, viewingSecretKey); 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..a66e5d991676 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 GrumpkinScalar, 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: GrumpkinScalar, 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: GrumpkinScalar, 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.test.ts b/yarn-project/circuit-types/src/logs/l1_payload/encrypted_log_incoming_body/encrypted_event_log_incoming_body.test.ts index 3ff13a7b8675..6e431995d265 100644 --- a/yarn-project/circuit-types/src/logs/l1_payload/encrypted_log_incoming_body/encrypted_event_log_incoming_body.test.ts +++ b/yarn-project/circuit-types/src/logs/l1_payload/encrypted_log_incoming_body/encrypted_event_log_incoming_body.test.ts @@ -34,12 +34,8 @@ describe('encrypt log incoming body', () => { it('encrypt an event log incoming body, generate input for noir test', () => { // The following 2 are arbitrary fixed values - fixed in order to test a match with Noir - const ephSecretKey: GrumpkinScalar = new GrumpkinScalar( - 0x23b3127c127b1f29a7adff5cccf8fb06649e7ca01d9de27b21624098b897babdn, - ); - const viewingSecretKey: GrumpkinScalar = new GrumpkinScalar( - 0x1fdd0dd8c99b21af8e00d2d130bdc263b36dadcbea84ac5ec9293a0660deca01n, - ); + const ephSecretKey = new GrumpkinScalar(0x23b3127c127b1f29a7adff5cccf8fb06649e7ca01d9de27b21624098b897babdn); + const viewingSecretKey = new GrumpkinScalar(0x1fdd0dd8c99b21af8e00d2d130bdc263b36dadcbea84ac5ec9293a0660deca01n); const viewingPubKey = grumpkin.mul(Grumpkin.generator, viewingSecretKey); 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..0574f1e0b9a5 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 GrumpkinScalar, 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: GrumpkinScalar, 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..300ee0dd879e 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 GrumpkinScalar, 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: GrumpkinScalar, 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: GrumpkinScalar, 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.test.ts b/yarn-project/circuit-types/src/logs/l1_payload/encrypted_log_incoming_body/encrypted_note_log_incoming_body.test.ts index d6a3dbfd1102..18613e08e6ed 100644 --- a/yarn-project/circuit-types/src/logs/l1_payload/encrypted_log_incoming_body/encrypted_note_log_incoming_body.test.ts +++ b/yarn-project/circuit-types/src/logs/l1_payload/encrypted_log_incoming_body/encrypted_note_log_incoming_body.test.ts @@ -35,12 +35,8 @@ describe('encrypt log incoming body', () => { it('encrypt a note log incoming body, generate input for noir test', () => { // The following 2 are arbitrary fixed values - fixed in order to test a match with Noir - const ephSecretKey: GrumpkinScalar = new GrumpkinScalar( - 0x23b3127c127b1f29a7adff5cccf8fb06649e7ca01d9de27b21624098b897babdn, - ); - const viewingSecretKey: GrumpkinScalar = new GrumpkinScalar( - 0x1fdd0dd8c99b21af8e00d2d130bdc263b36dadcbea84ac5ec9293a0660deca01n, - ); + const ephSecretKey = new GrumpkinScalar(0x23b3127c127b1f29a7adff5cccf8fb06649e7ca01d9de27b21624098b897babdn); + const viewingSecretKey = new GrumpkinScalar(0x1fdd0dd8c99b21af8e00d2d130bdc263b36dadcbea84ac5ec9293a0660deca01n); const viewingPubKey = grumpkin.mul(Grumpkin.generator, viewingSecretKey); 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..ffcb15f6de5e 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 GrumpkinScalar, 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: GrumpkinScalar, 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..bbc3b8b53755 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, GrumpkinScalar, 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: GrumpkinScalar, public recipient: AztecAddress, public recipientIvpkApp: PublicKey) {} /** * Serializes the log body @@ -13,7 +13,7 @@ export class EncryptedLogOutgoingBody { */ public toBuffer(): Buffer { // The serialization of Fq is [high, low] check `grumpkin_private_key.nr` - const ephSkBytes = serializeToBuffer([this.ephSk.high, this.ephSk.low]); + const ephSkBytes = serializeToBuffer([this.ephSk.hi, this.ephSk.lo]); return serializeToBuffer(ephSkBytes, this.recipient, this.recipientIvpkApp); } @@ -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 = GrumpkinScalar.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: GrumpkinScalar, 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: GrumpkinScalar, ephPk: PublicKey, ): EncryptedLogOutgoingBody { const input = Buffer.isBuffer(ciphertext) ? ciphertext : Buffer.from(ciphertext.map((x: bigint) => Number(x))); @@ -91,10 +91,10 @@ 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: GrumpkinScalar, 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. - return poseidon2Hash([ovskApp.high, ovskApp.low, ephPk.x, ephPk.y, GeneratorIndex.SYMMETRIC_KEY]).toBuffer(); + return poseidon2Hash([ovskApp.hi, ovskApp.lo, ephPk.x, ephPk.y, GeneratorIndex.SYMMETRIC_KEY]).toBuffer(); } } 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..4feccb927b66 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 GrumpkinScalar, 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: GrumpkinScalar, 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..09586a355fe4 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 GrumpkinScalar, 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: GrumpkinScalar, 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: GrumpkinScalar) { 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: GrumpkinScalar) { 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..1f53c1e00c18 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 GrumpkinScalar, 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: GrumpkinScalar, 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: GrumpkinScalar) { 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: GrumpkinScalar) { 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..97043f375764 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 GrumpkinScalar, type KeyValidationRequest, type PublicKey, computeIvpkApp, @@ -47,7 +47,7 @@ export abstract class L1Payload { */ protected _encrypt( contractAddress: AztecAddress, - ephSk: GrumpkinPrivateKey, + ephSk: GrumpkinScalar, 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.skAppAsGrumpkinScalar, 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: GrumpkinScalar, + fromCiphertext: (incomingBodySlice: Buffer, ivskApp: GrumpkinScalar, 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: GrumpkinScalar, + fromCiphertext: (incomingBodySlice: Buffer, ivskApp: GrumpkinScalar, 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..82cd805e9d31 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 GrumpkinScalar, 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: GrumpkinScalar, recipient: AztecAddress, ivpk: PublicKey, ovKeys: KeyValidationRequest, @@ -65,17 +65,17 @@ export class TaggedLog { static decryptAsIncoming( encryptedLog: EncryptedL2Log, - ivsk: GrumpkinPrivateKey, + ivsk: GrumpkinScalar, payloadType: typeof L1EventPayload, ): TaggedLog | undefined; static decryptAsIncoming( data: Buffer | bigint[], - ivsk: GrumpkinPrivateKey, + ivsk: GrumpkinScalar, payloadType?: typeof L1NotePayload, ): TaggedLog | undefined; static decryptAsIncoming( data: Buffer | bigint[] | EncryptedL2Log, - ivsk: GrumpkinPrivateKey, + ivsk: GrumpkinScalar, payloadType: typeof L1NotePayload | typeof L1EventPayload = L1NotePayload, ): TaggedLog | undefined { try { @@ -111,17 +111,17 @@ export class TaggedLog { static decryptAsOutgoing( encryptedLog: EncryptedL2Log, - ivsk: GrumpkinPrivateKey, + ivsk: GrumpkinScalar, payloadType: typeof L1EventPayload, ): TaggedLog | undefined; static decryptAsOutgoing( data: Buffer | bigint[], - ivsk: GrumpkinPrivateKey, + ivsk: GrumpkinScalar, payloadType?: typeof L1NotePayload, ): TaggedLog | undefined; static decryptAsOutgoing( data: Buffer | bigint[] | EncryptedL2Log, - ovsk: GrumpkinPrivateKey, + ovsk: GrumpkinScalar, payloadType: typeof L1NotePayload | typeof L1EventPayload = L1NotePayload, ) { try { diff --git a/yarn-project/circuits.js/src/barretenberg/crypto/schnorr/index.test.ts b/yarn-project/circuits.js/src/barretenberg/crypto/schnorr/index.test.ts index db2e2101e6e6..94763421d661 100644 --- a/yarn-project/circuits.js/src/barretenberg/crypto/schnorr/index.test.ts +++ b/yarn-project/circuits.js/src/barretenberg/crypto/schnorr/index.test.ts @@ -1,6 +1,7 @@ +import { GrumpkinScalar } from '@aztec/foundation/fields'; + import { TextEncoder } from 'util'; -import { GrumpkinScalar } from '../../../index.js'; import { Schnorr } from './index.js'; describe('schnorr', () => { 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..92c33f47e56e 100644 --- a/yarn-project/circuits.js/src/barretenberg/crypto/schnorr/index.ts +++ b/yarn-project/circuits.js/src/barretenberg/crypto/schnorr/index.ts @@ -1,8 +1,7 @@ import { BarretenbergSync } from '@aztec/bb.js'; -import { Point } from '@aztec/foundation/fields'; +import { type GrumpkinScalar, Point } from '@aztec/foundation/fields'; import { numToUInt32BE } from '@aztec/foundation/serialize'; -import { type GrumpkinPrivateKey } from '../../../types/grumpkin_private_key.js'; import { type PublicKey } from '../../../types/public_key.js'; import { SchnorrSignature } from './signature.js'; @@ -19,7 +18,7 @@ export class Schnorr { * @param privateKey - The private key. * @returns A grumpkin public key. */ - public computePublicKey(privateKey: GrumpkinPrivateKey): PublicKey { + public computePublicKey(privateKey: GrumpkinScalar): 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 +30,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: GrumpkinScalar) { 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..34934e248a8b 100644 --- a/yarn-project/circuits.js/src/keys/derivation.ts +++ b/yarn-project/circuits.js/src/keys/derivation.ts @@ -1,10 +1,9 @@ import { AztecAddress } from '@aztec/foundation/aztec-address'; import { poseidon2Hash, sha512ToGrumpkinScalar } from '@aztec/foundation/crypto'; -import { Fq, type Fr, type GrumpkinScalar } from '@aztec/foundation/fields'; +import { Fq, type Fr, 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 { type PublicKey } from '../types/public_key.js'; import { PublicKeys } from '../types/public_keys.js'; import { type KeyPrefix } from './key_types.js'; @@ -12,13 +11,13 @@ import { getKeyGenerator } from './utils.js'; const curve = new Grumpkin(); -export function computeAppNullifierSecretKey(masterNullifierSecretKey: GrumpkinPrivateKey, app: AztecAddress): Fr { +export function computeAppNullifierSecretKey(masterNullifierSecretKey: GrumpkinScalar, 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: GrumpkinScalar, app: AztecAddress, keyPrefix: KeyPrefix): Fr { const generator = getKeyGenerator(keyPrefix); - return poseidon2Hash([skM.high, skM.low, app, generator]); + return poseidon2Hash([skM.hi, skM.lo, app, generator]); } export function computeIvpkApp(ivpk: PublicKey, address: AztecAddress) { @@ -29,7 +28,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: GrumpkinScalar, address: AztecAddress) { return ivsk; // Computing the siloed key is actually useless because we can derive the master key from it // Issue(#6955) @@ -40,11 +39,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: GrumpkinScalar, 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 GrumpkinScalar.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..4fb96fabd0ea 100644 --- a/yarn-project/circuits.js/src/structs/key_validation_request.ts +++ b/yarn-project/circuits.js/src/structs/key_validation_request.ts @@ -1,8 +1,7 @@ -import { Fr, Point } from '@aztec/foundation/fields'; +import { Fr, GrumpkinScalar, 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'; /** * Request for validating keys used in the app. @@ -14,11 +13,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 | GrumpkinScalar, ) { - // 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 GrumpkinScalar (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 GrumpkinScalar 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 +26,8 @@ export class KeyValidationRequest { return serializeToBuffer(this.pkM, this.skApp); } - get skAppAsGrumpkinPrivateKey() { - return new GrumpkinPrivateKey(this.skApp.toBigInt()); + get skAppAsGrumpkinScalar() { + return new GrumpkinScalar(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..99e1faedb38f 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,17 @@ +import { GrumpkinScalar } from '@aztec/foundation/fields'; import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize'; -import { GrumpkinPrivateKey } 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: GrumpkinScalar, /** 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(GrumpkinScalar), reader.readNumber()); } toBuffer() { @@ -20,6 +19,6 @@ export class KeyValidationHint { } static empty() { - return new KeyValidationHint(GrumpkinPrivateKey.zero(), 0); + return new KeyValidationHint(GrumpkinScalar.zero(), 0); } } diff --git a/yarn-project/circuits.js/src/tests/factories.ts b/yarn-project/circuits.js/src/tests/factories.ts index d25a74bbc2ff..9e7154f93931 100644 --- a/yarn-project/circuits.js/src/tests/factories.ts +++ b/yarn-project/circuits.js/src/tests/factories.ts @@ -37,7 +37,6 @@ import { Fr, FunctionData, FunctionSelector, - type GrumpkinPrivateKey, GrumpkinScalar, KeyValidationRequest, KeyValidationRequestAndGenerator, @@ -576,11 +575,11 @@ export function makePoint(seed = 1): Point { } /** - * Creates an arbitrary grumpkin private key. + * Creates an arbitrary grumpkin scalar. * @param seed - Seed to generate the values. - * @returns A GrumpkinPrivateKey. + * @returns A GrumpkinScalar. */ -export function makeGrumpkinPrivateKey(seed = 1): GrumpkinPrivateKey { +export function makeGrumpkinScalar(seed = 1): GrumpkinScalar { 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 deleted file mode 100644 index fa2e53e3b9d0..000000000000 --- a/yarn-project/circuits.js/src/types/grumpkin_private_key.ts +++ /dev/null @@ -1,5 +0,0 @@ -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; diff --git a/yarn-project/circuits.js/src/types/index.ts b/yarn-project/circuits.js/src/types/index.ts index 7b5ccf3c9a1f..e928d0676526 100644 --- a/yarn-project/circuits.js/src/types/index.ts +++ b/yarn-project/circuits.js/src/types/index.ts @@ -1,6 +1,5 @@ export * from './contract_function_dao.js'; export * from './deployment_info.js'; -export * from './grumpkin_private_key.js'; export * from './partial_address.js'; export * from './public_key.js'; export * from './public_keys.js'; 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..b1492648f86a 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,6 @@ import { type CompleteAddress, type DebugLogger, Fr, - type GrumpkinPrivateKey, GrumpkinScalar, type PXE, type Wallet, @@ -20,7 +19,7 @@ import { ChildContract } from '@aztec/noir-contracts.js/Child'; import { setup } from './fixtures/utils.js'; function itShouldBehaveLikeAnAccountContract( - getAccountContract: (encryptionKey: GrumpkinPrivateKey) => AccountContract, + getAccountContract: (encryptionKey: GrumpkinScalar) => AccountContract, walletSetup: (pxe: PXE, secretKey: Fr, accountContract: AccountContract) => Promise, walletAt: (pxe: PXE, accountContract: AccountContract, address: CompleteAddress) => Promise, ) { @@ -79,7 +78,7 @@ describe('e2e_account_contracts', () => { describe('schnorr single-key account', () => { itShouldBehaveLikeAnAccountContract( - (encryptionKey: GrumpkinPrivateKey) => new SingleKeyAccountContract(encryptionKey), + (encryptionKey: GrumpkinScalar) => 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 1aacec321666..8e982733c990 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, + GrumpkinScalar, 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, GrumpkinScalar][] = Array.from({ length: numberOfAccounts }).map(_ => [ Fr.random(), - GrumpkinPrivateKey.random(), + GrumpkinScalar.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..44a4f8306b67 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,6 @@ import { type CompleteAddress, ExtendedNote, Fr, - type GrumpkinPrivateKey, GrumpkinScalar, Note, Schnorr, @@ -22,7 +21,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 = PRIVATE_KEY) { super(SchnorrHardcodedAccountContractArtifact); } diff --git a/yarn-project/foundation/src/fields/fields.test.ts b/yarn-project/foundation/src/fields/fields.test.ts index b11d4db941c3..2f8686bb4c5b 100644 --- a/yarn-project/foundation/src/fields/fields.test.ts +++ b/yarn-project/foundation/src/fields/fields.test.ts @@ -4,8 +4,8 @@ describe('GrumpkinScalar Serialization', () => { // Test case for GrumpkinScalar.fromHighLow it('fromHighLow should serialize and deserialize correctly', () => { const original = GrumpkinScalar.random(); - const high = original.high; - const low = original.low; + const high = original.hi; + const low = original.lo; const deserialized = GrumpkinScalar.fromHighLow(high, low); diff --git a/yarn-project/foundation/src/fields/fields.ts b/yarn-project/foundation/src/fields/fields.ts index 8220b48efc4f..42584f5f5841 100644 --- a/yarn-project/foundation/src/fields/fields.ts +++ b/yarn-project/foundation/src/fields/fields.ts @@ -310,11 +310,11 @@ export class Fq extends BaseField { return `Fq<${this.toString()}>`; } - get low(): Fr { + get lo(): Fr { return new Fr(this.toBigInt() & Fq.LOW_MASK); } - get high(): Fr { + get hi(): Fr { return new Fr(this.toBigInt() >> Fq.HIGH_SHIFT); } diff --git a/yarn-project/key-store/src/key_store.ts b/yarn-project/key-store/src/key_store.ts index f3705a92425f..4df9ce6e3fe5 100644 --- a/yarn-project/key-store/src/key_store.ts +++ b/yarn-project/key-store/src/key_store.ts @@ -5,7 +5,6 @@ import { Fq, Fr, GeneratorIndex, - type GrumpkinPrivateKey, GrumpkinScalar, KEY_PREFIXES, type KeyPrefix, @@ -139,7 +138,7 @@ export class KeyStore { } // Now we find the secret key for the public key - let skM: GrumpkinPrivateKey | undefined; + let skM: GrumpkinScalar | undefined; { const skMsBuffer = this.#keys.get(`${account.toString()}-${keyPrefix}sk_m`); if (!skMsBuffer) { @@ -232,12 +231,7 @@ export class KeyStore { const masterIncomingViewingSecretKey = GrumpkinScalar.fromBuffer(masterIncomingViewingSecretKeyBuffer); return Promise.resolve( - poseidon2Hash([ - masterIncomingViewingSecretKey.high, - masterIncomingViewingSecretKey.low, - app, - GeneratorIndex.IVSK_M, - ]), + poseidon2Hash([masterIncomingViewingSecretKey.hi, masterIncomingViewingSecretKey.lo, app, GeneratorIndex.IVSK_M]), ); } @@ -258,12 +252,7 @@ export class KeyStore { const masterOutgoingViewingSecretKey = GrumpkinScalar.fromBuffer(masterOutgoingViewingSecretKeyBuffer); return Promise.resolve( - poseidon2Hash([ - masterOutgoingViewingSecretKey.high, - masterOutgoingViewingSecretKey.low, - app, - GeneratorIndex.OVSK_M, - ]), + poseidon2Hash([masterOutgoingViewingSecretKey.hi, masterOutgoingViewingSecretKey.lo, app, GeneratorIndex.OVSK_M]), ); } @@ -274,7 +263,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..210acd1a56e4 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,6 @@ import { GasFees, GasSettings, GlobalVariables, - type GrumpkinPrivateKey, GrumpkinScalar, Header, KernelCircuitPublicInputs, @@ -152,7 +151,7 @@ import type { Gas as GasNoir, GasSettings as GasSettingsNoir, GlobalVariables as GlobalVariablesNoir, - GrumpkinPrivateKey as GrumpkinPrivateKeyNoir, + EmbeddedCurveScalar as GrumpkinScalarNoir, Header as HeaderNoir, KernelCircuitPublicInputs as KernelCircuitPublicInputsNoir, KernelData as KernelDataNoir, @@ -303,14 +302,14 @@ export function mapPointFromNoir(point: NoirPoint): Point { } /** - * Maps a GrumpkinPrivateKey to a noir GrumpkinPrivateKey. - * @param privateKey - The GrumpkinPrivateKey. - * @returns The noir GrumpkinPrivateKey. + * Maps a GrumpkinScalar to a noir GrumpkinScalar. + * @param privateKey - The GrumpkinScalar. + * @returns The noir GrumpkinScalar. */ -export function mapGrumpkinPrivateKeyToNoir(privateKey: GrumpkinPrivateKey): GrumpkinPrivateKeyNoir { +export function mapGrumpkinScalarToNoir(privateKey: GrumpkinScalar): GrumpkinScalarNoir { return { - high: mapFieldToNoir(privateKey.high), - low: mapFieldToNoir(privateKey.low), + hi: mapFieldToNoir(privateKey.hi), + lo: mapFieldToNoir(privateKey.lo), }; } @@ -321,18 +320,18 @@ export function mapGrumpkinPrivateKeyToNoir(privateKey: GrumpkinPrivateKey): Gru */ export function mapKeyValidationHintToNoir(hint: KeyValidationHint): KeyValidationHintNoir { return { - sk_m: mapGrumpkinPrivateKeyToNoir(hint.skM), + sk_m: mapGrumpkinScalarToNoir(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 GrumpkinScalar to a GrumpkinScalar. + * @param privateKey - The noir GrumpkinScalar. + * @returns The GrumpkinScalar. */ -export function mapGrumpkinPrivateKeyFromNoir(privateKey: GrumpkinPrivateKeyNoir): GrumpkinPrivateKey { - return GrumpkinScalar.fromHighLow(mapFieldFromNoir(privateKey.high), mapFieldFromNoir(privateKey.low)); +export function mapGrumpkinScalarFromNoir(privateKey: GrumpkinScalarNoir): GrumpkinScalar { + return GrumpkinScalar.fromHighLow(mapFieldFromNoir(privateKey.hi), mapFieldFromNoir(privateKey.lo)); } /** diff --git a/yarn-project/pxe/src/kernel_oracle/index.ts b/yarn-project/pxe/src/kernel_oracle/index.ts index c7f55240771f..294d72b7cbaa 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 GrumpkinScalar, 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..5511100a5e13 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 GrumpkinScalar, 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..8fb954ea9866 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,6 @@ import { AztecAddress, CompleteAddress, Fr, - type GrumpkinPrivateKey, INITIAL_L2_BLOCK_NUM, KeyValidationRequest, MAX_NOTE_HASHES_PER_TX, @@ -80,9 +79,9 @@ describe('Note Processor', () => { const app = AztecAddress.random(); - let ownerIvskM: GrumpkinPrivateKey; + let ownerIvskM: GrumpkinScalar; let ownerIvpkM: PublicKey; - let ownerOvskM: GrumpkinPrivateKey; + let ownerOvskM: GrumpkinScalar; let ownerOvKeys: KeyValidationRequest; let account: CompleteAddress; diff --git a/yarn-project/simulator/src/avm/opcodes/multi_scalar_mul.test.ts b/yarn-project/simulator/src/avm/opcodes/multi_scalar_mul.test.ts index 1c4e76fb3c35..133f215dfad9 100644 --- a/yarn-project/simulator/src/avm/opcodes/multi_scalar_mul.test.ts +++ b/yarn-project/simulator/src/avm/opcodes/multi_scalar_mul.test.ts @@ -46,7 +46,7 @@ describe('MultiScalarMul Opcode', () => { const scalarsLength = scalars.length * 2; // multiplied by 2 since we will store them as lo and hi limbs in avm memory // Transform the points and scalars into the format that we will write to memory // We just store the x and y coordinates here, and handle the infinities when we write to memory - const storedScalars: Field[] = scalars.flatMap(s => [new Field(s.low), new Field(s.high)]); + const storedScalars: Field[] = scalars.flatMap(s => [new Field(s.lo), new Field(s.hi)]); // Points are stored as [x1, y1, inf1, x2, y2, inf2, ...] where the types are [Field, Field, Uint8, Field, Field, Uint8, ...] const storedPoints: MemoryValue[] = points .map(p => p.toFields()) @@ -86,7 +86,7 @@ describe('MultiScalarMul Opcode', () => { const scalarsLength = scalars.length * 2; // multiplied by 2 since we will store them as lo and hi limbs in avm memory // Transform the points and scalars into the format that we will write to memory // We just store the x and y coordinates here, and handle the infinities when we write to memory - const storedScalars: Field[] = scalars.flatMap(s => [new Field(s.low), new Field(s.high)]); + const storedScalars: Field[] = scalars.flatMap(s => [new Field(s.lo), new Field(s.hi)]); // Points are stored as [x1, y1, inf1, x2, y2, inf2, ...] where the types are [Field, Field, Uint8, Field, Field, Uint8, ...] const storedPoints: MemoryValue[] = points .map(p => p.toFields()) diff --git a/yarn-project/simulator/src/client/private_execution.test.ts b/yarn-project/simulator/src/client/private_execution.test.ts index 1b5c4c42b3f8..1ee5b7bdf197 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 GrumpkinScalar, 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: GrumpkinScalar; + let ownerOvskM: GrumpkinScalar; + let recipientNskM: GrumpkinScalar; + let recipientOvskM: GrumpkinScalar; const treeHeights: { [name: string]: number } = { noteHash: NOTE_HASH_TREE_HEIGHT,