diff --git a/noir-projects/aztec-nr/aztec/src/context/private_context.nr b/noir-projects/aztec-nr/aztec/src/context/private_context.nr index 0fcdaa74bac3..d9080d045c43 100644 --- a/noir-projects/aztec-nr/aztec/src/context/private_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/private_context.nr @@ -4,7 +4,7 @@ use crate::{ hash::{hash_args_array, ArgsHasher}, oracle::{ arguments, returns, call_private_function::call_private_function_internal, - enqueue_public_function_call::enqueue_public_function_call_internal, context::get_portal_address, + enqueue_public_function_call::enqueue_public_function_call_internal, header::get_header_at, nullifier_key::{get_nullifier_key_pair, NullifierKeyPair} } }; diff --git a/noir-projects/aztec-nr/aztec/src/oracle.nr b/noir-projects/aztec-nr/aztec/src/oracle.nr index a8ad7838d6fa..57415dc95759 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle.nr @@ -4,7 +4,6 @@ mod arguments; mod call_private_function; -mod context; mod get_contract_instance; mod get_l1_to_l2_membership_witness; mod get_nullifier_membership_witness; diff --git a/noir-projects/aztec-nr/aztec/src/oracle/context.nr b/noir-projects/aztec-nr/aztec/src/oracle/context.nr deleted file mode 100644 index 56e1b2295491..000000000000 --- a/noir-projects/aztec-nr/aztec/src/oracle/context.nr +++ /dev/null @@ -1,9 +0,0 @@ -use dep::protocol_types::address::{AztecAddress, EthAddress}; - -#[oracle(getPortalContractAddress)] -fn _get_portal_address(_contract_address: AztecAddress) -> EthAddress {} - -unconstrained pub fn get_portal_address(contract_address: AztecAddress) -> EthAddress { - let portal_address = _get_portal_address(contract_address); - portal_address -} diff --git a/noir-projects/noir-contracts/contracts/test_contract/src/main.nr b/noir-projects/noir-contracts/contracts/test_contract/src/main.nr index 535e96dc43a5..57afceced0c8 100644 --- a/noir-projects/noir-contracts/contracts/test_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/test_contract/src/main.nr @@ -22,7 +22,7 @@ contract Test { }, deploy::deploy_contract as aztec_deploy_contract, oracle::{ - get_public_key::get_public_key as get_public_key_oracle, context::get_portal_address, + get_public_key::get_public_key as get_public_key_oracle, unsafe_rand::unsafe_rand }, log::emit_unencrypted_log_from_private @@ -49,10 +49,9 @@ contract Test { [pub_key.x, pub_key.y] } - // Get the portal contract address through an oracle call #[aztec(private)] - fn get_portal_contract_address(aztec_address: AztecAddress) -> EthAddress { - get_portal_address(aztec_address) + fn get_portal_contract_address() -> EthAddress { + context.this_portal_address() } // Get the address of the l1 portal for this contract (taken from the input context) diff --git a/noir-projects/noir-contracts/contracts/token_bridge_contract/src/main.nr b/noir-projects/noir-contracts/contracts/token_bridge_contract/src/main.nr index c5814ed81ce9..c0a7053dbb1e 100644 --- a/noir-projects/noir-contracts/contracts/token_bridge_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/token_bridge_contract/src/main.nr @@ -31,6 +31,16 @@ contract TokenBridge { } // docs:end:token_bridge_storage_and_constructor + #[aztec(private)] + fn get_portal_address() -> EthAddress { + context.this_portal_address() + } + + #[aztec(public)] + fn get_portal_address_public() -> EthAddress { + context.this_portal_address() + } + // docs:start:claim_public // Consumes a L1->L2 message and calls the token contract to mint the appropriate amount publicly #[aztec(public)] diff --git a/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr b/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr index 32a89fcc704a..35d9e5733797 100644 --- a/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr @@ -6,7 +6,6 @@ mod util; // Uses the token bridge contract, which tells which input token we need to talk to and handles the exit funds to L1 contract Uniswap { use dep::aztec::prelude::{FunctionSelector, AztecAddress, EthAddress, Map, PublicMutable}; - use dep::aztec::oracle::context::get_portal_address; use dep::aztec::context::gas::GasOpts; use dep::authwit::auth::{ @@ -65,8 +64,8 @@ contract Uniswap { Uniswap::at(context.this_address())._approve_bridge_and_exit_input_asset_to_L1(input_asset, input_asset_bridge, input_amount).call(&mut context); // Create swap message and send to Outbox for Uniswap Portal // this ensures the integrity of what the user originally intends to do on L1. - let input_asset_bridge_portal_address = get_portal_address(input_asset_bridge); - let output_asset_bridge_portal_address = get_portal_address(output_asset_bridge); + let input_asset_bridge_portal_address = TokenBridge::at(input_asset_bridge).get_portal_address_public().call(&mut context); + let output_asset_bridge_portal_address = TokenBridge::at(output_asset_bridge).get_portal_address_public().call(&mut context); // ensure portal exists - else funds might be lost assert( !input_asset_bridge_portal_address.is_zero(), "L1 portal address of input_asset's bridge is 0" @@ -123,8 +122,8 @@ contract Uniswap { // Create swap message and send to Outbox for Uniswap Portal // this ensures the integrity of what the user originally intends to do on L1. - let input_asset_bridge_portal_address = get_portal_address(input_asset_bridge); - let output_asset_bridge_portal_address = get_portal_address(output_asset_bridge); + let input_asset_bridge_portal_address = TokenBridge::at(input_asset_bridge).get_portal_address().call(&mut context); + let output_asset_bridge_portal_address = TokenBridge::at(output_asset_bridge).get_portal_address().call(&mut context); // ensure portal exists - else funds might be lost assert( !input_asset_bridge_portal_address.is_zero(), "L1 portal address of input_asset's bridge is 0" diff --git a/yarn-project/simulator/src/client/private_execution.test.ts b/yarn-project/simulator/src/client/private_execution.test.ts index 512060e99486..9e2b8fe0d834 100644 --- a/yarn-project/simulator/src/client/private_execution.test.ts +++ b/yarn-project/simulator/src/client/private_execution.test.ts @@ -1041,16 +1041,13 @@ describe('Private Execution test suite', () => { describe('Context oracles', () => { it("Should be able to get and return the contract's portal contract address", async () => { const portalContractAddress = EthAddress.random(); - const aztecAddressToQuery = AztecAddress.random(); // Tweak the contract artifact so we can extract return values const artifact = getFunctionArtifact(TestContractArtifact, 'get_portal_contract_address'); - const args = [aztecAddressToQuery.toField()]; + const args: Fr[] = []; - // Overwrite the oracle return value - oracle.getPortalContractAddress.mockResolvedValue(portalContractAddress); - const result = await runSimulator({ artifact, args }); + const result = await runSimulator({ artifact, args, portalContractAddress }); expect(result.returnValues).toEqual([portalContractAddress.toField()]); });