@@ -3,14 +3,16 @@ import { Fr } from '@aztec/foundation/fields';
33import { type Logger , createLogger } from '@aztec/foundation/log' ;
44import { ProtocolContractAddress , ProtocolContractsList } from '@aztec/protocol-contracts' ;
55import { computeFeePayerBalanceStorageSlot } from '@aztec/protocol-contracts/fee-juice' ;
6- import { AvmCircuitPublicInputs , AvmExecutionHints , AvmTxHint , type RevertCode } from '@aztec/stdlib/avm' ;
6+ import { AvmCircuitPublicInputs , AvmExecutionHints , AvmTxHint , RevertCode } from '@aztec/stdlib/avm' ;
77import { SimulationError } from '@aztec/stdlib/errors' ;
88import type { Gas , GasUsed } from '@aztec/stdlib/gas' ;
9- import type { DebugLog } from '@aztec/stdlib/logs' ;
9+ import { DebugLog } from '@aztec/stdlib/logs' ;
10+ import { schemas } from '@aztec/stdlib/schemas' ;
1011import type { MerkleTreeWriteOperations } from '@aztec/stdlib/trees' ;
1112import { type GlobalVariables , PublicCallRequestWithCalldata , Tx , TxExecutionPhase } from '@aztec/stdlib/tx' ;
1213
1314import { strict as assert } from 'assert' ;
15+ import { z } from 'zod' ;
1416
1517import type { AvmFinalizedCallResult } from '../avm/avm_contract_call_result.js' ;
1618import { AvmSimulator } from '../avm/index.js' ;
@@ -27,17 +29,43 @@ import type { PublicPersistableStateManager } from '../state_manager/state_manag
2729import { PublicTxContext } from './public_tx_context.js' ;
2830import type { PublicTxSimulatorInterface } from './public_tx_simulator_interface.js' ;
2931
30- export type PublicTxResult = {
31- // Simulation result.
32- gasUsed : GasUsed ; // Gas used during the execution of this tx
33- revertCode : RevertCode ;
34- revertReason ?: SimulationError ; // Revert reason, if any
35- appLogicReturnValue ?: Fr [ ] ; // Return/revert value of the app logic phase
36- logs : DebugLog [ ] ;
37- // For the proving request.
38- hints ?: AvmExecutionHints ;
39- publicInputs : AvmCircuitPublicInputs ;
40- } ;
32+ export class PublicTxResult {
33+ constructor (
34+ // Simulation result.
35+ public gasUsed : GasUsed ,
36+ public revertCode : RevertCode ,
37+ public revertReason : SimulationError | undefined , // Revert reason, if any
38+ public appLogicReturnValue : Fr [ ] | undefined , // Return/revert value of the app logic phase
39+ public logs : DebugLog [ ] ,
40+ // For the proving request.
41+ public hints : AvmExecutionHints | undefined ,
42+ public publicInputs : AvmCircuitPublicInputs ,
43+ ) { }
44+
45+ static get schema ( ) {
46+ return z
47+ . object ( {
48+ gasUsed : schemas . GasUsed ,
49+ revertCode : RevertCode . schema ,
50+ revertReason : SimulationError . schema . optional ( ) ,
51+ appLogicReturnValue : z . array ( schemas . Fr ) . optional ( ) ,
52+ logs : z . array ( DebugLog . schema ) ,
53+ hints : AvmExecutionHints . schema . optional ( ) ,
54+ publicInputs : AvmCircuitPublicInputs . schema ,
55+ } )
56+ . transform (
57+ ( { gasUsed, revertCode, revertReason, appLogicReturnValue, logs, hints, publicInputs } ) =>
58+ new PublicTxResult ( gasUsed , revertCode , revertReason , appLogicReturnValue , logs , hints , publicInputs ) ,
59+ ) ;
60+ }
61+
62+ // TODO(fcarreiro): complete this.
63+ static get partialSchema ( ) {
64+ return z . object ( {
65+ revertCode : RevertCode . schema ,
66+ } ) ;
67+ }
68+ }
4169
4270export type PublicTxSimulatorConfig = {
4371 proverId : Fr ;
0 commit comments