Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(devnet): loosened devnet chain id restrictions #448

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Next release

- fix(devnet): loosened devnet chain id restrictions
- chore: Move crates under a madara subdir
- chore(nix): resolve flake and direnv compatibility issues
- fix: Gateway path fix
Expand Down
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ You can choose between different build modes:

Start the Madara client with a basic set of arguments depending on your chosen mode:

> [!NOTE]
> Head to the [Configuration](#%EF%B8%8F-configuration) section to learn more about
> customizing your node.

#### Full Node

Synchronizes the state of the chain from genesis.
Expand Down Expand Up @@ -125,16 +129,16 @@ cargo run --release -- \
A node in a private local network.

```bash
cargo run --release -- \
--name Madara \
--devnet \
--base-path /var/lib/madara \
--preset sepolia
cargo run --release -- \
--name Madara \
--devnet \
--base-path ../madara_db \
--chain-config-override=chain_id=MY_CUSTOM_DEVNET
```

> [!NOTE]
> Head to the [Configuration](#%EF%B8%8F-configuration) section to learn more about
> customizing your node.
> [!CAUTION]
> Make sure to use a unique `chain_id` for your devnet to avoid potential replay
> attacks in other chains with the same chain id!

#### 4. Presets

Expand Down
5 changes: 0 additions & 5 deletions crates/madara/node/src/cli/block_production.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ pub struct BlockProductionParams {
#[arg(env = "MADARA_BLOCK_PRODUCTION_DISABLED", long, alias = "no-block-production")]
pub block_production_disabled: bool,

/// Launch a devnet with a production chain id (like SN_MAINNET, SN_SEPOLIA).
/// This in unsafe because your devnet transactions can be replayed on the actual network.
#[arg(env = "MADARA_OVERRIDE_DEVNET_CHAIN_ID", long, default_value_t = false)]
pub override_devnet_chain_id: bool,

/// Create this number of contracts in the genesis block for the devnet configuration.
#[arg(env = "MADARA_DEVNET_CONTRACTS", long, default_value_t = 10)]
pub devnet_contracts: u64,
Expand Down
12 changes: 0 additions & 12 deletions crates/madara/node/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ pub use db::*;
pub use gateway::*;
pub use l2::*;
pub use rpc::*;
use starknet_api::core::ChainId;
use std::str::FromStr;
pub use telemetry::*;

Expand Down Expand Up @@ -313,17 +312,6 @@ pub enum NetworkType {
Devnet,
}

impl NetworkType {
pub fn chain_id(&self) -> ChainId {
match self {
NetworkType::Main => ChainId::Mainnet,
NetworkType::Test => ChainId::Sepolia,
NetworkType::Integration => ChainId::IntegrationSepolia,
NetworkType::Devnet => ChainId::Other("MADARA_DEVNET".to_string()),
}
}
}

#[derive(Debug, Clone, clap::ValueEnum)]
#[value(rename_all = "kebab-case")]
pub enum ChainPreset {
Expand Down
20 changes: 9 additions & 11 deletions crates/madara/node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod util;

use anyhow::{bail, Context};
use clap::Parser;
use cli::{NetworkType, RunCmd};
use cli::RunCmd;
use http::{HeaderName, HeaderValue};
use mc_analytics::Analytics;
use mc_block_import::BlockImporter;
Expand All @@ -20,6 +20,7 @@ use mc_telemetry::{SysInfo, TelemetryService};
use mp_oracle::pragma::PragmaOracleBuilder;
use mp_utils::service::{MadaraServiceId, ServiceMonitor};
use service::{BlockProductionService, GatewayService, L1SyncService, L2SyncService, RpcService};
use starknet_api::core::ChainId;
use std::sync::Arc;

const GREET_IMPL_NAME: &str = "Madara";
Expand Down Expand Up @@ -50,16 +51,13 @@ async fn main() -> anyhow::Result<()> {
run_cmd.chain_config()?
};

// Check if the devnet is running with the correct chain id.
if run_cmd.devnet && chain_config.chain_id != NetworkType::Devnet.chain_id() {
if !run_cmd.block_production_params.override_devnet_chain_id {
tracing::error!("You're running a devnet with the network config of {:?}. This means that devnet transactions can be replayed on the actual network. Use `--network=devnet` instead. Or if this is the expected behavior please pass `--override-devnet-chain-id`", chain_config.chain_name);
panic!();
} else {
// This log is immediately flooded with devnet accounts and so this can be missed.
// Should we add a delay here to make this clearly visisble?
tracing::warn!("You're running a devnet with the network config of {:?}. This means that devnet transactions can be replayed on the actual network.", run_cmd.network);
}
// Check if the devnet is running with the correct chain id. This is purely
// to avoid accidental setups which would allow for replay attacks. This is
// possible if the devnet has the same chain id as another popular chain,
// allowing txs which occur on it to also be replayed on that other chain.
if run_cmd.devnet && (chain_config.chain_id == ChainId::Mainnet || chain_config.chain_id == ChainId::Sepolia) {
tracing::error!("You're running a devnet with the network config of {0}. This means that devnet transactions can be replayed on the actual {0} network. Use `--network=devnet` instead.", chain_config.chain_name);
anyhow::bail!("Devnet")
}

let node_name = run_cmd.node_name_or_provide().await.to_string();
Expand Down
Loading