Skip to content

Commit

Permalink
fix: exclude starknet signing key from relayer config file (#334)
Browse files Browse the repository at this point in the history
* use enum variant

* refactor

* use named field

* example relayer config file

* ignore relayer.toml config

* starknet wallet always has felts

* update example relayer config

* class hashes before contract addresses

* Properly save and load wallet files

---------

Co-authored-by: Soares Chen <[email protected]>
  • Loading branch information
rnbguy and soareschen authored Mar 4, 2025
1 parent 4f58f27 commit 1f68335
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ target/
.snfoundry_versioned_programs/

.env
relayer.toml

# vscode
.vscode/
Expand Down
62 changes: 62 additions & 0 deletions relayer.toml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
[starknet_chain_config]
poll_interval = "40s"
block_time = { secs = 30, nanos = 0 }

json_rpc_url = "https://starknet-sepolia.public.blastapi.io/rpc/v0_7"
# json_rpc_url = "https://starknet-sepolia.reddio.com/rpc/v0_7"

# -- to be filled
# private information
# toml file containing the `account_address`, `public_key` and `signing_key` as Felt
relayer_wallet = ""

[starknet_chain_config.contract_classes]
erc20 = "0x04570481e743c3fdd442c44d968030b375cce8ec1471ccfd1a1dc48613060c3c"
ics20 = "0x04d2f862a3e23f094983b7e2df83f4875fbd6b8571c5a53478e0be8962f87b30"
ibc_client = "0x0305e76f607a3c39f2955902a41d820a4b2559e9e3e8bed681f32c2e87831901"

[starknet_chain_config.contract_addresses]
ibc_client = "0x05d78cad8c0efc496d5ce0bdce66bbae7aa9d97860448a5af84019227383bb2a"
ibc_core = "0x04cf1183281f8e60abcb58466b0d01f3eb273e64799d8e6ad2cea1578ef5e91a"

[cosmos_chain_config]
id = 'osmo-test-5'
account_prefix = 'osmo'
store_prefix = 'ibc'
rpc_timeout = { secs = 10, nanos = 0 }
address_type = 'cosmos'
max_msg_num = 4
max_tx_size = 1048576

rpc_addr = 'https://rpc.testnet.osmosis.zone'
# rpc_addr = 'https://rpc.osmotest5.osmosis.zone'
grpc_addr = 'https://grpc.testnet.osmosis.zone'
event_source = { mode = 'push', url = 'wss://rpc.testnet.osmosis.zone/websocket' }

# -- to be filled
# private information
# hermes-v1 key should be present at `<key_store_folder>/<key_name>.json`
key_store_folder = ""
key_name = ''

# https://www.mintscan.io/osmosis-testnet
block_time = { secs = 0, nanos = 520000000 }
clock_drift = { secs = 1, nanos = 0 }
max_block_time = { secs = 10, nanos = 0 }
compat_mode = "v0.37"
extension_options = [ ]
poll_interval = { secs = 1, nanos = 0 }

[cosmos_chain_config.gas_config]
default_gas = 200000
max_gas = 400000
gas_multiplier = 1.25
gas_price = { price = 0.0025, denom = 'uosmo' }
fee_granter = ''
dynamic_gas_config = { multiplier = 1.1, max = 1.6, eip_query_type = "Osmosis", denom = "uosmo" }

[cosmos_chain_config.gas_config.max_fee]
amount = [ { amount = "25000", denom = 'uosmo' } ]
gas_limit = 400000
payer = ''
granter = ''
1 change: 1 addition & 0 deletions relayer/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use serde::{Deserialize, Serialize};
use starknet::core::types::Felt;

use crate::impls::types::address::StarknetAddress;
use crate::types::wallet::StarknetWallet;

#[derive(Debug, Serialize, Deserialize)]
pub struct StarknetRelayerConfig {
Expand All @@ -16,7 +15,7 @@ pub struct StarknetRelayerConfig {
#[derive(Debug, Serialize, Deserialize)]
pub struct StarknetChainConfig {
pub json_rpc_url: String,
pub relayer_wallet: StarknetWallet,
pub relayer_wallet: String,
#[serde(with = "humantime_serde")]
pub poll_interval: Duration,
pub block_time: Duration,
Expand Down
8 changes: 7 additions & 1 deletion relayer/crates/starknet-cli/src/contexts/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,18 @@ impl ConfigUpdater<StarknetChainDriver, StarknetRelayerConfig> for UpdateStarkne
.next(),
};

let relayer_wallet_path = chain_driver
.chain_store_dir
.join("wallets/relayer.toml")
.display()
.to_string();

let chain_config = StarknetChainConfig {
json_rpc_url: format!(
"http://{}:{}/",
chain_driver.node_config.rpc_addr, chain_driver.node_config.rpc_port
),
relayer_wallet,
relayer_wallet: relayer_wallet_path,
poll_interval: chain_driver.chain.poll_interval,
block_time: chain_driver.chain.block_time,
contract_addresses,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ use hermes_cosmos_test_components::bootstrap::traits::types::genesis_config::Cha
use hermes_error::impls::UseHermesError;
use hermes_error::types::HermesError;
use hermes_runtime::types::runtime::HermesRuntime;
use hermes_runtime_components::traits::fs::create_dir::CanCreateDir;
use hermes_runtime_components::traits::fs::write_file::CanWriteStringToFile;
use hermes_runtime_components::traits::runtime::{
HasRuntime, RuntimeGetterComponent, RuntimeTypeProviderComponent,
};
Expand Down Expand Up @@ -116,6 +118,19 @@ impl ChainDriverBuilder<StarknetBootstrap> for StarknetBootstrapComponents {
) -> Result<StarknetChainDriver, HermesError> {
let runtime = bootstrap.runtime.clone();

let chain_store_dir = bootstrap.chain_store_dir.clone();

runtime.create_dir(&chain_store_dir.join("wallets")).await?;

for (name, wallet) in wallets.iter() {
let wallet_str = toml::to_string_pretty(wallet)?;
let wallet_path = chain_store_dir.join(format!("wallets/{name}.toml"));

runtime
.write_string_to_file(&wallet_path, &wallet_str)
.await?;
}

let relayer_wallet = wallets
.get("relayer")
.ok_or_else(|| StarknetBootstrap::raise_error("expect relayer wallet to be present"))?
Expand Down Expand Up @@ -181,6 +196,7 @@ impl ChainDriverBuilder<StarknetBootstrap> for StarknetBootstrapComponents {
let chain_driver = StarknetChainDriver {
runtime,
chain,
chain_store_dir,
genesis_config,
node_config,
wallets,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::collections::BTreeMap;
use std::path::PathBuf;

use cgp::core::component::UseDelegate;
use cgp::core::error::{ErrorRaiserComponent, ErrorTypeProviderComponent};
Expand Down Expand Up @@ -28,6 +29,7 @@ use tokio::process::Child;
pub struct StarknetChainDriver {
pub runtime: HermesRuntime,
pub chain: StarknetChain,
pub chain_store_dir: PathBuf,
pub genesis_config: StarknetGenesisConfig,
pub node_config: StarknetNodeConfig,
pub wallets: BTreeMap<String, StarknetWallet>,
Expand Down
1 change: 1 addition & 0 deletions relayer/crates/starknet-relayer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ eyre = { workspace = true }
serde = { workspace = true }
url = { workspace = true }
futures = { workspace = true }
toml = { workspace = true }

tiny-bip39 = { workspace = true }
20 changes: 13 additions & 7 deletions relayer/crates/starknet-relayer/src/contexts/builder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use alloc::sync::Arc;
use core::marker::PhantomData;
use core::ops::Deref;
use std::path::PathBuf;

use cgp::core::component::UseDelegate;
use cgp::core::error::{ErrorRaiserComponent, ErrorTypeProviderComponent};
Expand All @@ -25,11 +26,13 @@ use hermes_relayer_components::multi::traits::birelay_at::BiRelayTypeAtComponent
use hermes_relayer_components::multi::traits::chain_at::ChainTypeAtComponent;
use hermes_relayer_components::multi::traits::relay_at::RelayTypeAtComponent;
use hermes_runtime::types::runtime::HermesRuntime;
use hermes_runtime_components::traits::fs::read_file::CanReadFileAsString;
use hermes_runtime_components::traits::runtime::{
RuntimeGetterComponent, RuntimeTypeProviderComponent,
};
use hermes_starknet_chain_components::impls::types::config::StarknetChainConfig;
use hermes_starknet_chain_components::types::client_id::ClientId as StarknetClientId;
use hermes_starknet_chain_components::types::wallet::StarknetWallet;
use hermes_starknet_chain_context::contexts::chain::{StarknetChain, StarknetChainFields};
use hermes_starknet_chain_context::contexts::encoding::event::StarknetEventEncoding;
use hermes_starknet_chain_context::impls::error::HandleStarknetChainError;
Expand Down Expand Up @@ -226,23 +229,26 @@ impl StarknetBuilder {
return Err(eyre!("Starknet chain has a different ID as configured. Expected: {expected_chain_id}, got: {chain_id}").into());
}

let wallet_path = PathBuf::from(self.starknet_chain_config.relayer_wallet.clone());

let wallet_str = self.runtime.read_file_as_string(&wallet_path).await?;

let relayer_wallet: StarknetWallet = toml::from_str(&wallet_str)
.map_err(|e| eyre!("Failed to parse relayer wallet: {e}"))?;

let account = SingleOwnerAccount::new(
rpc_client.clone(),
LocalWallet::from_signing_key(SigningKey::from_secret_scalar(
self.starknet_chain_config.relayer_wallet.signing_key,
relayer_wallet.signing_key,
)),
*self.starknet_chain_config.relayer_wallet.account_address,
*relayer_wallet.account_address,
chain_id_felt,
ExecutionEncoding::New,
);

let proof_signer = Secp256k1KeyPair::from_mnemonic(
bip39::Mnemonic::from_entropy(
&self
.starknet_chain_config
.relayer_wallet
.signing_key
.to_bytes_be(),
&relayer_wallet.signing_key.to_bytes_be(),
bip39::Language::English,
)
.expect("valid mnemonic")
Expand Down

0 comments on commit 1f68335

Please sign in to comment.