Skip to content

Commit

Permalink
Parameterize Holesky contract addresses (#343)
Browse files Browse the repository at this point in the history
* [WIP] Update Aligned to 0.7.0

We must wait until Aligned uploads the release for 0.7.0.

Once it's uploaded we need to add a batcher payment service arg
to the `updateChain` call in the Aligned polling service.

* Update Aligned to 0.7.0

* Update Aligned branch

* Update Aligned and Bridge contracts

* Update Aligned Foundry submodule

* Remove bridge addr constants and parameterize them
  • Loading branch information
gabrielbosio authored Sep 25, 2024
1 parent b9ca11d commit 7dac115
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 76 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
29 changes: 13 additions & 16 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::{
eth::{
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
53 changes: 12 additions & 41 deletions core/src/eth.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 @@ -100,15 +99,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 @@ -199,15 +191,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 @@ -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)?;
Expand Down Expand Up @@ -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");

Expand Down
3 changes: 0 additions & 3 deletions core/src/utils/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
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;
21 changes: 5 additions & 16 deletions example/app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 7dac115

Please sign in to comment.