Skip to content

Commit

Permalink
final touches
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed May 17, 2024
1 parent 17a4e2d commit 319e407
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,15 +302,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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class PrivateCircuitPublicInputs {
*/
public nullifierReadRequests: Tuple<ReadRequest, typeof MAX_NULLIFIER_READ_REQUESTS_PER_CALL>,
/**
* Nullifier key validation requests created by the corresponding function call.
* Key validation requests created by the corresponding function call.
*/
public keyValidationRequests: Tuple<KeyValidationRequest, typeof MAX_KEY_VALIDATION_REQUESTS_PER_CALL>,
/**
Expand Down
9 changes: 9 additions & 0 deletions yarn-project/key-store/src/test_key_store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
1 change: 0 additions & 1 deletion yarn-project/key-store/src/test_key_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/pxe/src/kernel_oracle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/pxe/src/kernel_prover/proving_data_oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string | undefined>;
}

0 comments on commit 319e407

Please sign in to comment.