From a649422ef3e74845edd986fc5fcc917f3b6c7bad Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 29 Feb 2024 13:50:12 +0000 Subject: [PATCH 01/18] refactor: replacing use of L2Tx with TxEffect --- .../archiver/src/archiver/archiver.ts | 6 +- .../archiver/src/archiver/archiver_store.ts | 4 +- .../src/archiver/archiver_store_test_suite.ts | 6 +- .../archiver/kv_archiver_store/block_store.ts | 8 +- .../kv_archiver_store/kv_archiver_store.ts | 6 +- .../archiver/kv_archiver_store/log_store.ts | 2 +- .../memory_archiver_store.ts | 12 +- .../src/aztec-node/http_rpc_server.ts | 4 +- .../aztec-node/src/aztec-node/server.ts | 6 +- yarn-project/aztec.js/src/contract/sent_tx.ts | 6 +- .../aztec.js/src/rpc_clients/pxe_client.ts | 4 +- .../aztec.js/src/wallet/base_wallet.ts | 6 +- .../src/aztec_node/rpc/aztec_node_client.ts | 4 +- yarn-project/circuit-types/src/index.ts | 1 - .../src/interfaces/aztec-node.ts | 10 +- .../circuit-types/src/interfaces/pxe.ts | 10 +- yarn-project/circuit-types/src/l2_block.ts | 25 +--- .../circuit-types/src/l2_block_source.ts | 10 +- yarn-project/circuit-types/src/l2_tx.test.ts | 15 -- yarn-project/circuit-types/src/l2_tx.ts | 134 ------------------ yarn-project/circuit-types/src/tx_effect.ts | 26 +++- .../src/e2e_non_contract_account.test.ts | 2 +- yarn-project/p2p/src/client/mocks.ts | 6 +- .../pxe/src/pxe_http/pxe_http_server.ts | 4 +- .../pxe/src/pxe_service/pxe_service.ts | 12 +- .../src/pxe_service/test/pxe_service.test.ts | 6 +- 26 files changed, 93 insertions(+), 242 deletions(-) delete mode 100644 yarn-project/circuit-types/src/l2_tx.test.ts delete mode 100644 yarn-project/circuit-types/src/l2_tx.ts diff --git a/yarn-project/archiver/src/archiver/archiver.ts b/yarn-project/archiver/src/archiver/archiver.ts index 5b7ffc3c591..5ec4f2e2b2f 100644 --- a/yarn-project/archiver/src/archiver/archiver.ts +++ b/yarn-project/archiver/src/archiver/archiver.ts @@ -10,7 +10,7 @@ import { L2BlockL2Logs, L2BlockSource, L2LogsSource, - L2Tx, + TxEffect, LogFilter, LogType, TxHash, @@ -419,8 +419,8 @@ export class Archiver implements ArchiveSource { return blocks.length === 0 ? undefined : blocks[0]; } - public getL2Tx(txHash: TxHash): Promise { - return this.store.getL2Tx(txHash); + public getTxEffect(txHash: TxHash): Promise { + return this.store.getTxEffect(txHash); } /** diff --git a/yarn-project/archiver/src/archiver/archiver_store.ts b/yarn-project/archiver/src/archiver/archiver_store.ts index f5449bcc26f..d282698aa78 100644 --- a/yarn-project/archiver/src/archiver/archiver_store.ts +++ b/yarn-project/archiver/src/archiver/archiver_store.ts @@ -5,7 +5,7 @@ import { L1ToL2Message, L2Block, L2BlockL2Logs, - L2Tx, + TxEffect, LogFilter, LogType, TxHash, @@ -51,7 +51,7 @@ export interface ArchiverDataStore { * @param txHash - The txHash of the l2 tx. * @returns The requested L2 tx. */ - getL2Tx(txHash: TxHash): Promise; + getTxEffect(txHash: TxHash): Promise; /** * Append new logs to the store's list. diff --git a/yarn-project/archiver/src/archiver/archiver_store_test_suite.ts b/yarn-project/archiver/src/archiver/archiver_store_test_suite.ts index be90e7da57c..1f4658c988d 100644 --- a/yarn-project/archiver/src/archiver/archiver_store_test_suite.ts +++ b/yarn-project/archiver/src/archiver/archiver_store_test_suite.ts @@ -151,7 +151,7 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch }); }); - describe('getL2Tx', () => { + describe('getTxEffect', () => { beforeEach(async () => { await Promise.all( blocks.map(block => store.addLogs(block.body.encryptedLogs, block.body.unencryptedLogs, block.number)), @@ -167,12 +167,12 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch () => blocks[1].getTx(0), ])('retrieves a previously stored transaction', async getExpectedTx => { const expectedTx = getExpectedTx(); - const actualTx = await store.getL2Tx(expectedTx.txHash); + const actualTx = await store.getTxEffect(expectedTx.txHash); expect(actualTx).toEqual(expectedTx); }); it('returns undefined if tx is not found', async () => { - await expect(store.getL2Tx(new TxHash(Fr.random().toBuffer()))).resolves.toBeUndefined(); + await expect(store.getTxEffect(new TxHash(Fr.random().toBuffer()))).resolves.toBeUndefined(); }); }); diff --git a/yarn-project/archiver/src/archiver/kv_archiver_store/block_store.ts b/yarn-project/archiver/src/archiver/kv_archiver_store/block_store.ts index 49bac68d66b..0d961a11cb5 100644 --- a/yarn-project/archiver/src/archiver/kv_archiver_store/block_store.ts +++ b/yarn-project/archiver/src/archiver/kv_archiver_store/block_store.ts @@ -1,4 +1,4 @@ -import { INITIAL_L2_BLOCK_NUM, L2Block, L2Tx, TxHash } from '@aztec/circuit-types'; +import { INITIAL_L2_BLOCK_NUM, L2Block, TxEffect, TxHash } from '@aztec/circuit-types'; import { AztecAddress } from '@aztec/circuits.js'; import { createDebugLogger } from '@aztec/foundation/log'; import { AztecKVStore, AztecMap, Range } from '@aztec/kv-store'; @@ -98,8 +98,8 @@ export class BlockStore { * @param txHash - The txHash of the l2 tx. * @returns The requested L2 tx. */ - getL2Tx(txHash: TxHash): L2Tx | undefined { - const [blockNumber, txIndex] = this.getL2TxLocation(txHash) ?? []; + getTxEffect(txHash: TxHash): TxEffect | undefined { + const [blockNumber, txIndex] = this.getTxEffectLocation(txHash) ?? []; if (typeof blockNumber !== 'number' || typeof txIndex !== 'number') { return undefined; } @@ -113,7 +113,7 @@ export class BlockStore { * @param txHash - The txHash of the l2 tx. * @returns The block number and index of the tx. */ - getL2TxLocation(txHash: TxHash): [blockNumber: number, txIndex: number] | undefined { + getTxEffectLocation(txHash: TxHash): [blockNumber: number, txIndex: number] | undefined { return this.#txIndex.get(txHash.toString()); } diff --git a/yarn-project/archiver/src/archiver/kv_archiver_store/kv_archiver_store.ts b/yarn-project/archiver/src/archiver/kv_archiver_store/kv_archiver_store.ts index 27f7073109a..946d65ffb5a 100644 --- a/yarn-project/archiver/src/archiver/kv_archiver_store/kv_archiver_store.ts +++ b/yarn-project/archiver/src/archiver/kv_archiver_store/kv_archiver_store.ts @@ -5,7 +5,7 @@ import { L1ToL2Message, L2Block, L2BlockL2Logs, - L2Tx, + TxEffect, LogFilter, LogType, TxHash, @@ -97,8 +97,8 @@ export class KVArchiverDataStore implements ArchiverDataStore { * @param txHash - The txHash of the l2 tx. * @returns The requested L2 tx. */ - getL2Tx(txHash: TxHash): Promise { - return Promise.resolve(this.#blockStore.getL2Tx(txHash)); + getTxEffect(txHash: TxHash): Promise { + return Promise.resolve(this.#blockStore.getTxEffect(txHash)); } /** diff --git a/yarn-project/archiver/src/archiver/kv_archiver_store/log_store.ts b/yarn-project/archiver/src/archiver/kv_archiver_store/log_store.ts index b29e3d67818..e7eef6fa1c9 100644 --- a/yarn-project/archiver/src/archiver/kv_archiver_store/log_store.ts +++ b/yarn-project/archiver/src/archiver/kv_archiver_store/log_store.ts @@ -88,7 +88,7 @@ export class LogStore { throw new Error('Missing txHash'); } - const [blockNumber, txIndex] = this.blockStore.getL2TxLocation(filter.txHash) ?? []; + const [blockNumber, txIndex] = this.blockStore.getTxEffectLocation(filter.txHash) ?? []; if (typeof blockNumber !== 'number' || typeof txIndex !== 'number') { return { logs: [], maxLogsHit: false }; } diff --git a/yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts b/yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts index 9d27331589e..e97a0088e6a 100644 --- a/yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts +++ b/yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts @@ -8,7 +8,7 @@ import { L2Block, L2BlockContext, L2BlockL2Logs, - L2Tx, + TxEffect, LogFilter, LogId, LogType, @@ -32,9 +32,9 @@ export class MemoryArchiverStore implements ArchiverDataStore { private l2BlockContexts: L2BlockContext[] = []; /** - * An array containing all the L2 Txs in the L2 blocks that have been fetched so far. + * An array containing all the the effects in the L2 blocks that have been fetched so far. */ - private l2Txs: L2Tx[] = []; + private txEffects: TxEffect[] = []; /** * An array containing all the encrypted logs that have been fetched so far. @@ -114,7 +114,7 @@ export class MemoryArchiverStore implements ArchiverDataStore { */ public addBlocks(blocks: L2Block[]): Promise { this.l2BlockContexts.push(...blocks.map(block => new L2BlockContext(block))); - this.l2Txs.push(...blocks.flatMap(b => b.getTxs())); + this.txEffects.push(...blocks.flatMap(b => b.getTxs())); return Promise.resolve(true); } @@ -236,8 +236,8 @@ export class MemoryArchiverStore implements ArchiverDataStore { * @param txHash - The txHash of the l2 tx. * @returns The requested L2 tx. */ - public getL2Tx(txHash: TxHash): Promise { - const l2Tx = this.l2Txs.find(tx => tx.txHash.equals(txHash)); + public getTxEffect(txHash: TxHash): Promise { + const l2Tx = this.txEffects.find(tx => tx.txHash.equals(txHash)); return Promise.resolve(l2Tx); } diff --git a/yarn-project/aztec-node/src/aztec-node/http_rpc_server.ts b/yarn-project/aztec-node/src/aztec-node/http_rpc_server.ts index fbbbed51794..efe1ff8fef4 100644 --- a/yarn-project/aztec-node/src/aztec-node/http_rpc_server.ts +++ b/yarn-project/aztec-node/src/aztec-node/http_rpc_server.ts @@ -6,7 +6,7 @@ import { L1ToL2MessageAndIndex, L2Block, L2BlockL2Logs, - L2Tx, + TxEffect, LogId, SiblingPath, Tx, @@ -36,7 +36,7 @@ export function createAztecNodeRpcServer(node: AztecNode) { FunctionSelector, Header, L2Block, - L2Tx, + TxEffect, LogId, TxHash, SiblingPath, diff --git a/yarn-project/aztec-node/src/aztec-node/server.ts b/yarn-project/aztec-node/src/aztec-node/server.ts index a1dd850558a..2f610ebd07f 100644 --- a/yarn-project/aztec-node/src/aztec-node/server.ts +++ b/yarn-project/aztec-node/src/aztec-node/server.ts @@ -12,7 +12,7 @@ import { L2BlockL2Logs, L2BlockSource, L2LogsSource, - L2Tx, + TxEffect, LogFilter, LogType, MerkleTreeId, @@ -285,8 +285,8 @@ export class AztecNodeService implements AztecNode { await this.p2pClient!.sendTx(tx); } - public getTx(txHash: TxHash): Promise { - return this.blockSource.getL2Tx(txHash); + public getTxEffect(txHash: TxHash): Promise { + return this.blockSource.getTxEffect(txHash); } /** diff --git a/yarn-project/aztec.js/src/contract/sent_tx.ts b/yarn-project/aztec.js/src/contract/sent_tx.ts index 1b544f10b4f..be3166b2b24 100644 --- a/yarn-project/aztec.js/src/contract/sent_tx.ts +++ b/yarn-project/aztec.js/src/contract/sent_tx.ts @@ -68,15 +68,15 @@ export class SentTx { } if (opts?.debug) { const txHash = await this.getTxHash(); - const tx = (await this.pxe.getTx(txHash))!; + const tx = (await this.pxe.getTxEffect(txHash))!; const visibleNotes = await this.pxe.getNotes({ txHash }); receipt.debugInfo = { newNoteHashes: tx.newNoteHashes, newNullifiers: tx.newNullifiers, newPublicDataWrites: tx.newPublicDataWrites, newL2ToL1Msgs: tx.newL2ToL1Msgs, - newContracts: tx.newContracts, - newContractData: tx.newContractData, + newContracts: tx.contractLeaves, + newContractData: tx.contractData, visibleNotes, }; } diff --git a/yarn-project/aztec.js/src/rpc_clients/pxe_client.ts b/yarn-project/aztec.js/src/rpc_clients/pxe_client.ts index 61a7a480985..8cd5b3f2a66 100644 --- a/yarn-project/aztec.js/src/rpc_clients/pxe_client.ts +++ b/yarn-project/aztec.js/src/rpc_clients/pxe_client.ts @@ -6,7 +6,7 @@ import { ExtendedUnencryptedL2Log, L2Block, L2BlockL2Logs, - L2Tx, + TxEffect, LogId, Note, PXE, @@ -48,7 +48,7 @@ export const createPXEClient = (url: string, fetch = makeFetch([1, 2, 3], false) Fr, GrumpkinScalar, L2Block, - L2Tx, + TxEffect, LogId, Note, Point, diff --git a/yarn-project/aztec.js/src/wallet/base_wallet.ts b/yarn-project/aztec.js/src/wallet/base_wallet.ts index 63b732c62e6..a1a0f9ff883 100644 --- a/yarn-project/aztec.js/src/wallet/base_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/base_wallet.ts @@ -7,7 +7,7 @@ import { FunctionCall, GetUnencryptedLogsResponse, L2Block, - L2Tx, + TxEffect, LogFilter, NoteFilter, PXE, @@ -75,8 +75,8 @@ export abstract class BaseWallet implements Wallet { sendTx(tx: Tx): Promise { return this.pxe.sendTx(tx); } - getTx(txHash: TxHash): Promise { - return this.pxe.getTx(txHash); + getTxEffect(txHash: TxHash): Promise { + return this.pxe.getTxEffect(txHash); } getTxReceipt(txHash: TxHash): Promise { return this.pxe.getTxReceipt(txHash); diff --git a/yarn-project/circuit-types/src/aztec_node/rpc/aztec_node_client.ts b/yarn-project/circuit-types/src/aztec_node/rpc/aztec_node_client.ts index 4946ead7690..dad9b3513fb 100644 --- a/yarn-project/circuit-types/src/aztec_node/rpc/aztec_node_client.ts +++ b/yarn-project/circuit-types/src/aztec_node/rpc/aztec_node_client.ts @@ -9,10 +9,10 @@ import { ContractData, ExtendedContractData } from '../../contract_data.js'; import { AztecNode } from '../../interfaces/aztec-node.js'; import { L1ToL2MessageAndIndex } from '../../l1_to_l2_message.js'; import { L2Block } from '../../l2_block.js'; -import { L2Tx } from '../../l2_tx.js'; import { ExtendedUnencryptedL2Log, L2BlockL2Logs, LogId } from '../../logs/index.js'; import { SiblingPath } from '../../sibling_path/index.js'; import { Tx, TxHash } from '../../tx/index.js'; +import { TxEffect } from '../../tx_effect.js'; /** * Creates a JSON-RPC client to remotely talk to an Aztec Node. @@ -34,7 +34,7 @@ export function createAztecNodeClient(url: string, fetch = defaultFetch): AztecN FunctionSelector, Header, L2Block, - L2Tx, + TxEffect, LogId, TxHash, SiblingPath, diff --git a/yarn-project/circuit-types/src/index.ts b/yarn-project/circuit-types/src/index.ts index 8904cdd5873..fbcdc2343e5 100644 --- a/yarn-project/circuit-types/src/index.ts +++ b/yarn-project/circuit-types/src/index.ts @@ -11,7 +11,6 @@ export * from './body.js'; export * from './l2_block_context.js'; export * from './l2_block_downloader/index.js'; export * from './l2_block_source.js'; -export * from './l2_tx.js'; export * from './tx_effect.js'; export * from './logs/index.js'; export * from './merkle_tree_id.js'; diff --git a/yarn-project/circuit-types/src/interfaces/aztec-node.ts b/yarn-project/circuit-types/src/interfaces/aztec-node.ts index e3b287c8c43..0509ee90db8 100644 --- a/yarn-project/circuit-types/src/interfaces/aztec-node.ts +++ b/yarn-project/circuit-types/src/interfaces/aztec-node.ts @@ -15,7 +15,6 @@ import { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/types/c import { ContractData, ExtendedContractData } from '../contract_data.js'; import { L1ToL2MessageAndIndex } from '../l1_to_l2_message.js'; import { L2Block } from '../l2_block.js'; -import { L2Tx } from '../l2_tx.js'; import { GetUnencryptedLogsResponse, L2BlockL2Logs, LogFilter, LogType } from '../logs/index.js'; import { MerkleTreeId } from '../merkle_tree_id.js'; import { SiblingPath } from '../sibling_path/index.js'; @@ -23,6 +22,7 @@ import { Tx, TxHash } from '../tx/index.js'; import { SequencerConfig } from './configs.js'; import { NullifierMembershipWitness } from './nullifier_tree.js'; import { PublicDataWitness } from './public_data_tree.js'; +import { TxEffect } from '../tx_effect.js'; /** Helper type for a specific L2 block number or the latest block number */ type BlockNumber = number | 'latest'; @@ -231,11 +231,11 @@ export interface AztecNode { sendTx(tx: Tx): Promise; /** - * Get a settled tx. - * @param txHash - The txHash being requested. - * @returns The tx requested. + * Get a tx effect. + * @param txHash - The hash of a transaction which resulted in the returned tx effect. + * @returns The requested tx effect. */ - getTx(txHash: TxHash): Promise; + getTxEffect(txHash: TxHash): Promise; /** * Method to retrieve pending txs. diff --git a/yarn-project/circuit-types/src/interfaces/pxe.ts b/yarn-project/circuit-types/src/interfaces/pxe.ts index eaa4fcc63df..7a0b3784afb 100644 --- a/yarn-project/circuit-types/src/interfaces/pxe.ts +++ b/yarn-project/circuit-types/src/interfaces/pxe.ts @@ -5,7 +5,6 @@ import { NodeInfo } from '@aztec/types/interfaces'; import { AuthWitness } from '../auth_witness.js'; import { ContractData, ExtendedContractData } from '../contract_data.js'; import { L2Block } from '../l2_block.js'; -import { L2Tx } from '../l2_tx.js'; import { GetUnencryptedLogsResponse, LogFilter } from '../logs/index.js'; import { ExtendedNote } from '../notes/index.js'; import { NoteFilter } from '../notes/note_filter.js'; @@ -13,6 +12,7 @@ import { Tx, TxHash, TxReceipt } from '../tx/index.js'; import { TxExecutionRequest } from '../tx_execution_request.js'; import { DeployedContract } from './deployed-contract.js'; import { SyncStatus } from './sync-status.js'; +import { TxEffect } from '../tx_effect.js'; // docs:start:pxe-interface /** @@ -145,11 +145,11 @@ export interface PXE { getTxReceipt(txHash: TxHash): Promise; /** - * Fetches a transaction by its hash. - * @param txHash - The transaction hash - * @returns A transaction object or undefined if the transaction hasn't been mined yet + * Get a tx effect. + * @param txHash - The hash of a transaction which resulted in the returned tx effect. + * @returns The requested tx effect. */ - getTx(txHash: TxHash): Promise; + getTxEffect(txHash: TxHash): Promise; /** * Gets the storage value at the given contract storage slot. diff --git a/yarn-project/circuit-types/src/l2_block.ts b/yarn-project/circuit-types/src/l2_block.ts index 57e4738461a..bfca9b1e60e 100644 --- a/yarn-project/circuit-types/src/l2_block.ts +++ b/yarn-project/circuit-types/src/l2_block.ts @@ -1,4 +1,4 @@ -import { Body, L2Tx, TxHash } from '@aztec/circuit-types'; +import { Body, TxEffect, TxHash } from '@aztec/circuit-types'; import { AppendOnlyTreeSnapshot, Header, STRING_ENCODING } from '@aztec/circuits.js'; import { makeAppendOnlyTreeSnapshot, makeHeader } from '@aztec/circuits.js/testing'; import { sha256 } from '@aztec/foundation/crypto'; @@ -236,28 +236,9 @@ export class L2Block { * @param txIndex - The index of the tx in the block. * @returns The tx. */ - getTx(txIndex: number) { + getTx(txIndex: number): TxEffect { this.assertIndexInRange(txIndex); - - const txEffect = this.body.txEffects[txIndex]; - - const newNoteHashes = txEffect.newNoteHashes.filter(x => !x.isZero()); - const newNullifiers = txEffect.newNullifiers.filter(x => !x.isZero()); - const newPublicDataWrites = txEffect.newPublicDataWrites.filter(x => !x.isEmpty()); - const newL2ToL1Msgs = txEffect.newL2ToL1Msgs.filter(x => !x.isZero()); - const newContracts = txEffect.contractLeaves.filter(x => !x.isZero()); - const newContractData = txEffect.contractData.filter(x => !x.isEmpty()); - - return new L2Tx( - newNoteHashes, - newNullifiers, - newPublicDataWrites, - newL2ToL1Msgs, - newContracts, - newContractData, - this.hash(), - Number(this.header.globalVariables.blockNumber.toBigInt()), - ); + return this.body.txEffects[txIndex]; } /** diff --git a/yarn-project/circuit-types/src/l2_block_source.ts b/yarn-project/circuit-types/src/l2_block_source.ts index 02e5b6dcda5..ca60496af36 100644 --- a/yarn-project/circuit-types/src/l2_block_source.ts +++ b/yarn-project/circuit-types/src/l2_block_source.ts @@ -1,8 +1,8 @@ import { EthAddress } from '@aztec/circuits.js'; import { L2Block } from './l2_block.js'; -import { L2Tx } from './l2_tx.js'; import { TxHash } from './tx/tx_hash.js'; +import { TxEffect } from './tx_effect.js'; /** * Interface of classes allowing for the retrieval of L2 blocks. @@ -42,11 +42,11 @@ export interface L2BlockSource { getBlocks(from: number, limit: number): Promise; /** - * Gets an l2 tx. - * @param txHash - The txHash of the l2 tx. - * @returns The requested L2 tx. + * Gets a tx effect. + * @param txHash - The hash of a transaction which resulted in the returned tx effect. + * @returns The requested tx effect. */ - getL2Tx(txHash: TxHash): Promise; + getTxEffect(txHash: TxHash): Promise; /** * Starts the L2 block source. diff --git a/yarn-project/circuit-types/src/l2_tx.test.ts b/yarn-project/circuit-types/src/l2_tx.test.ts deleted file mode 100644 index 460943240cf..00000000000 --- a/yarn-project/circuit-types/src/l2_tx.test.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { L2Tx } from './l2_tx.js'; - -describe('L2Tx', () => { - it('convert to and from buffer', () => { - const tx = L2Tx.random(); - const buf = tx.toBuffer(); - expect(L2Tx.fromBuffer(buf)).toEqual(tx); - }); - - it('converts to and from string', () => { - const tx = L2Tx.random(); - const str = tx.toString(); - expect(L2Tx.fromString(str)).toEqual(tx); - }); -}); diff --git a/yarn-project/circuit-types/src/l2_tx.ts b/yarn-project/circuit-types/src/l2_tx.ts deleted file mode 100644 index 4c5d9514cd3..00000000000 --- a/yarn-project/circuit-types/src/l2_tx.ts +++ /dev/null @@ -1,134 +0,0 @@ -import { - MAX_NEW_CONTRACTS_PER_TX, - MAX_NEW_L2_TO_L1_MSGS_PER_TX, - MAX_NEW_NOTE_HASHES_PER_TX, - MAX_NEW_NULLIFIERS_PER_TX, - MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, - Vector, -} from '@aztec/circuits.js'; -import { times } from '@aztec/foundation/collection'; -import { Fr } from '@aztec/foundation/fields'; -import { BufferReader, numToUInt32BE } from '@aztec/foundation/serialize'; - -import { ContractData } from './contract_data.js'; -import { PublicDataWrite } from './public_data_write.js'; -import { TxHash } from './tx/tx_hash.js'; - -/** - * The string encoding used for serializing L2Tx objects to strings. - */ -const STRING_ENCODING: BufferEncoding = 'hex'; - -/** - * Represents an L2 transaction. - */ -export class L2Tx { - /** - * The transaction's hash. - * Note: It's the first nullifier emitted by the kernel circuit. - */ - public readonly txHash: TxHash; - - constructor( - /** - * New note hashes created by the transaction. - */ - public newNoteHashes: Fr[], - /** - * New nullifiers created by the transaction. - */ - public newNullifiers: Fr[], - /** - * New public data writes created by the transaction. - */ - public newPublicDataWrites: PublicDataWrite[], - /** - * New L2 to L1 messages created by the transaction. - */ - public newL2ToL1Msgs: Fr[], - /** - * New contracts leaves created by the transaction to be inserted into the contract tree. - */ - public newContracts: Fr[], - /** - * New contract data created by the transaction. - */ - public newContractData: ContractData[], - /** - * The unique identifier of the block containing the transaction. - */ - public blockHash: Fr, - /** - * The block number in which the transaction was included. - */ - public blockNumber: number, - ) { - this.txHash = new TxHash(this.newNullifiers[0].toBuffer()); - } - - /** - * Deserializes the L2Tx object from a Buffer. - * @param buffer - Buffer or BufferReader object to deserialize. - * @returns An instance of L2Tx. - */ - static fromBuffer(buffer: Buffer | BufferReader): L2Tx { - const reader = BufferReader.asReader(buffer); - return new L2Tx( - reader.readVector(Fr), - reader.readVector(Fr), - reader.readVector(PublicDataWrite), - reader.readVector(Fr), - reader.readVector(Fr), - reader.readVector(ContractData), - Fr.fromBuffer(reader), - reader.readNumber(), - ); - } - - /** - * Deserializes an L2Tx object from a string. - * @param str - String to deserialize. - * @returns An instance of L2Tx. - */ - static fromString(str: string) { - return L2Tx.fromBuffer(Buffer.from(str, STRING_ENCODING)); - } - - /** - * Serializes the Tx object into a Buffer. - * @returns Buffer representation of the Tx object. - */ - toBuffer() { - return Buffer.concat([ - new Vector(this.newNoteHashes).toBuffer(), - new Vector(this.newNullifiers).toBuffer(), - new Vector(this.newPublicDataWrites).toBuffer(), - new Vector(this.newL2ToL1Msgs).toBuffer(), - new Vector(this.newContracts).toBuffer(), - new Vector(this.newContractData).toBuffer(), - this.blockHash.toBuffer(), - numToUInt32BE(this.blockNumber), - ]); - } - - /** - * Returns a string representation of the L2Tx object. - */ - toString(): string { - return this.toBuffer().toString(STRING_ENCODING); - } - - static random() { - const rand = (min: number, max: number) => Math.floor(Math.random() * max) + min; - return new L2Tx( - times(rand(0, MAX_NEW_NOTE_HASHES_PER_TX), Fr.random), - times(rand(1, MAX_NEW_NULLIFIERS_PER_TX), Fr.random), - times(rand(0, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX), PublicDataWrite.random), - times(rand(0, MAX_NEW_L2_TO_L1_MSGS_PER_TX), Fr.random), - times(rand(0, MAX_NEW_CONTRACTS_PER_TX), Fr.random), - times(rand(0, MAX_NEW_CONTRACTS_PER_TX), ContractData.random), - Fr.random(), - 123, - ); - } -} diff --git a/yarn-project/circuit-types/src/tx_effect.ts b/yarn-project/circuit-types/src/tx_effect.ts index b3830ac57c3..0e31a6a3b92 100644 --- a/yarn-project/circuit-types/src/tx_effect.ts +++ b/yarn-project/circuit-types/src/tx_effect.ts @@ -1,4 +1,4 @@ -import { ContractData, LogType, PublicDataWrite, TxL2Logs } from '@aztec/circuit-types'; +import { ContractData, LogType, PublicDataWrite, TxHash, TxL2Logs } from '@aztec/circuit-types'; import { Fr, MAX_NEW_CONTRACTS_PER_TX, @@ -67,9 +67,9 @@ export class TxEffect { } /** - * Deserializes the L2Tx object from a Buffer. + * Deserializes the TxEffect object from a Buffer. * @param buffer - Buffer or BufferReader object to deserialize. - * @returns An instance of L2Tx. + * @returns An instance of TxEffect. */ static fromBuffer(buffer: Buffer | BufferReader): TxEffect { const reader = BufferReader.asReader(buffer); @@ -141,4 +141,24 @@ export class TxEffect { TxL2Logs.random(numPublicCallsPerTx, numUnencryptedLogsPerCall, LogType.UNENCRYPTED), ); } + + /** + * Returns a string representation of the TxEffect object. + */ + toString(): string { + return this.toBuffer().toString('hex'); + } + + /** + * Deserializes an TxEffect object from a string. + * @param str - String to deserialize. + * @returns An instance of TxEffect. + */ + static fromString(str: string) { + return TxEffect.fromBuffer(Buffer.from(str, 'hex')); + } + + get txHash(): TxHash { + return new TxHash(this.newNullifiers[0].toBuffer()); + } } diff --git a/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts b/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts index 597fe7e944e..cb0710268b7 100644 --- a/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts +++ b/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts @@ -45,7 +45,7 @@ describe('e2e_non_contract_account', () => { const receipt = await contractWithNoContractWallet.methods.emit_nullifier(nullifier).send().wait({ interval: 0.1 }); expect(receipt.status).toBe(TxStatus.MINED); - const tx = await aztecNode!.getTx(receipt.txHash); + const tx = await aztecNode!.getTxEffect(receipt.txHash); const expectedSiloedNullifier = siloNullifier(contract.address, nullifier); const siloedNullifier = tx!.newNullifiers[1]; diff --git a/yarn-project/p2p/src/client/mocks.ts b/yarn-project/p2p/src/client/mocks.ts index 99bf33d033f..1353c1deaf4 100644 --- a/yarn-project/p2p/src/client/mocks.ts +++ b/yarn-project/p2p/src/client/mocks.ts @@ -1,4 +1,4 @@ -import { L2Block, L2BlockSource, L2Tx, TxHash } from '@aztec/circuit-types'; +import { L2Block, L2BlockSource, TxEffect, TxHash } from '@aztec/circuit-types'; import { EthAddress } from '@aztec/circuits.js'; /** @@ -6,7 +6,7 @@ import { EthAddress } from '@aztec/circuits.js'; */ export class MockBlockSource implements L2BlockSource { private l2Blocks: L2Block[] = []; - private l2Txs: L2Tx[] = []; + private l2Txs: TxEffect[] = []; constructor(private numBlocks = 100) { for (let i = 0; i < this.numBlocks; i++) { @@ -64,7 +64,7 @@ export class MockBlockSource implements L2BlockSource { * @param txHash - The txHash of the l2 tx. * @returns The requested L2 tx. */ - getL2Tx(txHash: TxHash) { + getTxEffect(txHash: TxHash) { const l2Tx = this.l2Txs.find(tx => tx.txHash.equals(txHash)); return Promise.resolve(l2Tx); } diff --git a/yarn-project/pxe/src/pxe_http/pxe_http_server.ts b/yarn-project/pxe/src/pxe_http/pxe_http_server.ts index 1a379c9d0a9..d9adaea5806 100644 --- a/yarn-project/pxe/src/pxe_http/pxe_http_server.ts +++ b/yarn-project/pxe/src/pxe_http/pxe_http_server.ts @@ -7,7 +7,7 @@ import { ExtendedUnencryptedL2Log, L2Block, L2BlockL2Logs, - L2Tx, + TxEffect, LogId, Note, PXE, @@ -48,7 +48,7 @@ export function createPXERpcServer(pxeService: PXE): JsonRpcServer { ExtendedNote, AuthWitness, L2Block, - L2Tx, + TxEffect, LogId, }, { Tx, TxReceipt, L2BlockL2Logs }, diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index 90515343744..a7e45b06180 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -10,7 +10,7 @@ import { GetUnencryptedLogsResponse, KeyStore, L2Block, - L2Tx, + TxEffect, LogFilter, MerkleTreeId, NoteFilter, @@ -336,7 +336,7 @@ export class PXEService implements PXE { * @remarks More than a single nonce may be returned since there might be more than one nonce for a given note. */ private async getNoteNonces(note: ExtendedNote): Promise { - const tx = await this.node.getTx(note.txHash); + const tx = await this.node.getTxEffect(note.txHash); if (!tx) { throw new Error(`Unknown tx: ${note.txHash}`); } @@ -413,7 +413,7 @@ export class PXEService implements PXE { public async sendTx(tx: Tx): Promise { const txHash = tx.getTxHash(); - if (await this.node.getTx(txHash)) { + if (await this.node.getTxEffect(txHash)) { throw new Error(`A settled tx with equal hash ${txHash.toString()} exists.`); } this.log.info(`Sending transaction ${txHash}`); @@ -449,7 +449,7 @@ export class PXEService implements PXE { txReceipt = new TxReceipt(txHash, TxStatus.PENDING, ''); } - const settledTx = await this.node.getTx(txHash); + const settledTx = await this.node.getTxEffect(txHash); if (settledTx) { txReceipt = new TxReceipt(txHash, TxStatus.MINED, '', settledTx.blockHash.toBuffer(), settledTx.blockNumber); } @@ -457,8 +457,8 @@ export class PXEService implements PXE { return txReceipt; } - public async getTx(txHash: TxHash): Promise { - return await this.node.getTx(txHash); + public async getTxEffect(txHash: TxHash): Promise { + return await this.node.getTxEffect(txHash); } async getBlockNumber(): Promise { diff --git a/yarn-project/pxe/src/pxe_service/test/pxe_service.test.ts b/yarn-project/pxe/src/pxe_service/test/pxe_service.test.ts index 2258dca6566..4fb92a292bc 100644 --- a/yarn-project/pxe/src/pxe_service/test/pxe_service.test.ts +++ b/yarn-project/pxe/src/pxe_service/test/pxe_service.test.ts @@ -1,4 +1,4 @@ -import { AztecNode, INITIAL_L2_BLOCK_NUM, L2Tx, PXE, mockTx } from '@aztec/circuit-types'; +import { AztecNode, INITIAL_L2_BLOCK_NUM, TxEffect, PXE, mockTx } from '@aztec/circuit-types'; import { Grumpkin } from '@aztec/circuits.js/barretenberg'; import { L1ContractAddresses } from '@aztec/ethereum'; import { EthAddress } from '@aztec/foundation/eth-address'; @@ -54,10 +54,10 @@ describe('PXEService', () => { }); it('throws when submitting a tx with a nullifier of already settled tx', async () => { - const settledTx = L2Tx.random(); + const settledTx = TxEffect.random(); const duplicateTx = mockTx(); - node.getTx.mockResolvedValue(settledTx); + node.getTxEffect.mockResolvedValue(settledTx); const pxe = new PXEService(keyStore, node, db, config); await expect(pxe.sendTx(duplicateTx)).rejects.toThrowError(/A settled tx with equal hash/); From 191d293176a9a4bfd96255df5f03371cf88371b6 Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 29 Feb 2024 14:50:40 +0000 Subject: [PATCH 02/18] WIP --- .../archiver/src/archiver/archiver.ts | 7 +++- .../archiver/src/archiver/archiver_store.ts | 16 ++++++--- .../archiver/kv_archiver_store/block_store.ts | 31 ++++++++++++----- .../kv_archiver_store/kv_archiver_store.ts | 18 +++++++--- .../archiver/kv_archiver_store/log_store.ts | 2 +- .../memory_archiver_store.ts | 32 +++++++++++++---- .../src/aztec-node/http_rpc_server.ts | 2 +- .../aztec-node/src/aztec-node/server.ts | 23 ++++++++++++- .../aztec.js/src/rpc_clients/pxe_client.ts | 2 +- .../aztec.js/src/wallet/base_wallet.ts | 2 +- .../src/interfaces/aztec-node.ts | 14 ++++++-- .../circuit-types/src/interfaces/pxe.ts | 2 +- .../circuit-types/src/l2_block_source.ts | 8 +++++ .../src/e2e_non_contract_account.test.ts | 8 ++--- .../end-to-end/src/e2e_state_vars.test.ts | 10 +++--- yarn-project/p2p/src/client/mocks.ts | 34 ++++++++++++++----- .../pxe/src/pxe_http/pxe_http_server.ts | 2 +- .../pxe/src/pxe_service/pxe_service.ts | 25 +++----------- .../src/pxe_service/test/pxe_service.test.ts | 2 +- 19 files changed, 169 insertions(+), 71 deletions(-) diff --git a/yarn-project/archiver/src/archiver/archiver.ts b/yarn-project/archiver/src/archiver/archiver.ts index 5ec4f2e2b2f..93721d773d2 100644 --- a/yarn-project/archiver/src/archiver/archiver.ts +++ b/yarn-project/archiver/src/archiver/archiver.ts @@ -10,10 +10,11 @@ import { L2BlockL2Logs, L2BlockSource, L2LogsSource, - TxEffect, LogFilter, LogType, + TxEffect, TxHash, + TxReceipt, UnencryptedL2Log, } from '@aztec/circuit-types'; import { @@ -423,6 +424,10 @@ export class Archiver implements ArchiveSource { return this.store.getTxEffect(txHash); } + public getSettledTxReceipt(txHash: TxHash): Promise { + return this.store.getSettledTxReceipt(txHash); + } + /** * Get the extended contract data for this contract. * @param contractAddress - The contract data address. diff --git a/yarn-project/archiver/src/archiver/archiver_store.ts b/yarn-project/archiver/src/archiver/archiver_store.ts index d282698aa78..b573aa18336 100644 --- a/yarn-project/archiver/src/archiver/archiver_store.ts +++ b/yarn-project/archiver/src/archiver/archiver_store.ts @@ -5,10 +5,11 @@ import { L1ToL2Message, L2Block, L2BlockL2Logs, - TxEffect, LogFilter, LogType, + TxEffect, TxHash, + TxReceipt, } from '@aztec/circuit-types'; import { Fr } from '@aztec/circuits.js'; import { AztecAddress } from '@aztec/foundation/aztec-address'; @@ -47,12 +48,19 @@ export interface ArchiverDataStore { getBlocks(from: number, limit: number): Promise; /** - * Gets an l2 tx. - * @param txHash - The txHash of the l2 tx. - * @returns The requested L2 tx. + * Gets a tx effect. + * @param txHash - The txHash of the tx corresponding to the tx effect. + * @returns The requested tx effect (or undefined if not found). */ getTxEffect(txHash: TxHash): Promise; + /** + * Gets a receipt of a settled tx. + * @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): Promise; + /** * Append new logs to the store's list. * @param encryptedLogs - The encrypted logs to be added to the store. diff --git a/yarn-project/archiver/src/archiver/kv_archiver_store/block_store.ts b/yarn-project/archiver/src/archiver/kv_archiver_store/block_store.ts index 0d961a11cb5..13aee92f55e 100644 --- a/yarn-project/archiver/src/archiver/kv_archiver_store/block_store.ts +++ b/yarn-project/archiver/src/archiver/kv_archiver_store/block_store.ts @@ -1,4 +1,4 @@ -import { INITIAL_L2_BLOCK_NUM, L2Block, TxEffect, TxHash } from '@aztec/circuit-types'; +import { INITIAL_L2_BLOCK_NUM, L2Block, TxEffect, TxHash, TxReceipt, TxStatus } from '@aztec/circuit-types'; import { AztecAddress } from '@aztec/circuits.js'; import { createDebugLogger } from '@aztec/foundation/log'; import { AztecKVStore, AztecMap, Range } from '@aztec/kv-store'; @@ -94,12 +94,12 @@ export class BlockStore { } /** - * Gets an l2 tx. - * @param txHash - The txHash of the l2 tx. - * @returns The requested L2 tx. + * Gets a tx effect. + * @param txHash - The txHash of the tx corresponding to the tx effect. + * @returns The requested tx effect (or undefined if not found). */ getTxEffect(txHash: TxHash): TxEffect | undefined { - const [blockNumber, txIndex] = this.getTxEffectLocation(txHash) ?? []; + const [blockNumber, txIndex] = this.getTxLocation(txHash) ?? []; if (typeof blockNumber !== 'number' || typeof txIndex !== 'number') { return undefined; } @@ -109,11 +109,26 @@ export class BlockStore { } /** - * Looks up which block included the requested L2 tx. - * @param txHash - The txHash of the l2 tx. + * Gets a receipt of a settled tx. + * @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 { + const [blockNumber, txIndex] = this.getTxLocation(txHash) ?? []; + if (typeof blockNumber !== 'number' || typeof txIndex !== 'number') { + return undefined; + } + + const block = this.getBlock(blockNumber)!; + return new TxReceipt(txHash, TxStatus.MINED, '', block.hash().toBuffer(), block.number); + } + + /** + * Looks up which block included the requested tx effect. + * @param txHash - The txHash of the tx. * @returns The block number and index of the tx. */ - getTxEffectLocation(txHash: TxHash): [blockNumber: number, txIndex: number] | undefined { + getTxLocation(txHash: TxHash): [blockNumber: number, txIndex: number] | undefined { return this.#txIndex.get(txHash.toString()); } diff --git a/yarn-project/archiver/src/archiver/kv_archiver_store/kv_archiver_store.ts b/yarn-project/archiver/src/archiver/kv_archiver_store/kv_archiver_store.ts index 946d65ffb5a..85b07369c91 100644 --- a/yarn-project/archiver/src/archiver/kv_archiver_store/kv_archiver_store.ts +++ b/yarn-project/archiver/src/archiver/kv_archiver_store/kv_archiver_store.ts @@ -5,10 +5,11 @@ import { L1ToL2Message, L2Block, L2BlockL2Logs, - TxEffect, LogFilter, LogType, + TxEffect, TxHash, + TxReceipt, } from '@aztec/circuit-types'; import { Fr } from '@aztec/circuits.js'; import { AztecAddress } from '@aztec/foundation/aztec-address'; @@ -93,14 +94,23 @@ export class KVArchiverDataStore implements ArchiverDataStore { } /** - * Gets an l2 tx. - * @param txHash - The txHash of the l2 tx. - * @returns The requested L2 tx. + * Gets a tx effect. + * @param txHash - The txHash of the tx corresponding to the tx effect. + * @returns The requested tx effect (or undefined if not found). */ getTxEffect(txHash: TxHash): Promise { return Promise.resolve(this.#blockStore.getTxEffect(txHash)); } + /** + * Gets a receipt of a settled tx. + * @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): Promise { + return Promise.resolve(this.#blockStore.getSettledTxReceipt(txHash)); + } + /** * Append new logs to the store's list. * @param encryptedLogs - The logs to be added to the store. diff --git a/yarn-project/archiver/src/archiver/kv_archiver_store/log_store.ts b/yarn-project/archiver/src/archiver/kv_archiver_store/log_store.ts index e7eef6fa1c9..c5cc67a7c51 100644 --- a/yarn-project/archiver/src/archiver/kv_archiver_store/log_store.ts +++ b/yarn-project/archiver/src/archiver/kv_archiver_store/log_store.ts @@ -88,7 +88,7 @@ export class LogStore { throw new Error('Missing txHash'); } - const [blockNumber, txIndex] = this.blockStore.getTxEffectLocation(filter.txHash) ?? []; + const [blockNumber, txIndex] = this.blockStore.getTxLocation(filter.txHash) ?? []; if (typeof blockNumber !== 'number' || typeof txIndex !== 'number') { return { logs: [], maxLogsHit: false }; } diff --git a/yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts b/yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts index e97a0088e6a..bcb61d9fb74 100644 --- a/yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts +++ b/yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts @@ -8,11 +8,13 @@ import { L2Block, L2BlockContext, L2BlockL2Logs, - TxEffect, LogFilter, LogId, LogType, + TxEffect, TxHash, + TxReceipt, + TxStatus, UnencryptedL2Log, } from '@aztec/circuit-types'; import { Fr, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/circuits.js'; @@ -232,13 +234,31 @@ export class MemoryArchiverStore implements ArchiverDataStore { } /** - * Gets an l2 tx. - * @param txHash - The txHash of the l2 tx. - * @returns The requested L2 tx. + * Gets a tx effect. + * @param txHash - The txHash of the tx effect. + * @returns The requested tx effect. */ public getTxEffect(txHash: TxHash): Promise { - const l2Tx = this.txEffects.find(tx => tx.txHash.equals(txHash)); - return Promise.resolve(l2Tx); + const txEffect = this.txEffects.find(tx => tx.txHash.equals(txHash)); + return Promise.resolve(txEffect); + } + + /** + * Gets a receipt of a settled tx. + * @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 { + for (const blockContext of this.l2BlockContexts) { + for (const currentTxHash of blockContext.getTxHashes()) { + if (currentTxHash.equals(txHash)) { + return Promise.resolve( + new TxReceipt(txHash, TxStatus.MINED, '', blockContext.block.hash().toBuffer(), blockContext.block.number), + ); + } + } + } + return Promise.resolve(undefined); } /** diff --git a/yarn-project/aztec-node/src/aztec-node/http_rpc_server.ts b/yarn-project/aztec-node/src/aztec-node/http_rpc_server.ts index efe1ff8fef4..2ebef33c85e 100644 --- a/yarn-project/aztec-node/src/aztec-node/http_rpc_server.ts +++ b/yarn-project/aztec-node/src/aztec-node/http_rpc_server.ts @@ -6,10 +6,10 @@ import { L1ToL2MessageAndIndex, L2Block, L2BlockL2Logs, - TxEffect, LogId, SiblingPath, Tx, + TxEffect, TxHash, } from '@aztec/circuit-types'; import { FunctionSelector, Header } from '@aztec/circuits.js'; diff --git a/yarn-project/aztec-node/src/aztec-node/server.ts b/yarn-project/aztec-node/src/aztec-node/server.ts index 2f610ebd07f..9a15fa6502b 100644 --- a/yarn-project/aztec-node/src/aztec-node/server.ts +++ b/yarn-project/aztec-node/src/aztec-node/server.ts @@ -12,7 +12,6 @@ import { L2BlockL2Logs, L2BlockSource, L2LogsSource, - TxEffect, LogFilter, LogType, MerkleTreeId, @@ -21,7 +20,10 @@ import { SequencerConfig, SiblingPath, Tx, + TxEffect, TxHash, + TxReceipt, + TxStatus, } from '@aztec/circuit-types'; import { ARCHIVE_HEIGHT, @@ -285,6 +287,25 @@ export class AztecNodeService implements AztecNode { await this.p2pClient!.sendTx(tx); } + public async getTxReceipt(txHash: TxHash): Promise { + let txReceipt = new TxReceipt(txHash, TxStatus.DROPPED, 'Tx dropped by P2P node.'); + + // We first check if the tx is in pending (instead of first checking if it is mined) because if we first check + // for mined and then for pending there could be a race condition where the tx is mined between the two checks + // and we would incorrectly return a TxReceipt with status DROPPED + const pendingTx = await this.getPendingTxByHash(txHash); + if (pendingTx) { + txReceipt = new TxReceipt(txHash, TxStatus.PENDING, ''); + } + + const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash); + if (settledTxReceipt) { + txReceipt = settledTxReceipt; + } + + return txReceipt; + } + public getTxEffect(txHash: TxHash): Promise { return this.blockSource.getTxEffect(txHash); } diff --git a/yarn-project/aztec.js/src/rpc_clients/pxe_client.ts b/yarn-project/aztec.js/src/rpc_clients/pxe_client.ts index 8cd5b3f2a66..ea873ab3ef0 100644 --- a/yarn-project/aztec.js/src/rpc_clients/pxe_client.ts +++ b/yarn-project/aztec.js/src/rpc_clients/pxe_client.ts @@ -6,11 +6,11 @@ import { ExtendedUnencryptedL2Log, L2Block, L2BlockL2Logs, - TxEffect, LogId, Note, PXE, Tx, + TxEffect, TxExecutionRequest, TxHash, TxReceipt, diff --git a/yarn-project/aztec.js/src/wallet/base_wallet.ts b/yarn-project/aztec.js/src/wallet/base_wallet.ts index a1a0f9ff883..b84b8371181 100644 --- a/yarn-project/aztec.js/src/wallet/base_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/base_wallet.ts @@ -7,12 +7,12 @@ import { FunctionCall, GetUnencryptedLogsResponse, L2Block, - TxEffect, LogFilter, NoteFilter, PXE, SyncStatus, Tx, + TxEffect, TxExecutionRequest, TxHash, TxReceipt, diff --git a/yarn-project/circuit-types/src/interfaces/aztec-node.ts b/yarn-project/circuit-types/src/interfaces/aztec-node.ts index 0509ee90db8..c9b7bd55d0f 100644 --- a/yarn-project/circuit-types/src/interfaces/aztec-node.ts +++ b/yarn-project/circuit-types/src/interfaces/aztec-node.ts @@ -18,11 +18,11 @@ import { L2Block } from '../l2_block.js'; import { GetUnencryptedLogsResponse, L2BlockL2Logs, LogFilter, LogType } from '../logs/index.js'; import { MerkleTreeId } from '../merkle_tree_id.js'; import { SiblingPath } from '../sibling_path/index.js'; -import { Tx, TxHash } from '../tx/index.js'; +import { Tx, TxHash, TxReceipt } from '../tx/index.js'; +import { TxEffect } from '../tx_effect.js'; import { SequencerConfig } from './configs.js'; import { NullifierMembershipWitness } from './nullifier_tree.js'; import { PublicDataWitness } from './public_data_tree.js'; -import { TxEffect } from '../tx_effect.js'; /** Helper type for a specific L2 block number or the latest block number */ type BlockNumber = number | 'latest'; @@ -230,6 +230,16 @@ export interface AztecNode { */ sendTx(tx: Tx): Promise; + /** + * Fetches a transaction receipt for a given transaction hash. Returns a mined receipt if it was added + * to the chain, a pending receipt if it's still in the mempool of the connected Aztec node, or a dropped + * receipt if not found in the connected Aztec node. + * + * @param txHash - The transaction hash. + * @returns A receipt of the transaction. + */ + getTxReceipt(txHash: TxHash): Promise; + /** * Get a tx effect. * @param txHash - The hash of a transaction which resulted in the returned tx effect. diff --git a/yarn-project/circuit-types/src/interfaces/pxe.ts b/yarn-project/circuit-types/src/interfaces/pxe.ts index 7a0b3784afb..e32101b0971 100644 --- a/yarn-project/circuit-types/src/interfaces/pxe.ts +++ b/yarn-project/circuit-types/src/interfaces/pxe.ts @@ -9,10 +9,10 @@ import { GetUnencryptedLogsResponse, LogFilter } from '../logs/index.js'; import { ExtendedNote } from '../notes/index.js'; import { NoteFilter } from '../notes/note_filter.js'; import { Tx, TxHash, TxReceipt } from '../tx/index.js'; +import { TxEffect } from '../tx_effect.js'; import { TxExecutionRequest } from '../tx_execution_request.js'; import { DeployedContract } from './deployed-contract.js'; import { SyncStatus } from './sync-status.js'; -import { TxEffect } from '../tx_effect.js'; // docs:start:pxe-interface /** diff --git a/yarn-project/circuit-types/src/l2_block_source.ts b/yarn-project/circuit-types/src/l2_block_source.ts index ca60496af36..f60e545d3e4 100644 --- a/yarn-project/circuit-types/src/l2_block_source.ts +++ b/yarn-project/circuit-types/src/l2_block_source.ts @@ -2,6 +2,7 @@ import { EthAddress } from '@aztec/circuits.js'; import { L2Block } from './l2_block.js'; import { TxHash } from './tx/tx_hash.js'; +import { TxReceipt } from './tx/tx_receipt.js'; import { TxEffect } from './tx_effect.js'; /** @@ -48,6 +49,13 @@ export interface L2BlockSource { */ getTxEffect(txHash: TxHash): Promise; + /** + * Gets a receipt of a settled tx. + * @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): Promise; + /** * Starts the L2 block source. * @param blockUntilSynced - If true, blocks until the data source has fully synced. diff --git a/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts b/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts index cb0710268b7..dad669968ec 100644 --- a/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts +++ b/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts @@ -75,10 +75,10 @@ describe('e2e_non_contract_account', () => { const receipt = await contract.methods.set_constant(value).send().wait({ interval: 0.1 }); - // check that 1 commitment was created - const tx = await pxe.getTx(receipt.txHash); - const nonZeroCommitments = tx?.newNoteHashes.filter(c => c.value > 0); - expect(nonZeroCommitments?.length).toBe(1); + // check that 1 note hash was created + const tx = await pxe.getTxEffect(receipt.txHash); + const nonZeroNoteHashes = tx?.newNoteHashes.filter(c => c.value > 0); + expect(nonZeroNoteHashes?.length).toBe(1); // Add the note const note = new Note([new Fr(value)]); diff --git a/yarn-project/end-to-end/src/e2e_state_vars.test.ts b/yarn-project/end-to-end/src/e2e_state_vars.test.ts index 79d84e5da15..df5ed570b87 100644 --- a/yarn-project/end-to-end/src/e2e_state_vars.test.ts +++ b/yarn-project/end-to-end/src/e2e_state_vars.test.ts @@ -74,7 +74,7 @@ describe('e2e_state_vars', () => { // Send the transaction and wait for it to be mined (wait function throws if the tx is not mined) const receipt = await contract.methods.initialize_private(RANDOMNESS, POINTS).send().wait(); - const tx = await wallet.getTx(receipt.txHash); + const tx = await wallet.getTxEffect(receipt.txHash); expect(tx?.newNoteHashes.length).toEqual(1); // 1 for the tx, another for the initializer expect(tx?.newNullifiers.length).toEqual(2); @@ -99,7 +99,7 @@ describe('e2e_state_vars', () => { const noteBefore = await contract.methods.get_legendary_card().view(); const receipt = await contract.methods.update_legendary_card(RANDOMNESS, POINTS).send().wait(); - const tx = await wallet.getTx(receipt.txHash); + const tx = await wallet.getTxEffect(receipt.txHash); expect(tx?.newNoteHashes.length).toEqual(1); // 1 for the tx, another for the nullifier of the previous note expect(tx?.newNullifiers.length).toEqual(2); @@ -122,7 +122,7 @@ describe('e2e_state_vars', () => { .update_legendary_card(RANDOMNESS + 2n, POINTS + 1n) .send() .wait(); - const tx = await wallet.getTx(receipt.txHash); + const tx = await wallet.getTxEffect(receipt.txHash); expect(tx?.newNoteHashes.length).toEqual(1); // 1 for the tx, another for the nullifier of the previous note expect(tx?.newNullifiers.length).toEqual(2); @@ -136,7 +136,7 @@ describe('e2e_state_vars', () => { expect(await contract.methods.is_legendary_initialized().view()).toEqual(true); const noteBefore = await contract.methods.get_legendary_card().view(); const receipt = await contract.methods.increase_legendary_points().send().wait(); - const tx = await wallet.getTx(receipt.txHash); + const tx = await wallet.getTxEffect(receipt.txHash); expect(tx?.newNoteHashes.length).toEqual(1); // 1 for the tx, another for the nullifier of the previous note expect(tx?.newNullifiers.length).toEqual(2); @@ -157,7 +157,7 @@ describe('e2e_state_vars', () => { expect(await contract.methods.is_priv_imm_initialized().view()).toEqual(false); const receipt = await contract.methods.initialize_private_immutable(RANDOMNESS, POINTS).send().wait(); - const tx = await wallet.getTx(receipt.txHash); + const tx = await wallet.getTxEffect(receipt.txHash); expect(tx?.newNoteHashes.length).toEqual(1); // 1 for the tx, another for the initializer expect(tx?.newNullifiers.length).toEqual(2); diff --git a/yarn-project/p2p/src/client/mocks.ts b/yarn-project/p2p/src/client/mocks.ts index 1353c1deaf4..1b2134ac45d 100644 --- a/yarn-project/p2p/src/client/mocks.ts +++ b/yarn-project/p2p/src/client/mocks.ts @@ -1,4 +1,4 @@ -import { L2Block, L2BlockSource, TxEffect, TxHash } from '@aztec/circuit-types'; +import { L2Block, L2BlockSource, TxEffect, TxHash, TxReceipt, TxStatus } from '@aztec/circuit-types'; import { EthAddress } from '@aztec/circuits.js'; /** @@ -6,13 +6,13 @@ import { EthAddress } from '@aztec/circuits.js'; */ export class MockBlockSource implements L2BlockSource { private l2Blocks: L2Block[] = []; - private l2Txs: TxEffect[] = []; + private txEffects: TxEffect[] = []; constructor(private numBlocks = 100) { for (let i = 0; i < this.numBlocks; i++) { const block = L2Block.random(i); this.l2Blocks.push(block); - this.l2Txs.push(...block.getTxs()); + this.txEffects.push(...block.getTxs()); } } @@ -60,13 +60,29 @@ export class MockBlockSource implements L2BlockSource { } /** - * Gets an l2 tx. - * @param txHash - The txHash of the l2 tx. - * @returns The requested L2 tx. + * Gets a tx effect. + * @param txHash - The hash of a transaction which resulted in the returned tx effect. + * @returns The requested tx effect. */ - getTxEffect(txHash: TxHash) { - const l2Tx = this.l2Txs.find(tx => tx.txHash.equals(txHash)); - return Promise.resolve(l2Tx); + public getTxEffect(txHash: TxHash) { + const txEffect = this.txEffects.find(tx => tx.txHash.equals(txHash)); + return Promise.resolve(txEffect); + } + + /** + * Gets a receipt of a settled tx. + * @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 { + for (const block of this.l2Blocks) { + for (const txEffect of block.body.txEffects) { + if (txEffect.txHash.equals(txHash)) { + return Promise.resolve(new TxReceipt(txHash, TxStatus.MINED, '', block.hash().toBuffer(), block.number)); + } + } + } + return Promise.resolve(undefined); } /** diff --git a/yarn-project/pxe/src/pxe_http/pxe_http_server.ts b/yarn-project/pxe/src/pxe_http/pxe_http_server.ts index d9adaea5806..9e03421c649 100644 --- a/yarn-project/pxe/src/pxe_http/pxe_http_server.ts +++ b/yarn-project/pxe/src/pxe_http/pxe_http_server.ts @@ -7,11 +7,11 @@ import { ExtendedUnencryptedL2Log, L2Block, L2BlockL2Logs, - TxEffect, LogId, Note, PXE, Tx, + TxEffect, TxExecutionRequest, TxHash, TxReceipt, diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index a7e45b06180..b38d23b605d 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -10,13 +10,13 @@ import { GetUnencryptedLogsResponse, KeyStore, L2Block, - TxEffect, LogFilter, MerkleTreeId, NoteFilter, PXE, SimulationError, Tx, + TxEffect, TxExecutionRequest, TxHash, TxL2Logs, @@ -438,27 +438,12 @@ export class PXEService implements PXE { }); } - public async getTxReceipt(txHash: TxHash): Promise { - let txReceipt = new TxReceipt(txHash, TxStatus.DROPPED, 'Tx dropped by P2P node.'); - - // We first check if the tx is in pending (instead of first checking if it is mined) because if we first check - // for mined and then for pending there could be a race condition where the tx is mined between the two checks - // and we would incorrectly return a TxReceipt with status DROPPED - const pendingTx = await this.node.getPendingTxByHash(txHash); - if (pendingTx) { - txReceipt = new TxReceipt(txHash, TxStatus.PENDING, ''); - } - - const settledTx = await this.node.getTxEffect(txHash); - if (settledTx) { - txReceipt = new TxReceipt(txHash, TxStatus.MINED, '', settledTx.blockHash.toBuffer(), settledTx.blockNumber); - } - - return txReceipt; + public getTxReceipt(txHash: TxHash): Promise { + return this.node.getTxReceipt(txHash); } - public async getTxEffect(txHash: TxHash): Promise { - return await this.node.getTxEffect(txHash); + public getTxEffect(txHash: TxHash): Promise { + return this.node.getTxEffect(txHash); } async getBlockNumber(): Promise { diff --git a/yarn-project/pxe/src/pxe_service/test/pxe_service.test.ts b/yarn-project/pxe/src/pxe_service/test/pxe_service.test.ts index 4fb92a292bc..55f38ec3036 100644 --- a/yarn-project/pxe/src/pxe_service/test/pxe_service.test.ts +++ b/yarn-project/pxe/src/pxe_service/test/pxe_service.test.ts @@ -1,4 +1,4 @@ -import { AztecNode, INITIAL_L2_BLOCK_NUM, TxEffect, PXE, mockTx } from '@aztec/circuit-types'; +import { AztecNode, INITIAL_L2_BLOCK_NUM, PXE, TxEffect, mockTx } from '@aztec/circuit-types'; import { Grumpkin } from '@aztec/circuits.js/barretenberg'; import { L1ContractAddresses } from '@aztec/ethereum'; import { EthAddress } from '@aztec/foundation/eth-address'; From a07154eed7cfe790b8e72a5b2c35848710e6d337 Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 29 Feb 2024 15:03:32 +0000 Subject: [PATCH 03/18] formatting fix --- yarn-project/pxe/src/pxe_service/pxe_service.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index b38d23b605d..3fb2aafe023 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -21,9 +21,8 @@ import { TxHash, TxL2Logs, TxReceipt, - TxStatus, getNewContractPublicFunctions, - isNoirCallStackUnresolved, + isNoirCallStackUnresolved } from '@aztec/circuit-types'; import { TxPXEProcessingStats } from '@aztec/circuit-types/stats'; import { From caa951f89b653797adb13da59e5752cc16007300 Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 29 Feb 2024 15:16:37 +0000 Subject: [PATCH 04/18] fmt --- yarn-project/pxe/src/pxe_service/pxe_service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index 3fb2aafe023..4ce8bd72187 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -22,7 +22,7 @@ import { TxL2Logs, TxReceipt, getNewContractPublicFunctions, - isNoirCallStackUnresolved + isNoirCallStackUnresolved, } from '@aztec/circuit-types'; import { TxPXEProcessingStats } from '@aztec/circuit-types/stats'; import { From b802d017576f2f35b41bcafb8f8c74384bfd9ad6 Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 29 Feb 2024 15:56:52 +0000 Subject: [PATCH 05/18] fix --- yarn-project/aztec.js/src/contract/sent_tx.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/yarn-project/aztec.js/src/contract/sent_tx.ts b/yarn-project/aztec.js/src/contract/sent_tx.ts index be3166b2b24..75a3f2b1025 100644 --- a/yarn-project/aztec.js/src/contract/sent_tx.ts +++ b/yarn-project/aztec.js/src/contract/sent_tx.ts @@ -71,12 +71,12 @@ export class SentTx { const tx = (await this.pxe.getTxEffect(txHash))!; const visibleNotes = await this.pxe.getNotes({ txHash }); receipt.debugInfo = { - newNoteHashes: tx.newNoteHashes, - newNullifiers: tx.newNullifiers, - newPublicDataWrites: tx.newPublicDataWrites, - newL2ToL1Msgs: tx.newL2ToL1Msgs, - newContracts: tx.contractLeaves, - newContractData: tx.contractData, + newNoteHashes: tx.newNoteHashes.filter(n => !n.isZero()), + newNullifiers: tx.newNullifiers.filter(n => !n.isZero()), + newPublicDataWrites: tx.newPublicDataWrites.filter(p => !p.isEmpty()), + newL2ToL1Msgs: tx.newL2ToL1Msgs.filter(l => !l.isZero()), + newContracts: tx.contractLeaves.filter(c => !c.isZero()), + newContractData: tx.contractData.filter(c => !c.isEmpty()), visibleNotes, }; } From 06d148c8d25845ccc2cbdcc634c18c3d5f8e57b4 Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 29 Feb 2024 16:02:08 +0000 Subject: [PATCH 06/18] fix2 --- yarn-project/archiver/src/rpc/archiver_server.ts | 5 ++++- yarn-project/aztec-node/src/aztec-node/http_rpc_server.ts | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/yarn-project/archiver/src/rpc/archiver_server.ts b/yarn-project/archiver/src/rpc/archiver_server.ts index a620e2925be..48e7463cbc9 100644 --- a/yarn-project/archiver/src/rpc/archiver_server.ts +++ b/yarn-project/archiver/src/rpc/archiver_server.ts @@ -6,6 +6,8 @@ import { L1ToL2Message, L2Block, L2BlockL2Logs, + TxEffect, + TxReceipt, } from '@aztec/circuit-types'; import { EthAddress, Fr } from '@aztec/circuits.js'; import { JsonRpcServer } from '@aztec/foundation/json-rpc/server'; @@ -30,8 +32,9 @@ export function createArchiverRpcServer(archiverService: Archiver): JsonRpcServe L1ToL2Message, L2Block, L2BlockL2Logs, + TxEffect, }, - {}, + { TxReceipt }, ['start', 'stop'], ); } diff --git a/yarn-project/aztec-node/src/aztec-node/http_rpc_server.ts b/yarn-project/aztec-node/src/aztec-node/http_rpc_server.ts index 2ebef33c85e..213478e41d0 100644 --- a/yarn-project/aztec-node/src/aztec-node/http_rpc_server.ts +++ b/yarn-project/aztec-node/src/aztec-node/http_rpc_server.ts @@ -11,6 +11,7 @@ import { Tx, TxEffect, TxHash, + TxReceipt, } from '@aztec/circuit-types'; import { FunctionSelector, Header } from '@aztec/circuits.js'; import { AztecAddress } from '@aztec/foundation/aztec-address'; @@ -42,7 +43,7 @@ export function createAztecNodeRpcServer(node: AztecNode) { SiblingPath, L1ToL2MessageAndIndex, }, - { Tx, L2BlockL2Logs }, + { Tx, TxReceipt, L2BlockL2Logs }, // disable methods not part of the AztecNode interface ['start', 'stop'], ); From 34d897fa0048dff6a7360c95987baca4f2d0ec5e Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 29 Feb 2024 15:25:12 +0000 Subject: [PATCH 07/18] refactor: dropping 'new' from TxEffect's properties --- yarn-project/aztec.js/src/contract/sent_tx.ts | 12 ++++----- yarn-project/circuit-types/src/body.ts | 2 +- yarn-project/circuit-types/src/l2_block.ts | 2 +- .../circuit-types/src/tx/tx_receipt.ts | 14 +++++----- yarn-project/circuit-types/src/tx_effect.ts | 26 +++++++++---------- .../src/e2e_deploy_contract.test.ts | 2 +- .../src/e2e_inclusion_proofs_contract.test.ts | 10 +++---- .../src/e2e_non_contract_account.test.ts | 4 +-- .../e2e_pending_commitments_contract.test.ts | 4 +-- .../end-to-end/src/e2e_state_vars.test.ts | 20 +++++++------- .../src/integration_l1_publisher.test.ts | 4 +-- .../src/note_processor/note_processor.test.ts | 2 +- .../pxe/src/note_processor/note_processor.ts | 4 +-- .../pxe/src/pxe_service/pxe_service.ts | 4 +-- .../src/world-state-db/merkle_trees.ts | 6 ++--- 15 files changed, 58 insertions(+), 58 deletions(-) diff --git a/yarn-project/aztec.js/src/contract/sent_tx.ts b/yarn-project/aztec.js/src/contract/sent_tx.ts index 75a3f2b1025..64379ce0c42 100644 --- a/yarn-project/aztec.js/src/contract/sent_tx.ts +++ b/yarn-project/aztec.js/src/contract/sent_tx.ts @@ -71,12 +71,12 @@ export class SentTx { const tx = (await this.pxe.getTxEffect(txHash))!; const visibleNotes = await this.pxe.getNotes({ txHash }); receipt.debugInfo = { - newNoteHashes: tx.newNoteHashes.filter(n => !n.isZero()), - newNullifiers: tx.newNullifiers.filter(n => !n.isZero()), - newPublicDataWrites: tx.newPublicDataWrites.filter(p => !p.isEmpty()), - newL2ToL1Msgs: tx.newL2ToL1Msgs.filter(l => !l.isZero()), - newContracts: tx.contractLeaves.filter(c => !c.isZero()), - newContractData: tx.contractData.filter(c => !c.isEmpty()), + noteHashes: tx.noteHashes.filter(n => !n.isZero()), + nullifiers: tx.nullifiers.filter(n => !n.isZero()), + publicDataWrites: tx.publicDataWrites.filter(p => !p.isEmpty()), + l2ToL1Msgs: tx.l2ToL1Msgs.filter(l => !l.isZero()), + contractsLeaves: tx.contractLeaves.filter(c => !c.isZero()), + contractData: tx.contractData.filter(c => !c.isEmpty()), visibleNotes, }; } diff --git a/yarn-project/circuit-types/src/body.ts b/yarn-project/circuit-types/src/body.ts index 2314a723fff..e69b6da0b8a 100644 --- a/yarn-project/circuit-types/src/body.ts +++ b/yarn-project/circuit-types/src/body.ts @@ -74,7 +74,7 @@ export class Body { get numberOfTxs() { // We gather all the txEffects that are not empty (the ones that have been padded by checking the first newNullifier of the txEffect); - return this.txEffects.reduce((acc, txEffect) => (!txEffect.newNullifiers[0].equals(Fr.ZERO) ? acc + 1 : acc), 0); + return this.txEffects.reduce((acc, txEffect) => (!txEffect.nullifiers[0].equals(Fr.ZERO) ? acc + 1 : acc), 0); } static random( diff --git a/yarn-project/circuit-types/src/l2_block.ts b/yarn-project/circuit-types/src/l2_block.ts index bfca9b1e60e..78981b7a82d 100644 --- a/yarn-project/circuit-types/src/l2_block.ts +++ b/yarn-project/circuit-types/src/l2_block.ts @@ -250,7 +250,7 @@ export class L2Block { this.assertIndexInRange(txIndex); // Gets the first nullifier of the tx specified by txIndex - const firstNullifier = this.body.txEffects[txIndex].newNullifiers[0]; + const firstNullifier = this.body.txEffects[txIndex].nullifiers[0]; return new TxHash(firstNullifier.toBuffer()); } diff --git a/yarn-project/circuit-types/src/tx/tx_receipt.ts b/yarn-project/circuit-types/src/tx/tx_receipt.ts index 0136ab07026..b29d1b13810 100644 --- a/yarn-project/circuit-types/src/tx/tx_receipt.ts +++ b/yarn-project/circuit-types/src/tx/tx_receipt.ts @@ -83,27 +83,27 @@ interface DebugInfo { /** * New note hashes created by the transaction. */ - newNoteHashes: Fr[]; + noteHashes: Fr[]; /** * New nullifiers created by the transaction. */ - newNullifiers: Fr[]; + nullifiers: Fr[]; /** * New public data writes created by the transaction. */ - newPublicDataWrites: PublicDataWrite[]; + publicDataWrites: PublicDataWrite[]; /** * New L2 to L1 messages created by the transaction. */ - newL2ToL1Msgs: Fr[]; + l2ToL1Msgs: Fr[]; /** - * New contracts leafs created by the transaction to be inserted into the contract tree. + * New contracts leaves created by the transaction to be inserted into the contract tree. */ - newContracts: Fr[]; + contractsLeaves: Fr[]; /** * New contract data created by the transaction. */ - newContractData: ContractData[]; + contractData: ContractData[]; /** * Notes created in this tx which belong to accounts which are registered in the PXE which was used to submit the * tx. You will not receive notes of accounts which are not registered in the PXE here even though they were diff --git a/yarn-project/circuit-types/src/tx_effect.ts b/yarn-project/circuit-types/src/tx_effect.ts index 0e31a6a3b92..f5dff9d4778 100644 --- a/yarn-project/circuit-types/src/tx_effect.ts +++ b/yarn-project/circuit-types/src/tx_effect.ts @@ -17,19 +17,19 @@ export class TxEffect { /** * The note hashes to be inserted into the note hash tree. */ - public newNoteHashes: Tuple, + public noteHashes: Tuple, /** * The nullifiers to be inserted into the nullifier tree. */ - public newNullifiers: Tuple, + public nullifiers: Tuple, /** * The L2 to L1 messages to be inserted into the messagebox on L1. */ - public newL2ToL1Msgs: Tuple, + public l2ToL1Msgs: Tuple, /** * The public data writes to be inserted into the public data tree. */ - public newPublicDataWrites: Tuple, + public publicDataWrites: Tuple, /** * The leaves of the new contract data that will be inserted into the contracts tree. */ @@ -46,10 +46,10 @@ export class TxEffect { ) {} toBuffer(): Buffer { - const nonZeroNoteHashes = this.newNoteHashes.filter(h => !h.isZero()); - const nonZeroNullifiers = this.newNullifiers.filter(h => !h.isZero()); - const nonZeroL2ToL1Msgs = this.newL2ToL1Msgs.filter(h => !h.isZero()); - const nonZeroPublicDataWrites = this.newPublicDataWrites.filter(h => !h.isEmpty()); + const nonZeroNoteHashes = this.noteHashes.filter(h => !h.isZero()); + const nonZeroNullifiers = this.nullifiers.filter(h => !h.isZero()); + const nonZeroL2ToL1Msgs = this.l2ToL1Msgs.filter(h => !h.isZero()); + const nonZeroPublicDataWrites = this.publicDataWrites.filter(h => !h.isEmpty()); const nonZeroContractLeaves = this.contractLeaves.filter(h => !h.isZero()); const nonZeroContractData = this.contractData.filter(h => !h.isEmpty()); @@ -97,10 +97,10 @@ export class TxEffect { } hash() { - const noteHashesBuffer = Buffer.concat(this.newNoteHashes.map(x => x.toBuffer())); - const nullifiersBuffer = Buffer.concat(this.newNullifiers.map(x => x.toBuffer())); - const newL2ToL1MsgsBuffer = Buffer.concat(this.newL2ToL1Msgs.map(x => x.toBuffer())); - const publicDataUpdateRequestsBuffer = Buffer.concat(this.newPublicDataWrites.map(x => x.toBuffer())); + const noteHashesBuffer = Buffer.concat(this.noteHashes.map(x => x.toBuffer())); + const nullifiersBuffer = Buffer.concat(this.nullifiers.map(x => x.toBuffer())); + const newL2ToL1MsgsBuffer = Buffer.concat(this.l2ToL1Msgs.map(x => x.toBuffer())); + const publicDataUpdateRequestsBuffer = Buffer.concat(this.publicDataWrites.map(x => x.toBuffer())); const encryptedLogsHashKernel0 = this.encryptedLogs.hash(); const unencryptedLogsHashKernel0 = this.unencryptedLogs.hash(); @@ -159,6 +159,6 @@ export class TxEffect { } get txHash(): TxHash { - return new TxHash(this.newNullifiers[0].toBuffer()); + return new TxHash(this.nullifiers[0].toBuffer()); } } diff --git a/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts b/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts index bf1f6537cc7..beba774f639 100644 --- a/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts @@ -181,7 +181,7 @@ describe('e2e_deploy_contract', () => { const contract = await registerContract(testWallet, TestContract); const receipt = await contract.methods.emit_nullifier(10).send().wait({ debug: true }); const expected = siloNullifier(contract.address, new Fr(10)); - expect(receipt.debugInfo?.newNullifiers[1]).toEqual(expected); + expect(receipt.debugInfo?.nullifiers[1]).toEqual(expected); }, 30_000, ); diff --git a/yarn-project/end-to-end/src/e2e_inclusion_proofs_contract.test.ts b/yarn-project/end-to-end/src/e2e_inclusion_proofs_contract.test.ts index 2aabcbdec16..b49bb0451e2 100644 --- a/yarn-project/end-to-end/src/e2e_inclusion_proofs_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_inclusion_proofs_contract.test.ts @@ -54,7 +54,7 @@ describe('e2e_inclusion_proofs_contract', () => { describe('proves note existence and its nullifier non-existence and nullifier non-existence failure case', () => { // Owner of a note let noteCreationBlockNumber: number; - let newNoteHashes, visibleNotes: any; + let noteHashes, visibleNotes: any; const value = 100n; let validNoteBlockNumber: any; @@ -63,11 +63,11 @@ describe('e2e_inclusion_proofs_contract', () => { const receipt = await contract.methods.create_note(owner, value).send().wait({ debug: true }); noteCreationBlockNumber = receipt.blockNumber!; - ({ newNoteHashes, visibleNotes } = receipt.debugInfo!); + ({ noteHashes, visibleNotes } = receipt.debugInfo!); }); it('should return the correct values for creating a note', () => { - expect(newNoteHashes.length).toBe(1); + expect(noteHashes.length).toBe(1); expect(visibleNotes.length).toBe(1); const [receivedValue, receivedOwner, _randomness] = visibleNotes[0].note.items; expect(receivedValue.toBigInt()).toBe(value); @@ -158,7 +158,7 @@ describe('e2e_inclusion_proofs_contract', () => { const receipt = await contract.methods.create_note(owner, value).send().wait({ debug: true }); noteCreationBlockNumber = receipt.blockNumber!; - const { newNoteHashes, visibleNotes } = receipt.debugInfo!; + const { noteHashes: newNoteHashes, visibleNotes } = receipt.debugInfo!; expect(newNoteHashes.length).toBe(1); expect(visibleNotes.length).toBe(1); @@ -224,7 +224,7 @@ describe('e2e_inclusion_proofs_contract', () => { // Choose random block number between deployment and current block number to test archival node const blockNumber = await getRandomBlockNumberSinceDeployment(); const block = await pxe.getBlock(blockNumber); - const nullifier = block?.body.txEffects[0].newNullifiers[0]; + const nullifier = block?.body.txEffects[0].nullifiers[0]; await contract.methods.test_nullifier_inclusion(nullifier!, true, blockNumber).send().wait(); await contract.methods.test_nullifier_inclusion(nullifier!, false, 0n).send().wait(); diff --git a/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts b/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts index dad669968ec..a19e3a80841 100644 --- a/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts +++ b/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts @@ -47,7 +47,7 @@ describe('e2e_non_contract_account', () => { const tx = await aztecNode!.getTxEffect(receipt.txHash); const expectedSiloedNullifier = siloNullifier(contract.address, nullifier); - const siloedNullifier = tx!.newNullifiers[1]; + const siloedNullifier = tx!.nullifiers[1]; expect(siloedNullifier.equals(expectedSiloedNullifier)).toBeTruthy(); }, 120_000); @@ -77,7 +77,7 @@ describe('e2e_non_contract_account', () => { // check that 1 note hash was created const tx = await pxe.getTxEffect(receipt.txHash); - const nonZeroNoteHashes = tx?.newNoteHashes.filter(c => c.value > 0); + const nonZeroNoteHashes = tx?.noteHashes.filter(c => c.value > 0); expect(nonZeroNoteHashes?.length).toBe(1); // Add the note diff --git a/yarn-project/end-to-end/src/e2e_pending_commitments_contract.test.ts b/yarn-project/end-to-end/src/e2e_pending_commitments_contract.test.ts index 614575addc9..71a80455c38 100644 --- a/yarn-project/end-to-end/src/e2e_pending_commitments_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_pending_commitments_contract.test.ts @@ -23,7 +23,7 @@ describe('e2e_pending_commitments_contract', () => { const blockNum = await aztecNode!.getBlockNumber(); const block = (await aztecNode!.getBlocks(blockNum, 1))[0]; - const commitmentsArray = block.body.txEffects.flatMap(txEffect => txEffect.newNoteHashes); + const commitmentsArray = block.body.txEffects.flatMap(txEffect => txEffect.noteHashes); // all new commitments should be zero (should be squashed) for (let c = 0; c < exceptFirstFew; c++) { @@ -39,7 +39,7 @@ describe('e2e_pending_commitments_contract', () => { const blockNum = await aztecNode!.getBlockNumber(); const block = (await aztecNode!.getBlocks(blockNum, 1))[0]; - const nullifierArray = block.body.txEffects.flatMap(txEffect => txEffect.newNullifiers); + const nullifierArray = block.body.txEffects.flatMap(txEffect => txEffect.nullifiers); // 0th nullifier should be nonzero (txHash), all others should be zero (should be squashed) for (let n = 0; n < exceptFirstFew + 1; n++) { diff --git a/yarn-project/end-to-end/src/e2e_state_vars.test.ts b/yarn-project/end-to-end/src/e2e_state_vars.test.ts index df5ed570b87..d23bca46d30 100644 --- a/yarn-project/end-to-end/src/e2e_state_vars.test.ts +++ b/yarn-project/end-to-end/src/e2e_state_vars.test.ts @@ -75,9 +75,9 @@ describe('e2e_state_vars', () => { const receipt = await contract.methods.initialize_private(RANDOMNESS, POINTS).send().wait(); const tx = await wallet.getTxEffect(receipt.txHash); - expect(tx?.newNoteHashes.length).toEqual(1); + expect(tx?.noteHashes.length).toEqual(1); // 1 for the tx, another for the initializer - expect(tx?.newNullifiers.length).toEqual(2); + expect(tx?.nullifiers.length).toEqual(2); expect(await contract.methods.is_legendary_initialized().view()).toEqual(true); }); @@ -100,9 +100,9 @@ describe('e2e_state_vars', () => { const receipt = await contract.methods.update_legendary_card(RANDOMNESS, POINTS).send().wait(); const tx = await wallet.getTxEffect(receipt.txHash); - expect(tx?.newNoteHashes.length).toEqual(1); + expect(tx?.noteHashes.length).toEqual(1); // 1 for the tx, another for the nullifier of the previous note - expect(tx?.newNullifiers.length).toEqual(2); + expect(tx?.nullifiers.length).toEqual(2); const noteAfter = await contract.methods.get_legendary_card().view(); @@ -123,9 +123,9 @@ describe('e2e_state_vars', () => { .send() .wait(); const tx = await wallet.getTxEffect(receipt.txHash); - expect(tx?.newNoteHashes.length).toEqual(1); + expect(tx?.noteHashes.length).toEqual(1); // 1 for the tx, another for the nullifier of the previous note - expect(tx?.newNullifiers.length).toEqual(2); + expect(tx?.nullifiers.length).toEqual(2); const { points, randomness } = await contract.methods.get_legendary_card().view(); expect(points).toEqual(POINTS + 1n); @@ -137,9 +137,9 @@ describe('e2e_state_vars', () => { const noteBefore = await contract.methods.get_legendary_card().view(); const receipt = await contract.methods.increase_legendary_points().send().wait(); const tx = await wallet.getTxEffect(receipt.txHash); - expect(tx?.newNoteHashes.length).toEqual(1); + expect(tx?.noteHashes.length).toEqual(1); // 1 for the tx, another for the nullifier of the previous note - expect(tx?.newNullifiers.length).toEqual(2); + expect(tx?.nullifiers.length).toEqual(2); const { points, randomness } = await contract.methods.get_legendary_card().view(); expect(points).toEqual(noteBefore.points + 1n); @@ -158,9 +158,9 @@ describe('e2e_state_vars', () => { const receipt = await contract.methods.initialize_private_immutable(RANDOMNESS, POINTS).send().wait(); const tx = await wallet.getTxEffect(receipt.txHash); - expect(tx?.newNoteHashes.length).toEqual(1); + expect(tx?.noteHashes.length).toEqual(1); // 1 for the tx, another for the initializer - expect(tx?.newNullifiers.length).toEqual(2); + expect(tx?.nullifiers.length).toEqual(2); expect(await contract.methods.is_priv_imm_initialized().view()).toEqual(true); }); diff --git a/yarn-project/end-to-end/src/integration_l1_publisher.test.ts b/yarn-project/end-to-end/src/integration_l1_publisher.test.ts index d282e0795a3..d6e628aeb66 100644 --- a/yarn-project/end-to-end/src/integration_l1_publisher.test.ts +++ b/yarn-project/end-to-end/src/integration_l1_publisher.test.ts @@ -258,7 +258,7 @@ describe('L1Publisher integration', () => { messages: { l1ToL2Messages: l1ToL2Messages.map(m => `0x${m.toBuffer().toString('hex').padStart(64, '0')}`), l2ToL1Messages: block.body.txEffects - .flatMap(txEffect => txEffect.newL2ToL1Msgs) + .flatMap(txEffect => txEffect.l2ToL1Msgs) .map(m => `0x${m.toBuffer().toString('hex').padStart(64, '0')}`), }, block: { @@ -415,7 +415,7 @@ describe('L1Publisher integration', () => { expect(await inbox.read.contains([l1ToL2Messages[j].toString()])).toBeTruthy(); } - const newL2ToL1MsgsArray = block.body.txEffects.flatMap(txEffect => txEffect.newL2ToL1Msgs); + const newL2ToL1MsgsArray = block.body.txEffects.flatMap(txEffect => txEffect.l2ToL1Msgs); // check that values are not in the outbox for (let j = 0; j < newL2ToL1MsgsArray.length; j++) { diff --git a/yarn-project/pxe/src/note_processor/note_processor.test.ts b/yarn-project/pxe/src/note_processor/note_processor.test.ts index 7e35292ec07..e96143f5f1f 100644 --- a/yarn-project/pxe/src/note_processor/note_processor.test.ts +++ b/yarn-project/pxe/src/note_processor/note_processor.test.ts @@ -109,7 +109,7 @@ describe('Note Processor', () => { encryptedLogsArr.push(encryptedLogs); ownedL1NotePayloads.push(...payloads); for (let i = 0; i < TXS_PER_BLOCK; i++) { - block.body.txEffects[i].newNoteHashes = newNotes + block.body.txEffects[i].noteHashes = newNotes .map(n => computeMockNoteHash(n.notePayload.note)) .slice(i * MAX_NEW_NOTE_HASHES_PER_TX, (i + 1) * MAX_NEW_NOTE_HASHES_PER_TX) as Tuple< Fr, diff --git a/yarn-project/pxe/src/note_processor/note_processor.ts b/yarn-project/pxe/src/note_processor/note_processor.ts index 7542b086831..cf5ecaae3fe 100644 --- a/yarn-project/pxe/src/note_processor/note_processor.ts +++ b/yarn-project/pxe/src/note_processor/note_processor.ts @@ -125,7 +125,7 @@ export class NoteProcessor { this.stats.txs++; const dataStartIndexForTx = dataEndIndexForBlock - (txLogs.length - indexOfTxInABlock) * MAX_NEW_NOTE_HASHES_PER_TX; - const newNoteHashes = block.body.txEffects[indexOfTxInABlock].newNoteHashes; + const newNoteHashes = block.body.txEffects[indexOfTxInABlock].noteHashes; // Note: Each tx generates a `TxL2Logs` object and for this reason we can rely on its index corresponding // to the index of a tx in a block. const txFunctionLogs = txLogs[indexOfTxInABlock].functionLogs; @@ -213,7 +213,7 @@ export class NoteProcessor { } const newNullifiers: Fr[] = blocksAndNotes.flatMap(b => - b.blockContext.block.body.txEffects.flatMap(txEffect => txEffect.newNullifiers), + b.blockContext.block.body.txEffects.flatMap(txEffect => txEffect.nullifiers), ); const removedNotes = await this.db.removeNullifiedNotes(newNullifiers, this.publicKey); removedNotes.forEach(noteDao => { diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index 4ce8bd72187..7e83afc6e12 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -341,8 +341,8 @@ export class PXEService implements PXE { } const nonces: Fr[] = []; - const firstNullifier = tx.newNullifiers[0]; - const hashes = tx.newNoteHashes; + const firstNullifier = tx.nullifiers[0]; + const hashes = tx.noteHashes; for (let i = 0; i < hashes.length; ++i) { const hash = hashes[i]; if (hash.equals(Fr.ZERO)) { diff --git a/yarn-project/world-state/src/world-state-db/merkle_trees.ts b/yarn-project/world-state/src/world-state-db/merkle_trees.ts index 4d72a6035e7..de119f5ac58 100644 --- a/yarn-project/world-state/src/world-state-db/merkle_trees.ts +++ b/yarn-project/world-state/src/world-state-db/merkle_trees.ts @@ -510,7 +510,7 @@ export class MerkleTrees implements MerkleTreeDb { // Sync the append only trees for (const [tree, leaves] of [ [MerkleTreeId.CONTRACT_TREE, l2Block.body.txEffects.flatMap(txEffect => txEffect.contractLeaves)], - [MerkleTreeId.NOTE_HASH_TREE, l2Block.body.txEffects.flatMap(txEffect => txEffect.newNoteHashes)], + [MerkleTreeId.NOTE_HASH_TREE, l2Block.body.txEffects.flatMap(txEffect => txEffect.noteHashes)], [MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l2Block.body.l1ToL2Messages], ] as const) { await this.#appendLeaves( @@ -521,13 +521,13 @@ export class MerkleTrees implements MerkleTreeDb { // Sync the indexed trees await (this.trees[MerkleTreeId.NULLIFIER_TREE] as StandardIndexedTree).batchInsert( - l2Block.body.txEffects.flatMap(txEffect => txEffect.newNullifiers.map(nullifier => nullifier.toBuffer())), + l2Block.body.txEffects.flatMap(txEffect => txEffect.nullifiers.map(nullifier => nullifier.toBuffer())), NULLIFIER_SUBTREE_HEIGHT, ); const publicDataTree = this.trees[MerkleTreeId.PUBLIC_DATA_TREE] as StandardIndexedTree; - const publicDataWrites = l2Block.body.txEffects.flatMap(txEffect => txEffect.newPublicDataWrites); + const publicDataWrites = l2Block.body.txEffects.flatMap(txEffect => txEffect.publicDataWrites); // We insert the public data tree leaves with one batch per tx to avoid updating the same key twice for (let i = 0; i < publicDataWrites.length / MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX; i++) { From 51102ddcb1d8f94e4b3111fa4a9e5f1c41ac663e Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 29 Feb 2024 18:45:54 +0000 Subject: [PATCH 08/18] fix --- .../end-to-end/src/e2e_state_vars.test.ts | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/yarn-project/end-to-end/src/e2e_state_vars.test.ts b/yarn-project/end-to-end/src/e2e_state_vars.test.ts index d23bca46d30..1b7327ce6a9 100644 --- a/yarn-project/end-to-end/src/e2e_state_vars.test.ts +++ b/yarn-project/end-to-end/src/e2e_state_vars.test.ts @@ -72,12 +72,10 @@ describe('e2e_state_vars', () => { it('initialize PrivateMutable', async () => { expect(await contract.methods.is_legendary_initialized().view()).toEqual(false); // Send the transaction and wait for it to be mined (wait function throws if the tx is not mined) - const receipt = await contract.methods.initialize_private(RANDOMNESS, POINTS).send().wait(); + const { debugInfo } = await contract.methods.initialize_private(RANDOMNESS, POINTS).send().wait({ debug: true }); - const tx = await wallet.getTxEffect(receipt.txHash); - expect(tx?.noteHashes.length).toEqual(1); // 1 for the tx, another for the initializer - expect(tx?.nullifiers.length).toEqual(2); + expect(debugInfo!.nullifiers.length).toEqual(2); expect(await contract.methods.is_legendary_initialized().view()).toEqual(true); }); @@ -97,12 +95,14 @@ describe('e2e_state_vars', () => { it('replace with same value', async () => { expect(await contract.methods.is_legendary_initialized().view()).toEqual(true); const noteBefore = await contract.methods.get_legendary_card().view(); - const receipt = await contract.methods.update_legendary_card(RANDOMNESS, POINTS).send().wait(); + const { debugInfo } = await contract.methods + .update_legendary_card(RANDOMNESS, POINTS) + .send() + .wait({ debug: true }); - const tx = await wallet.getTxEffect(receipt.txHash); - expect(tx?.noteHashes.length).toEqual(1); + expect(debugInfo!.noteHashes.length).toEqual(1); // 1 for the tx, another for the nullifier of the previous note - expect(tx?.nullifiers.length).toEqual(2); + expect(debugInfo!.nullifiers.length).toEqual(2); const noteAfter = await contract.methods.get_legendary_card().view(); @@ -118,14 +118,14 @@ describe('e2e_state_vars', () => { it('replace PrivateMutable with other values', async () => { expect(await contract.methods.is_legendary_initialized().view()).toEqual(true); - const receipt = await contract.methods + const { debugInfo } = await contract.methods .update_legendary_card(RANDOMNESS + 2n, POINTS + 1n) .send() - .wait(); - const tx = await wallet.getTxEffect(receipt.txHash); - expect(tx?.noteHashes.length).toEqual(1); + .wait({ debug: true }); + + expect(debugInfo!.noteHashes.length).toEqual(1); // 1 for the tx, another for the nullifier of the previous note - expect(tx?.nullifiers.length).toEqual(2); + expect(debugInfo!.nullifiers.length).toEqual(2); const { points, randomness } = await contract.methods.get_legendary_card().view(); expect(points).toEqual(POINTS + 1n); @@ -135,11 +135,11 @@ describe('e2e_state_vars', () => { it('replace PrivateMutable dependent on prior value', async () => { expect(await contract.methods.is_legendary_initialized().view()).toEqual(true); const noteBefore = await contract.methods.get_legendary_card().view(); - const receipt = await contract.methods.increase_legendary_points().send().wait(); - const tx = await wallet.getTxEffect(receipt.txHash); - expect(tx?.noteHashes.length).toEqual(1); + const { debugInfo } = await contract.methods.increase_legendary_points().send().wait({ debug: true }); + + expect(debugInfo!.noteHashes.length).toEqual(1); // 1 for the tx, another for the nullifier of the previous note - expect(tx?.nullifiers.length).toEqual(2); + expect(debugInfo!.nullifiers.length).toEqual(2); const { points, randomness } = await contract.methods.get_legendary_card().view(); expect(points).toEqual(noteBefore.points + 1n); @@ -155,12 +155,14 @@ describe('e2e_state_vars', () => { it('initialize PrivateImmutable', async () => { expect(await contract.methods.is_priv_imm_initialized().view()).toEqual(false); - const receipt = await contract.methods.initialize_private_immutable(RANDOMNESS, POINTS).send().wait(); + const { debugInfo } = await contract.methods + .initialize_private_immutable(RANDOMNESS, POINTS) + .send() + .wait({ debug: true }); - const tx = await wallet.getTxEffect(receipt.txHash); - expect(tx?.noteHashes.length).toEqual(1); + expect(debugInfo!.noteHashes.length).toEqual(1); // 1 for the tx, another for the initializer - expect(tx?.nullifiers.length).toEqual(2); + expect(debugInfo!.nullifiers.length).toEqual(2); expect(await contract.methods.is_priv_imm_initialized().view()).toEqual(true); }); From e4c0b648c7ced5ac6ac14e2aeb37503df1337cad Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 29 Feb 2024 18:48:16 +0000 Subject: [PATCH 09/18] adding logs to debug info --- yarn-project/aztec.js/src/contract/sent_tx.ts | 2 ++ yarn-project/circuit-types/src/tx/tx_receipt.ts | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/yarn-project/aztec.js/src/contract/sent_tx.ts b/yarn-project/aztec.js/src/contract/sent_tx.ts index 64379ce0c42..27982f3903f 100644 --- a/yarn-project/aztec.js/src/contract/sent_tx.ts +++ b/yarn-project/aztec.js/src/contract/sent_tx.ts @@ -77,6 +77,8 @@ export class SentTx { l2ToL1Msgs: tx.l2ToL1Msgs.filter(l => !l.isZero()), contractsLeaves: tx.contractLeaves.filter(c => !c.isZero()), contractData: tx.contractData.filter(c => !c.isEmpty()), + encryptedLogs: tx.encryptedLogs.unrollLogs(), + unencryptedLogs: tx.unencryptedLogs.unrollLogs(), visibleNotes, }; } diff --git a/yarn-project/circuit-types/src/tx/tx_receipt.ts b/yarn-project/circuit-types/src/tx/tx_receipt.ts index b29d1b13810..20bff1300f7 100644 --- a/yarn-project/circuit-types/src/tx/tx_receipt.ts +++ b/yarn-project/circuit-types/src/tx/tx_receipt.ts @@ -104,6 +104,11 @@ interface DebugInfo { * New contract data created by the transaction. */ contractData: ContractData[]; + /** + * The logs emitted by the tx + */ + encryptedLogs: Buffer[]; + unencryptedLogs: Buffer[]; /** * Notes created in this tx which belong to accounts which are registered in the PXE which was used to submit the * tx. You will not receive notes of accounts which are not registered in the PXE here even though they were From 2ca7758db189969db3196c9b31d503385c4a6fa6 Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 29 Feb 2024 18:48:51 +0000 Subject: [PATCH 10/18] using debugInfo more --- .../src/e2e_non_contract_account.test.ts | 43 +++++++------------ 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts b/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts index a19e3a80841..9b17f6d1161 100644 --- a/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts +++ b/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts @@ -1,22 +1,10 @@ -import { - AztecNode, - DebugLogger, - ExtendedNote, - Fr, - Note, - PXE, - SignerlessWallet, - TxStatus, - Wallet, - toBigInt, -} from '@aztec/aztec.js'; +import { DebugLogger, ExtendedNote, Fr, Note, PXE, SignerlessWallet, Wallet, toBigInt } from '@aztec/aztec.js'; import { siloNullifier } from '@aztec/circuits.js/hash'; import { TestContract } from '@aztec/noir-contracts.js/Test'; import { setup } from './fixtures/utils.js'; describe('e2e_non_contract_account', () => { - let aztecNode: AztecNode | undefined; let pxe: PXE; let nonContractAccountWallet: Wallet; let teardown: () => Promise; @@ -27,7 +15,7 @@ describe('e2e_non_contract_account', () => { let wallet: Wallet; beforeEach(async () => { - ({ teardown, aztecNode, pxe, wallet, logger } = await setup(1)); + ({ teardown, pxe, wallet, logger } = await setup(1)); nonContractAccountWallet = new SignerlessWallet(pxe); logger(`Deploying L2 contract...`); @@ -42,12 +30,13 @@ describe('e2e_non_contract_account', () => { // Send transaction as arbitrary non-contract account const nullifier = new Fr(940); - const receipt = await contractWithNoContractWallet.methods.emit_nullifier(nullifier).send().wait({ interval: 0.1 }); - expect(receipt.status).toBe(TxStatus.MINED); + const { debugInfo } = await contractWithNoContractWallet.methods + .emit_nullifier(nullifier) + .send() + .wait({ interval: 0.1, debug: true }); - const tx = await aztecNode!.getTxEffect(receipt.txHash); const expectedSiloedNullifier = siloNullifier(contract.address, nullifier); - const siloedNullifier = tx!.nullifiers[1]; + const siloedNullifier = debugInfo!.nullifiers[1]; expect(siloedNullifier.equals(expectedSiloedNullifier)).toBeTruthy(); }, 120_000); @@ -56,14 +45,14 @@ describe('e2e_non_contract_account', () => { const contractWithNoContractWallet = await TestContract.at(contract.address, nonContractAccountWallet); // Send transaction as arbitrary non-contract account - const tx = contractWithNoContractWallet.methods.emit_msg_sender().send(); - const receipt = await tx.wait({ interval: 0.1 }); - expect(receipt.status).toBe(TxStatus.MINED); + const { debugInfo } = await contractWithNoContractWallet.methods + .emit_msg_sender() + .send() + .wait({ interval: 0.1, debug: true }); - const logs = (await tx.getUnencryptedLogs()).logs; + const logs = debugInfo!.unencryptedLogs; expect(logs.length).toBe(1); - - const msgSender = toBigInt(logs[0].log.data); + const msgSender = toBigInt(logs[0]); expect(msgSender).toBe(0n); }, 120_000); @@ -73,12 +62,10 @@ describe('e2e_non_contract_account', () => { it('can set and get a constant', async () => { const value = 123n; - const receipt = await contract.methods.set_constant(value).send().wait({ interval: 0.1 }); + const receipt = await contract.methods.set_constant(value).send().wait({ interval: 0.1, debug: true }); // check that 1 note hash was created - const tx = await pxe.getTxEffect(receipt.txHash); - const nonZeroNoteHashes = tx?.noteHashes.filter(c => c.value > 0); - expect(nonZeroNoteHashes?.length).toBe(1); + expect(receipt.debugInfo!.noteHashes.length).toBe(1); // Add the note const note = new Note([new Fr(value)]); From 7af2f4ed6c6e7e1284b64067fae2c420779a876e Mon Sep 17 00:00:00 2001 From: benesjan Date: Fri, 1 Mar 2024 07:36:46 +0000 Subject: [PATCH 11/18] fix --- yarn-project/aztec.js/src/contract/sent_tx.ts | 2 -- .../circuit-types/src/tx/tx_receipt.ts | 5 ----- .../src/e2e_non_contract_account.test.ts | 20 ++++++++++--------- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/yarn-project/aztec.js/src/contract/sent_tx.ts b/yarn-project/aztec.js/src/contract/sent_tx.ts index 27982f3903f..64379ce0c42 100644 --- a/yarn-project/aztec.js/src/contract/sent_tx.ts +++ b/yarn-project/aztec.js/src/contract/sent_tx.ts @@ -77,8 +77,6 @@ export class SentTx { l2ToL1Msgs: tx.l2ToL1Msgs.filter(l => !l.isZero()), contractsLeaves: tx.contractLeaves.filter(c => !c.isZero()), contractData: tx.contractData.filter(c => !c.isEmpty()), - encryptedLogs: tx.encryptedLogs.unrollLogs(), - unencryptedLogs: tx.unencryptedLogs.unrollLogs(), visibleNotes, }; } diff --git a/yarn-project/circuit-types/src/tx/tx_receipt.ts b/yarn-project/circuit-types/src/tx/tx_receipt.ts index 20bff1300f7..b29d1b13810 100644 --- a/yarn-project/circuit-types/src/tx/tx_receipt.ts +++ b/yarn-project/circuit-types/src/tx/tx_receipt.ts @@ -104,11 +104,6 @@ interface DebugInfo { * New contract data created by the transaction. */ contractData: ContractData[]; - /** - * The logs emitted by the tx - */ - encryptedLogs: Buffer[]; - unencryptedLogs: Buffer[]; /** * Notes created in this tx which belong to accounts which are registered in the PXE which was used to submit the * tx. You will not receive notes of accounts which are not registered in the PXE here even though they were diff --git a/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts b/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts index 9b17f6d1161..ef7e51ca910 100644 --- a/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts +++ b/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts @@ -45,14 +45,13 @@ describe('e2e_non_contract_account', () => { const contractWithNoContractWallet = await TestContract.at(contract.address, nonContractAccountWallet); // Send transaction as arbitrary non-contract account - const { debugInfo } = await contractWithNoContractWallet.methods - .emit_msg_sender() - .send() - .wait({ interval: 0.1, debug: true }); + const tx = contractWithNoContractWallet.methods.emit_msg_sender().send(); + await tx.wait({ interval: 0.1 }); - const logs = debugInfo!.unencryptedLogs; + const logs = (await tx.getUnencryptedLogs()).logs; expect(logs.length).toBe(1); - const msgSender = toBigInt(logs[0]); + + const msgSender = toBigInt(logs[0].log.data); expect(msgSender).toBe(0n); }, 120_000); @@ -62,10 +61,13 @@ describe('e2e_non_contract_account', () => { it('can set and get a constant', async () => { const value = 123n; - const receipt = await contract.methods.set_constant(value).send().wait({ interval: 0.1, debug: true }); + const { txHash, debugInfo } = await contract.methods + .set_constant(value) + .send() + .wait({ interval: 0.1, debug: true }); // check that 1 note hash was created - expect(receipt.debugInfo!.noteHashes.length).toBe(1); + expect(debugInfo!.noteHashes.length).toBe(1); // Add the note const note = new Note([new Fr(value)]); @@ -78,7 +80,7 @@ describe('e2e_non_contract_account', () => { contract.address, storageSlot, noteTypeId, - receipt.txHash, + txHash, ); await wallet.addNote(extendedNote); From 57816431a53b3fdd88802fb0a6904d1055fb7b96 Mon Sep 17 00:00:00 2001 From: benesjan Date: Fri, 1 Mar 2024 08:13:07 +0000 Subject: [PATCH 12/18] fix --- yarn-project/archiver/src/rpc/archiver_client.ts | 3 ++- .../circuit-types/src/aztec_node/rpc/aztec_node_client.ts | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/yarn-project/archiver/src/rpc/archiver_client.ts b/yarn-project/archiver/src/rpc/archiver_client.ts index c902d366f89..d6635fbdcad 100644 --- a/yarn-project/archiver/src/rpc/archiver_client.ts +++ b/yarn-project/archiver/src/rpc/archiver_client.ts @@ -6,6 +6,7 @@ import { L1ToL2Message, L2Block, L2BlockL2Logs, + TxReceipt, } from '@aztec/circuit-types'; import { EthAddress, Fr } from '@aztec/circuits.js'; import { createJsonRpcClient, makeFetch } from '@aztec/foundation/json-rpc/client'; @@ -26,7 +27,7 @@ export const createArchiverClient = (url: string, fetch = makeFetch([1, 2, 3], t L2Block, L2BlockL2Logs, }, - {}, + { TxReceipt }, false, 'archiver', fetch, diff --git a/yarn-project/circuit-types/src/aztec_node/rpc/aztec_node_client.ts b/yarn-project/circuit-types/src/aztec_node/rpc/aztec_node_client.ts index dad9b3513fb..4996f784d5a 100644 --- a/yarn-project/circuit-types/src/aztec_node/rpc/aztec_node_client.ts +++ b/yarn-project/circuit-types/src/aztec_node/rpc/aztec_node_client.ts @@ -11,7 +11,7 @@ import { L1ToL2MessageAndIndex } from '../../l1_to_l2_message.js'; import { L2Block } from '../../l2_block.js'; import { ExtendedUnencryptedL2Log, L2BlockL2Logs, LogId } from '../../logs/index.js'; import { SiblingPath } from '../../sibling_path/index.js'; -import { Tx, TxHash } from '../../tx/index.js'; +import { Tx, TxHash, TxReceipt } from '../../tx/index.js'; import { TxEffect } from '../../tx_effect.js'; /** @@ -40,7 +40,7 @@ export function createAztecNodeClient(url: string, fetch = defaultFetch): AztecN SiblingPath, L1ToL2MessageAndIndex, }, - { Tx, L2BlockL2Logs }, + { Tx, TxReceipt, L2BlockL2Logs }, false, 'node', fetch, From ad3434f420fc2e276e5ce7164db1ae4c477b5266 Mon Sep 17 00:00:00 2001 From: benesjan Date: Fri, 1 Mar 2024 08:24:55 +0000 Subject: [PATCH 13/18] cleanup --- .../end-to-end/src/e2e_inclusion_proofs_contract.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yarn-project/end-to-end/src/e2e_inclusion_proofs_contract.test.ts b/yarn-project/end-to-end/src/e2e_inclusion_proofs_contract.test.ts index b49bb0451e2..501fcdd0a91 100644 --- a/yarn-project/end-to-end/src/e2e_inclusion_proofs_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_inclusion_proofs_contract.test.ts @@ -158,9 +158,9 @@ describe('e2e_inclusion_proofs_contract', () => { const receipt = await contract.methods.create_note(owner, value).send().wait({ debug: true }); noteCreationBlockNumber = receipt.blockNumber!; - const { noteHashes: newNoteHashes, visibleNotes } = receipt.debugInfo!; + const { noteHashes, visibleNotes } = receipt.debugInfo!; - expect(newNoteHashes.length).toBe(1); + expect(noteHashes.length).toBe(1); expect(visibleNotes.length).toBe(1); const [receivedValue, receivedOwner, _randomness] = visibleNotes[0].note.items; expect(receivedValue.toBigInt()).toBe(value); From 00b778d67353a31b15f1837212e8b3e7b2c534ae Mon Sep 17 00:00:00 2001 From: benesjan Date: Fri, 1 Mar 2024 09:17:33 +0000 Subject: [PATCH 14/18] fix --- .../src/e2e_inclusion_proofs_contract.test.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/yarn-project/end-to-end/src/e2e_inclusion_proofs_contract.test.ts b/yarn-project/end-to-end/src/e2e_inclusion_proofs_contract.test.ts index 501fcdd0a91..37c3ee7318b 100644 --- a/yarn-project/end-to-end/src/e2e_inclusion_proofs_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_inclusion_proofs_contract.test.ts @@ -96,17 +96,15 @@ describe('e2e_inclusion_proofs_contract', () => { await contract.methods.test_note_validity(owner, false, 0n, false).send().wait(); }); - describe('we will test the vailure case by nullifying a note', () => { - let receipt: any; - let currentBlockNumber: any; + describe('we will test the failure case by nullifying a note', () => { + let currentBlockNumber: number; + // We test the failure case now --> The proof should fail when the nullifier already exists it('nullifies a note and grabs block number', async () => { - receipt = await contract.methods.nullify_note(owner).send().wait({ debug: true }); + const { debugInfo } = await contract.methods.nullify_note(owner).send().wait({ debug: true }); currentBlockNumber = await pxe.getBlockNumber(); - const { newNullifiers } = receipt!.debugInfo!; - expect(newNullifiers.length).toBe(2); - // const nullifier = newNullifiers[1]; + expect(debugInfo!.nullifiers.length).toBe(2); }); // Note: getLowNullifierMembershipWitness returns the membership witness of the nullifier itself and not From 4de7e87b319e213dd667cfe2af961b40cda7b903 Mon Sep 17 00:00:00 2001 From: benesjan Date: Fri, 1 Mar 2024 11:30:04 +0000 Subject: [PATCH 15/18] updated naming --- .../e2e_pending_commitments_contract.test.ts | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/yarn-project/end-to-end/src/e2e_pending_commitments_contract.test.ts b/yarn-project/end-to-end/src/e2e_pending_commitments_contract.test.ts index 71a80455c38..27544cba41e 100644 --- a/yarn-project/end-to-end/src/e2e_pending_commitments_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_pending_commitments_contract.test.ts @@ -19,19 +19,19 @@ describe('e2e_pending_commitments_contract', () => { afterEach(() => teardown()); - const expectCommitmentsSquashedExcept = async (exceptFirstFew: number) => { + const expectNoteHashesSquashedExcept = async (exceptFirstFew: number) => { const blockNum = await aztecNode!.getBlockNumber(); const block = (await aztecNode!.getBlocks(blockNum, 1))[0]; - const commitmentsArray = block.body.txEffects.flatMap(txEffect => txEffect.noteHashes); + const noteHashes = block.body.txEffects.flatMap(txEffect => txEffect.noteHashes); - // all new commitments should be zero (should be squashed) + // all new note hashes should be zero (should be squashed) for (let c = 0; c < exceptFirstFew; c++) { - expect(commitmentsArray[c]).not.toEqual(Fr.ZERO); + expect(noteHashes).not.toEqual(Fr.ZERO); } - for (let c = exceptFirstFew; c < commitmentsArray.length; c++) { - expect(commitmentsArray[c]).toEqual(Fr.ZERO); + for (let c = exceptFirstFew; c < noteHashes.length; c++) { + expect(noteHashes).toEqual(Fr.ZERO); } }; @@ -90,7 +90,7 @@ describe('e2e_pending_commitments_contract', () => { expect(receipt.status).toBe(TxStatus.MINED); - await expectCommitmentsSquashedExcept(0); + await expectNoteHashesSquashedExcept(0); await expectNullifiersSquashedExcept(0); }, 60_000); @@ -113,7 +113,7 @@ describe('e2e_pending_commitments_contract', () => { expect(receipt.status).toBe(TxStatus.MINED); - await expectCommitmentsSquashedExcept(0); + await expectNoteHashesSquashedExcept(0); await expectNullifiersSquashedExcept(0); }, 60_000); @@ -137,7 +137,7 @@ describe('e2e_pending_commitments_contract', () => { expect(receipt.status).toBe(TxStatus.MINED); - await expectCommitmentsSquashedExcept(1); + await expectNoteHashesSquashedExcept(1); await expectNullifiersSquashedExcept(0); }, 60_000); @@ -155,7 +155,7 @@ describe('e2e_pending_commitments_contract', () => { const receipt0 = await deployedContract.methods.insert_note(mintAmount, owner).send().wait(); expect(receipt0.status).toBe(TxStatus.MINED); - await expectCommitmentsSquashedExcept(1); // first TX just creates 1 persistent note + await expectNoteHashesSquashedExcept(1); // first TX just creates 1 persistent note await expectNullifiersSquashedExcept(0); // create another note, and nullify it and AND nullify the above-created note in the same TX @@ -173,7 +173,7 @@ describe('e2e_pending_commitments_contract', () => { expect(receipt1.status).toBe(TxStatus.MINED); // second TX creates 1 note, but it is squashed! - await expectCommitmentsSquashedExcept(0); + await expectNoteHashesSquashedExcept(0); // the nullifier corresponding to this transient note is squashed, but the // other nullifier corresponding to the persistent note becomes persistent itself. await expectNullifiersSquashedExcept(1); @@ -192,8 +192,8 @@ describe('e2e_pending_commitments_contract', () => { expect(receipt.status).toBe(TxStatus.MINED); - // There is a single new commitment/note. - await expectCommitmentsSquashedExcept(1); + // There is a single new note hash. + await expectNoteHashesSquashedExcept(1); const receipt2 = await deployedContract.methods .test_insert_then_get_then_nullify_all_in_nested_calls( From 21783bf3b812d8380222c8f8bb97cdae273f0edf Mon Sep 17 00:00:00 2001 From: benesjan Date: Fri, 1 Mar 2024 11:52:37 +0000 Subject: [PATCH 16/18] fix --- .../end-to-end/src/e2e_pending_commitments_contract.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yarn-project/end-to-end/src/e2e_pending_commitments_contract.test.ts b/yarn-project/end-to-end/src/e2e_pending_commitments_contract.test.ts index 27544cba41e..f3c7c1a83a4 100644 --- a/yarn-project/end-to-end/src/e2e_pending_commitments_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_pending_commitments_contract.test.ts @@ -27,11 +27,11 @@ describe('e2e_pending_commitments_contract', () => { // all new note hashes should be zero (should be squashed) for (let c = 0; c < exceptFirstFew; c++) { - expect(noteHashes).not.toEqual(Fr.ZERO); + expect(noteHashes[c]).not.toEqual(Fr.ZERO); } for (let c = exceptFirstFew; c < noteHashes.length; c++) { - expect(noteHashes).toEqual(Fr.ZERO); + expect(noteHashes[c]).toEqual(Fr.ZERO); } }; From 66035e0cf03526e53daade8e59301ac9401e2994 Mon Sep 17 00:00:00 2001 From: benesjan Date: Fri, 1 Mar 2024 11:54:04 +0000 Subject: [PATCH 17/18] nuking unnecessary undefined --- .../src/e2e_pending_commitments_contract.test.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/yarn-project/end-to-end/src/e2e_pending_commitments_contract.test.ts b/yarn-project/end-to-end/src/e2e_pending_commitments_contract.test.ts index f3c7c1a83a4..63b25858a22 100644 --- a/yarn-project/end-to-end/src/e2e_pending_commitments_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_pending_commitments_contract.test.ts @@ -4,7 +4,7 @@ import { PendingCommitmentsContract } from '@aztec/noir-contracts.js/PendingComm import { setup } from './fixtures/utils.js'; describe('e2e_pending_commitments_contract', () => { - let aztecNode: AztecNode | undefined; + let aztecNode: AztecNode; let wallet: Wallet; let logger: DebugLogger; let owner: AztecAddress; @@ -20,8 +20,8 @@ describe('e2e_pending_commitments_contract', () => { afterEach(() => teardown()); const expectNoteHashesSquashedExcept = async (exceptFirstFew: number) => { - const blockNum = await aztecNode!.getBlockNumber(); - const block = (await aztecNode!.getBlocks(blockNum, 1))[0]; + const blockNum = await aztecNode.getBlockNumber(); + const block = (await aztecNode.getBlocks(blockNum, 1))[0]; const noteHashes = block.body.txEffects.flatMap(txEffect => txEffect.noteHashes); @@ -36,8 +36,8 @@ describe('e2e_pending_commitments_contract', () => { }; const expectNullifiersSquashedExcept = async (exceptFirstFew: number) => { - const blockNum = await aztecNode!.getBlockNumber(); - const block = (await aztecNode!.getBlocks(blockNum, 1))[0]; + const blockNum = await aztecNode.getBlockNumber(); + const block = (await aztecNode.getBlocks(blockNum, 1))[0]; const nullifierArray = block.body.txEffects.flatMap(txEffect => txEffect.nullifiers); From 49cb21a0f12c5e80e9748ce69ed3cc25aa9823a4 Mon Sep 17 00:00:00 2001 From: benesjan Date: Fri, 1 Mar 2024 12:00:25 +0000 Subject: [PATCH 18/18] PendingCommitmentsContract -> PendingNoteHashesContract --- .circleci/config.yml | 8 +++---- .../sandbox/references/sandbox-reference.md | 2 +- noir-projects/noir-contracts/Nargo.toml | 2 +- .../Nargo.toml | 2 +- .../src/main.nr | 8 +++---- .../end-to-end/src/cli_docs_sandbox.test.ts | 2 +- ... e2e_pending_note_hashes_contract.test.ts} | 8 +++---- .../src/client/private_execution.test.ts | 21 ++++++++----------- 8 files changed, 25 insertions(+), 28 deletions(-) rename noir-projects/noir-contracts/contracts/{pending_commitments_contract => pending_note_hashes_contract}/Nargo.toml (83%) rename noir-projects/noir-contracts/contracts/{pending_commitments_contract => pending_note_hashes_contract}/src/main.nr (98%) rename yarn-project/end-to-end/src/{e2e_pending_commitments_contract.test.ts => e2e_pending_note_hashes_contract.test.ts} (96%) diff --git a/.circleci/config.yml b/.circleci/config.yml index 3b6041e8bef..2e4c59e004a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -893,7 +893,7 @@ jobs: command: cond_spot_run_compose end-to-end 4 ./scripts/docker-compose.yml TEST=e2e_inclusion_proofs_contract.test.ts aztec_manifest_key: end-to-end - e2e-pending-commitments-contract: + e2e-pending-note-hashes-contract: docker: - image: aztecprotocol/alpine-build-image resource_class: small @@ -902,7 +902,7 @@ jobs: - *setup_env - run: name: "Test" - command: cond_spot_run_compose end-to-end 4 ./scripts/docker-compose.yml TEST=e2e_pending_commitments_contract.test.ts + command: cond_spot_run_compose end-to-end 4 ./scripts/docker-compose.yml TEST=e2e_pending_note_hashes_contract.test.ts aztec_manifest_key: end-to-end e2e-ordering: @@ -1493,7 +1493,7 @@ workflows: - e2e-account-contracts: *e2e_test - e2e-escrow-contract: *e2e_test - e2e-inclusion-proofs-contract: *e2e_test - - e2e-pending-commitments-contract: *e2e_test + - e2e-pending-note-hashes-contract: *e2e_test - e2e-ordering: *e2e_test - e2e-counter: *e2e_test - e2e-private-voting: *e2e_test @@ -1539,7 +1539,7 @@ workflows: - e2e-account-contracts - e2e-escrow-contract - e2e-inclusion-proofs-contract - - e2e-pending-commitments-contract + - e2e-pending-note-hashes-contract - e2e-ordering - e2e-counter - e2e-private-voting diff --git a/docs/docs/developers/sandbox/references/sandbox-reference.md b/docs/docs/developers/sandbox/references/sandbox-reference.md index 17e57e6cde5..04048676ccc 100644 --- a/docs/docs/developers/sandbox/references/sandbox-reference.md +++ b/docs/docs/developers/sandbox/references/sandbox-reference.md @@ -193,7 +193,7 @@ ImportTestContractArtifact InclusionProofsContractArtifact LendingContractArtifact ParentContractArtifact -PendingCommitmentsContractArtifact +PendingNoteHashesContractArtifact PriceFeedContractArtifact SchnorrAccountContractArtifact SchnorrHardcodedAccountContractArtifact diff --git a/noir-projects/noir-contracts/Nargo.toml b/noir-projects/noir-contracts/Nargo.toml index 61eeb44fa70..08b4006f56b 100644 --- a/noir-projects/noir-contracts/Nargo.toml +++ b/noir-projects/noir-contracts/Nargo.toml @@ -21,7 +21,7 @@ members = [ "contracts/inclusion_proofs_contract", "contracts/lending_contract", "contracts/parent_contract", - "contracts/pending_commitments_contract", + "contracts/pending_note_hashes_contract", "contracts/price_feed_contract", "contracts/schnorr_account_contract", "contracts/schnorr_hardcoded_account_contract", diff --git a/noir-projects/noir-contracts/contracts/pending_commitments_contract/Nargo.toml b/noir-projects/noir-contracts/contracts/pending_note_hashes_contract/Nargo.toml similarity index 83% rename from noir-projects/noir-contracts/contracts/pending_commitments_contract/Nargo.toml rename to noir-projects/noir-contracts/contracts/pending_note_hashes_contract/Nargo.toml index 87ecd53b2cd..027377bc236 100644 --- a/noir-projects/noir-contracts/contracts/pending_commitments_contract/Nargo.toml +++ b/noir-projects/noir-contracts/contracts/pending_note_hashes_contract/Nargo.toml @@ -1,5 +1,5 @@ [package] -name = "pending_commitments_contract" +name = "pending_note_hashes_contract" authors = [""] compiler_version = ">=0.18.0" type = "contract" diff --git a/noir-projects/noir-contracts/contracts/pending_commitments_contract/src/main.nr b/noir-projects/noir-contracts/contracts/pending_note_hashes_contract/src/main.nr similarity index 98% rename from noir-projects/noir-contracts/contracts/pending_commitments_contract/src/main.nr rename to noir-projects/noir-contracts/contracts/pending_note_hashes_contract/src/main.nr index fae26b23fc9..4115f9c34c7 100644 --- a/noir-projects/noir-contracts/contracts/pending_commitments_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/pending_note_hashes_contract/src/main.nr @@ -2,7 +2,7 @@ // read (eventually even nullified) in the same TX. This contract // also contains some "bad" test cases to ensure that notes cannot // be read/nullified before their creation etc. -contract PendingCommitments { +contract PendingNoteHashes { // Libs use dep::std::option::Option; use dep::value_note::{balance_utils, filter::filter_notes_min_sum, value_note::{VALUE_NOTE_LEN, ValueNote}}; @@ -47,7 +47,7 @@ contract PendingCommitments { note0.value } - // Confirm cannot access commitments inserted later in same function + // Confirm cannot access note hashes inserted later in same function #[aztec(private)] fn test_bad_get_then_insert_flat(amount: Field, owner: AztecAddress) -> Field { let owner_balance = storage.balances.at(owner); @@ -108,7 +108,7 @@ contract PendingCommitments { } // Test pending note hashes with note insertion done in a nested call - // and "read" / get of that pending note/commitment in another nested call + // and "read" / get of that pending note hash in another nested call // Realistic way to describe this test is "Mint note A, then burn note A in the same transaction" #[aztec(private)] fn test_insert_then_get_then_nullify_all_in_nested_calls( @@ -248,7 +248,7 @@ contract PendingCommitments { // that is created/inserted later in execution but in the parent. // NOTE: This test is especially important in an end-to-end context because the parent call // (and therefore the insertion) will be processed in an earlier kernel iteration, but the - // nested call (later kernel iteration) should not be able to read the commitment despite + // nested call (later kernel iteration) should not be able to read the note hash despite // it being present at that stage in the kernel. // If we can somehow force the simulator to allow execution to succeed can ensure that this test fails in the kernel // #[aztec(private)] diff --git a/yarn-project/end-to-end/src/cli_docs_sandbox.test.ts b/yarn-project/end-to-end/src/cli_docs_sandbox.test.ts index a3cf6e66db3..2e1a031da41 100644 --- a/yarn-project/end-to-end/src/cli_docs_sandbox.test.ts +++ b/yarn-project/end-to-end/src/cli_docs_sandbox.test.ts @@ -116,7 +116,7 @@ ImportTestContractArtifact InclusionProofsContractArtifact LendingContractArtifact ParentContractArtifact -PendingCommitmentsContractArtifact +PendingNoteHashesContractArtifact PriceFeedContractArtifact ReaderContractArtifact SchnorrAccountContractArtifact diff --git a/yarn-project/end-to-end/src/e2e_pending_commitments_contract.test.ts b/yarn-project/end-to-end/src/e2e_pending_note_hashes_contract.test.ts similarity index 96% rename from yarn-project/end-to-end/src/e2e_pending_commitments_contract.test.ts rename to yarn-project/end-to-end/src/e2e_pending_note_hashes_contract.test.ts index 63b25858a22..f4d772af157 100644 --- a/yarn-project/end-to-end/src/e2e_pending_commitments_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_pending_note_hashes_contract.test.ts @@ -1,15 +1,15 @@ import { AztecAddress, AztecNode, CompleteAddress, DebugLogger, Fr, TxStatus, Wallet } from '@aztec/aztec.js'; -import { PendingCommitmentsContract } from '@aztec/noir-contracts.js/PendingCommitments'; +import { PendingNoteHashesContract } from '@aztec/noir-contracts.js/PendingNoteHashes'; import { setup } from './fixtures/utils.js'; -describe('e2e_pending_commitments_contract', () => { +describe('e2e_pending_note_hashes_contract', () => { let aztecNode: AztecNode; let wallet: Wallet; let logger: DebugLogger; let owner: AztecAddress; let teardown: () => Promise; - let contract: PendingCommitmentsContract; + let contract: PendingNoteHashesContract; beforeEach(async () => { let accounts: CompleteAddress[]; @@ -53,7 +53,7 @@ describe('e2e_pending_commitments_contract', () => { const deployContract = async () => { logger(`Deploying L2 contract...`); - contract = await PendingCommitmentsContract.deploy(wallet).send().deployed(); + contract = await PendingNoteHashesContract.deploy(wallet).send().deployed(); logger('L2 contract deployed'); return contract; }; diff --git a/yarn-project/simulator/src/client/private_execution.test.ts b/yarn-project/simulator/src/client/private_execution.test.ts index 6ad0271bf49..7fc20389560 100644 --- a/yarn-project/simulator/src/client/private_execution.test.ts +++ b/yarn-project/simulator/src/client/private_execution.test.ts @@ -47,7 +47,7 @@ import { ChildContractArtifact, ImportTestContractArtifact, ParentContractArtifact, - PendingCommitmentsContractArtifact, + PendingNoteHashesContractArtifact, StatefulTestContractArtifact, TestContractArtifact, TokenContractArtifact, @@ -880,10 +880,10 @@ describe('Private Execution test suite', () => { beforeEach(() => { oracle.getFunctionArtifact.mockImplementation((_, selector) => - Promise.resolve(getFunctionArtifactWithSelector(PendingCommitmentsContractArtifact, selector)), + Promise.resolve(getFunctionArtifactWithSelector(PendingNoteHashesContractArtifact, selector)), ); oracle.getFunctionArtifactByName.mockImplementation((_, functionName: string) => - Promise.resolve(getFunctionArtifact(PendingCommitmentsContractArtifact, functionName)), + Promise.resolve(getFunctionArtifact(PendingNoteHashesContractArtifact, functionName)), ); }); @@ -893,10 +893,7 @@ describe('Private Execution test suite', () => { const amountToTransfer = 100n; const contractAddress = AztecAddress.random(); - const artifact = getFunctionArtifact( - PendingCommitmentsContractArtifact, - 'test_insert_then_get_then_nullify_flat', - ); + const artifact = getFunctionArtifact(PendingNoteHashesContractArtifact, 'test_insert_then_get_then_nullify_flat'); const args = [amountToTransfer, owner]; const result = await runSimulator({ @@ -955,14 +952,14 @@ describe('Private Execution test suite', () => { const contractAddress = AztecAddress.random(); const artifact = getFunctionArtifact( - PendingCommitmentsContractArtifact, + PendingNoteHashesContractArtifact, 'test_insert_then_get_then_nullify_all_in_nested_calls', ); - const insertArtifact = getFunctionArtifact(PendingCommitmentsContractArtifact, 'insert_note'); + const insertArtifact = getFunctionArtifact(PendingNoteHashesContractArtifact, 'insert_note'); - const getThenNullifyArtifact = getFunctionArtifact(PendingCommitmentsContractArtifact, 'get_then_nullify_note'); + const getThenNullifyArtifact = getFunctionArtifact(PendingNoteHashesContractArtifact, 'get_then_nullify_note'); - const getZeroArtifact = getFunctionArtifact(PendingCommitmentsContractArtifact, 'get_note_zero_balance'); + const getZeroArtifact = getFunctionArtifact(PendingNoteHashesContractArtifact, 'get_note_zero_balance'); const insertFnSelector = FunctionSelector.fromNameAndParameters(insertArtifact.name, insertArtifact.parameters); const getThenNullifyFnSelector = FunctionSelector.fromNameAndParameters( @@ -1048,7 +1045,7 @@ describe('Private Execution test suite', () => { const contractAddress = AztecAddress.random(); - const artifact = getFunctionArtifact(PendingCommitmentsContractArtifact, 'test_bad_get_then_insert_flat'); + const artifact = getFunctionArtifact(PendingNoteHashesContractArtifact, 'test_bad_get_then_insert_flat'); const args = [amountToTransfer, owner]; const result = await runSimulator({