Skip to content

Commit

Permalink
more txe
Browse files Browse the repository at this point in the history
  • Loading branch information
fcarreiro committed Sep 23, 2024
1 parent 566ddd5 commit 8725339
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
7 changes: 7 additions & 0 deletions noir-projects/aztec-nr/aztec/src/test/helpers/cheatcodes.nr
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ unconstrained pub fn set_fn_selector(selector: FunctionSelector) {
oracle_set_function_selector(selector)
}

unconstrained pub fn set_is_static_call(is_static: bool) {
oracle_set_is_static_call(is_static)
}

#[oracle(reset)]
unconstrained fn oracle_reset() {}

Expand Down Expand Up @@ -157,6 +161,9 @@ unconstrained fn oracle_get_msg_sender() -> AztecAddress {}
#[oracle(setMsgSender)]
unconstrained fn oracle_set_msg_sender(msg_sender: AztecAddress) {}

#[oracle(setIsStaticCall)]
unconstrained fn oracle_set_is_static_call(is_static: bool) {}

#[oracle(getSideEffectsCounter)]
unconstrained fn oracle_get_side_effects_counter() -> u32 {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ impl TestEnvironment {
cheatcodes::set_fn_selector(fn_selector);
cheatcodes::set_contract_address(target_address);
cheatcodes::set_msg_sender(original_contract_address);
cheatcodes::set_is_static_call(call_interface.get_is_static());
let mut inputs = cheatcodes::get_public_context_inputs();
inputs.calldata_length = call_interface.get_args().len() as Field;
inputs.is_static_call = call_interface.get_is_static();
Expand All @@ -164,6 +165,7 @@ impl TestEnvironment {
cheatcodes::set_contract_address(original_contract_address);
cheatcodes::set_msg_sender(original_msg_sender);
cheatcodes::set_calldata(calldata);
cheatcodes::set_is_static_call(call_interface.get_is_static());
result
}

Expand Down
2 changes: 2 additions & 0 deletions noir-projects/aztec-nr/aztec/src/test/helpers/utils.nr
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ impl<let N: u32, let M: u32> Deployer<N, M> {
cheatcodes::set_fn_selector(call_interface.get_selector());
cheatcodes::set_contract_address(instance.to_address());
cheatcodes::set_msg_sender(original_contract_address);
cheatcodes::set_is_static_call(call_interface.get_is_static());
let mut inputs = cheatcodes::get_public_context_inputs();
inputs.calldata_length = call_interface.get_args().len() as Field;
inputs.is_static_call = call_interface.get_is_static();
Expand All @@ -97,6 +98,7 @@ impl<let N: u32, let M: u32> Deployer<N, M> {
cheatcodes::set_contract_address(original_contract_address);
cheatcodes::set_msg_sender(original_msg_sender);
cheatcodes::set_calldata(calldata);
cheatcodes::set_is_static_call(call_interface.get_is_static());
instance
}

Expand Down
8 changes: 6 additions & 2 deletions yarn-project/txe/src/oracle/txe_oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export class TXE implements TypedOracle {
private contractAddress: AztecAddress;
private msgSender: AztecAddress;
private functionSelector = FunctionSelector.fromField(new Fr(0));
private isStaticCall = false;
// This will hold the _real_ calldata. That is, the one without the PublicContextInputs.
// TODO: Remove this comment once PublicContextInputs are removed.
private calldata: Fr[] = [];
Expand Down Expand Up @@ -281,9 +282,12 @@ export class TXE implements TypedOracle {
return Promise.resolve(this.contractAddress);
}

setIsStaticCall(isStatic: boolean) {
this.isStaticCall = isStatic;
}

getIsStaticCall() {
// Fixed false value copied from getPublicContextInputs.
return false;
return this.isStaticCall;
}

getRandomField() {
Expand Down
5 changes: 5 additions & 0 deletions yarn-project/txe/src/txe_service/txe_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,11 @@ export class TXEService {
return toForeignCallResult([toSingle(functionSelector.toField())]);
}

setIsStaticCall(isStaticCall: ForeignCallSingle) {
(this.typedOracle as TXE).setIsStaticCall(fromSingle(isStaticCall).toBool());
return toForeignCallResult([]);
}

avmOpcodeIsStaticCall() {
const isStaticCall = (this.typedOracle as TXE).getIsStaticCall();
return toForeignCallResult([toSingle(new Fr(isStaticCall ? 1 : 0))]);
Expand Down

0 comments on commit 8725339

Please sign in to comment.