Skip to content
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: initial is_valid eip1271 style wallet + minimal test changes #1935

Merged
merged 12 commits into from
Sep 6, 2023
1 change: 1 addition & 0 deletions yarn-project/acir-simulator/src/acvm/acvm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const ONE_ACVM_FIELD: ACVMField = `0x${'00'.repeat(Fr.SIZE_IN_BYTES - 1)}
type ORACLE_NAMES =
| 'computeSelector'
| 'packArguments'
| 'getAuthWitness'
| 'getSecretKey'
| 'getNote'
| 'getNotes'
Expand Down
7 changes: 7 additions & 0 deletions yarn-project/acir-simulator/src/client/db_oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ export interface DBOracle extends CommitmentsDB {
*/
getCompleteAddress(address: AztecAddress): Promise<CompleteAddress>;

/**
* Retrieve the auth witness for a given message hash.
* @param message_hash - The message hash.
* @returns A Promise that resolves to an array of field elements representing the auth witness.
*/
getAuthWitness(message_hash: Fr): Promise<Fr[]>;

/**
* Retrieve the secret key associated with a specific public key.
* The function only allows access to the secret keys of the transaction creator,
Expand Down
3 changes: 3 additions & 0 deletions yarn-project/acir-simulator/src/client/private_execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ export class PrivateFunctionExecution {
packArguments: async args => {
return toACVMField(await this.context.packedArgsCache.pack(args.map(fromACVMField)));
},
getAuthWitness: async ([messageHash]) => {
return (await this.context.db.getAuthWitness(fromACVMField(messageHash))).map(toACVMField);
},
getSecretKey: ([ownerX], [ownerY]) => this.context.getSecretKey(this.contractAddress, ownerX, ownerY),
getPublicKey: async ([acvmAddress]) => {
const address = frToAztecAddress(fromACVMField(acvmAddress));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ export class AztecRPCServer implements AztecRPC {
this.clientInfo = `${name.split('/')[name.split('/').length - 1]}@${version}`;
}

public async addAuthWitness(messageHash: Fr, witness: Fr[]) {
await this.db.addAuthWitness(messageHash, witness);
return Promise.resolve();
}

/**
* Starts the Aztec RPC server by beginning the synchronisation process between the Aztec node and the database.
*
Expand Down
14 changes: 14 additions & 0 deletions yarn-project/aztec-rpc/src/database/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ import { NoteSpendingInfoDao } from './note_spending_info_dao.js';
* addresses, storage slots, and nullifiers.
*/
export interface Database extends ContractDatabase {
/**
* Add a auth witness to the database.
* @param messageHash - The message hash.
* @param witness - An array of field elements representing the auth witness.
*/
addAuthWitness(messageHash: Fr, witness: Fr[]): Promise<void>;

/**
* Fetching the auth witness for a given message hash.
* @param messageHash - The message hash.
* @returns A Promise that resolves to an array of field elements representing the auth witness.
*/
getAuthWitness(messageHash: Fr): Promise<Fr[]>;

/**
* Get auxiliary transaction data based on contract address and storage slot.
* It searches for matching NoteSpendingInfoDao objects in the MemoryDB's noteSpendingInfoTable
Expand Down
20 changes: 20 additions & 0 deletions yarn-project/aztec-rpc/src/database/memory_db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,31 @@ export class MemoryDB extends MemoryContractDatabase implements Database {
private treeRoots: Record<MerkleTreeId, Fr> | undefined;
private globalVariablesHash: Fr | undefined;
private addresses: CompleteAddress[] = [];
private authWitnesses: Record<string, Fr[]> = {};

constructor(logSuffix?: string) {
super(createDebugLogger(logSuffix ? 'aztec:memory_db_' + logSuffix : 'aztec:memory_db'));
}

/**
* Add a auth witness to the database.
* @param messageHash - The message hash.
* @param witness - An array of field elements representing the auth witness.
*/
public addAuthWitness(messageHash: Fr, witness: Fr[]): Promise<void> {
this.authWitnesses[messageHash.toString()] = witness;
return Promise.resolve();
}

/**
* Fetching the auth witness for a given message hash.
* @param messageHash - The message hash.
* @returns A Promise that resolves to an array of field elements representing the auth witness.
*/
public getAuthWitness(messageHash: Fr): Promise<Fr[]> {
return Promise.resolve(this.authWitnesses[messageHash.toString()]);
}

public addNoteSpendingInfo(noteSpendingInfoDao: NoteSpendingInfoDao) {
this.noteSpendingInfoTable.push(noteSpendingInfoDao);
return Promise.resolve();
Expand Down
6 changes: 6 additions & 0 deletions yarn-project/aztec-rpc/src/simulator_oracle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ export class SimulatorOracle implements DBOracle {
return completeAddress;
}

async getAuthWitness(messageHash: Fr): Promise<Fr[]> {
const witness = await this.db.getAuthWitness(messageHash);
if (!witness) throw new Error(`Unknown auth witness for message hash ${messageHash.toString()}`);
return witness;
}

async getNotes(contractAddress: AztecAddress, storageSlot: Fr) {
const noteDaos = await this.db.getNoteSpendingInfo(contractAddress, storageSlot);
return noteDaos.map(({ contractAddress, storageSlot, nonce, notePreimage, siloedNullifier, index }) => ({
Expand Down
Loading