From eaa2761c575943ca832976a8832fbb80c81e1c09 Mon Sep 17 00:00:00 2001 From: benesjan Date: Tue, 9 Jul 2024 15:01:41 +0000 Subject: [PATCH] cleanup --- .../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 | 1 - yarn-project/aztec.js/src/utils/pub_key.ts | 4 ++-- yarn-project/circuit-types/src/index.ts | 2 +- .../logs/l1_payload/encrypt_buffer.test.ts | 4 ++-- .../src/logs/l1_payload/encrypt_buffer.ts | 10 +++------ .../l1_payload/encrypted_log_header.test.ts | 8 ++----- .../logs/l1_payload/encrypted_log_header.ts | 6 +++--- .../encrypted_event_log_incoming_body.test.ts | 8 ++----- .../encrypted_event_log_incoming_body.ts | 4 ++-- .../encrypted_log_incoming_body.ts | 6 +++--- .../encrypted_note_log_incoming_body.test.ts | 8 ++----- .../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 +++++++------- .../barretenberg/crypto/schnorr/index.test.ts | 3 ++- .../src/barretenberg/crypto/schnorr/index.ts | 7 +++---- .../circuits.js/src/keys/derivation.ts | 13 ++++++------ .../src/structs/key_validation_request.ts | 13 ++++++------ .../read_request_hints/key_validation_hint.ts | 9 ++++---- .../circuits.js/src/tests/factories.ts | 7 +++---- .../src/types/grumpkin_private_key.ts | 5 ----- yarn-project/circuits.js/src/types/index.ts | 1 - .../src/e2e_account_contracts.test.ts | 5 ++--- .../src/fixtures/snapshot_manager.ts | 6 +++--- .../writing_an_account_contract.test.ts | 3 +-- yarn-project/key-store/src/key_store.ts | 19 ++++------------- .../src/type_conversion.ts | 21 +++++++++---------- yarn-project/pxe/src/kernel_oracle/index.ts | 4 ++-- .../src/kernel_prover/proving_data_oracle.ts | 4 ++-- .../src/note_processor/note_processor.test.ts | 5 ++--- .../src/client/private_execution.test.ts | 10 ++++----- 39 files changed, 121 insertions(+), 163 deletions(-) delete mode 100644 yarn-project/circuits.js/src/types/grumpkin_private_key.ts diff --git a/yarn-project/accounts/src/schnorr/account_contract.ts b/yarn-project/accounts/src/schnorr/account_contract.ts index 9f1f0b92149..7bb4c6dda1f 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 EmbeddedCurveScalar } 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: EmbeddedCurveScalar) { + 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: EmbeddedCurveScalar) {} + 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 de8fb49b2f7..b80e306587e 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 EmbeddedCurveScalar, 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: EmbeddedCurveScalar, + 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: EmbeddedCurveScalar, + 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 68f282a8cf8..ed2de53ebfe 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 EmbeddedCurveScalar } 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: EmbeddedCurveScalar) { + 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: EmbeddedCurveScalar, 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 11584f94878..da92a710ac7 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 EmbeddedCurveScalar, 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: EmbeddedCurveScalar, + 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 22d56dacc6b..ea5fba3f345 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, - 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 4a05fa3e364..ab7388a5c16 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 EmbeddedCurveScalar, 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: EmbeddedCurveScalar): 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 b8ecd004c81..e9154e4c24a 100644 --- a/yarn-project/circuit-types/src/index.ts +++ b/yarn-project/circuit-types/src/index.ts @@ -1,4 +1,4 @@ -export { CompleteAddress, EmbeddedCurveScalar, 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 3db91fe87a0..6f38c689e99 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 b3a87d96841..d19c2452390 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 EmbeddedCurveScalar, 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: EmbeddedCurveScalar, - 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: EmbeddedCurveScalar): 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 af5a63c9f81..bf93841caa5 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 1fcd2008964..a66e5d99167 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 EmbeddedCurveScalar, 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: EmbeddedCurveScalar, 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: EmbeddedCurveScalar, + 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 3ff13a7b867..6e431995d26 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 18d04350800..0574f1e0b9a 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 EmbeddedCurveScalar, 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: EmbeddedCurveScalar, + 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 488dcdecf42..300ee0dd879 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 EmbeddedCurveScalar, 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: EmbeddedCurveScalar, + 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: EmbeddedCurveScalar, 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 d6a3dbfd110..18613e08e6e 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 6e991bb21a8..ffcb15f6de5 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 EmbeddedCurveScalar, 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: EmbeddedCurveScalar, + 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 09e3f728c30..bbc3b8b5375 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, EmbeddedCurveScalar, 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: EmbeddedCurveScalar, public recipient: AztecAddress, public recipientIvpkApp: PublicKey) {} + constructor(public ephSk: GrumpkinScalar, 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 = EmbeddedCurveScalar.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: EmbeddedCurveScalar, 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: EmbeddedCurveScalar, + ovskApp: GrumpkinScalar, 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: EmbeddedCurveScalar, 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. 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 6d0b5f085a6..4feccb927b6 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 EmbeddedCurveScalar, 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: EmbeddedCurveScalar, 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 4a5e475f034..09586a355fe 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 EmbeddedCurveScalar, 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: EmbeddedCurveScalar, 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: EmbeddedCurveScalar) { + 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: EmbeddedCurveScalar) { + 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 cf981ac2844..1f53c1e00c1 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 EmbeddedCurveScalar, 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: EmbeddedCurveScalar, 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: EmbeddedCurveScalar) { + 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: EmbeddedCurveScalar) { + 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 045b8cf59e4..97043f37576 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 EmbeddedCurveScalar, + type GrumpkinScalar, type KeyValidationRequest, type PublicKey, computeIvpkApp, @@ -47,7 +47,7 @@ export abstract class L1Payload { */ protected _encrypt( contractAddress: AztecAddress, - ephSk: EmbeddedCurveScalar, + 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.skAppAsEmbeddedCurveScalar, + ovKeys.skAppAsGrumpkinScalar, ephPk, ); @@ -96,8 +96,8 @@ export abstract class L1Payload { */ protected static _decryptAsIncoming( data: Buffer, - ivsk: EmbeddedCurveScalar, - fromCiphertext: (incomingBodySlice: Buffer, ivskApp: EmbeddedCurveScalar, 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: EmbeddedCurveScalar, - fromCiphertext: (incomingBodySlice: Buffer, ivskApp: EmbeddedCurveScalar, 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 26102e78cc7..82cd805e9d3 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 EmbeddedCurveScalar, 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: EmbeddedCurveScalar, + ephSk: GrumpkinScalar, recipient: AztecAddress, ivpk: PublicKey, ovKeys: KeyValidationRequest, @@ -65,17 +65,17 @@ export class TaggedLog { static decryptAsIncoming( encryptedLog: EncryptedL2Log, - ivsk: EmbeddedCurveScalar, + ivsk: GrumpkinScalar, payloadType: typeof L1EventPayload, ): TaggedLog | undefined; static decryptAsIncoming( data: Buffer | bigint[], - ivsk: EmbeddedCurveScalar, + ivsk: GrumpkinScalar, payloadType?: typeof L1NotePayload, ): TaggedLog | undefined; static decryptAsIncoming( data: Buffer | bigint[] | EncryptedL2Log, - ivsk: EmbeddedCurveScalar, + ivsk: GrumpkinScalar, payloadType: typeof L1NotePayload | typeof L1EventPayload = L1NotePayload, ): TaggedLog | undefined { try { @@ -111,17 +111,17 @@ export class TaggedLog { static decryptAsOutgoing( encryptedLog: EncryptedL2Log, - ivsk: EmbeddedCurveScalar, + ivsk: GrumpkinScalar, payloadType: typeof L1EventPayload, ): TaggedLog | undefined; static decryptAsOutgoing( data: Buffer | bigint[], - ivsk: EmbeddedCurveScalar, + ivsk: GrumpkinScalar, payloadType?: typeof L1NotePayload, ): TaggedLog | undefined; static decryptAsOutgoing( data: Buffer | bigint[] | EncryptedL2Log, - ovsk: EmbeddedCurveScalar, + 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 db2e2101e6e..94763421d66 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 1d5ea03c039..92c33f47e56 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 EmbeddedCurveScalar } 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: EmbeddedCurveScalar): 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: EmbeddedCurveScalar) { + 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 4f9c308e295..34934e248a8 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 { 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 +11,11 @@ import { getKeyGenerator } from './utils.js'; const curve = new Grumpkin(); -export function computeAppNullifierSecretKey(masterNullifierSecretKey: EmbeddedCurveScalar, 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: EmbeddedCurveScalar, app: AztecAddress, keyPrefix: KeyPrefix): Fr { +export function computeAppSecretKey(skM: GrumpkinScalar, app: AztecAddress, keyPrefix: KeyPrefix): Fr { const generator = getKeyGenerator(keyPrefix); return poseidon2Hash([skM.hi, skM.lo, app, generator]); } @@ -29,7 +28,7 @@ export function computeIvpkApp(ivpk: PublicKey, address: AztecAddress) { return curve.add(curve.mul(Grumpkin.generator, I), ivpk); } -export function computeIvskApp(ivsk: EmbeddedCurveScalar, 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: EmbeddedCurveScalar, address: AztecAddress) return new Fq((I.toBigInt() + ivsk.toBigInt()) % Fq.MODULUS); } -export function computeOvskApp(ovsk: EmbeddedCurveScalar, 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 EmbeddedCurveScalar.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 90aa245ebf6..4fb96fabd0e 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 { EmbeddedCurveScalar } 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 | EmbeddedCurveScalar, + skApp: Fr | GrumpkinScalar, ) { - // I am doing this conversion here because in some places skApp is represented as EmbeddedCurveScalar (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 EmbeddedCurveScalar 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 skAppAsEmbeddedCurveScalar() { - return new EmbeddedCurveScalar(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 991e5736d46..99e1faedb38 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 { EmbeddedCurveScalar } from '../../types/grumpkin_private_key.js'; - export class KeyValidationHint { constructor( /** Master secret key used to derive sk_app and pk_m. */ - public skM: EmbeddedCurveScalar, + 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(EmbeddedCurveScalar), reader.readNumber()); + return new KeyValidationHint(reader.readObject(GrumpkinScalar), reader.readNumber()); } toBuffer() { @@ -20,6 +19,6 @@ export class KeyValidationHint { } static empty() { - return new KeyValidationHint(EmbeddedCurveScalar.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 7f6e1b9c113..9e7154f9393 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 EmbeddedCurveScalar, 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 EmbeddedCurveScalar. + * @returns A GrumpkinScalar. */ -export function makeEmbeddedCurveScalar(seed = 1): EmbeddedCurveScalar { +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 b1726206036..00000000000 --- 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 EmbeddedCurveScalar = GrumpkinScalar; -export const EmbeddedCurveScalar = GrumpkinScalar; diff --git a/yarn-project/circuits.js/src/types/index.ts b/yarn-project/circuits.js/src/types/index.ts index 7b5ccf3c9a1..e928d067652 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 9a5b75bae4f..b1492648f86 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 EmbeddedCurveScalar, 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: EmbeddedCurveScalar) => 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: EmbeddedCurveScalar) => 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 20ea1ccb592..8e982733c99 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, - EmbeddedCurveScalar, + 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, EmbeddedCurveScalar][] = Array.from({ length: numberOfAccounts }).map(_ => [ + const accountKeys: [Fr, GrumpkinScalar][] = Array.from({ length: numberOfAccounts }).map(_ => [ Fr.random(), - EmbeddedCurveScalar.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 2ae8bfe12d8..44a4f8306b6 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 EmbeddedCurveScalar, 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: EmbeddedCurveScalar = PRIVATE_KEY) { + constructor(private privateKey = 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 b630995463d..4df9ce6e3fe 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 EmbeddedCurveScalar, GrumpkinScalar, KEY_PREFIXES, type KeyPrefix, @@ -139,7 +138,7 @@ export class KeyStore { } // Now we find the secret key for the public key - let skM: EmbeddedCurveScalar | 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.hi, - masterIncomingViewingSecretKey.lo, - 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.hi, - masterOutgoingViewingSecretKey.lo, - 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 775758e48ab..210acd1a56e 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 EmbeddedCurveScalar, GrumpkinScalar, Header, KernelCircuitPublicInputs, @@ -152,7 +151,7 @@ import type { Gas as GasNoir, GasSettings as GasSettingsNoir, GlobalVariables as GlobalVariablesNoir, - EmbeddedCurveScalar as EmbeddedCurveScalarNoir, + EmbeddedCurveScalar as GrumpkinScalarNoir, Header as HeaderNoir, KernelCircuitPublicInputs as KernelCircuitPublicInputsNoir, KernelData as KernelDataNoir, @@ -303,11 +302,11 @@ export function mapPointFromNoir(point: NoirPoint): Point { } /** - * Maps a EmbeddedCurveScalar to a noir EmbeddedCurveScalar. - * @param privateKey - The EmbeddedCurveScalar. - * @returns The noir EmbeddedCurveScalar. + * Maps a GrumpkinScalar to a noir GrumpkinScalar. + * @param privateKey - The GrumpkinScalar. + * @returns The noir GrumpkinScalar. */ -export function mapEmbeddedCurveScalarToNoir(privateKey: EmbeddedCurveScalar): EmbeddedCurveScalarNoir { +export function mapGrumpkinScalarToNoir(privateKey: GrumpkinScalar): GrumpkinScalarNoir { return { hi: mapFieldToNoir(privateKey.hi), lo: mapFieldToNoir(privateKey.lo), @@ -321,17 +320,17 @@ export function mapEmbeddedCurveScalarToNoir(privateKey: EmbeddedCurveScalar): E */ export function mapKeyValidationHintToNoir(hint: KeyValidationHint): KeyValidationHintNoir { return { - sk_m: mapEmbeddedCurveScalarToNoir(hint.skM), + sk_m: mapGrumpkinScalarToNoir(hint.skM), request_index: mapNumberToNoir(hint.requestIndex), }; } /** - * Maps a noir EmbeddedCurveScalar to a EmbeddedCurveScalar. - * @param privateKey - The noir EmbeddedCurveScalar. - * @returns The EmbeddedCurveScalar. + * Maps a noir GrumpkinScalar to a GrumpkinScalar. + * @param privateKey - The noir GrumpkinScalar. + * @returns The GrumpkinScalar. */ -export function mapEmbeddedCurveScalarFromNoir(privateKey: EmbeddedCurveScalarNoir): EmbeddedCurveScalar { +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 23ecee44a0f..294d72b7cba 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 EmbeddedCurveScalar, + 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 d2c4db478d6..5511100a5e1 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 EmbeddedCurveScalar, + 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 b94c450ea64..8fb954ea986 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 EmbeddedCurveScalar, INITIAL_L2_BLOCK_NUM, KeyValidationRequest, MAX_NOTE_HASHES_PER_TX, @@ -80,9 +79,9 @@ describe('Note Processor', () => { const app = AztecAddress.random(); - let ownerIvskM: EmbeddedCurveScalar; + let ownerIvskM: GrumpkinScalar; let ownerIvpkM: PublicKey; - let ownerOvskM: EmbeddedCurveScalar; + let ownerOvskM: GrumpkinScalar; 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 1a434eac2f1..1ee5b7bdf19 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 EmbeddedCurveScalar, + 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: EmbeddedCurveScalar; - let ownerOvskM: EmbeddedCurveScalar; - let recipientNskM: EmbeddedCurveScalar; - let recipientOvskM: EmbeddedCurveScalar; + let ownerNskM: GrumpkinScalar; + let ownerOvskM: GrumpkinScalar; + let recipientNskM: GrumpkinScalar; + let recipientOvskM: GrumpkinScalar; const treeHeights: { [name: string]: number } = { noteHash: NOTE_HASH_TREE_HEIGHT,