diff --git a/docs/docs/developers/contracts/writing_contracts/portals/deploy_with_portal.md b/docs/docs/developers/contracts/writing_contracts/portals/deploy_with_portal.md index 2277e588facc..34c6d593d0a1 100644 --- a/docs/docs/developers/contracts/writing_contracts/portals/deploy_with_portal.md +++ b/docs/docs/developers/contracts/writing_contracts/portals/deploy_with_portal.md @@ -3,11 +3,9 @@ title: How to deploy a contract with a Portal --- - Deploy to L1 using Viem, Foundry or your preferred tool; -- Deploy to L2 passing in the address of the L1 portal as its portal contract; +- Deploy to L2 passing in the address of the L1 portal as an argument; ```typescript - const deploymentTx = Contract.deploy(wallet).send({ - portalContract: tokenPortalAddress, - }); + const deploymentTx = Contract.deploy(wallet, tokenPortalAddress).send(); ``` - Initialize l1 with l2 address for access control. diff --git a/noir-projects/aztec-nr/aztec/src/context/avm_context.nr b/noir-projects/aztec-nr/aztec/src/context/avm_context.nr index c4a6350af39b..7414561d61e5 100644 --- a/noir-projects/aztec-nr/aztec/src/context/avm_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/avm_context.nr @@ -215,9 +215,6 @@ impl ContextInterface for AvmContext { fn this_address(self) -> AztecAddress { address() } - fn this_portal_address(self) -> EthAddress { - portal() - } fn chain_id(self) -> Field { chain_id() } diff --git a/noir-projects/aztec-nr/aztec/src/context/interface.nr b/noir-projects/aztec-nr/aztec/src/context/interface.nr index a076158d71da..868612027b07 100644 --- a/noir-projects/aztec-nr/aztec/src/context/interface.nr +++ b/noir-projects/aztec-nr/aztec/src/context/interface.nr @@ -14,7 +14,6 @@ trait ContextInterface { fn push_new_nullifier(&mut self, nullifier: Field, nullified_commitment: Field); fn msg_sender(self) -> AztecAddress; fn this_address(self) -> AztecAddress; - fn this_portal_address(self) -> EthAddress; fn chain_id(self) -> Field; fn version(self) -> Field; fn selector(self) -> FunctionSelector; 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 33dd48fd262f..eefc5390a459 100644 --- a/noir-projects/aztec-nr/aztec/src/context/private_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/private_context.nr @@ -83,10 +83,6 @@ impl ContextInterface for PrivateContext { self.inputs.call_context.storage_contract_address } - fn this_portal_address(self) -> EthAddress { - self.inputs.call_context.portal_contract_address - } - fn chain_id(self) -> Field { self.inputs.private_global_variables.chain_id } diff --git a/noir-projects/aztec-nr/aztec/src/context/public_context.nr b/noir-projects/aztec-nr/aztec/src/context/public_context.nr index ba70631a79fc..8236b2e7bd18 100644 --- a/noir-projects/aztec-nr/aztec/src/context/public_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/public_context.nr @@ -184,10 +184,6 @@ impl ContextInterface for PublicContext { self.inputs.call_context.storage_contract_address } - fn this_portal_address(self) -> EthAddress { - self.inputs.call_context.portal_contract_address - } - fn chain_id(self) -> Field { self.inputs.public_global_variables.chain_id } diff --git a/noir-projects/noir-contracts/contracts/avm_test_contract/src/main.nr b/noir-projects/noir-contracts/contracts/avm_test_contract/src/main.nr index 7eb12dd0e7c8..10a02855db5e 100644 --- a/noir-projects/noir-contracts/contracts/avm_test_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/avm_test_contract/src/main.nr @@ -206,11 +206,6 @@ contract AvmTest { context.msg_sender() } - #[aztec(public-vm)] - fn get_portal() -> pub EthAddress { - context.this_portal_address() - } - #[aztec(public-vm)] fn get_fee_per_l1_gas() -> pub Field { context.fee_per_l1_gas() diff --git a/noir-projects/noir-contracts/contracts/gas_token_contract/src/main.nr b/noir-projects/noir-contracts/contracts/gas_token_contract/src/main.nr index ec1adf321160..cc19bf9f5f27 100644 --- a/noir-projects/noir-contracts/contracts/gas_token_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/gas_token_contract/src/main.nr @@ -2,13 +2,20 @@ mod lib; contract GasToken { use dep::aztec::protocol_types::{abis::function_selector::FunctionSelector, address::{AztecAddress, EthAddress}}; - use dep::aztec::{hash::compute_secret_hash, state_vars::{PublicMutable, Map}}; + use dep::aztec::{hash::compute_secret_hash, state_vars::{SharedImmutable, PublicMutable, Map}}; use crate::lib::{calculate_fee, get_bridge_gas_msg_hash}; #[aztec(storage)] struct Storage { balances: Map>, + portal_address: SharedImmutable, + } + + #[aztec(public)] + #[aztec(initializer)] + fn constructor(portal_address: EthAddress) { + storage.portal_address.initialize(portal_address); } #[aztec(public)] @@ -16,7 +23,12 @@ contract GasToken { let content_hash = get_bridge_gas_msg_hash(to, amount); // Consume message and emit nullifier - context.consume_l1_to_l2_message(content_hash, secret, context.this_portal_address(), leaf_index); + context.consume_l1_to_l2_message( + content_hash, + secret, + storage.portal_address.read_public(), + leaf_index + ); let new_balance = storage.balances.at(to).read() + U128::from_integer(amount); storage.balances.at(to).write(new_balance); 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 736e09506c0f..c33c791c911d 100644 --- a/noir-projects/noir-contracts/contracts/test_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/test_contract/src/main.nr @@ -2,7 +2,7 @@ contract Test { use dep::aztec::prelude::{ AztecAddress, EthAddress, FunctionSelector, NoteHeader, NoteGetterOptions, NoteViewerOptions, - PrivateContext, PrivateImmutable, PrivateSet + PrivateContext, PrivateImmutable, PrivateSet, SharedImmutable }; use dep::aztec::protocol_types::{ @@ -24,10 +24,7 @@ contract Test { note_getter_options::NoteStatus }, deploy::deploy_contract as aztec_deploy_contract, - oracle::{ - get_public_key::get_public_key as get_public_key_oracle, - unsafe_rand::unsafe_rand - }, + oracle::{get_public_key::get_public_key as get_public_key_oracle, unsafe_rand::unsafe_rand}, log::emit_unencrypted_log_from_private }; use dep::token_portal_content_hash_lib::{get_mint_private_content_hash, get_mint_public_content_hash}; @@ -52,17 +49,6 @@ contract Test { [pub_key.x, pub_key.y] } - #[aztec(private)] - 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) - #[aztec(private)] - fn get_this_portal_address() -> EthAddress { - context.this_portal_address() - } - // Get the address of this contract (taken from the input context) #[aztec(private)] fn get_this_address() -> AztecAddress { @@ -206,12 +192,12 @@ contract Test { // Purely exists for testing #[aztec(public)] - fn create_l2_to_l1_message_public(amount: Field, secret_hash: Field) { + fn create_l2_to_l1_message_public(amount: Field, secret_hash: Field, portal_address: EthAddress) { // Create a commitment to the amount let note = DummyNote::new(amount, secret_hash); // Public oracle call to emit new commitment. - context.message_portal(context.this_portal_address(), note.get_commitment()); + context.message_portal(portal_address, note.get_commitment()); } #[aztec(public)] @@ -274,30 +260,27 @@ contract Test { to: AztecAddress, amount: Field, secret: Field, - message_leaf_index: Field + message_leaf_index: Field, + portal_address: EthAddress ) { let content_hash = get_mint_public_content_hash(to, amount); // Consume message and emit nullifier - context.consume_l1_to_l2_message( - content_hash, - secret, - context.this_portal_address(), - message_leaf_index - ); + context.consume_l1_to_l2_message(content_hash, secret, portal_address, message_leaf_index); } #[aztec(private)] fn consume_mint_private_message( secret_hash_for_redeeming_minted_notes: Field, amount: Field, - secret_for_L1_to_L2_message_consumption: Field + secret_for_L1_to_L2_message_consumption: Field, + portal_address: EthAddress ) { // Consume L1 to L2 message and emit nullifier let content_hash = get_mint_private_content_hash(secret_hash_for_redeeming_minted_notes, amount); context.consume_l1_to_l2_message( content_hash, secret_for_L1_to_L2_message_consumption, - context.this_portal_address() + portal_address ); } @@ -393,10 +376,13 @@ contract Test { fn test_shared_mutable_private_getter_for_registry_contract( contract_address_to_read: AztecAddress, storage_slot_of_shared_mutable: Field, - address_to_get_in_registry: AztecAddress, + address_to_get_in_registry: AztecAddress ) { // We have to derive this slot to get the location of the shared mutable inside the Map - let derived_slot = dep::aztec::hash::pedersen_hash([storage_slot_of_shared_mutable, address_to_get_in_registry.to_field()], 0); + let derived_slot = dep::aztec::hash::pedersen_hash( + [storage_slot_of_shared_mutable, address_to_get_in_registry.to_field()], + 0 + ); // It's a bit wonky because we need to know the delay for get_current_value_in_private to work correctly let registry_private_getter: SharedMutablePrivateGetter = SharedMutablePrivateGetter::new(context, contract_address_to_read, derived_slot); let nullifier_public_key = registry_private_getter.get_current_value_in_private(); @@ -407,10 +393,14 @@ contract Test { #[aztec(private)] fn test_shared_mutable_private_getter( contract_address_to_read: AztecAddress, - storage_slot_of_shared_mutable: Field, + storage_slot_of_shared_mutable: Field ) { // It's a bit wonky because we need to know the delay for get_current_value_in_private to work correctly - let test: SharedMutablePrivateGetter = SharedMutablePrivateGetter::new(context, contract_address_to_read, storage_slot_of_shared_mutable); + let test: SharedMutablePrivateGetter = SharedMutablePrivateGetter::new( + context, + contract_address_to_read, + storage_slot_of_shared_mutable + ); let authorized = test.get_current_value_in_private(); emit_unencrypted_log_from_private(&mut context, authorized); @@ -419,10 +409,7 @@ contract Test { #[aztec(public)] fn delay() { // We use this as a util function to "mine a block" - dep::aztec::log::emit_unencrypted_log( - &mut context, - "dummy" - ); + dep::aztec::log::emit_unencrypted_log(&mut context, "dummy"); } // Purely exists for testing 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 28226b5b10b1..1172b4e90130 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 @@ -6,7 +6,7 @@ // Bridge has to be set as a minter on the token before it can be used contract TokenBridge { - use dep::aztec::prelude::{FunctionSelector, AztecAddress, EthAddress, PublicMutable}; + use dep::aztec::prelude::{FunctionSelector, AztecAddress, EthAddress, PublicMutable, SharedImmutable}; use dep::aztec::{context::Context, hash::compute_secret_hash}; @@ -20,25 +20,26 @@ contract TokenBridge { #[aztec(storage)] struct Storage { token: PublicMutable, + portal_address: SharedImmutable, } // Constructs the contract. - #[aztec(private)] + #[aztec(public)] #[aztec(initializer)] - fn constructor(token: AztecAddress) { - let selector = FunctionSelector::from_signature("_initialize((Field))"); - context.call_public_function(context.this_address(), selector, [token.to_field()]); + fn constructor(token: AztecAddress, portal_address: EthAddress) { + storage.token.write(token); + storage.portal_address.initialize(portal_address); } // docs:end:token_bridge_storage_and_constructor #[aztec(private)] fn get_portal_address() -> EthAddress { - context.this_portal_address() + storage.portal_address.read_private() } #[aztec(public)] fn get_portal_address_public() -> EthAddress { - context.this_portal_address() + storage.portal_address.read_public() } // docs:start:claim_public @@ -51,7 +52,7 @@ contract TokenBridge { context.consume_l1_to_l2_message( content_hash, secret, - context.this_portal_address(), + storage.portal_address.read_public(), message_leaf_index ); @@ -72,7 +73,7 @@ contract TokenBridge { ) { // Send an L2 to L1 message let content = get_withdraw_content_hash(recipient, amount, caller_on_l1); - context.message_portal(context.this_portal_address(), content); + context.message_portal(storage.portal_address.read_public(), content); // Burn tokens Token::at(storage.token.read()).burn_public(context.msg_sender(), amount, nonce).call(&mut context); @@ -92,7 +93,7 @@ contract TokenBridge { context.consume_l1_to_l2_message( content_hash, secret_for_L1_to_L2_message_consumption, - context.this_portal_address() + storage.portal_address.read_private() ); // Mint tokens on L2 @@ -120,7 +121,7 @@ contract TokenBridge { ) { // Send an L2 to L1 message let content = get_withdraw_content_hash(recipient, amount, caller_on_l1); - context.message_portal(context.this_portal_address(), content); + context.message_portal(storage.portal_address.read_private(), content); // docs:start:call_assert_token_is_same // Assert that user provided token address is same as seen in storage. @@ -143,21 +144,6 @@ contract TokenBridge { storage.token.read() } - // /// Unconstrained /// - - // docs:start:read_token - unconstrained fn token() -> pub AztecAddress { - storage.token.read() - } - // docs:end:read_token - - #[aztec(public)] - #[aztec(internal)] - #[aztec(noinitcheck)] - fn _initialize(token: AztecAddress) { - storage.token.write(token); - } - // docs:start:call_mint_on_token // This is a public call as we need to read from public storage. // Also, note that user hashes their secret in private and only sends the hash in 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 35d9e5733797..f8227136c67c 100644 --- a/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr @@ -5,7 +5,7 @@ mod util; // Has two separate flows for private and public respectively // 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::prelude::{FunctionSelector, AztecAddress, EthAddress, Map, PublicMutable, SharedImmutable}; use dep::aztec::context::gas::GasOpts; use dep::authwit::auth::{ @@ -24,9 +24,16 @@ contract Uniswap { // tracks the nonce used to create the approval message for burning funds // gets incremented each time after use to prevent replay attacks nonce_for_burn_approval: PublicMutable, + portal_address: SharedImmutable, } // docs:end:uniswap_setup + #[aztec(public)] + #[aztec(initializer)] + fn constructor(portal_address: EthAddress) { + storage.portal_address.initialize(portal_address); + } + // docs:start:swap_public #[aztec(public)] fn swap_public( @@ -84,7 +91,7 @@ contract Uniswap { secret_hash_for_L1_to_l2_message, caller_on_L1 ); - context.message_portal(context.this_portal_address(), content_hash); + context.message_portal(storage.portal_address.read_public(), content_hash); } // docs:end:swap_public @@ -142,7 +149,7 @@ contract Uniswap { secret_hash_for_L1_to_l2_message, caller_on_L1 ); - context.message_portal(context.this_portal_address(), content_hash); + context.message_portal(storage.portal_address.read_private(), content_hash); } // docs:end:swap_private @@ -197,11 +204,12 @@ contract Uniswap { // increment nonce_for_burn_approval so it won't be used again storage.nonce_for_burn_approval.write(nonce_for_burn_approval + 1); + let this_portal_address = storage.portal_address.read_public(); // Exit to L1 Uniswap Portal ! TokenBridge::at(token_bridge).exit_to_l1_public( - context.this_portal_address(), + this_portal_address, amount, - context.this_portal_address(), + this_portal_address, nonce_for_burn_approval ).call(&mut context) } diff --git a/yarn-project/aztec.js/src/contract/deploy_method.ts b/yarn-project/aztec.js/src/contract/deploy_method.ts index 54ef3025e2b1..214e83c7d0e6 100644 --- a/yarn-project/aztec.js/src/contract/deploy_method.ts +++ b/yarn-project/aztec.js/src/contract/deploy_method.ts @@ -6,7 +6,7 @@ import { getContractInstanceFromDeployParams, } from '@aztec/circuits.js'; import { type ContractArtifact, type FunctionArtifact, getInitializer } from '@aztec/foundation/abi'; -import { type EthAddress } from '@aztec/foundation/eth-address'; +import { EthAddress } from '@aztec/foundation/eth-address'; import { type Fr } from '@aztec/foundation/fields'; import { createDebugLogger } from '@aztec/foundation/log'; import { type ContractInstanceWithAddress } from '@aztec/types/contracts'; @@ -26,8 +26,6 @@ import { DeploySentTx } from './deploy_sent_tx.js'; * Allows specifying a portal contract, contract address salt, and additional send method options. */ export type DeployOptions = { - /** The Ethereum address of the Portal contract. */ - portalContract?: EthAddress; /** An optional salt value used to deterministically calculate the contract address. */ contractAddressSalt?: Fr; /** Set to true to *not* include the sender in the address computation. */ @@ -209,7 +207,6 @@ export class DeployMethod extends Bas this.instance = getContractInstanceFromDeployParams(this.artifact, { constructorArgs: this.args, salt: options.contractAddressSalt, - portalAddress: options.portalContract, publicKey: this.publicKey, constructorArtifact: this.constructorArtifact, deployer: options.universalDeploy ? AztecAddress.ZERO : this.wallet.getAddress(), diff --git a/yarn-project/circuits.js/src/contract/contract_instance.ts b/yarn-project/circuits.js/src/contract/contract_instance.ts index 4b3e135b3e71..853eff04949c 100644 --- a/yarn-project/circuits.js/src/contract/contract_instance.ts +++ b/yarn-project/circuits.js/src/contract/contract_instance.ts @@ -26,14 +26,14 @@ export function getContractInstanceFromDeployParams( constructorArgs?: any[]; salt?: Fr; publicKey?: PublicKey; - portalAddress?: EthAddress; deployer?: AztecAddress; }, ): ContractInstanceWithAddress { const args = opts.constructorArgs ?? []; const salt = opts.salt ?? Fr.random(); const publicKey = opts.publicKey ?? Point.ZERO; - const portalContractAddress = opts.portalAddress ?? EthAddress.ZERO; + // @todo @LHerskind purge + const portalContractAddress = EthAddress.ZERO; const constructorArtifact = getConstructorArtifact(artifact, opts.constructorArtifact); const deployer = opts.deployer ?? AztecAddress.ZERO; diff --git a/yarn-project/circuits.js/src/structs/call_context.ts b/yarn-project/circuits.js/src/structs/call_context.ts index b542a46b1e06..b63c0667115d 100644 --- a/yarn-project/circuits.js/src/structs/call_context.ts +++ b/yarn-project/circuits.js/src/structs/call_context.ts @@ -9,6 +9,8 @@ import { CALL_CONTEXT_LENGTH } from '../constants.gen.js'; import { Gas } from './gas.js'; import { GasSettings } from './gas_settings.js'; +// @todo @lherskind Purge the portalContractAddress in here + /** * Call context. */ diff --git a/yarn-project/cli/src/cmds/add_contract.ts b/yarn-project/cli/src/cmds/add_contract.ts index 36b2a9fcbf43..612888ae766d 100644 --- a/yarn-project/cli/src/cmds/add_contract.ts +++ b/yarn-project/cli/src/cmds/add_contract.ts @@ -19,7 +19,7 @@ export async function addContract( initializationHash: Fr, salt: Fr, publicKey: Point | undefined, - portalContract: EthAddress | undefined, + portalAddress: EthAddress | undefined, deployer: AztecAddress | undefined, debugLogger: DebugLogger, log: LogFn, @@ -30,7 +30,7 @@ export async function addContract( salt, initializationHash, contractClassId: getContractClassFromArtifact(artifact).id, - portalContractAddress: portalContract ?? EthAddress.ZERO, + portalContractAddress: portalAddress ?? EthAddress.ZERO, publicKeysHash: computePublicKeysHash(publicKey), address, deployer: deployer ?? AztecAddress.ZERO, diff --git a/yarn-project/cli/src/cmds/deploy.ts b/yarn-project/cli/src/cmds/deploy.ts index 904418fa629a..b937989f981f 100644 --- a/yarn-project/cli/src/cmds/deploy.ts +++ b/yarn-project/cli/src/cmds/deploy.ts @@ -50,8 +50,9 @@ export async function deploy( const deploy = deployer.deploy(...args); - await deploy.create({ contractAddressSalt: salt, portalContract: portalAddress }); - const tx = deploy.send({ contractAddressSalt: salt, portalContract: portalAddress }); + // @todo @lherskind purge properly. Currently we still have the portal address in the arguments + await deploy.create({ contractAddressSalt: salt }); + const tx = deploy.send({ contractAddressSalt: salt }); const txHash = await tx.getTxHash(); debugLogger.verbose(`Deploy tx sent with hash ${txHash}`); if (wait) { diff --git a/yarn-project/end-to-end/src/flakey_e2e_deploy_contract/contract_class_registration.test.ts b/yarn-project/end-to-end/src/flakey_e2e_deploy_contract/contract_class_registration.test.ts index 5ce50aa73691..e1ad4e07dab0 100644 --- a/yarn-project/end-to-end/src/flakey_e2e_deploy_contract/contract_class_registration.test.ts +++ b/yarn-project/end-to-end/src/flakey_e2e_deploy_contract/contract_class_registration.test.ts @@ -96,13 +96,11 @@ describe('e2e_deploy_contract contract class registration', () => { const deployInstance = async (opts: { constructorName?: string; deployer?: AztecAddress } = {}) => { const initArgs = [wallet.getAddress(), 42] as StatefulContractCtorArgs; const salt = Fr.random(); - const portalAddress = EthAddress.random(); const publicKey = Point.random(); const instance = getContractInstanceFromDeployParams(artifact, { constructorArgs: initArgs, salt, publicKey, - portalAddress, constructorArtifact: opts.constructorName, deployer: opts.deployer, }); @@ -122,7 +120,6 @@ describe('e2e_deploy_contract contract class registration', () => { const registered = await t.registerContract(wallet, StatefulTestContract, { constructorName: opts.constructorName, salt: instance.salt, - portalAddress: instance.portalContractAddress, publicKey, initArgs, deployer: opts.deployer, diff --git a/yarn-project/end-to-end/src/flakey_e2e_deploy_contract/deploy_test.ts b/yarn-project/end-to-end/src/flakey_e2e_deploy_contract/deploy_test.ts index 192853b47869..59fa7eab35bb 100644 --- a/yarn-project/end-to-end/src/flakey_e2e_deploy_contract/deploy_test.ts +++ b/yarn-project/end-to-end/src/flakey_e2e_deploy_contract/deploy_test.ts @@ -65,19 +65,17 @@ export class DeployTest { opts: { salt?: Fr; publicKey?: Point; - portalAddress?: EthAddress; initArgs?: any[]; constructorName?: string; deployer?: AztecAddress; } = {}, ): Promise { - const { salt, publicKey, portalAddress, initArgs, constructorName, deployer } = opts; + const { salt, publicKey, initArgs, constructorName, deployer } = opts; const instance = getContractInstanceFromDeployParams(contractArtifact.artifact, { constructorArgs: initArgs ?? [], constructorArtifact: constructorName, salt, publicKey, - portalAddress, deployer, }); await wallet.registerContract({ artifact: contractArtifact.artifact, instance }); diff --git a/yarn-project/end-to-end/src/flakey_e2e_deploy_contract/legacy.test.ts b/yarn-project/end-to-end/src/flakey_e2e_deploy_contract/legacy.test.ts index 5bb33ab2cadf..b46128b7995f 100644 --- a/yarn-project/end-to-end/src/flakey_e2e_deploy_contract/legacy.test.ts +++ b/yarn-project/end-to-end/src/flakey_e2e_deploy_contract/legacy.test.ts @@ -90,7 +90,7 @@ describe('e2e_deploy_contract legacy', () => { const portalContract = EthAddress.random(); // ContractDeployer was instantiated with wallet so we don't have to pass it to wait(...) - const receipt = await deployer.deploy().send({ portalContract }).wait(); + const receipt = await deployer.deploy().send().wait(); const address = receipt.contract.address; const expectedPortal = portalContract.toString(); diff --git a/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts b/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts index 63975935c910..53510b1f16ce 100644 --- a/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts +++ b/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts @@ -101,15 +101,13 @@ export async function deployAndInitializeTokenAndBridgeContracts( const token = await TokenContract.deploy(wallet, owner, 'TokenName', 'TokenSymbol', 18).send().deployed(); // deploy l2 token bridge and attach to the portal - const bridge = await TokenBridgeContract.deploy(wallet, token.address) - .send({ portalContract: tokenPortalAddress }) - .deployed(); + const bridge = await TokenBridgeContract.deploy(wallet, token.address, tokenPortalAddress).send().deployed(); if ((await token.methods.admin().simulate()) !== owner.toBigInt()) { throw new Error(`Token admin is not ${owner}`); } - if (!(await bridge.methods.token().simulate()).equals(token.address)) { + if (!(await bridge.methods.get_token().simulate()).equals(token.address)) { throw new Error(`Bridge token is not ${token.address}`); } diff --git a/yarn-project/end-to-end/src/shared/gas_portal_test_harness.ts b/yarn-project/end-to-end/src/shared/gas_portal_test_harness.ts index 7a0c7625302c..39b9f67b0155 100644 --- a/yarn-project/end-to-end/src/shared/gas_portal_test_harness.ts +++ b/yarn-project/end-to-end/src/shared/gas_portal_test_harness.ts @@ -43,7 +43,8 @@ export class GasPortalTestingHarnessFactory { private async createMock() { const wallet = this.config.wallet; - const gasL2 = await GasTokenContract.deploy(wallet) + // In this case we are not using a portal we just yolo it. + const gasL2 = await GasTokenContract.deploy(wallet, EthAddress.ZERO) .send({ contractAddressSalt: getCanonicalGasToken(EthAddress.ZERO).instance.salt, }) diff --git a/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts b/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts index f23c35ea442a..d9944d99b54c 100644 --- a/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts +++ b/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts @@ -146,9 +146,7 @@ export const uniswapL1L2TestSuite = ( client: walletClient, }); // deploy l2 uniswap contract and attach to portal - uniswapL2Contract = await UniswapContract.deploy(ownerWallet) - .send({ portalContract: uniswapPortalAddress }) - .deployed(); + uniswapL2Contract = await UniswapContract.deploy(ownerWallet, uniswapPortalAddress).send().deployed(); const registryAddress = (await pxe.getNodeInfo()).l1ContractAddresses.registryAddress; diff --git a/yarn-project/protocol-contracts/src/gas-token/index.ts b/yarn-project/protocol-contracts/src/gas-token/index.ts index d38126bf262f..8d6b12abee2e 100644 --- a/yarn-project/protocol-contracts/src/gas-token/index.ts +++ b/yarn-project/protocol-contracts/src/gas-token/index.ts @@ -5,7 +5,7 @@ import { GasTokenArtifact } from './artifact.js'; /** Returns the canonical deployment of the gas token. */ export function getCanonicalGasToken(l1Bridge: EthAddress): ProtocolContract { - return getCanonicalProtocolContract(GasTokenArtifact, 1, [], Point.ZERO, l1Bridge); + return getCanonicalProtocolContract(GasTokenArtifact, 1, [l1Bridge], Point.ZERO); } export function getCanonicalGasTokenAddress(l1Bridge: EthAddress): AztecAddress { diff --git a/yarn-project/protocol-contracts/src/multi-call-entrypoint/index.ts b/yarn-project/protocol-contracts/src/multi-call-entrypoint/index.ts index 1d33cee36ed3..0fff4efeed9b 100644 --- a/yarn-project/protocol-contracts/src/multi-call-entrypoint/index.ts +++ b/yarn-project/protocol-contracts/src/multi-call-entrypoint/index.ts @@ -4,7 +4,7 @@ import { type ProtocolContract, getCanonicalProtocolContract } from '../protocol import { MultiCallEntrypointArtifact } from './artifact.js'; export function getCanonicalMultiCallEntrypointContract(): ProtocolContract { - return getCanonicalProtocolContract(MultiCallEntrypointArtifact, 1, [], Point.ZERO, EthAddress.ZERO); + return getCanonicalProtocolContract(MultiCallEntrypointArtifact, 1, [], Point.ZERO); } export function getCanonicalMultiCallEntrypointAddress(): AztecAddress { diff --git a/yarn-project/protocol-contracts/src/protocol_contract.ts b/yarn-project/protocol-contracts/src/protocol_contract.ts index 8286373e9da6..45c3a4eb2ab3 100644 --- a/yarn-project/protocol-contracts/src/protocol_contract.ts +++ b/yarn-project/protocol-contracts/src/protocol_contract.ts @@ -1,6 +1,5 @@ import { type AztecAddress, - EthAddress, getContractClassFromArtifact, getContractInstanceFromDeployParams, } from '@aztec/circuits.js'; @@ -26,7 +25,6 @@ export function getCanonicalProtocolContract( salt: Fr | number | bigint, constructorArgs: any[] = [], publicKey: Point = Point.ZERO, - portalAddress = EthAddress.ZERO, ): ProtocolContract { // TODO(@spalladino): This computes the contract class from the artifact twice. const contractClass = getContractClassFromArtifact(artifact); @@ -34,7 +32,6 @@ export function getCanonicalProtocolContract( constructorArgs, salt: new Fr(salt), publicKey, - portalAddress, }); return { instance, diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index 9f1d341533d6..8d0e08d76f96 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -533,6 +533,7 @@ export class PXEService implements PXE { contractAddress, execRequest.functionData.selector, ); + // @todo @LHerskind purge const portalContract = await this.contractDataOracle.getPortalContractAddress(contractAddress); return { @@ -548,11 +549,11 @@ export class PXEService implements PXE { async #simulate(txRequest: TxExecutionRequest, msgSender?: AztecAddress): Promise { // TODO - Pause syncing while simulating. - const { contractAddress, functionArtifact, portalContract } = await this.#getSimulationParameters(txRequest); + const { contractAddress, functionArtifact} = await this.#getSimulationParameters(txRequest); this.log.debug('Executing simulator...'); try { - const result = await this.simulator.run(txRequest, functionArtifact, contractAddress, portalContract, msgSender); + const result = await this.simulator.run(txRequest, functionArtifact, contractAddress, msgSender); this.log.verbose(`Simulation completed for ${contractAddress.toString()}:${functionArtifact.name}`); return result; } catch (err) { diff --git a/yarn-project/simulator/src/avm/avm_simulator.test.ts b/yarn-project/simulator/src/avm/avm_simulator.test.ts index 411d6c8fa84b..1bfdb707250d 100644 --- a/yarn-project/simulator/src/avm/avm_simulator.test.ts +++ b/yarn-project/simulator/src/avm/avm_simulator.test.ts @@ -188,11 +188,6 @@ describe('AVM simulator: transpiled Noir contracts', () => { await testEnvGetter('sender', sender, 'get_sender'); }); - it('portal', async () => { - const portal = EthAddress.fromField(new Fr(1)); - await testEnvGetter('portal', portal, 'get_portal'); - }); - it('getFeePerL1Gas', async () => { const fee = new Fr(1); await testEnvGetter('feePerL1Gas', fee, 'get_fee_per_l1_gas'); diff --git a/yarn-project/simulator/src/client/private_execution.test.ts b/yarn-project/simulator/src/client/private_execution.test.ts index 9e2b8fe0d834..288af6d5f452 100644 --- a/yarn-project/simulator/src/client/private_execution.test.ts +++ b/yarn-project/simulator/src/client/private_execution.test.ts @@ -97,13 +97,11 @@ describe('Private Execution test suite', () => { args = [], msgSender = AztecAddress.ZERO, contractAddress = defaultContractAddress, - portalContractAddress = EthAddress.ZERO, txContext = {}, }: { artifact: FunctionArtifact; msgSender?: AztecAddress; contractAddress?: AztecAddress; - portalContractAddress?: EthAddress; args?: any[]; txContext?: Partial>; }) => { @@ -119,7 +117,7 @@ describe('Private Execution test suite', () => { gasSettings: GasSettings.default(), }); - return acirSimulator.run(txRequest, artifact, contractAddress, portalContractAddress, msgSender); + return acirSimulator.run(txRequest, artifact, contractAddress, msgSender); }; const insertLeaves = async (leaves: Fr[], name = 'noteHash') => { @@ -555,7 +553,12 @@ describe('Private Execution test suite', () => { ); const computeArgs = () => - encodeArguments(artifact, [secretHashForRedeemingNotes, bridgedAmount, secretForL1ToL2MessageConsumption]); + encodeArguments(artifact, [ + secretHashForRedeemingNotes, + bridgedAmount, + secretForL1ToL2MessageConsumption, + crossChainMsgSender ?? preimage.sender.sender, + ]); const mockOracles = async (updateHeader = true) => { const tree = await insertLeaves([preimage.hash()], 'l1ToL2Messages'); @@ -576,7 +579,6 @@ describe('Private Execution test suite', () => { contractAddress, artifact, args, - portalContractAddress: crossChainMsgSender ?? preimage.sender.sender, txContext: { version: new Fr(1n), chainId: new Fr(1n) }, }); @@ -601,7 +603,6 @@ describe('Private Execution test suite', () => { contractAddress, artifact, args, - portalContractAddress: crossChainMsgSender ?? preimage.sender.sender, txContext: { version: new Fr(1n), chainId: new Fr(1n) }, }), ).rejects.toThrow('Message not in state'); @@ -623,7 +624,6 @@ describe('Private Execution test suite', () => { contractAddress, artifact, args, - portalContractAddress: crossChainMsgSender ?? preimage.sender.sender, txContext: { version: new Fr(1n), chainId: new Fr(1n) }, }), ).rejects.toThrow('Message not in state'); @@ -644,7 +644,6 @@ describe('Private Execution test suite', () => { contractAddress, artifact, args, - portalContractAddress: crossChainMsgSender ?? preimage.sender.sender, txContext: { version: new Fr(1n), chainId: new Fr(1n) }, }), ).rejects.toThrow('Message not in state'); @@ -664,7 +663,6 @@ describe('Private Execution test suite', () => { contractAddress, artifact, args, - portalContractAddress: crossChainMsgSender ?? preimage.sender.sender, txContext: { version: new Fr(1n), chainId: new Fr(2n) }, }), ).rejects.toThrow('Message not in state'); @@ -684,7 +682,6 @@ describe('Private Execution test suite', () => { contractAddress, artifact, args, - portalContractAddress: crossChainMsgSender ?? preimage.sender.sender, txContext: { version: new Fr(2n), chainId: new Fr(1n) }, }), ).rejects.toThrow('Message not in state'); @@ -705,7 +702,6 @@ describe('Private Execution test suite', () => { contractAddress, artifact, args, - portalContractAddress: crossChainMsgSender ?? preimage.sender.sender, txContext: { version: new Fr(1n), chainId: new Fr(1n) }, }), ).rejects.toThrow('Message not in state'); @@ -726,7 +722,6 @@ describe('Private Execution test suite', () => { contractAddress, artifact, args, - portalContractAddress: crossChainMsgSender ?? preimage.sender.sender, txContext: { version: new Fr(1n), chainId: new Fr(1n) }, }), ).rejects.toThrow('Message not in state'); @@ -1039,18 +1034,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(); - - // Tweak the contract artifact so we can extract return values - const artifact = getFunctionArtifact(TestContractArtifact, 'get_portal_contract_address'); - - const args: Fr[] = []; - - const result = await runSimulator({ artifact, args, portalContractAddress }); - expect(result.returnValues).toEqual([portalContractAddress.toField()]); - }); - it('this_address should return the current context address', async () => { const contractAddress = AztecAddress.random(); @@ -1061,17 +1044,6 @@ describe('Private Execution test suite', () => { const result = await runSimulator({ artifact, args: [], contractAddress }); expect(result.returnValues).toEqual([contractAddress.toField()]); }); - - it("this_portal_address should return the current context's portal address", async () => { - const portalContractAddress = EthAddress.random(); - - // Tweak the contract artifact so we can extract return values - const artifact = getFunctionArtifact(TestContractArtifact, 'get_this_portal_address'); - - // Overwrite the oracle return value - const result = await runSimulator({ artifact, args: [], portalContractAddress }); - expect(result.returnValues).toEqual([portalContractAddress.toField()]); - }); }); describe('Private global variables', () => { diff --git a/yarn-project/simulator/src/client/simulator.ts b/yarn-project/simulator/src/client/simulator.ts index 25bd77e8688e..6dc74a84091c 100644 --- a/yarn-project/simulator/src/client/simulator.ts +++ b/yarn-project/simulator/src/client/simulator.ts @@ -9,7 +9,7 @@ import { encodeArguments, } from '@aztec/foundation/abi'; import { AztecAddress } from '@aztec/foundation/aztec-address'; -import { type EthAddress } from '@aztec/foundation/eth-address'; +import { EthAddress } from '@aztec/foundation/eth-address'; import { Fr } from '@aztec/foundation/fields'; import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log'; @@ -69,7 +69,6 @@ export class AcirSimulator { request: TxExecutionRequest, entryPointArtifact: FunctionArtifactWithDebugMetadata, contractAddress: AztecAddress, - portalContractAddress: EthAddress, msgSender = AztecAddress.ZERO, ): Promise { if (entryPointArtifact.functionType !== FunctionType.SECRET) { @@ -89,6 +88,9 @@ export class AcirSimulator { // reserve the first side effect for the tx hash (inserted by the private kernel) const startSideEffectCounter = 1; + // @todo @lherskind Purge the portalContractAddress in here + const portalContractAddress = EthAddress.ZERO; + const transactionFee = Fr.ZERO; const callContext = new CallContext( msgSender, diff --git a/yarn-project/simulator/src/public/index.test.ts b/yarn-project/simulator/src/public/index.test.ts index 6f74908fadde..bf742a3e52d8 100644 --- a/yarn-project/simulator/src/public/index.test.ts +++ b/yarn-project/simulator/src/public/index.test.ts @@ -351,11 +351,10 @@ describe('ACIR public execution simulator', () => { const createL2ToL1MessagePublicArtifact = TestContractArtifact.functions.find( f => f.name === 'create_l2_to_l1_message_public', )!; - const args = encodeArguments(createL2ToL1MessagePublicArtifact, params); - const portalContractAddress = EthAddress.random(); + const args = encodeArguments(createL2ToL1MessagePublicArtifact, [...params, portalContractAddress]); - const callContext = makeCallContext(contractAddress, { portalContractAddress }); + const callContext = makeCallContext(contractAddress); publicContracts.getBytecode.mockResolvedValue(createL2ToL1MessagePublicArtifact.bytecode); @@ -425,7 +424,14 @@ describe('ACIR public execution simulator', () => { secret, ); - const computeArgs = () => encodeArguments(mintPublicArtifact, [tokenRecipient, bridgedAmount, secret, leafIndex]); + const computeArgs = () => + encodeArguments(mintPublicArtifact, [ + tokenRecipient, + bridgedAmount, + secret, + leafIndex, + crossChainMsgSender ?? preimage.sender.sender, + ]); const computeCallContext = () => makeCallContext(contractAddress, { diff --git a/yarn-project/types/src/contracts/contract_instance.ts b/yarn-project/types/src/contracts/contract_instance.ts index 8f14656bc900..f8b6b022c564 100644 --- a/yarn-project/types/src/contracts/contract_instance.ts +++ b/yarn-project/types/src/contracts/contract_instance.ts @@ -17,7 +17,7 @@ export interface ContractInstance { /** Hash of the selector and arguments to the constructor. */ initializationHash: Fr; /** Optional address of the L1 portal contract. */ - portalContractAddress: EthAddress; + portalContractAddress: EthAddress; // @todo @LHerskind Purge /** Optional hash of the struct of public keys used for encryption and nullifying by this contract. */ publicKeysHash: Fr; /** Optional deployer address or zero if this was a universal deploy. */