Skip to content

Commit

Permalink
malus-collator: implement malicious collator submitting same collatio…
Browse files Browse the repository at this point in the history
…n to all backing groups (#6924)

## Issues
- [[#5049] Elastic scaling: zombienet
tests](#5049)
- [[#4526] Add zombienet tests for malicious
collators](#4526)

## Description
Modified the undying collator to include a malus mode, in which it
submits the same collation to all assigned backing groups.

## TODO
* [X] Implement malicious collator that submits the same collation to
all backing groups;
* [X] Avoid the core index check in the collation generation subsystem:
https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/node/collation-generation/src/lib.rs#L552-L553;
* [X] Resolve the mismatch between the descriptor and the commitments
core index: #7104
* [X] Implement `duplicate_collations` test with zombienet-sdk;
* [X] Add PRdoc.
  • Loading branch information
sw10pa authored Jan 30, 2025
1 parent 07d4b46 commit 48f69cc
Show file tree
Hide file tree
Showing 15 changed files with 596 additions and 35 deletions.
16 changes: 16 additions & 0 deletions .gitlab/pipeline/zombienet/polkadot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -464,3 +464,19 @@ zombienet-polkadot-functional-async-backing-6-seconds-rate:
- unset NEXTEST_FAILURE_OUTPUT
- unset NEXTEST_SUCCESS_OUTPUT
- cargo nextest run --archive-file ./artifacts/polkadot-zombienet-tests.tar.zst --no-capture -- functional::async_backing_6_seconds_rate::async_backing_6_seconds_rate_test

zombienet-polkadot-functional-duplicate-collations:
extends:
- .zombienet-polkadot-common
needs:
- job: build-polkadot-zombienet-tests
artifacts: true
before_script:
- !reference [ ".zombienet-polkadot-common", "before_script" ]
- export POLKADOT_IMAGE="${ZOMBIENET_INTEGRATION_TEST_IMAGE}"
- export X_INFRA_INSTANCE=spot # use spot by default
script:
# we want to use `--no-capture` in zombienet tests.
- unset NEXTEST_FAILURE_OUTPUT
- unset NEXTEST_SUCCESS_OUTPUT
- cargo nextest run --archive-file ./artifacts/polkadot-zombienet-tests.tar.zst --no-capture -- functional::duplicate_collations::duplicate_collations_test
3 changes: 3 additions & 0 deletions Cargo.lock

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

9 changes: 8 additions & 1 deletion polkadot/node/test/service/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
use pallet_staking::Forcing;
use polkadot_primitives::{
AccountId, AssignmentId, SchedulerParams, ValidatorId, MAX_CODE_SIZE, MAX_POV_SIZE,
node_features, AccountId, AssignmentId, NodeFeatures, SchedulerParams, ValidatorId,
MAX_CODE_SIZE, MAX_POV_SIZE,
};
use polkadot_service::chain_spec::Extensions;
use polkadot_test_runtime::BABE_GENESIS_EPOCH_CONFIG;
Expand Down Expand Up @@ -110,6 +111,11 @@ fn polkadot_testnet_genesis(
const ENDOWMENT: u128 = 1_000_000 * DOTS;
const STASH: u128 = 100 * DOTS;

// Prepare node features with V2 receipts enabled.
let mut node_features = NodeFeatures::new();
node_features.resize(node_features::FeatureIndex::CandidateReceiptV2 as usize + 1, false);
node_features.set(node_features::FeatureIndex::CandidateReceiptV2 as u8 as usize, true);

serde_json::json!({
"balances": {
"balances": endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect::<Vec<_>>(),
Expand Down Expand Up @@ -158,6 +164,7 @@ fn polkadot_testnet_genesis(
no_show_slots: 10,
minimum_validation_upgrade_delay: 5,
max_downward_message_size: 1024,
node_features,
scheduler_params: SchedulerParams {
group_rotation_frequency: 20,
paras_availability_period: 4,
Expand Down
2 changes: 2 additions & 0 deletions polkadot/parachain/test-parachains/undying/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ codec = { features = ["derive"], workspace = true }
dlmalloc = { features = ["global"], workspace = true }
log = { workspace = true }
polkadot-parachain-primitives = { features = ["wasm-api"], workspace = true }
polkadot-primitives = { workspace = true, default-features = false }
tiny-keccak = { features = ["keccak"], workspace = true }

# We need to make sure the global allocator is disabled until we have support of full substrate externalities
Expand All @@ -30,5 +31,6 @@ std = [
"codec/std",
"log/std",
"polkadot-parachain-primitives/std",
"polkadot-primitives/std",
"sp-io/std",
]
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ futures-timer = { workspace = true }
log = { workspace = true, default-features = true }

polkadot-cli = { workspace = true, default-features = true }
polkadot-erasure-coding = { workspace = true, default-features = true }
polkadot-node-primitives = { workspace = true, default-features = true }
polkadot-node-subsystem = { workspace = true, default-features = true }
polkadot-primitives = { workspace = true, default-features = true }
polkadot-service = { features = ["rococo-native"], workspace = true, default-features = true }
test-parachain-undying = { workspace = true }

sc-cli = { workspace = true, default-features = true }
sc-client-api = { workspace = true, default-features = true }
sc-service = { workspace = true, default-features = true }
sp-core = { workspace = true, default-features = true }

Expand Down
13 changes: 13 additions & 0 deletions polkadot/parachain/test-parachains/undying/collator/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ pub struct ExportGenesisWasmCommand {
pub output: Option<PathBuf>,
}

/// Enum representing different types of malicious behaviors for collators.
#[derive(Debug, Parser, Clone, PartialEq, clap::ValueEnum)]
pub enum MalusType {
/// No malicious behavior.
None,
/// Submit the same collations to all assigned cores.
DuplicateCollations,
}

#[allow(missing_docs)]
#[derive(Debug, Parser)]
#[group(skip)]
Expand All @@ -81,6 +90,10 @@ pub struct RunCmd {
/// we compute per block.
#[arg(long, default_value_t = 1)]
pub pvf_complexity: u32,

/// Specifies the malicious behavior of the collator.
#[arg(long, value_enum, default_value_t = MalusType::None)]
pub malus_type: MalusType,
}

#[allow(missing_docs)]
Expand Down
Loading

0 comments on commit 48f69cc

Please sign in to comment.