Skip to content

Commit

Permalink
Remove bridge addr constants and parameterize them
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielbosio committed Sep 24, 2024
1 parent 066a86d commit 81d486e
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 58 deletions.
3 changes: 3 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ SAVE_PROOF=true/false # also false if other than "true" or variable were to be n
# BATCHER_ETH_ADDR=<optional>
# ETH_RPC_URL=<optional>
# PROOF_GENERATOR_ADDR=<optional>
# BRIDGE_HOLESKY_ETH_ADDR=<optional>
# BRIDGE_ACCOUNT_HOLESKY_ETH_ADDR=<optional>
# ALIGNED_SM_HOLESKY_ETH_ADDR=<optional>

## You can choose to use a keystore or private key for your signing wallet.
## Leave empty if choosing Anvil Devnet.
Expand Down
21 changes: 8 additions & 13 deletions contract_deployer/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use aligned_sdk::core::types::Chain;
use log::{debug, error, info};
use mina_bridge_core::{
mina_polling_service::query_root,
Expand All @@ -7,11 +6,8 @@ use mina_bridge_core::{
MinaAccountValidationConstructorArgs, MinaBridgeConstructorArgs, SolStateHash,
},
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;
Expand Down Expand Up @@ -47,18 +43,17 @@ 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 = MinaBridgeConstructorArgs::new(aligned_sm_addr, root_hash)
let bridge_constructor_args = MinaBridgeConstructorArgs::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)
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);
Expand Down
2 changes: 1 addition & 1 deletion core/abi/MinaAccountValidation.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/abi/MinaBridge.json

Large diffs are not rendered by default.

53 changes: 12 additions & 41 deletions core/src/smart_contract_utility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@ 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;

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},
},
};

Expand Down Expand Up @@ -97,15 +96,8 @@ pub async fn update_chain(
wallet: Wallet<SigningKey>,
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}"))?;
Expand Down Expand Up @@ -196,15 +188,8 @@ pub async fn update_chain(
}

pub async fn get_bridge_tip_hash(chain: &Chain, eth_rpc_url: &str) -> Result<SolStateHash, 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)?;
Expand All @@ -225,15 +210,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)?;
Expand Down Expand Up @@ -266,15 +244,8 @@ pub async fn validate_account(
eth_rpc_url: &str,
batcher_payment_service: &str,
) -> Result<Account, 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");

Expand Down
2 changes: 0 additions & 2 deletions core/src/utils/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ 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 = "0x8aED2F71774a98354091F8a885a19fA9C8659169";
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 = "0x9Cbb0439EB42FBda982851068D52b1871F72Bea9";

// Aligned related constants
pub const PROOF_GENERATOR_ADDR: &str = "0x66f9664f97F2b50F62D13eA064982f936dE76657";
Expand Down
32 changes: 32 additions & 0 deletions core/src/utils/contract.rs
Original file line number Diff line number Diff line change
@@ -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<String, String> {
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<String, String> {
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<String, String> {
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()),
}
}
1 change: 1 addition & 0 deletions core/src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod constants;
pub mod contract;
pub mod env;
pub mod wallet;
pub mod wallet_alloy;

0 comments on commit 81d486e

Please sign in to comment.