diff --git a/.env.template b/.env.template index bbb654c2..396301cc 100644 --- a/.env.template +++ b/.env.template @@ -7,6 +7,9 @@ SAVE_PROOF=true/false # also false if other than "true" or variable were to be n # BATCHER_ETH_ADDR= # ETH_RPC_URL= # PROOF_GENERATOR_ADDR= +# BRIDGE_HOLESKY_ETH_ADDR= +# BRIDGE_ACCOUNT_HOLESKY_ETH_ADDR= +# ALIGNED_SM_HOLESKY_ETH_ADDR= ## You can choose to use a keystore or private key for your signing wallet. ## Leave empty if choosing Anvil Devnet. diff --git a/contract_deployer/src/main.rs b/contract_deployer/src/main.rs index 50c95034..49c2a1d8 100644 --- a/contract_deployer/src/main.rs +++ b/contract_deployer/src/main.rs @@ -1,4 +1,3 @@ -use aligned_sdk::core::types::Chain; use log::{debug, error, info}; use mina_bridge_core::{ eth::{ @@ -7,11 +6,8 @@ use mina_bridge_core::{ }, mina::query_root, utils::{ - constants::{ - ALIGNED_SM_DEVNET_ETH_ADDR, ALIGNED_SM_HOLESKY_ETH_ADDR, BRIDGE_TRANSITION_FRONTIER_LEN, - }, - env::EnvironmentVariables, - wallet_alloy::get_wallet, + constants::BRIDGE_TRANSITION_FRONTIER_LEN, contract::get_aligned_sm_contract_addr, + env::EnvironmentVariables, wallet_alloy::get_wallet, }, }; use std::process; @@ -47,18 +43,19 @@ async fn main() { process::exit(1); }); - let aligned_sm_addr = match chain { - Chain::Devnet => ALIGNED_SM_DEVNET_ETH_ADDR, - Chain::Holesky => ALIGNED_SM_HOLESKY_ETH_ADDR, - _ => todo!(), - }; + let aligned_sm_addr = get_aligned_sm_contract_addr(&chain).unwrap_or_else(|err| { + error!("{err}"); + process::exit(1); + }); let bridge_constructor_args = - MinaStateSettlementConstructorArgs::new(aligned_sm_addr, root_hash).unwrap_or_else(|err| { - error!("Failed to make constructor args for bridge contract call: {err}"); - process::exit(1); - }); - let account_constructor_args = MinaAccountValidationConstructorArgs::new(aligned_sm_addr) + MinaStateSettlementConstructorArgs::new(&aligned_sm_addr, root_hash).unwrap_or_else( + |err| { + error!("Failed to make constructor args for bridge contract call: {err}"); + process::exit(1); + }, + ); + let account_constructor_args = MinaAccountValidationConstructorArgs::new(&aligned_sm_addr) .unwrap_or_else(|err| { error!("Failed to make constructor args for account contract call: {err}"); process::exit(1); diff --git a/core/src/eth.rs b/core/src/eth.rs index c6a51bdb..e6d47ede 100644 --- a/core/src/eth.rs +++ b/core/src/eth.rs @@ -7,7 +7,7 @@ use alloy::providers::ProviderBuilder; use alloy::sol; use ethers::{abi::AbiEncode, prelude::*}; use k256::ecdsa::SigningKey; -use log::{debug, error, info}; +use log::{debug, info}; use mina_p2p_messages::v2::StateHash; use serde::{Deserialize, Serialize}; use serde_with::serde_as; @@ -15,10 +15,9 @@ use serde_with::serde_as; use crate::{ proof::{account_proof::MinaAccountPubInputs, state_proof::MinaStatePubInputs}, sol::serialization::SolSerialize, - utils::constants::{ - ANVIL_CHAIN_ID, BRIDGE_ACCOUNT_DEVNET_ETH_ADDR, BRIDGE_ACCOUNT_HOLESKY_ETH_ADDR, - BRIDGE_DEVNET_ETH_ADDR, BRIDGE_HOLESKY_ETH_ADDR, BRIDGE_TRANSITION_FRONTIER_LEN, - HOLESKY_CHAIN_ID, + utils::{ + constants::{ANVIL_CHAIN_ID, BRIDGE_TRANSITION_FRONTIER_LEN, HOLESKY_CHAIN_ID}, + contract::{get_account_validation_contract_addr, get_bridge_contract_addr}, }, }; @@ -100,15 +99,8 @@ pub async fn update_chain( wallet: Wallet, batcher_payment_service: &str, ) -> Result<(), String> { - let bridge_eth_addr = Address::from_str(match chain { - Chain::Devnet => BRIDGE_DEVNET_ETH_ADDR, - Chain::Holesky => BRIDGE_HOLESKY_ETH_ADDR, - _ => { - error!("Unimplemented Ethereum contract on selected chain"); - unimplemented!() - } - }) - .map_err(|err| err.to_string())?; + let bridge_eth_addr = + Address::from_str(&get_bridge_contract_addr(chain)?).map_err(|err| err.to_string())?; let serialized_pub_input = bincode::serialize(pub_input) .map_err(|err| format!("Failed to serialize public inputs: {err}"))?; @@ -199,15 +191,8 @@ pub async fn update_chain( } pub async fn get_bridge_tip_hash(chain: &Chain, eth_rpc_url: &str) -> Result { - let bridge_eth_addr = Address::from_str(match chain { - Chain::Devnet => BRIDGE_DEVNET_ETH_ADDR, - Chain::Holesky => BRIDGE_HOLESKY_ETH_ADDR, - _ => { - error!("Unimplemented Ethereum contract on selected chain"); - unimplemented!() - } - }) - .map_err(|err| err.to_string())?; + let bridge_eth_addr = + Address::from_str(&get_bridge_contract_addr(chain)?).map_err(|err| err.to_string())?; debug!("Creating contract instance"); let mina_bridge_contract = mina_bridge_contract_call_only(eth_rpc_url, bridge_eth_addr)?; @@ -228,15 +213,8 @@ pub async fn get_bridge_chain_state_hashes( chain: &Chain, eth_rpc_url: &str, ) -> Result<[StateHash; BRIDGE_TRANSITION_FRONTIER_LEN], String> { - let bridge_eth_addr = Address::from_str(match chain { - Chain::Devnet => BRIDGE_DEVNET_ETH_ADDR, - Chain::Holesky => BRIDGE_HOLESKY_ETH_ADDR, - _ => { - error!("Unimplemented Ethereum contract on selected chain"); - unimplemented!() - } - }) - .map_err(|err| err.to_string())?; + let bridge_eth_addr = + Address::from_str(&get_bridge_contract_addr(chain)?).map_err(|err| err.to_string())?; debug!("Creating contract instance"); let mina_bridge_contract = mina_bridge_contract_call_only(eth_rpc_url, bridge_eth_addr)?; @@ -269,15 +247,8 @@ pub async fn validate_account( eth_rpc_url: &str, batcher_payment_service: &str, ) -> Result<(), String> { - let bridge_eth_addr = Address::from_str(match chain { - Chain::Devnet => BRIDGE_ACCOUNT_DEVNET_ETH_ADDR, - Chain::Holesky => BRIDGE_ACCOUNT_HOLESKY_ETH_ADDR, - _ => { - error!("Unimplemented Ethereum contract on selected chain"); - unimplemented!() - } - }) - .map_err(|err| err.to_string())?; + let bridge_eth_addr = Address::from_str(&get_account_validation_contract_addr(chain)?) + .map_err(|err| err.to_string())?; debug!("Creating contract instance"); diff --git a/core/src/utils/constants.rs b/core/src/utils/constants.rs index 3d154220..392da9f3 100644 --- a/core/src/utils/constants.rs +++ b/core/src/utils/constants.rs @@ -18,12 +18,9 @@ pub const MINA_HASH_SIZE: usize = 32; // Bridge related constants pub const BRIDGE_DEVNET_ETH_ADDR: &str = "0x700b6A60ce7EaaEA56F065753d8dcB9653dbAD35"; -pub const BRIDGE_HOLESKY_ETH_ADDR: &str = "0x8ee69DeEb2692E1D260356419FB716AA55e37Ee4"; pub const BRIDGE_TRANSITION_FRONTIER_LEN: usize = 16; pub const BRIDGE_ACCOUNT_DEVNET_ETH_ADDR: &str = "0xA15BB66138824a1c7167f5E85b957d04Dd34E468"; -pub const BRIDGE_ACCOUNT_HOLESKY_ETH_ADDR: &str = "0xF2e55D6ddde772dAcaEfEb5bbA4C0E76B0d80d1d"; // Aligned related constants pub const PROOF_GENERATOR_ADDR: &str = "0x66f9664f97F2b50F62D13eA064982f936dE76657"; pub const ALIGNED_SM_DEVNET_ETH_ADDR: &str = "0x1613beB3B2C4f22Ee086B2b38C1476A3cE7f78E8"; -pub const ALIGNED_SM_HOLESKY_ETH_ADDR: &str = "0x39cFAb7498d73d75F3cb38a3d321de451779989D"; diff --git a/core/src/utils/contract.rs b/core/src/utils/contract.rs new file mode 100644 index 00000000..d555d217 --- /dev/null +++ b/core/src/utils/contract.rs @@ -0,0 +1,32 @@ +use aligned_sdk::core::types::Chain; + +use super::constants::{ + ALIGNED_SM_DEVNET_ETH_ADDR, BRIDGE_ACCOUNT_DEVNET_ETH_ADDR, BRIDGE_DEVNET_ETH_ADDR, +}; + +pub fn get_bridge_contract_addr(chain: &Chain) -> Result { + match chain { + Chain::Devnet => Ok(BRIDGE_DEVNET_ETH_ADDR.to_owned()), + Chain::Holesky => std::env::var("BRIDGE_HOLESKY_ETH_ADDR") + .map_err(|err| format!("Error getting Bridge contract address: {err}")), + _ => Err("Unimplemented Ethereum contract on selected chain".to_owned()), + } +} + +pub fn get_account_validation_contract_addr(chain: &Chain) -> Result { + match chain { + Chain::Devnet => Ok(BRIDGE_ACCOUNT_DEVNET_ETH_ADDR.to_owned()), + Chain::Holesky => std::env::var("BRIDGE_ACCOUNT_HOLESKY_ETH_ADDR") + .map_err(|err| format!("Error getting Account validation contract address: {err}")), + _ => Err("Unimplemented Ethereum contract on selected chain".to_owned()), + } +} + +pub fn get_aligned_sm_contract_addr(chain: &Chain) -> Result { + match chain { + Chain::Devnet => Ok(ALIGNED_SM_DEVNET_ETH_ADDR.to_owned()), + Chain::Holesky => std::env::var("ALIGNED_SM_HOLESKY_ETH_ADDR") + .map_err(|err| format!("Error getting Aligned SM contract address: {err}")), + _ => Err("Unimplemented Ethereum contract on selected chain".to_owned()), + } +} diff --git a/core/src/utils/mod.rs b/core/src/utils/mod.rs index 6e24fa03..698644a5 100644 --- a/core/src/utils/mod.rs +++ b/core/src/utils/mod.rs @@ -1,4 +1,5 @@ pub mod constants; +pub mod contract; pub mod env; pub mod wallet; pub mod wallet_alloy; diff --git a/example/app/src/main.rs b/example/app/src/main.rs index 44dd029b..217ee0ac 100644 --- a/example/app/src/main.rs +++ b/example/app/src/main.rs @@ -12,10 +12,7 @@ use mina_bridge_core::{ AccountVerificationData, }, utils::{ - constants::{ - BRIDGE_ACCOUNT_DEVNET_ETH_ADDR, BRIDGE_ACCOUNT_HOLESKY_ETH_ADDR, - BRIDGE_DEVNET_ETH_ADDR, BRIDGE_HOLESKY_ETH_ADDR, - }, + contract::{get_account_validation_contract_addr, get_bridge_contract_addr}, env::EnvironmentVariables, wallet, wallet_alloy, }, @@ -86,22 +83,14 @@ async fn main() { Command::DeployContract => { // TODO(xqft): we might as well use the Chain type from Alloy, it isn't right to add // aligned-sdk as a dependency only for this type. - let state_settlement_addr = match chain { - Chain::Devnet => BRIDGE_DEVNET_ETH_ADDR, - Chain::Holesky => BRIDGE_HOLESKY_ETH_ADDR, - _ => todo!(), - }; + let state_settlement_addr = get_bridge_contract_addr(&chain).unwrap(); - let account_validation_addr = match chain { - Chain::Devnet => BRIDGE_ACCOUNT_DEVNET_ETH_ADDR, - Chain::Holesky => BRIDGE_ACCOUNT_HOLESKY_ETH_ADDR, - _ => todo!(), - }; + let account_validation_addr = get_account_validation_contract_addr(&chain).unwrap(); let contract = SudokuValidity::deploy( &provider, - Address::from_str(state_settlement_addr).unwrap(), - Address::from_str(account_validation_addr).unwrap(), + Address::from_str(&state_settlement_addr).unwrap(), + Address::from_str(&account_validation_addr).unwrap(), ) .await .map_err(|err| err.to_string())