Skip to content

Commit

Permalink
chore: remove get_portal_address oracle
Browse files Browse the repository at this point in the history
  • Loading branch information
fcarreiro committed Apr 18, 2024
1 parent c6783b0 commit 47cdc26
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 70 deletions.
26 changes: 25 additions & 1 deletion docs/docs/misc/migration_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
};
Expand Down
1 change: 0 additions & 1 deletion noir-projects/aztec-nr/aztec/src/oracle.nr
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 0 additions & 9 deletions noir-projects/aztec-nr/aztec/src/oracle/context.nr

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -54,12 +54,6 @@ 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)
}

// Get the address of the l1 portal for this contract (taken from the input context)
#[aztec(private)]
fn get_this_portal_address() -> EthAddress {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
6 changes: 0 additions & 6 deletions yarn-project/simulator/src/acvm/oracle/oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,6 @@ export class Oracle {
return message.toFields().map(toACVMField);
}

async getPortalContractAddress([aztecAddress]: ACVMField[]): Promise<ACVMField> {
const contractAddress = AztecAddress.fromString(aztecAddress);
const portalContactAddress = await this.typedOracle.getPortalContractAddress(contractAddress);
return toACVMField(portalContactAddress);
}

async storageRead([startStorageSlot]: ACVMField[], [numberOfElements]: ACVMField[]): Promise<ACVMField[]> {
const values = await this.typedOracle.storageRead(fromACVMField(startStorageSlot), +numberOfElements);
return values.map(toACVMField);
Expand Down
5 changes: 0 additions & 5 deletions yarn-project/simulator/src/acvm/oracle/typed_oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -187,10 +186,6 @@ export abstract class TypedOracle {
throw new OracleMethodNotAvailableError('getL1ToL2MembershipWitness');
}

getPortalContractAddress(_contractAddress: AztecAddress): Promise<EthAddress> {
throw new OracleMethodNotAvailableError('getPortalContractAddress');
}

storageRead(_startStorageSlot: Fr, _numberOfElements: number): Promise<Fr[]> {
throw new OracleMethodNotAvailableError('storageRead');
}
Expand Down
15 changes: 0 additions & 15 deletions yarn-project/simulator/src/client/private_execution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1039,21 +1039,6 @@ 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()];

// Overwrite the oracle return value
oracle.getPortalContractAddress.mockResolvedValue(portalContractAddress);
const result = await runSimulator({ artifact, args });
expect(result.returnValues).toEqual([portalContractAddress.toField()]);
});

it('this_address should return the current context address', async () => {
const contractAddress = AztecAddress.random();

Expand Down
10 changes: 0 additions & 10 deletions yarn-project/simulator/src/client/view_data_oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 0 additions & 10 deletions yarn-project/simulator/src/public/public_execution_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 47cdc26

Please sign in to comment.