Skip to content
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion barretenberg/ts/src/barretenberg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class BarretenbergSync extends BarretenbergApiSync {
return barretenbergSyncSingletonPromise;
}

static getSingleton() {
static async getSingleton() {
if (!barretenbergSyncSingleton) {
throw new Error('First call BarretenbergSync.initSingleton() on @aztec/bb.js module.');
}
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/accounts/src/defaults/account_contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { DefaultAccountInterface } from '../defaults/account_interface.js';
*/
export abstract class DefaultAccountContract implements AccountContract {
abstract getAuthWitnessProvider(address: CompleteAddress): AuthWitnessProvider;
abstract getDeploymentArgs(): any[] | undefined;
abstract getDeploymentArgs(): Promise<any[] | undefined>;

constructor(private artifact: ContractArtifact) {}

Expand Down
8 changes: 4 additions & 4 deletions yarn-project/accounts/src/ecdsa/ecdsa_k/account_contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export class EcdsaKAccountContract extends DefaultAccountContract {
super(EcdsaKAccountContractArtifact as ContractArtifact);
}

getDeploymentArgs() {
const signingPublicKey = new Ecdsa().computePublicKey(this.signingPrivateKey);
async getDeploymentArgs() {
const signingPublicKey = await new Ecdsa().computePublicKey(this.signingPrivateKey);
return [signingPublicKey.subarray(0, 32), signingPublicKey.subarray(32, 64)];
}

Expand All @@ -30,9 +30,9 @@ export class EcdsaKAccountContract extends DefaultAccountContract {
class EcdsaKAuthWitnessProvider implements AuthWitnessProvider {
constructor(private signingPrivateKey: Buffer) {}

createAuthWit(messageHash: Fr): Promise<AuthWitness> {
async createAuthWit(messageHash: Fr): Promise<AuthWitness> {
const ecdsa = new Ecdsa();
const signature = ecdsa.constructSignature(messageHash.toBuffer(), this.signingPrivateKey);
const signature = await ecdsa.constructSignature(messageHash.toBuffer(), this.signingPrivateKey);
return Promise.resolve(new AuthWitness(messageHash, [...signature.r, ...signature.s]));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class EcdsaRSSHAccountContract extends DefaultAccountContract {
super(EcdsaRAccountContractArtifact as ContractArtifact);
}

getDeploymentArgs() {
async getDeploymentArgs() {
return [this.signingPublicKey.subarray(0, 32), this.signingPublicKey.subarray(32, 64)];
}

Expand Down
8 changes: 4 additions & 4 deletions yarn-project/accounts/src/schnorr/account_contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export class SchnorrAccountContract extends DefaultAccountContract {
super(SchnorrAccountContractArtifact as ContractArtifact);
}

getDeploymentArgs() {
const signingPublicKey = new Schnorr().computePublicKey(this.signingPrivateKey);
async getDeploymentArgs() {
const signingPublicKey = await new Schnorr().computePublicKey(this.signingPrivateKey);
return [signingPublicKey.x, signingPublicKey.y];
}

Expand All @@ -30,9 +30,9 @@ export class SchnorrAccountContract extends DefaultAccountContract {
class SchnorrAuthWitnessProvider implements AuthWitnessProvider {
constructor(private signingPrivateKey: GrumpkinScalar) {}

createAuthWit(messageHash: Fr): Promise<AuthWitness> {
async createAuthWit(messageHash: Fr): Promise<AuthWitness> {
const schnorr = new Schnorr();
const signature = schnorr.constructSignature(messageHash.toBuffer(), this.signingPrivateKey).toBuffer();
const signature = (await schnorr.constructSignature(messageHash.toBuffer(), this.signingPrivateKey)).toBuffer();
return Promise.resolve(new AuthWitness(messageHash, [...signature]));
}
}
6 changes: 3 additions & 3 deletions yarn-project/accounts/src/single_key/account_contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class SingleKeyAccountContract extends DefaultAccountContract {
super(SchnorrSingleKeyAccountContractArtifact as ContractArtifact);
}

getDeploymentArgs(): undefined {
async getDeploymentArgs(): Promise<undefined> {
return undefined;
}

Expand All @@ -33,9 +33,9 @@ export class SingleKeyAccountContract extends DefaultAccountContract {
class SingleKeyAuthWitnessProvider implements AuthWitnessProvider {
constructor(private privateKey: GrumpkinScalar, private account: CompleteAddress) {}

createAuthWit(messageHash: Fr): Promise<AuthWitness> {
async createAuthWit(messageHash: Fr): Promise<AuthWitness> {
const schnorr = new Schnorr();
const signature = schnorr.constructSignature(messageHash.toBuffer(), this.privateKey);
const signature = await schnorr.constructSignature(messageHash.toBuffer(), this.privateKey);
const witness = [...this.account.publicKeys.toFields(), ...signature.toBuffer(), this.account.partialAddress];
return Promise.resolve(new AuthWitness(messageHash, witness));
}
Expand Down
30 changes: 18 additions & 12 deletions yarn-project/accounts/src/testing/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,24 @@ export function getInitialTestAccountsWallets(pxe: PXE): Promise<AccountWalletWi
export async function getDeployedTestAccountsWallets(pxe: PXE): Promise<AccountWalletWithSecretKey[]> {
const registeredAccounts = await pxe.getRegisteredAccounts();
return Promise.all(
INITIAL_TEST_SECRET_KEYS.filter(initialSecretKey => {
const initialEncryptionKey = deriveMasterIncomingViewingSecretKey(initialSecretKey);
const publicKey = generatePublicKey(initialEncryptionKey);
return (
registeredAccounts.find(registered => registered.publicKeys.masterIncomingViewingPublicKey.equals(publicKey)) !=
undefined
);
}).map(secretKey => {
const signingKey = deriveSigningKey(secretKey);
// TODO(#5726): use actual salt here instead of hardcoding Fr.ZERO
return getSchnorrAccount(pxe, secretKey, signingKey, Fr.ZERO).getWallet();
}),
(
await Promise.all(
INITIAL_TEST_SECRET_KEYS.map(async initialSecretKey => {
const initialEncryptionKey = deriveMasterIncomingViewingSecretKey(initialSecretKey);
const publicKey = await generatePublicKey(initialEncryptionKey);
const found = registeredAccounts.find(registered =>
registered.publicKeys.masterIncomingViewingPublicKey.equals(publicKey),
);
return found ? initialSecretKey : undefined;
}),
)
)
.filter((secretKey): secretKey is Fr => !!secretKey)
.map(secretKey => {
const signingKey = deriveSigningKey(secretKey);
// TODO(#5726): use actual salt here instead of hardcoding Fr.ZERO
return getSchnorrAccount(pxe, secretKey, signingKey, Fr.ZERO).getWallet();
}),
);
}

Expand Down
14 changes: 7 additions & 7 deletions yarn-project/archiver/src/archiver/archiver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('Archiver', () => {

const GENESIS_ROOT = new Fr(GENESIS_ARCHIVE_ROOT).toString();

beforeEach(() => {
beforeEach(async () => {
now = +new Date();
publicClient = mock<PublicClient<HttpTransport, Chain>>({
// Return a block with a reasonable timestamp
Expand Down Expand Up @@ -137,7 +137,7 @@ describe('Archiver', () => {
(b, i) =>
(b.header.globalVariables.timestamp = new Fr(now + DefaultL1ContractsConfig.ethereumSlotDuration * (i + 1))),
);
const rollupTxs = blocks.map(makeRollupTx);
const rollupTxs = await Promise.all(blocks.map(makeRollupTx));

publicClient.getBlockNumber.mockResolvedValueOnce(2500n).mockResolvedValueOnce(2600n).mockResolvedValueOnce(2700n);

Expand Down Expand Up @@ -232,7 +232,7 @@ describe('Archiver', () => {

const numL2BlocksInTest = 2;

const rollupTxs = blocks.map(makeRollupTx);
const rollupTxs = await Promise.all(blocks.map(makeRollupTx));

// Here we set the current L1 block number to 102. L1 to L2 messages after this should not be read.
publicClient.getBlockNumber.mockResolvedValue(102n);
Expand Down Expand Up @@ -273,7 +273,7 @@ describe('Archiver', () => {

const numL2BlocksInTest = 2;

const rollupTxs = blocks.map(makeRollupTx);
const rollupTxs = await Promise.all(blocks.map(makeRollupTx));

publicClient.getBlockNumber.mockResolvedValueOnce(50n).mockResolvedValueOnce(100n);
rollupRead.status
Expand Down Expand Up @@ -308,7 +308,7 @@ describe('Archiver', () => {

const numL2BlocksInTest = 2;

const rollupTxs = blocks.map(makeRollupTx);
const rollupTxs = await Promise.all(blocks.map(makeRollupTx));

publicClient.getBlockNumber.mockResolvedValueOnce(50n).mockResolvedValueOnce(100n).mockResolvedValueOnce(150n);

Expand Down Expand Up @@ -409,11 +409,11 @@ describe('Archiver', () => {
* @param block - The L2Block.
* @returns A fake tx with calldata that corresponds to calling process in the Rollup contract.
*/
function makeRollupTx(l2Block: L2Block) {
async function makeRollupTx(l2Block: L2Block) {
const header = toHex(l2Block.header.toBuffer());
const body = toHex(l2Block.body.toBuffer());
const archive = toHex(l2Block.archive.root.toBuffer());
const blockHash = toHex(l2Block.header.hash().toBuffer());
const blockHash = toHex((await l2Block.header.hash()).toBuffer());
const input = encodeFunctionData({
abi: RollupAbi,
functionName: 'propose',
Expand Down
14 changes: 8 additions & 6 deletions yarn-project/archiver/src/archiver/archiver_store_test_suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch
},
});

beforeEach(() => {
beforeEach(async () => {
store = getStore();
blocks = times(10, i => makeL1Published(L2Block.random(i + 1), i + 10));
blocks = await Promise.all(times(10, async i => makeL1Published(await L2Block.random(i + 1), i + 10)));
});

describe('addBlocks', () => {
Expand Down Expand Up @@ -89,7 +89,9 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch
});

it('can unwind multiple empty blocks', async () => {
const emptyBlocks = times(10, i => makeL1Published(L2Block.random(i + 1, 0), i + 10));
const emptyBlocks = await Promise.all(
times(10, async i => makeL1Published(await L2Block.random(i + 1, 0), i + 10)),
);
await store.addBlocks(emptyBlocks);
expect(await store.getSynchedL2BlockNumber()).toBe(10);

Expand Down Expand Up @@ -284,7 +286,7 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch
const blockNum = 10;

beforeEach(async () => {
contractInstance = { ...SerializableContractInstance.random(), address: AztecAddress.random() };
contractInstance = { ...(await SerializableContractInstance.random()), address: AztecAddress.random() };
await store.addContractInstances([contractInstance], blockNum);
});

Expand Down Expand Up @@ -716,8 +718,8 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch
const numBlocks = 10;
const nullifiersPerBlock = new Map<number, Fr[]>();

beforeEach(() => {
blocks = times(numBlocks, (index: number) => L2Block.random(index + 1, 1));
beforeEach(async () => {
blocks = await Promise.all(times(numBlocks, (index: number) => L2Block.random(index + 1, 1)));

blocks.forEach((block, blockIndex) => {
nullifiersPerBlock.set(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export class BlockStore {
* @param txHash - The hash of a tx we try to get the receipt for.
* @returns The requested tx receipt (or undefined if not found).
*/
getSettledTxReceipt(txHash: TxHash): TxReceipt | undefined {
async getSettledTxReceipt(txHash: TxHash): Promise<TxReceipt | undefined> {
const [blockNumber, txIndex] = this.getTxLocation(txHash) ?? [];
if (typeof blockNumber !== 'number' || typeof txIndex !== 'number') {
return undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ export class MemoryArchiverStore implements ArchiverDataStore {
* @param txHash - The hash of a tx we try to get the receipt for.
* @returns The requested tx receipt (or undefined if not found).
*/
public getSettledTxReceipt(txHash: TxHash): Promise<TxReceipt | undefined> {
public async getSettledTxReceipt(txHash: TxHash): Promise<TxReceipt | undefined> {
for (const block of this.l2Blocks) {
for (const txEffect of block.data.body.txEffects) {
if (txEffect.txHash.equals(txHash)) {
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/archiver/src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export async function createArchiver(
async function registerProtocolContracts(store: KVArchiverDataStore) {
const blockNumber = 0;
for (const name of protocolContractNames) {
const contract = getCanonicalProtocolContract(name);
const contract = await getCanonicalProtocolContract(name);
const contractClassPublic: ContractClassPublic = {
...contract.contractClass,
privateFunctions: [],
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/archiver/src/test/mock_archiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class MockPrefilledArchiver extends MockArchiver {
messages.forEach((msgs, i) => this.setL1ToL2Messages(blocks[i].number, msgs));
}

public override createBlocks(numBlocks: number) {
public override async createBlocks(numBlocks: number) {
if (this.l2Blocks.length + numBlocks > this.precomputed.length) {
throw new Error(
`Not enough precomputed blocks to create ${numBlocks} more blocks (already at ${this.l2Blocks.length})`,
Expand Down
6 changes: 3 additions & 3 deletions yarn-project/archiver/src/test/mock_l2_block_source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ export class MockL2BlockSource implements L2BlockSource {

private log = createDebugLogger('aztec:archiver:mock_l2_block_source');

public createBlocks(numBlocks: number) {
public async createBlocks(numBlocks: number) {
for (let i = 0; i < numBlocks; i++) {
const blockNum = this.l2Blocks.length + 1;
const block = L2Block.random(blockNum);
const block = await L2Block.random(blockNum);
this.l2Blocks.push(block);
}

Expand Down Expand Up @@ -141,7 +141,7 @@ export class MockL2BlockSource implements L2BlockSource {
* @param txHash - The hash of a tx we try to get the receipt for.
* @returns The requested tx receipt (or undefined if not found).
*/
public getSettledTxReceipt(txHash: TxHash): Promise<TxReceipt | undefined> {
public async getSettledTxReceipt(txHash: TxHash): Promise<TxReceipt | undefined> {
for (const block of this.l2Blocks) {
for (const txEffect of block.body.txEffects) {
if (txEffect.txHash.equals(txHash)) {
Expand Down
6 changes: 3 additions & 3 deletions yarn-project/aztec-node/src/aztec-node/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('aztec node', () => {

describe('tx validation', () => {
it('tests that the node correctly validates double spends', async () => {
const txs = [mockTxForRollup(0x10000), mockTxForRollup(0x20000)];
const txs = [await mockTxForRollup(0x10000), await mockTxForRollup(0x20000)];
txs.forEach(tx => {
tx.data.constants.txContext.chainId = chainId;
});
Expand Down Expand Up @@ -117,7 +117,7 @@ describe('aztec node', () => {
});

it('tests that the node correctly validates chain id', async () => {
const tx = mockTxForRollup(0x10000);
const tx = await mockTxForRollup(0x10000);
tx.data.constants.txContext.chainId = chainId;

expect(await node.isValidTx(tx)).toBe(true);
Expand All @@ -129,7 +129,7 @@ describe('aztec node', () => {
});

it('tests that the node correctly validates max block numbers', async () => {
const txs = [mockTxForRollup(0x10000), mockTxForRollup(0x20000), mockTxForRollup(0x30000)];
const txs = [await mockTxForRollup(0x10000), await mockTxForRollup(0x20000), await mockTxForRollup(0x30000)];
txs.forEach(tx => {
tx.data.constants.txContext.chainId = chainId;
});
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/aztec-node/src/aztec-node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ export class AztecNodeService implements AztecNode {
true,
);

let l2toL1SubtreeRoots = l2toL1Subtrees.map(t => Fr.fromBuffer(t.getRoot(true)));
let l2toL1SubtreeRoots = await Promise.all(l2toL1Subtrees.map(async t => Fr.fromBuffer(await t.getRoot(true))));
if (l2toL1SubtreeRoots.length < 2) {
l2toL1SubtreeRoots = padArrayEnd(l2toL1SubtreeRoots, Fr.ZERO, 2);
}
Expand Down Expand Up @@ -750,7 +750,7 @@ export class AztecNodeService implements AztecNode {
*/
public async getPublicStorageAt(contract: AztecAddress, slot: Fr, blockNumber: L2BlockNumber): Promise<Fr> {
const committedDb = await this.#getWorldState(blockNumber);
const leafSlot = computePublicDataTreeLeafSlot(contract, slot);
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);

const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
if (!lowLeafResult || !lowLeafResult.alreadyPresent) {
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec.js/src/account/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface AccountContract {
/**
* Returns the deployment arguments for this instance, or undefined if this contract does not require deployment.
*/
getDeploymentArgs(): any[] | undefined;
getDeploymentArgs(): Promise<any[] | undefined>;

/**
* Returns the account interface for this account contract given a deployment at the provided address.
Expand Down
21 changes: 9 additions & 12 deletions yarn-project/aztec.js/src/account_manager/deploy_account_method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { EntrypointPayload, computeCombinedPayloadHash } from '../entrypoint/pay
*/
export class DeployAccountMethod extends DeployMethod {
#authWitnessProvider: AuthWitnessProvider;
#feePaymentArtifact: FunctionArtifact | undefined;
#feePaymentArtifact: Promise<FunctionArtifact | undefined>;

constructor(
authWitnessProvider: AuthWitnessProvider,
Expand All @@ -43,7 +43,7 @@ export class DeployAccountMethod extends DeployMethod {
this.#feePaymentArtifact =
typeof feePaymentNameOrArtifact === 'string'
? getFunctionArtifact(artifact, feePaymentNameOrArtifact)
: feePaymentNameOrArtifact;
: Promise.resolve(feePaymentNameOrArtifact);
}

protected override async getInitializeFunctionCalls(
Expand All @@ -58,23 +58,20 @@ export class DeployAccountMethod extends DeployMethod {
const feePayload = await EntrypointPayload.fromFeeOptions(address, fee);

exec.calls.push({
name: this.#feePaymentArtifact.name,
name: feePaymentArtifact.name,
to: address,
args: encodeArguments(this.#feePaymentArtifact, [emptyAppPayload, feePayload, false]),
selector: FunctionSelector.fromNameAndParameters(
this.#feePaymentArtifact.name,
this.#feePaymentArtifact.parameters,
),
type: this.#feePaymentArtifact.functionType,
isStatic: this.#feePaymentArtifact.isStatic,
returnTypes: this.#feePaymentArtifact.returnTypes,
args: encodeArguments(feePaymentArtifact, [emptyAppPayload, feePayload, false]),
selector: await FunctionSelector.fromNameAndParameters(feePaymentArtifact.name, feePaymentArtifact.parameters),
type: feePaymentArtifact.functionType,
isStatic: feePaymentArtifact.isStatic,
returnTypes: feePaymentArtifact.returnTypes,
});

exec.authWitnesses ??= [];
exec.packedArguments ??= [];

exec.authWitnesses.push(
await this.#authWitnessProvider.createAuthWit(computeCombinedPayloadHash(emptyAppPayload, feePayload)),
await this.#authWitnessProvider.createAuthWit(await computeCombinedPayloadHash(emptyAppPayload, feePayload)),
);

exec.packedArguments.push(...emptyAppPayload.packedArguments);
Expand Down
Loading