Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Apr 11, 2024
1 parent e9ab435 commit c22088e
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 6 deletions.
2 changes: 1 addition & 1 deletion barretenberg/sol/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The verification key is currently generated via [Barretenberg](https://github.co

## Generating Verification Keys and Proofs

Run `bootstrap.sh` to clone git submodules, download SRS and generate verification keys, relies on barretenberg already being compiled (run `./bootstrap` in `cpp`). The bootstrap will also install foundry to `./.foundry` so you can use `./.foundry/bin/forge` if you don't already have foundry installed.
Run `bootstrap.sh` to clone git submodules, download SRS and generate verification keys, relies on barretenberg already being compiled (run `./bootstrap` in `cpp`). The bootstrap will also install foundry to `./.foundry` so you can use `$PROJECT_ROOT/foundry/bin/forge` if you don't already have foundry installed.

# Tests

Expand Down
6 changes: 3 additions & 3 deletions noir-projects/aztec-nr/aztec/src/note/utils.nr
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ pub fn compute_note_hash_for_consumption<Note, N>(note: Note) -> Field where Not
} else {
// When nonce is nonzero, that means we are reading a settled note (from tree) created in a
// previous TX. So we need the unique_siloed_note_hash which has already been hashed with
// contract address and then nonce. This hash will match the existing leaf in the private
// data tree, so the kernel can just perform a membership check directly on this hash/leaf.
// contract address and then nonce. This hash will match the existing leaf in the note hash
// tree, so the kernel can just perform a membership check directly on this hash/leaf.
compute_unique_siloed_note_hash(note)
// IMPORTANT NOTE ON REDUNDANT SILOING BY CONTRACT ADDRESS: The note hash computed above is
// "siloed" by contract address. When a note hash is computed solely for the purpose of
Expand All @@ -81,7 +81,7 @@ pub fn compute_note_hash_for_consumption<Note, N>(note: Note) -> Field where Not
// be computed from a siloed note hash. After all, persistable note hashes and nullifiers are
// siloed by the kernel circuit. That being said, the siloed note hash computed above CAN be
// used for nullifier computation, and this achieves the (arguably unnecessary) property that
// nullifiers are computed from a note hash's fully-computed private data tree leaf.
// nullifiers are computed from a note hash's fully-computed note hash tree leaf.
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,6 @@ global NUM_BASE_PARITY_PER_ROOT_PARITY: u64 = 4;
* | MID | 8 < n ≤ 16 | 32 < hash_index ≤ 40 |
* | HIGH | 16 < n ≤ 48 | 40 < hash_index ≤ 48 |
* +-----------+-------------------------------+----------------------+
*
* Note: When modifying, modify `GeneratorIndexPacker` in packer.hpp accordingly.
*/
// Indices with size ≤ 8
global GENERATOR_INDEX__NOTE_HASH = 1;
Expand Down Expand Up @@ -234,3 +232,8 @@ global GENERATOR_INDEX__PUBLIC_CIRCUIT_PUBLIC_INPUTS = 43;
global GENERATOR_INDEX__FUNCTION_ARGS = 44;
global GENERATOR_INDEX__AUTHWIT_INNER = 45;
global GENERATOR_INDEX__AUTHWIT_OUTER = 46;
// Key related generators follow
global GENERATOR_INDEX__NSK_M = 47;
global GENERATOR_INDEX__IVSK_M = 48;
global GENERATOR_INDEX__OVSK_M = 49;
global GENERATOR_INDEX__TSK_M = 50;
1 change: 1 addition & 0 deletions yarn-project/circuit-types/src/keys/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './key_pair.js';
export * from './key_store.js';
export * from './new_key_store.js';
1 change: 1 addition & 0 deletions yarn-project/circuit-types/src/keys/key_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { type AztecAddress, type GrumpkinPrivateKey, type PublicKey } from '@azt
/**
* Represents a secure storage for managing keys.
* Provides functionality to create and retrieve accounts, private and public keys,
* TODO(#5627): 💣💣💣
*/
export interface KeyStore {
/**
Expand Down
36 changes: 36 additions & 0 deletions yarn-project/circuit-types/src/keys/new_key_store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { AztecAddress, Fr, PartialAddress, type PublicKey } from '@aztec/circuits.js';

/**
* Represents a secure storage for managing keys.
*/
export interface NewKeyStore {
/**
* Retrieves the master nullifier public key.
* @returns A Promise that resolves to the master nullifier public key.
*/
getMasterNullifierPublicKey(): Promise<PublicKey>;

/**
* Retrieves the master incoming viewing key.
* @returns A Promise that resolves to the master incoming viewing key.
*/
getMasterIncomingViewingPublicKey(): Promise<PublicKey>;

/**
* Retrieves the master outgoing viewing key.
* @returns A Promise that resolves to the master outgoing viewing key.
*/
getMasterOutgoingViewingPublicKey(): Promise<PublicKey>;

/**
* Retrieves the master tagging key.
* @returns A Promise that resolves to the master tagging key.
*/
getMasterTaggingPublicKey(): Promise<PublicKey>;

/**
* Retrieves the hash of the public keys.
* @returns A Promise that resolves to the hash of the public keys.
*/
getPublicKeysHash(): Promise<PublicKey>;
}
4 changes: 4 additions & 0 deletions yarn-project/circuits.js/src/constants.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,8 @@ export enum GeneratorIndex {
FUNCTION_ARGS = 44,
AUTHWIT_INNER = 45,
AUTHWIT_OUTER = 46,
NSK_M = 47,
IVSK_M = 48,
OVSK_M = 49,
TSK_M = 50,
}
40 changes: 40 additions & 0 deletions yarn-project/key-store/src/new_test_key_store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { type NewKeyStore, type KeyPair, type KeyStore, type PublicKey } from '@aztec/circuit-types';
import {
type AztecAddress,
type GrumpkinPrivateKey,
GrumpkinScalar,
Point,
computeNullifierSecretKey,
computeSiloedNullifierSecretKey,
derivePublicKey,
type Fr,
GeneratorIndex,
Fq,
} from '@aztec/circuits.js';
import { type Grumpkin } from '@aztec/circuits.js/barretenberg';
import { type AztecKVStore, type AztecMap } from '@aztec/kv-store';

import { ConstantKeyPair } from './key_pair.js';
import { poseidonHash } from '@aztec/foundation/crypto';
/**
* TestKeyStore is an implementation of the KeyStore interface, used for managing key pairs in a testing environment.
* It should be utilized in testing scenarios where secure key management is not required, and ease-of-use is prioritized.
* TODO: Potentially rename to not include 'Test' in the name.
*/
export class NewTestKeyStore implements NewKeyStore {
#keys: AztecMap<string, Buffer>;

constructor(private curve: Grumpkin, database: AztecKVStore) {
this.#keys = database.openMap('key_store');
}

public async addAccount(sk: Fr): Promise<PublicKey> {
const masterNullifierSecretKey = poseidonHash([sk], GeneratorIndex.NSK_M);
// TODO: Is converting from Fr to Fq an issue? Fr.MODULUS is < Fq.MODULUS so it wont' throw but should we refactor this?
const masterNullifierPublicKey = this.curve.mul(this.curve.generator(), Fq.fromBuffer(masterNullifierSecretKey.toBuffer()))
}

public async getMasterNullifierPublicKey(): Promise<PublicKey> {
return poseidonHash()
}
}
1 change: 1 addition & 0 deletions yarn-project/key-store/src/test_key_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { ConstantKeyPair } from './key_pair.js';
/**
* TestKeyStore is an implementation of the KeyStore interface, used for managing key pairs in a testing environment.
* It should be utilized in testing scenarios where secure key management is not required, and ease-of-use is prioritized.
* TODO(#5627): 💣💣💣
*/
export class TestKeyStore implements KeyStore {
#keys: AztecMap<string, Buffer>;
Expand Down

0 comments on commit c22088e

Please sign in to comment.