From b603ec9cb3d826a0b96da4e19ff90047070bf39e Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 9 May 2024 08:13:04 +0000 Subject: [PATCH] WIP --- .../src/aztec-node/http_rpc_server.ts | 3 +- .../aztec-node/src/aztec-node/server.ts | 20 +++--- .../src/aztec_node/rpc/aztec_node_client.ts | 4 +- yarn-project/circuit-types/src/mocks.ts | 20 +++--- .../circuit-types/src/tx/simulated_tx.ts | 66 ++++++++++--------- .../end-to-end/src/e2e_2_pxes.test.ts | 2 +- 6 files changed, 61 insertions(+), 54 deletions(-) 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 8270b171ffec..29abbb482119 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 @@ -5,6 +5,7 @@ import { L2Block, LogId, NullifierMembershipWitness, + ProcessOutput, PublicDataWitness, SiblingPath, Tx, @@ -41,7 +42,7 @@ export function createAztecNodeRpcServer(node: AztecNode) { PublicDataWitness, SiblingPath, }, - { Tx, TxReceipt, EncryptedL2BlockL2Logs, UnencryptedL2BlockL2Logs, NullifierMembershipWitness }, + { ProcessOutput, Tx, TxReceipt, EncryptedL2BlockL2Logs, UnencryptedL2BlockL2Logs, NullifierMembershipWitness }, // disable methods not part of the AztecNode interface ['start', 'stop'], ); diff --git a/yarn-project/aztec-node/src/aztec-node/server.ts b/yarn-project/aztec-node/src/aztec-node/server.ts index 980c9cf6df0c..6a748e212a7a 100644 --- a/yarn-project/aztec-node/src/aztec-node/server.ts +++ b/yarn-project/aztec-node/src/aztec-node/server.ts @@ -13,7 +13,7 @@ import { LogType, MerkleTreeId, NullifierMembershipWitness, - type ProcessOutput, + ProcessOutput, type ProverClient, type ProverConfig, PublicDataWitness, @@ -674,15 +674,15 @@ export class AztecNodeService implements AztecNode { } this.log.debug(`Simulated tx ${tx.getTxHash()} succeeds`); const [processedTx] = processedTxs; - return { - constants: processedTx.data.constants, - encryptedLogs: processedTx.encryptedLogs, - unencryptedLogs: processedTx.unencryptedLogs, - end: processedTx.data.end, - revertReason: processedTx.revertReason, - publicReturnValues: returns[0], - gasUsed: processedTx.gasUsed, - }; + return new ProcessOutput( + processedTx.encryptedLogs, + processedTx.unencryptedLogs, + processedTx.revertReason, + processedTx.data.constants, + processedTx.data.end, + returns[0], + processedTx.gasUsed, + ); } public async setConfig(config: Partial): Promise { 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 a68276d2e470..233fcb869402 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 { L2Block } from '../../l2_block.js'; import { EncryptedL2BlockL2Logs, ExtendedUnencryptedL2Log, LogId, UnencryptedL2BlockL2Logs } from '../../logs/index.js'; import { PublicDataWitness } from '../../public_data_witness.js'; import { SiblingPath } from '../../sibling_path/index.js'; -import { Tx, TxHash, TxReceipt } from '../../tx/index.js'; +import { ProcessOutput, Tx, TxHash, TxReceipt } from '../../tx/index.js'; import { TxEffect } from '../../tx_effect.js'; /** @@ -38,7 +38,7 @@ export function createAztecNodeClient(url: string, fetch = defaultFetch): AztecN PublicDataWitness, SiblingPath, }, - { Tx, TxReceipt, EncryptedL2BlockL2Logs, UnencryptedL2BlockL2Logs, NullifierMembershipWitness }, + { ProcessOutput, Tx, TxReceipt, EncryptedL2BlockL2Logs, UnencryptedL2BlockL2Logs, NullifierMembershipWitness }, false, 'node', fetch, diff --git a/yarn-project/circuit-types/src/mocks.ts b/yarn-project/circuit-types/src/mocks.ts index 9cda922037cc..a7260210d2cc 100644 --- a/yarn-project/circuit-types/src/mocks.ts +++ b/yarn-project/circuit-types/src/mocks.ts @@ -27,7 +27,7 @@ import { type ContractInstanceWithAddress, SerializableContractInstance } from ' import { EncryptedL2Log } from './logs/encrypted_l2_log.js'; import { EncryptedFunctionL2Logs, EncryptedTxL2Logs, Note, UnencryptedTxL2Logs } from './logs/index.js'; import { ExtendedNote } from './notes/index.js'; -import { type ProcessOutput, type ProcessReturnValues, SimulatedTx, Tx, TxHash } from './tx/index.js'; +import { ProcessOutput, type ProcessReturnValues, SimulatedTx, Tx, TxHash } from './tx/index.js'; /** * Testing utility to create empty logs composed from a single empty log. @@ -129,15 +129,15 @@ export const mockTxForRollup = (seed = 1, { hasLogs = false }: { hasLogs?: boole export const mockSimulatedTx = (seed = 1, hasLogs = true) => { const tx = mockTx(seed, { hasLogs }); const dec: ProcessReturnValues = [new Fr(1n), new Fr(2n), new Fr(3n), new Fr(4n)]; - const output: ProcessOutput = { - constants: makeCombinedConstantData(), - encryptedLogs: tx.encryptedLogs, - unencryptedLogs: tx.unencryptedLogs, - end: makeCombinedAccumulatedData(), - revertReason: undefined, - publicReturnValues: dec, - gasUsed: {}, - }; + const output = new ProcessOutput( + tx.encryptedLogs, + tx.unencryptedLogs, + undefined, + makeCombinedConstantData(), + makeCombinedAccumulatedData(), + dec, + {}, + ); return new SimulatedTx(tx, dec, output); }; diff --git a/yarn-project/circuit-types/src/tx/simulated_tx.ts b/yarn-project/circuit-types/src/tx/simulated_tx.ts index 61883a5d1f5d..d791e5ee8b72 100644 --- a/yarn-project/circuit-types/src/tx/simulated_tx.ts +++ b/yarn-project/circuit-types/src/tx/simulated_tx.ts @@ -2,41 +2,47 @@ import { CombinedAccumulatedData, CombinedConstantData, Fr, Gas } from '@aztec/c import { mapValues } from '@aztec/foundation/collection'; import { EncryptedTxL2Logs, UnencryptedTxL2Logs } from '../logs/index.js'; -import { type ProcessedTx, PublicKernelType } from './processed_tx.js'; +import { type SimulationError } from '../simulation_error.js'; +import { PublicKernelType } from './processed_tx.js'; import { Tx } from './tx.js'; /** Return values of simulating a circuit. */ export type ProcessReturnValues = Fr[] | undefined; -/** - * Outputs of processing the public component of a transaction. - * REFACTOR: Rename. - */ -export type ProcessOutput = Pick & - Pick & { publicReturnValues: ProcessReturnValues }; +export class ProcessOutput { + constructor( + public encryptedLogs: EncryptedTxL2Logs, + public unencryptedLogs: UnencryptedTxL2Logs, + public revertReason: SimulationError | undefined, + public constants: CombinedConstantData, + public end: CombinedAccumulatedData, + public publicReturnValues: ProcessReturnValues, + public gasUsed: Partial>, + ) {} -function processOutputToJSON(output: ProcessOutput) { - return { - encryptedLogs: output.encryptedLogs.toJSON(), - unencryptedLogs: output.unencryptedLogs.toJSON(), - revertReason: output.revertReason, - constants: output.constants.toBuffer().toString('hex'), - end: output.end.toBuffer().toString('hex'), - publicReturnValues: output.publicReturnValues?.map(fr => fr.toString()), - gasUsed: mapValues(output.gasUsed, gas => gas?.toJSON()), - }; -} + toJSON() { + return { + encryptedLogs: this.encryptedLogs.toJSON(), + unencryptedLogs: this.unencryptedLogs.toJSON(), + revertReason: this.revertReason, + constants: this.constants.toBuffer().toString('hex'), + end: this.end.toBuffer().toString('hex'), + publicReturnValues: this.publicReturnValues?.map(fr => fr.toString()), + gasUsed: mapValues(this.gasUsed, gas => gas?.toJSON()), + }; + } -function processOutputFromJSON(json: any): ProcessOutput { - return { - encryptedLogs: EncryptedTxL2Logs.fromJSON(json.encryptedLogs), - unencryptedLogs: UnencryptedTxL2Logs.fromJSON(json.unencryptedLogs), - revertReason: json.revertReason, - constants: CombinedConstantData.fromBuffer(Buffer.from(json.constants, 'hex')), - end: CombinedAccumulatedData.fromBuffer(Buffer.from(json.end, 'hex')), - publicReturnValues: json.publicReturnValues?.map(Fr.fromString), - gasUsed: mapValues(json.gasUsed, gas => (gas ? Gas.fromJSON(gas) : undefined)), - }; + static fromJSON(json: any): ProcessOutput { + return new ProcessOutput( + EncryptedTxL2Logs.fromJSON(json.encryptedLogs), + UnencryptedTxL2Logs.fromJSON(json.unencryptedLogs), + json.revertReason, + CombinedConstantData.fromBuffer(Buffer.from(json.constants, 'hex')), + CombinedAccumulatedData.fromBuffer(Buffer.from(json.end, 'hex')), + json.publicReturnValues?.map(Fr.fromString), + mapValues(json.gasUsed, gas => (gas ? Gas.fromJSON(gas) : undefined)), + ); + } } // REFACTOR: Review what we need to expose to the user when running a simulation. @@ -79,7 +85,7 @@ export class SimulatedTx { return { tx: this.tx.toJSON(), privateReturnValues: this.privateReturnValues?.map(fr => fr.toString()), - publicOutput: this.publicOutput && processOutputToJSON(this.publicOutput), + publicOutput: this.publicOutput && this.publicOutput.toJSON(), }; } @@ -90,7 +96,7 @@ export class SimulatedTx { */ public static fromJSON(obj: any) { const tx = Tx.fromJSON(obj.tx); - const publicOutput = obj.publicOutput ? processOutputFromJSON(obj.publicOutput) : undefined; + const publicOutput = obj.publicOutput ? ProcessOutput.fromJSON(obj.publicOutput) : undefined; const privateReturnValues = obj.privateReturnValues?.map(Fr.fromString); return new SimulatedTx(tx, privateReturnValues, publicOutput); diff --git a/yarn-project/end-to-end/src/e2e_2_pxes.test.ts b/yarn-project/end-to-end/src/e2e_2_pxes.test.ts index 733aaeedb158..7e185f169e04 100644 --- a/yarn-project/end-to-end/src/e2e_2_pxes.test.ts +++ b/yarn-project/end-to-end/src/e2e_2_pxes.test.ts @@ -111,7 +111,7 @@ describe('e2e_2_pxes', () => { await contract.methods.redeem_shield(recipient, balance, secret).send().wait(); }; - it.only('transfers funds from user A to B via PXE A followed by transfer from B to A via PXE B', async () => { + it('transfers funds from user A to B via PXE A followed by transfer from B to A via PXE B', async () => { const initialBalance = 987n; const transferAmount1 = 654n; const transferAmount2 = 323n;