From 88df4ac099c286fed78ee05b1b34eae8ba1aa60f Mon Sep 17 00:00:00 2001 From: fcarreiro Date: Wed, 17 Apr 2024 16:14:03 +0000 Subject: [PATCH] chore: remove get_portal_address oracle --- docs/docs/misc/migration_notes.md | 26 ++++++++++++++++++- .../aztec/src/context/private_context.nr | 2 +- noir-projects/aztec-nr/aztec/src/oracle.nr | 1 - .../aztec-nr/aztec/src/oracle/context.nr | 9 ------- .../contracts/test_contract/src/main.nr | 7 +++-- .../token_bridge_contract/src/main.nr | 10 +++++++ .../contracts/uniswap_contract/src/main.nr | 9 +++---- .../simulator/src/acvm/oracle/oracle.ts | 6 ----- .../simulator/src/acvm/oracle/typed_oracle.ts | 5 ---- .../src/client/private_execution.test.ts | 7 ++--- .../simulator/src/client/view_data_oracle.ts | 10 ------- .../src/public/public_execution_context.ts | 10 ------- 12 files changed, 45 insertions(+), 57 deletions(-) delete mode 100644 noir-projects/aztec-nr/aztec/src/oracle/context.nr diff --git a/docs/docs/misc/migration_notes.md b/docs/docs/misc/migration_notes.md index 7ccee0ee58f..e781e7e5069 100644 --- a/docs/docs/misc/migration_notes.md +++ b/docs/docs/misc/migration_notes.md @@ -6,7 +6,7 @@ keywords: [sandbox, cli, aztec, notes, migration, updating, upgrading] Aztec is in full-speed development. Literally every version breaks compatibility with the previous ones. This page attempts to target errors and difficulties you might encounter when upgrading, and how to resolve them. -## TBD +## 0.36.0 ### [Aztec.nr] Contract interfaces @@ -64,6 +64,30 @@ The `request_max_block_number` function has been renamed to `set_tx_max_block_nu + context.set_tx_max_block_number(value); ``` +### [Aztec.nr] Get portal address + +The `get_portal_address` oracle was removed. If you need to get the portal address of SomeContract, add the following methods to it + +``` +#[aztec(private)] +fn get_portal_address() -> EthAddress { + context.this_portal_address() +} + +#[aztec(public)] +fn get_portal_address_public() -> EthAddress { + context.this_portal_address() +} +``` + +and change the call to `get_portal_address` + +```diff +- let portal_address = get_portal_address(contract_address); ++ let portal_address = SomeContract::at(contract_address).get_portal_address().call(&mut context); +``` + + ### [Aztec.nr] Required gas limits for public-to-public calls When calling a public function from another public function using the `call_public_function` method, you must now specify how much gas you're allocating to the nested call. This will later allow you to limit the amount of gas consumed by the nested call, and handle any out of gas errors. 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 0c744e60d32..33dd48fd262 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 a8ad7838d6f..57415dc9575 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 56e1b229549..00000000000 --- 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 851b8e59ee6..e03a92b94d9 100644 --- a/noir-projects/noir-contracts/contracts/test_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/test_contract/src/main.nr @@ -27,7 +27,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 @@ -54,10 +54,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 32f9653915b..28226b5b10b 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 32a89fcc704..35d9e573379 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/acvm/oracle/oracle.ts b/yarn-project/simulator/src/acvm/oracle/oracle.ts index fb3b35f028c..2b967a7c98b 100644 --- a/yarn-project/simulator/src/acvm/oracle/oracle.ts +++ b/yarn-project/simulator/src/acvm/oracle/oracle.ts @@ -271,12 +271,6 @@ export class Oracle { return message.toFields().map(toACVMField); } - async getPortalContractAddress([aztecAddress]: ACVMField[]): Promise { - const contractAddress = AztecAddress.fromString(aztecAddress); - const portalContactAddress = await this.typedOracle.getPortalContractAddress(contractAddress); - return toACVMField(portalContactAddress); - } - async storageRead([startStorageSlot]: ACVMField[], [numberOfElements]: ACVMField[]): Promise { const values = await this.typedOracle.storageRead(fromACVMField(startStorageSlot), +numberOfElements); return values.map(toACVMField); diff --git a/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts b/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts index c362a04f8be..e0dd6ce24f4 100644 --- a/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts +++ b/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts @@ -18,7 +18,6 @@ import { } from '@aztec/circuits.js'; import { type FunctionSelector } from '@aztec/foundation/abi'; import { type AztecAddress } from '@aztec/foundation/aztec-address'; -import { type EthAddress } from '@aztec/foundation/eth-address'; import { Fr } from '@aztec/foundation/fields'; import { type ContractInstance } from '@aztec/types/contracts'; @@ -187,10 +186,6 @@ export abstract class TypedOracle { throw new OracleMethodNotAvailableError('getL1ToL2MembershipWitness'); } - getPortalContractAddress(_contractAddress: AztecAddress): Promise { - throw new OracleMethodNotAvailableError('getPortalContractAddress'); - } - storageRead(_startStorageSlot: Fr, _numberOfElements: number): Promise { throw new OracleMethodNotAvailableError('storageRead'); } diff --git a/yarn-project/simulator/src/client/private_execution.test.ts b/yarn-project/simulator/src/client/private_execution.test.ts index 512060e9948..9e2b8fe0d83 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()]); }); diff --git a/yarn-project/simulator/src/client/view_data_oracle.ts b/yarn-project/simulator/src/client/view_data_oracle.ts index 2a76c346474..7ab30411eda 100644 --- a/yarn-project/simulator/src/client/view_data_oracle.ts +++ b/yarn-project/simulator/src/client/view_data_oracle.ts @@ -239,16 +239,6 @@ export class ViewDataOracle extends TypedOracle { return await this.db.getL1ToL2MembershipWitness(contractAddress, messageHash, secret); } - /** - * Retrieves the portal contract address associated with the given contract address. - * Throws an error if the input contract address is not found or invalid. - * @param contractAddress - The address of the contract whose portal address is to be fetched. - * @returns The portal contract address. - */ - public override getPortalContractAddress(contractAddress: AztecAddress) { - return this.db.getPortalContractAddress(contractAddress); - } - /** * Read the public storage data. * @param startStorageSlot - The starting storage slot. diff --git a/yarn-project/simulator/src/public/public_execution_context.ts b/yarn-project/simulator/src/public/public_execution_context.ts index ad2c77b0dc9..adf3e893484 100644 --- a/yarn-project/simulator/src/public/public_execution_context.ts +++ b/yarn-project/simulator/src/public/public_execution_context.ts @@ -136,16 +136,6 @@ export class PublicExecutionContext extends TypedOracle { return Fr.fromBuffer(log.hash()); } - /** - * Retrieves the portal contract address associated with the given contract address. - * Returns zero address if the input contract address is not found or invalid. - * @param contractAddress - The address of the contract whose portal address is to be fetched. - * @returns The portal contract address. - */ - public override async getPortalContractAddress(contractAddress: AztecAddress) { - return (await this.contractsDb.getPortalContractAddress(contractAddress)) ?? EthAddress.ZERO; - } - /** * Read the public storage data. * @param startStorageSlot - The starting storage slot.