From ee28ff0427fcff32cea3d0b53e546fd36ee7fba1 Mon Sep 17 00:00:00 2001 From: benesjan Date: Fri, 17 May 2024 15:35:51 +0000 Subject: [PATCH] final touches --- .../private-kernel-lib/src/private_kernel_reset.nr | 6 +++--- .../src/structs/private_circuit_public_inputs.ts | 2 +- yarn-project/key-store/src/test_key_store.test.ts | 9 +++++++++ yarn-project/key-store/src/test_key_store.ts | 1 - .../noir-protocol-circuits-types/src/type_conversion.ts | 5 +---- yarn-project/pxe/src/kernel_oracle/index.ts | 2 +- .../build_private_kernel_reset_hints.ts | 2 +- .../pxe/src/kernel_prover/proving_data_oracle.ts | 4 ++-- 8 files changed, 18 insertions(+), 13 deletions(-) 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 31b2e22bc38f..418df560da34 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 @@ -303,15 +303,15 @@ mod tests { let remaining_nullifier_rr_index = builder.previous_kernel.add_read_request_for_pending_nullifier(1); let nullifier_rr = builder.previous_kernel.nullifier_read_requests.storage[remaining_nullifier_rr_index]; - let nk_validation_index = builder.previous_kernel.add_request_for_key_validation(GrumpkinPoint::new(1, 2), 27); - let nk_validation = builder.previous_kernel.key_validation_requests.storage[nk_validation_index]; + let key_validation_index = builder.previous_kernel.add_request_for_key_validation(GrumpkinPoint::new(1, 2), 27); + let key_validation = builder.previous_kernel.key_validation_requests.storage[key_validation_index]; // Check that they have been propagated to the next kernel let result = builder.execute(); assert_eq(result.validation_requests.note_hash_read_requests[0], note_hash_rr); assert_eq(result.validation_requests.nullifier_read_requests[0], nullifier_rr); - assert_eq(result.validation_requests.key_validation_requests[0], nk_validation); + assert_eq(result.validation_requests.key_validation_requests[0], key_validation); } #[test] diff --git a/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts index a6d7c3325b25..16655d7b53a4 100644 --- a/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts @@ -76,7 +76,7 @@ export class PrivateCircuitPublicInputs { */ public nullifierReadRequests: Tuple, /** - * Nullifier key validation requests created by the corresponding function call. + * Key validation requests created by the corresponding function call. */ public keyValidationRequests: Tuple, /** diff --git a/yarn-project/key-store/src/test_key_store.test.ts b/yarn-project/key-store/src/test_key_store.test.ts index 03713707dbd9..7a675b86d8fa 100644 --- a/yarn-project/key-store/src/test_key_store.test.ts +++ b/yarn-project/key-store/src/test_key_store.test.ts @@ -88,6 +88,15 @@ describe('TestKeyStore', () => { `"0x0fde74d5e504c73b58aad420dd72590fc6004571411e7f77c45378714195a52b"`, ); expect(generator).toBe(GeneratorIndex.NSK_M); + + // Manages to find master incoming viewing secret key for pub key + const [masterIncomingViewingSecretKey, generatorIncoming] = await keyStore.getMasterSecretKeyAndAppKeyGenerator( + masterIncomingViewingPublicKey, + ); + expect(masterIncomingViewingSecretKey.toString()).toMatchInlineSnapshot( + `"0x1f1f43082427fed511393bbabf8a471eb87af09f0e95bb740dc33e1ced1a54c1"`, + ); + expect(generatorIncoming).toBe(GeneratorIndex.IVSK_M); }); it('nullifier key rotation tests', async () => { diff --git a/yarn-project/key-store/src/test_key_store.ts b/yarn-project/key-store/src/test_key_store.ts index 605fbffac382..36f8f34ba697 100644 --- a/yarn-project/key-store/src/test_key_store.ts +++ b/yarn-project/key-store/src/test_key_store.ts @@ -301,7 +301,6 @@ export class TestKeyStore implements KeyStore { throw new Error(`Could not find sk_m for pk_m ${masterPublicKey.toString()}. This should not happen.`); } - // TODO(benesjan): make less ugly // Now we determine the key type and return generator accordingly let keyGenerator: KeyGenerator; if (skDbKey.includes('nsk_m')) { 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 d5d778f4864a..3613cc842b56 100644 --- a/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts +++ b/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts @@ -705,10 +705,7 @@ export function mapKeyValidationRequestsToNoir(request: KeyValidationRequest): K * @returns The TS KeyValidationRequest. */ export function mapKeyValidationRequestsFromNoir(request: KeyValidationRequestsNoir): KeyValidationRequest { - return new KeyValidationRequest( - mapPointFromNoir(request.pk_m), - mapFieldFromNoir(request.sk_app), - ); + return new KeyValidationRequest(mapPointFromNoir(request.pk_m), mapFieldFromNoir(request.sk_app)); } function mapScopedKeyValidationRequestsToNoir(request: ScopedKeyValidationRequest): ScopedKeyValidationRequestsNoir { diff --git a/yarn-project/pxe/src/kernel_oracle/index.ts b/yarn-project/pxe/src/kernel_oracle/index.ts index 25c608592fe8..6bafa6e704d3 100644 --- a/yarn-project/pxe/src/kernel_oracle/index.ts +++ b/yarn-project/pxe/src/kernel_oracle/index.ts @@ -69,7 +69,7 @@ export class KernelOracle implements ProvingDataOracle { return header.state.partial.noteHashTree.root; } - public getMasterSecretKey(nullifierPublicKey: Point): Promise<[GrumpkinPrivateKey, KeyGenerator]> { + public getMasterSecretKeyAndAppKeyGenerator(nullifierPublicKey: Point): Promise<[GrumpkinPrivateKey, KeyGenerator]> { return this.keyStore.getMasterSecretKeyAndAppKeyGenerator(nullifierPublicKey); } diff --git a/yarn-project/pxe/src/kernel_prover/private_inputs_builders/build_private_kernel_reset_hints.ts b/yarn-project/pxe/src/kernel_prover/private_inputs_builders/build_private_kernel_reset_hints.ts index ed19aaf1bc61..57ab35c9ef3e 100644 --- a/yarn-project/pxe/src/kernel_prover/private_inputs_builders/build_private_kernel_reset_hints.ts +++ b/yarn-project/pxe/src/kernel_prover/private_inputs_builders/build_private_kernel_reset_hints.ts @@ -64,7 +64,7 @@ async function getMasterSecretKeysAndAppKeyGenerators( if (request.isEmpty()) { break; } - [keys[i], generators[i]] = await oracle.getMasterSecretKey(request.masterPublicKey); + [keys[i], generators[i]] = await oracle.getMasterSecretKeyAndAppKeyGenerator(request.masterPublicKey); } return [keys, generators]; } 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 c05f575162f6..9a0df9807024 100644 --- a/yarn-project/pxe/src/kernel_prover/proving_data_oracle.ts +++ b/yarn-project/pxe/src/kernel_prover/proving_data_oracle.ts @@ -74,10 +74,10 @@ export interface ProvingDataOracle { * Retrieves the sk_m for the pk_m and a generator index of the key type. * @throws If the provided public key is not associated with any of the registered accounts. * @param masterPublicKey - The master public key to get secret key for. - * @returns A Promise that resolves to sk_m. + * @returns A Promise that resolves to sk_m and the corresponding app key generator. * @dev Used when feeding the sk_m to the kernel circuit for keys verification. */ - getMasterSecretKey(masterPublicKey: Point): Promise<[GrumpkinPrivateKey, KeyGenerator]>; + getMasterSecretKeyAndAppKeyGenerator(masterPublicKey: Point): Promise<[GrumpkinPrivateKey, KeyGenerator]>; getFunctionName(contractAddress: AztecAddress, selector: FunctionSelector): Promise; }