-
Notifications
You must be signed in to change notification settings - Fork 284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: demonstrating use of nsk_app to check nullification #6362
Changes from all commits
e57a82f
f20e5ba
7ff91a3
960f7d0
a852e80
fa883a6
20e7b2b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
import { generatePublicKey } from '@aztec/aztec.js'; | ||
import { type AccountWalletWithSecretKey } from '@aztec/aztec.js/wallet'; | ||
import { type PXE } from '@aztec/circuit-types'; | ||
import { GeneratorIndex } from '@aztec/circuits.js/constants'; | ||
import { sha512ToGrumpkinScalar } from '@aztec/foundation/crypto'; | ||
import { deriveMasterIncomingViewingSecretKey, deriveSigningKey } from '@aztec/circuits.js/keys'; | ||
import { Fr } from '@aztec/foundation/fields'; | ||
|
||
import { getSchnorrAccount } from '../schnorr/index.js'; | ||
|
@@ -14,7 +13,7 @@ export const INITIAL_TEST_SECRET_KEYS = [ | |
]; | ||
|
||
export const INITIAL_TEST_ENCRYPTION_KEYS = INITIAL_TEST_SECRET_KEYS.map(secretKey => | ||
sha512ToGrumpkinScalar([secretKey, GeneratorIndex.IVSK_M]), | ||
deriveMasterIncomingViewingSecretKey(secretKey), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sneaked this change in - it's better to use 1 function for this. |
||
); | ||
// TODO(#5837): come up with a standard signing key derivation scheme instead of using ivsk_m as signing keys here | ||
export const INITIAL_TEST_SIGNING_KEYS = INITIAL_TEST_ENCRYPTION_KEYS; | ||
|
@@ -43,14 +42,14 @@ export async function getDeployedTestAccountsWallets(pxe: PXE): Promise<AccountW | |
const registeredAccounts = await pxe.getRegisteredAccounts(); | ||
return Promise.all( | ||
INITIAL_TEST_SECRET_KEYS.filter(initialSecretKey => { | ||
const initialEncryptionKey = sha512ToGrumpkinScalar([initialSecretKey, GeneratorIndex.IVSK_M]); | ||
const initialEncryptionKey = deriveMasterIncomingViewingSecretKey(initialSecretKey); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sneaked this change in - it's better to use 1 function for this. |
||
const publicKey = generatePublicKey(initialEncryptionKey); | ||
return ( | ||
registeredAccounts.find(registered => registered.publicKeys.masterIncomingViewingPublicKey.equals(publicKey)) != | ||
undefined | ||
); | ||
}).map(secretKey => { | ||
const signingKey = sha512ToGrumpkinScalar([secretKey, GeneratorIndex.IVSK_M]); | ||
const signingKey = deriveSigningKey(secretKey); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sneaked this change in - it's better to use 1 function for this. |
||
// TODO(#5726): use actual salt here instead of hardcoding Fr.ZERO | ||
return getSchnorrAccount(pxe, secretKey, signingKey, Fr.ZERO).getWallet(); | ||
}), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import { type AccountWalletWithSecretKey } from '@aztec/aztec.js/wallet'; | ||
import { type PXE } from '@aztec/circuit-types'; | ||
import { Fr, GeneratorIndex } from '@aztec/circuits.js'; | ||
import { sha512ToGrumpkinScalar } from '@aztec/foundation/crypto'; | ||
import { Fr, deriveSigningKey } from '@aztec/circuits.js'; | ||
|
||
import { getSchnorrAccount } from '../schnorr/index.js'; | ||
|
||
|
@@ -12,24 +11,35 @@ import { getSchnorrAccount } from '../schnorr/index.js'; | |
*/ | ||
export function createAccount(pxe: PXE): Promise<AccountWalletWithSecretKey> { | ||
const secretKey = Fr.random(); | ||
const signingKey = sha512ToGrumpkinScalar([secretKey, GeneratorIndex.IVSK_M]); | ||
const signingKey = deriveSigningKey(secretKey); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sneaked this change in - it's better to use 1 function for this. |
||
return getSchnorrAccount(pxe, secretKey, signingKey).waitSetup(); | ||
} | ||
|
||
/** | ||
* Creates a given number of random accounts using the Schnorr account wallet. | ||
* @param pxe - PXE. | ||
* @param numberOfAccounts - How many accounts to create. | ||
* @param secrets - Optional array of secrets to use for the accounts. If empty, random secrets will be generated. | ||
* @throws If the secrets array is not empty and does not have the same length as the number of accounts. | ||
* @returns The created account wallets. | ||
*/ | ||
export async function createAccounts(pxe: PXE, numberOfAccounts = 1): Promise<AccountWalletWithSecretKey[]> { | ||
export async function createAccounts( | ||
pxe: PXE, | ||
numberOfAccounts = 1, | ||
secrets: Fr[] = [], | ||
): Promise<AccountWalletWithSecretKey[]> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added secrets param here to be able to generate nsk_app for the account (I need the secret for that). There is a getNullifierKeys API on PXE database which is used by oracles but it didn't seem to make sense to expose it on PXE as I don't think it will be needed by anything else but this 1 test case. |
||
const accounts = []; | ||
|
||
if (secrets.length == 0) { | ||
secrets = Array.from({ length: numberOfAccounts }, () => Fr.random()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch 👀 |
||
} else if (secrets.length > 0 && secrets.length !== numberOfAccounts) { | ||
throw new Error('Secrets array must be empty or have the same length as the number of accounts'); | ||
} | ||
|
||
// Prepare deployments | ||
for (let i = 0; i < numberOfAccounts; ++i) { | ||
const secretKey = Fr.random(); | ||
const signingKey = sha512ToGrumpkinScalar([secretKey, GeneratorIndex.IVSK_M]); | ||
const account = getSchnorrAccount(pxe, secretKey, signingKey); | ||
for (const secret of secrets) { | ||
const signingKey = deriveSigningKey(secret); | ||
const account = getSchnorrAccount(pxe, secret, signingKey); | ||
// Unfortunately the function below is not stateless and we call it here because it takes a long time to run and | ||
// the results get stored within the account object. By calling it here we increase the probability of all the | ||
// accounts being deployed in the same block because it makes the deploy() method basically instant. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -218,7 +218,6 @@ export const browserTestSuite = ( | |
createPXEClient, | ||
getSchnorrAccount, | ||
Contract, | ||
deriveKeys, | ||
Fr, | ||
ExtendedNote, | ||
Note, | ||
|
@@ -248,11 +247,9 @@ export const browserTestSuite = ( | |
knownAccounts.push(newAccount); | ||
} | ||
const owner = knownAccounts[0]; | ||
// TODO(#5726): this is messy, maybe we should expose publicKeysHash on account | ||
const publicKeysHash = deriveKeys(INITIAL_TEST_SECRET_KEYS[0]).publicKeys.hash(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was no longer necessary after I cleaned up the complete address. |
||
const ownerAddress = owner.getAddress(); | ||
const tx = new DeployMethod( | ||
publicKeysHash, | ||
owner.getCompleteAddress().publicKeys.hash(), | ||
owner, | ||
TokenContractArtifact, | ||
(a: AztecJs.AztecAddress) => Contract.at(a, TokenContractArtifact, owner), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -804,10 +804,6 @@ export class PXEService implements PXE { | |
return Promise.resolve(this.synchronizer.getSyncStatus()); | ||
} | ||
|
||
public getKeyStore() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nuked this as it seemed like something we don't want exposed and it was not used. |
||
return this.keyStore; | ||
} | ||
|
||
public async isContractClassPubliclyRegistered(id: Fr): Promise<boolean> { | ||
return !!(await this.node.getContractClass(id)); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sneaked this change in - it's better to use 1 function for this.