Skip to content

Commit

Permalink
chore: USe auth witness instead of eip1271
Browse files Browse the repository at this point in the history
  • Loading branch information
LHerskind committed Sep 4, 2023
1 parent c53ab46 commit ace2841
Show file tree
Hide file tree
Showing 22 changed files with 177 additions and 175 deletions.
2 changes: 1 addition & 1 deletion yarn-project/acir-simulator/src/acvm/acvm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const ONE_ACVM_FIELD: ACVMField = `0x${'00'.repeat(Fr.SIZE_IN_BYTES - 1)}
*/
type ORACLE_NAMES =
| 'packArguments'
| 'getEip1271Witness'
| 'getAuthWitness'
| 'getSecretKey'
| 'getNote'
| 'getNotes'
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/acir-simulator/src/client/db_oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export interface DBOracle extends CommitmentsDB {
* @param message_hash - The message hash.
* @returns A Promise that resolves to an array of field elements representing the eip-1271 witness.
*/
getEip1271Witness(message_hash: Fr): Promise<Fr[]>;
getAuthWitness(message_hash: Fr): Promise<Fr[]>;

/**
* Retrieve the secret key associated with a specific public key.
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/acir-simulator/src/client/private_execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ export class PrivateFunctionExecution {
packArguments: async args => {
return toACVMField(await this.context.packedArgsCache.pack(args.map(fromACVMField)));
},
getEip1271Witness: async ([messageHash]) => {
return (await this.context.db.getEip1271Witness(fromACVMField(messageHash))).map(toACVMField);
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]) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ export class AztecRPCServer implements AztecRPC {
this.clientInfo = `${name.split('/')[name.split('/').length - 1]}@${version}`;
}

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

Expand Down
12 changes: 6 additions & 6 deletions yarn-project/aztec-rpc/src/database/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ import { NoteSpendingInfoDao } from './note_spending_info_dao.js';
*/
export interface Database extends ContractDatabase {
/**
* Add a eip1271 witness to the database.
* Add a auth witness to the database.
* @param messageHash - The message hash.
* @param witness - An array of field elements representing the eip1271 witness.
* @param witness - An array of field elements representing the auth witness.
*/
addEip1271Witness(messageHash: Fr, witness: Fr[]): Promise<void>;
addAuthWitness(messageHash: Fr, witness: Fr[]): Promise<void>;

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

/**
* Get auxiliary transaction data based on contract address and storage slot.
Expand Down
18 changes: 9 additions & 9 deletions yarn-project/aztec-rpc/src/database/memory_db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,29 @@ export class MemoryDB extends MemoryContractDatabase implements Database {
private treeRoots: Record<MerkleTreeId, Fr> | undefined;
private globalVariablesHash: Fr | undefined;
private addresses: CompleteAddress[] = [];
private eip1271Witnesses: Record<string, Fr[]> = {};
private authWitnesses: Record<string, Fr[]> = {};

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

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

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

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

async getEip1271Witness(messageHash: Fr): Promise<Fr[]> {
const witness = await this.db.getEip1271Witness(messageHash);
if (!witness) throw new Error(`Unknown eip1271 witness for message hash ${messageHash.toString()}`);
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;
}

Expand Down

Large diffs are not rendered by default.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@ import { Schnorr } from '@aztec/circuits.js/barretenberg';
import { ContractAbi } from '@aztec/foundation/abi';
import { CompleteAddress, NodeInfo, PrivateKey } from '@aztec/types';

import Eip1271AccountContractAbi from '../../abis/schnorr_eip_1271_account_contract.json' assert { type: 'json' };
import { Eip1271AccountEntrypoint } from '../entrypoint/eip_1271_account_entrypoint.js';
import AuthWitnessAccountContractAbi from '../../abis/schnorr_auth_witness_account_contract.json' assert { type: 'json' };
import { AuthWitnessAccountEntrypoint } from '../entrypoint/auth_witness_account_entrypoint.js';
import { AccountContract } from './index.js';

/**
* Account contract that authenticates transactions using Schnorr signatures verified against
* the note encryption key, relying on a single private key for both encryption and authentication.
* Extended to pull verification data from the oracle instead of passed as arguments.
*/
export class Eip1271AccountContract implements AccountContract {
export class AuthWitnessAccountContract implements AccountContract {
constructor(private encryptionPrivateKey: PrivateKey) {}

public getDeploymentArgs() {
return Promise.resolve([]);
}

public async getEntrypoint({ address, partialAddress }: CompleteAddress, { chainId, version }: NodeInfo) {
return new Eip1271AccountEntrypoint(
return new AuthWitnessAccountEntrypoint(
address,
partialAddress,
this.encryptionPrivateKey,
Expand All @@ -30,6 +30,6 @@ export class Eip1271AccountContract implements AccountContract {
}

public getContractAbi(): ContractAbi {
return Eip1271AccountContractAbi as unknown as ContractAbi;
return AuthWitnessAccountContractAbi as unknown as ContractAbi;
}
}
2 changes: 1 addition & 1 deletion yarn-project/aztec.js/src/account/contract/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Entrypoint } from '../index.js';
export * from './ecdsa_account_contract.js';
export * from './schnorr_account_contract.js';
export * from './single_key_account_contract.js';
export * from './eip_1271_account_contract.js';
export * from './auth_witness_account_contract.js';

// docs:start:account-contract-interface
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Signer } from '@aztec/circuits.js/barretenberg';
import { ContractAbi, FunctionAbi, encodeArguments } from '@aztec/foundation/abi';
import { FunctionCall, PackedArguments, TxExecutionRequest } from '@aztec/types';

import SchnorrEip1271AccountContractAbi from '../../abis/schnorr_eip_1271_account_contract.json' assert { type: 'json' };
import SchnorrAuthWitnessAccountContractAbi from '../../abis/schnorr_auth_witness_account_contract.json' assert { type: 'json' };
import { generatePublicKey } from '../../index.js';
import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from '../../utils/defaults.js';
import { buildPayload, hashPayload } from './entrypoint_payload.js';
Expand All @@ -15,7 +15,7 @@ import { CreateTxRequestOpts, Entrypoint } from './index.js';
* secure and should not be used in real use cases.
* The entrypoint is extended to support signing and creating eip1271-like witnesses.
*/
export class Eip1271AccountEntrypoint implements Entrypoint {
export class AuthWitnessAccountEntrypoint implements Entrypoint {
constructor(
private address: AztecAddress,
private partialAddress: PartialAddress,
Expand All @@ -35,12 +35,12 @@ export class Eip1271AccountEntrypoint implements Entrypoint {
}

/**
* Creates an eip1271 witness for the given message. In this case, witness is the public key, the signature
* Creates an AuthWitness witness for the given message. In this case, witness is the public key, the signature
* and the partial address, to be used for verification.
* @param message - The message hash to sign.
* @returns [publicKey, signature, partialAddress] as Fr[].
*/
async createEip1271Witness(message: Buffer): Promise<Fr[]> {
async createAuthWitness(message: Buffer): Promise<Fr[]> {
const signature = this.sign(message);
const publicKey = await generatePublicKey(this.privateKey);

Expand All @@ -53,19 +53,19 @@ export class Eip1271AccountEntrypoint implements Entrypoint {
}

/**
* Returns the transaction request and the eip1271 witness for the given function calls.
* Returns the transaction request and the auth witness for the given function calls.
* Returning the witness here as a nonce is generated in the buildPayload action.
* @param executions - The function calls to execute
* @param opts - The options
* @returns The TxRequest, the eip1271 witness to insert in db and the message signed
* @returns The TxRequest, the auth witness to insert in db and the message signed
*/
async createTxExecutionRequestWithWitness(
executions: FunctionCall[],
opts: CreateTxRequestOpts = {},
): Promise<{
/** The transaction request */
txRequest: TxExecutionRequest;
/** The eip1271 witness */
/** The auth witness */
witness: Fr[];
/** The message signed */
message: Buffer;
Expand All @@ -76,7 +76,7 @@ export class Eip1271AccountEntrypoint implements Entrypoint {

const { payload, packedArguments: callsPackedArguments } = await buildPayload(executions);
const message = await hashPayload(payload);
const witness = await this.createEip1271Witness(message);
const witness = await this.createAuthWitness(message);

const args = [payload];
const abi = this.getEntrypointAbi();
Expand All @@ -97,7 +97,9 @@ export class Eip1271AccountEntrypoint implements Entrypoint {
}

private getEntrypointAbi(): FunctionAbi {
const abi = (SchnorrEip1271AccountContractAbi as any as ContractAbi).functions.find(f => f.name === 'entrypoint');
const abi = (SchnorrAuthWitnessAccountContractAbi as any as ContractAbi).functions.find(
f => f.name === 'entrypoint',
);
if (!abi) throw new Error(`Entrypoint abi for account contract not found`);
return abi;
}
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec.js/src/account/entrypoint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export * from './entrypoint_payload.js';
export * from './entrypoint_utils.js';
export * from './single_key_account_entrypoint.js';
export * from './stored_key_account_entrypoint.js';
export * from './eip_1271_account_entrypoint.js';
export * from './auth_witness_account_entrypoint.js';

/** Options for creating a tx request out of a set of function calls. */
export type CreateTxRequestOpts = {
Expand Down
22 changes: 11 additions & 11 deletions yarn-project/aztec.js/src/aztec_rpc_client/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
TxReceipt,
} from '@aztec/types';

import { CreateTxRequestOpts, Eip1271AccountEntrypoint, Entrypoint } from '../account/entrypoint/index.js';
import { AuthWitnessAccountEntrypoint, CreateTxRequestOpts, Entrypoint } from '../account/entrypoint/index.js';
import { CompleteAddress } from '../index.js';

/**
Expand Down Expand Up @@ -94,8 +94,8 @@ export abstract class BaseWallet implements Wallet {
getSyncStatus(): Promise<SyncStatus> {
return this.rpc.getSyncStatus();
}
addEip1271Witness(messageHash: Fr, witness: Fr[]) {
return this.rpc.addEip1271Witness(messageHash, witness);
addAuthWitness(messageHash: Fr, witness: Fr[]) {
return this.rpc.addAuthWitness(messageHash, witness);
}
}

Expand All @@ -112,17 +112,17 @@ export class EntrypointWallet extends BaseWallet {
}

/**
* A wallet implementation supporting EIP1271.
* A wallet implementation supporting auth witnesses.
* This wallet inserts eip1271-like witnesses into the RPC, which are then fetched using an oracle
* to provide authentication data to the contract during execution.
*/
export class EipEntrypointWallet extends BaseWallet {
constructor(rpc: AztecRPC, protected accountImpl: Eip1271AccountEntrypoint) {
export class AuthWitnessEntrypointWallet extends BaseWallet {
constructor(rpc: AztecRPC, protected accountImpl: AuthWitnessAccountEntrypoint) {
super(rpc);
}

/**
* Create a transaction request and add the eip1271 witness to the RPC.
* Create a transaction request and add the auth witness to the RPC.
* Note: When used in simulations, the witness that is inserted could be used later by attacker with
* access to the RPC.
* Meaning that if you were to use someone elses rpc with db you could send these transactions.
Expand All @@ -140,7 +140,7 @@ export class EipEntrypointWallet extends BaseWallet {
executions,
opts,
);
await this.rpc.addEip1271Witness(Fr.fromBuffer(message), witness);
await this.rpc.addAuthWitness(Fr.fromBuffer(message), witness);
return txRequest;
}

Expand All @@ -154,9 +154,9 @@ export class EipEntrypointWallet extends BaseWallet {
* approvals .
* @param messageHash - The message hash to sign
*/
async signAndAddEip1271Witness(messageHash: Buffer): Promise<void> {
const witness = await this.accountImpl.createEip1271Witness(messageHash);
await this.rpc.addEip1271Witness(Fr.fromBuffer(messageHash), witness);
async signAndAddAuthWitness(messageHash: Buffer): Promise<void> {
const witness = await this.accountImpl.createAuthWitness(messageHash);
await this.rpc.addAuthWitness(Fr.fromBuffer(messageHash), witness);
return Promise.resolve();
}
}
Expand Down
12 changes: 6 additions & 6 deletions yarn-project/end-to-end/src/e2e_account_contracts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { AztecRPCServer } from '@aztec/aztec-rpc';
import {
Account,
AccountContract,
AuthWitnessAccountContract,
AuthWitnessAccountEntrypoint,
AuthWitnessEntrypointWallet,
AztecRPC,
EcdsaAccountContract,
Eip1271AccountContract,
Eip1271AccountEntrypoint,
EipEntrypointWallet,
Fr,
SchnorrAccountContract,
SingleKeyAccountContract,
Expand Down Expand Up @@ -115,7 +115,7 @@ describe('e2e_account_contracts', () => {

describe('eip single-key account', () => {
itShouldBehaveLikeAnAccountContract(
(encryptionKey: PrivateKey) => new Eip1271AccountContract(encryptionKey),
(encryptionKey: PrivateKey) => new AuthWitnessAccountContract(encryptionKey),
async (
rpc: AztecRPC,
encryptionPrivateKey: PrivateKey,
Expand All @@ -127,8 +127,8 @@ describe('e2e_account_contracts', () => {
const tx = await account.deploy();
await tx.wait();
}
const entryPoint = (await account.getEntrypoint()) as unknown as Eip1271AccountEntrypoint;
const wallet = new EipEntrypointWallet(rpc, entryPoint);
const entryPoint = (await account.getEntrypoint()) as unknown as AuthWitnessAccountEntrypoint;
const wallet = new AuthWitnessEntrypointWallet(rpc, entryPoint);
return { account, wallet };
},
);
Expand Down
Loading

0 comments on commit ace2841

Please sign in to comment.