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 17, 2024
1 parent 84c930a commit 693f64f
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 26 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 @@ -65,6 +65,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);
```


## 0.33

### [Aztec.nr] Storage struct annotation
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 @@ -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
Expand All @@ -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)
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
7 changes: 2 additions & 5 deletions yarn-project/simulator/src/client/private_execution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()]);
});

Expand Down

0 comments on commit 693f64f

Please sign in to comment.