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 0823f19 commit 5437503
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
12 changes: 2 additions & 10 deletions yarn-project/txe/src/oracle/txe_oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -781,24 +781,17 @@ export class TXE implements TypedOracle {

// AVM oracles

async avmOpcodeCall(
targetContractAddress: AztecAddress,
functionSelector: FunctionSelector,
args: Fr[],
isStaticCall: boolean,
) {
async avmOpcodeCall(targetContractAddress: AztecAddress, args: Fr[], isStaticCall: boolean) {
// Store and modify env
const currentContractAddress = AztecAddress.fromField(this.contractAddress);
const currentMessageSender = AztecAddress.fromField(this.msgSender);
const currentFunctionSelector = FunctionSelector.fromField(this.functionSelector.toField());
this.setMsgSender(this.contractAddress);
this.setContractAddress(targetContractAddress);
this.setFunctionSelector(functionSelector);

const callContext = new CallContext(
/* msgSender */ currentContractAddress,
targetContractAddress,
functionSelector,
FunctionSelector.fromField(new Fr(PUBLIC_DISPATCH_SELECTOR)),
isStaticCall,
);

Expand All @@ -821,7 +814,6 @@ export class TXE implements TypedOracle {

this.setContractAddress(currentContractAddress);
this.setMsgSender(currentMessageSender);
this.setFunctionSelector(currentFunctionSelector);

return executionResult;
}
Expand Down
13 changes: 5 additions & 8 deletions yarn-project/txe/src/txe_service/txe_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,9 @@ export class TXEService {
args: ForeignCallArray,
) {
const parsedAddress = fromSingle(address);
const parsedSelector = FunctionSelector.fromField(fromSingle(functionSelector));
const result = await (this.typedOracle as TXE).avmOpcodeCall(parsedAddress, parsedSelector, fromArray(args), false);
const parsedSelector = fromSingle(functionSelector);
const extendedArgs = [parsedSelector, ...fromArray(args)];
const result = await (this.typedOracle as TXE).avmOpcodeCall(parsedAddress, extendedArgs, false);
if (!result.reverted) {
throw new ExpectedFailureError('Public call did not revert');
}
Expand Down Expand Up @@ -730,11 +731,9 @@ export class TXEService {
address: ForeignCallSingle,
_length: ForeignCallSingle,
args: ForeignCallArray,
functionSelector: ForeignCallSingle,
) {
const result = await (this.typedOracle as TXE).avmOpcodeCall(
fromSingle(address),
FunctionSelector.fromField(fromSingle(functionSelector)),
fromArray(args),
/* isStaticCall */ false,
);
Expand All @@ -754,19 +753,17 @@ export class TXEService {
}
}

return toForeignCallResult([toArray(result.returnValues), toSingle(new Fr(!result.reverted))]);
return toForeignCallResult([toSingle(new Fr(!result.reverted))]);
}

async avmOpcodeStaticCall(
_gas: ForeignCallArray,
address: ForeignCallSingle,
_length: ForeignCallSingle,
args: ForeignCallArray,
functionSelector: ForeignCallSingle,
) {
const result = await (this.typedOracle as TXE).avmOpcodeCall(
fromSingle(address),
FunctionSelector.fromField(fromSingle(functionSelector)),
fromArray(args),
/* isStaticCall */ true,
);
Expand All @@ -786,6 +783,6 @@ export class TXEService {
}
}

return toForeignCallResult([toArray(result.returnValues), toSingle(new Fr(!result.reverted))]);
return toForeignCallResult([toSingle(new Fr(!result.reverted))]);
}
}

0 comments on commit 5437503

Please sign in to comment.