Skip to content

Commit

Permalink
txe
Browse files Browse the repository at this point in the history
  • Loading branch information
fcarreiro committed Oct 29, 2024
1 parent a0119a5 commit 93d88d2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
12 changes: 12 additions & 0 deletions yarn-project/txe/src/oracle/txe_oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand All @@ -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<boolean> {
const nullifier = siloNullifier(targetAddress, innerNullifier!);
const db = await this.trees.getLatest();
Expand Down
14 changes: 14 additions & 0 deletions yarn-project/txe/src/txe_service/txe_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 93d88d2

Please sign in to comment.