Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed May 9, 2024
1 parent 508d92d commit 46e23cd
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 54 deletions.
3 changes: 2 additions & 1 deletion yarn-project/aztec-node/src/aztec-node/http_rpc_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
L2Block,
LogId,
NullifierMembershipWitness,
ProcessOutput,
PublicDataWitness,
SiblingPath,
Tx,
Expand Down Expand Up @@ -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'],
);
Expand Down
20 changes: 10 additions & 10 deletions yarn-project/aztec-node/src/aztec-node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
LogType,
MerkleTreeId,
NullifierMembershipWitness,
type ProcessOutput,
ProcessOutput,
type ProverClient,
type ProverConfig,
PublicDataWitness,
Expand Down Expand Up @@ -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<SequencerConfig & ProverConfig>): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand All @@ -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,
Expand Down
20 changes: 10 additions & 10 deletions yarn-project/circuit-types/src/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
};

Expand Down
66 changes: 36 additions & 30 deletions yarn-project/circuit-types/src/tx/simulated_tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProcessedTx, 'encryptedLogs' | 'unencryptedLogs' | 'revertReason' | 'gasUsed'> &
Pick<ProcessedTx['data'], 'constants' | 'end'> & { 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<Record<PublicKernelType, Gas>>,
) {}

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.
Expand Down Expand Up @@ -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(),
};
}

Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/e2e_2_pxes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 46e23cd

Please sign in to comment.