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

Add withhold attack mode for interop #5788

Merged
merged 4 commits into from
May 15, 2024
Merged
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 Cargo.lock

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

3 changes: 3 additions & 0 deletions beacon_node/beacon_chain/src/chain_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ pub struct ChainConfig {
pub epochs_per_migration: u64,
/// When set to true Light client server computes and caches state proofs for serving updates
pub enable_light_client_server: bool,
/// Enable malicious PeerDAS mode where node withholds data columns when publishing a block
pub malicious_withhold_count: usize,
}

impl Default for ChainConfig {
Expand Down Expand Up @@ -118,6 +120,7 @@ impl Default for ChainConfig {
always_prepare_payload: false,
epochs_per_migration: crate::migrate::DEFAULT_EPOCHS_PER_MIGRATION,
enable_light_client_server: false,
malicious_withhold_count: 0,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions beacon_node/http_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ sensitive_url = { workspace = true }
store = { workspace = true }
bytes = { workspace = true }
beacon_processor = { workspace = true }
rand = { workspace = true }

[dev-dependencies]
environment = { workspace = true }
Expand Down
15 changes: 15 additions & 0 deletions beacon_node/http_api/src/publish_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use eth2::types::{FullPayloadContents, PublishBlockRequest};
use execution_layer::ProvenancedPayload;
use lighthouse_network::{NetworkGlobals, PubsubMessage};
use network::NetworkMessage;
use rand::seq::SliceRandom;
use slog::{debug, error, info, warn, Logger};
use slot_clock::SlotClock;
use std::marker::PhantomData;
Expand Down Expand Up @@ -71,6 +72,7 @@ pub async fn publish_block<T: BeaconChainTypes, B: IntoGossipVerifiedBlockConten
let block = block_contents.inner_block().clone();
let delay = get_block_delay_ms(seen_timestamp, block.message(), &chain.slot_clock);
debug!(log, "Signed block received in HTTP API"; "slot" => block.slot());
let malicious_withhold_count = chain.config.malicious_withhold_count;

/* actually publish a block */
let publish_block = move |block: Arc<SignedBeaconBlock<T::EthSpec>>,
Expand Down Expand Up @@ -117,6 +119,19 @@ pub async fn publish_block<T: BeaconChainTypes, B: IntoGossipVerifiedBlockConten
}
}
if let Some(data_col_sidecars) = data_cols_opt {
let mut data_col_sidecars = data_col_sidecars.to_vec();
if malicious_withhold_count > 0 {
let columns_to_keep = data_col_sidecars
.len()
.saturating_sub(malicious_withhold_count);
// Randomize columns before dropping the last malicious_withhold_count items
data_col_sidecars.shuffle(&mut rand::thread_rng());
data_col_sidecars = data_col_sidecars
.into_iter()
.take(columns_to_keep)
.collect::<Vec<_>>();
}

for data_col in data_col_sidecars {
let subnet = DataColumnSubnetId::from_column_index::<T::EthSpec>(
data_col.index as usize,
Expand Down
6 changes: 6 additions & 0 deletions beacon_node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
subscribed to all data column subnets.")
.takes_value(false),
)
.arg(
Arg::with_name("malicious-withhold-count")
.long("malicious-withhold-count")
.help("TESTING ONLY do not use this")
.takes_value(true),
)
.arg(
Arg::with_name("subscribe-all-subnets")
.long("subscribe-all-subnets")
Expand Down
6 changes: 3 additions & 3 deletions beacon_node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,10 +443,10 @@ pub fn get_config<E: EthSpec>(
client_config.store.epochs_per_blob_prune = epochs_per_blob_prune;
}

if let Some(blob_prune_margin_epochs) =
clap_utils::parse_optional(cli_args, "blob-prune-margin-epochs")?
if let Some(malicious_withhold_count) =
clap_utils::parse_optional(cli_args, "malicious-withhold-count")?
{
client_config.store.blob_prune_margin_epochs = blob_prune_margin_epochs;
client_config.chain.malicious_withhold_count = malicious_withhold_count;
}

/*
Expand Down
5 changes: 4 additions & 1 deletion book/src/help_bn.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ OPTIONS:

--graffiti <GRAFFITI>
Specify your custom graffiti to be included in blocks. Defaults to the current version and commit, truncated
to fit in 32 bytes.
to fit in 32 bytes.
--historic-state-cache-size <SIZE>
Specifies how many states from the freezer database should cache in memory [default: 1]

Expand Down Expand Up @@ -324,6 +324,9 @@ OPTIONS:
--logfile-max-size <SIZE>
The maximum size (in MB) each log file can grow to before rotating. If set to 0, background file logging is
disabled. [default: 200]
--malicious-withhold-count <malicious-withhold-count>
TESTING ONLY do not use this

--max-skip-slots <NUM_SLOTS>
Refuse to skip more than this many slots when processing an attestation. This prevents nodes on minority
forks from wasting our time and disk space, but could also cause unnecessary consensus failures, so is
Expand Down
7 changes: 7 additions & 0 deletions lighthouse/tests/beacon_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1987,6 +1987,13 @@ fn epochs_per_migration_override() {
.run_with_zero_port()
.with_config(|config| assert_eq!(config.chain.epochs_per_migration, 128));
}
#[test]
fn malicious_withhold_count_flag() {
CommandLineTest::new()
.flag("malicious-withhold-count", Some("128"))
.run_with_zero_port()
.with_config(|config| assert_eq!(config.chain.malicious_withhold_count, 128));
}

// Tests for Slasher flags.
// Using `--slasher-max-db-size` to work around https://github.com/sigp/lighthouse/issues/2342
Expand Down
Loading