diff --git a/yarn-project/txe/src/oracle/txe_oracle.ts b/yarn-project/txe/src/oracle/txe_oracle.ts index b16be91beb1..e0911adf571 100644 --- a/yarn-project/txe/src/oracle/txe_oracle.ts +++ b/yarn-project/txe/src/oracle/txe_oracle.ts @@ -82,6 +82,8 @@ export class TXE implements TypedOracle { private msgSender: AztecAddress; private functionSelector = FunctionSelector.fromField(new Fr(0)); private isStaticCall = false; + // Return/revert data of the latest nested call. + private nestedCallReturndata: Fr[] = []; private contractDataOracle: ContractDataOracle; @@ -801,6 +803,8 @@ export class TXE implements TypedOracle { ); const executionResult = await this.executePublicFunction(args, callContext, this.sideEffectsCounter); + // Save return/revert data for later. + this.nestedCallReturndata = executionResult.returnValues; // Apply side effects if (!executionResult.reverted) { @@ -822,6 +826,14 @@ export class TXE implements TypedOracle { return executionResult; } + avmOpcodeReturndataSize(): number { + return this.nestedCallReturndata.length; + } + + avmOpcodeReturndataCopy(rdOffset: number, copySize: number): Fr[] { + return this.nestedCallReturndata.slice(rdOffset, rdOffset + copySize); + } + async avmOpcodeNullifierExists(innerNullifier: Fr, targetAddress: AztecAddress): Promise { const nullifier = siloNullifier(targetAddress, innerNullifier!); const db = await this.trees.getLatest(); diff --git a/yarn-project/txe/src/txe_service/txe_service.ts b/yarn-project/txe/src/txe_service/txe_service.ts index 7731f55b23f..07c9fc8b05c 100644 --- a/yarn-project/txe/src/txe_service/txe_service.ts +++ b/yarn-project/txe/src/txe_service/txe_service.ts @@ -711,6 +711,20 @@ export class TXEService { return toForeignCallResult([toSingle(version)]); } + avmOpcodeReturndataSize() { + const size = (this.typedOracle as TXE).avmOpcodeReturndataSize(); + return toForeignCallResult([toSingle(new Fr(size))]); + } + + avmOpcodeReturndataCopy(rdOffset: ForeignCallSingle, copySize: ForeignCallSingle) { + const returndata = (this.typedOracle as TXE).avmOpcodeReturndataCopy( + fromSingle(rdOffset).toNumber(), + fromSingle(copySize).toNumber(), + ); + // This is a slice, so we need to return the length as well. + return toForeignCallResult([toSingle(new Fr(returndata.length)), toArray(returndata)]); + } + async avmOpcodeCall( _gas: ForeignCallArray, address: ForeignCallSingle,