Skip to content

Commit

Permalink
fix critical vulnerability in ismp-grandpa
Browse files Browse the repository at this point in the history
  • Loading branch information
seunlanlege committed Jan 28, 2025
1 parent 5613582 commit f0e85db
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 39 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,13 @@ geth-primitives = { path = "./modules/consensus/geth-primitives", default-featur
sync-committee-primitives = { path = "./modules/consensus/sync-committee/primitives", default-features = false }
sync-committee-prover = { path = "./modules/consensus/sync-committee/prover" }
sync-committee-verifier = { path = "./modules/consensus/sync-committee/verifier", default-features = false }
grandpa-verifier-primitives = { version = "0.1.1", path = "./modules/consensus/grandpa/primitives", default-features = false }
grandpa-verifier = { version = "0.1.1", path = "./modules/consensus/grandpa/verifier", default-features = false }
grandpa-verifier-primitives = { version = "0.1.2", path = "./modules/consensus/grandpa/primitives", default-features = false }
grandpa-verifier = { version = "0.1.2", path = "./modules/consensus/grandpa/verifier", default-features = false }
grandpa-prover = { path = "./modules/consensus/grandpa/prover" }

# consensus clients
ismp-bsc = { path = "./modules/ismp/clients/bsc", default-features = false }
ismp-grandpa = { version = "15.0.0", path = "./modules/ismp/clients/grandpa", default-features = false }
ismp-grandpa = { version = "15.0.1", path = "./modules/ismp/clients/grandpa", default-features = false }
ismp-parachain = { version = "15.0.1", path = "./modules/ismp/clients/parachain/client", default-features = false }
ismp-parachain-inherent = { version = "15.0.0", path = "./modules/ismp/clients/parachain/inherent" }
ismp-parachain-runtime-api = { version = "15.0.0", path = "./modules/ismp/clients/parachain/runtime-api", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion modules/consensus/grandpa/primitives/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "grandpa-verifier-primitives"
version = "0.1.1"
version = "0.1.2"
edition = "2021"
authors = ["Polytope Labs <hello@polytope.technology>"]
license = "Apache-2.0"
Expand Down
15 changes: 2 additions & 13 deletions modules/consensus/grandpa/primitives/src/justification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use sp_consensus_grandpa::{
ScheduledChange, SetId, GRANDPA_ENGINE_ID,
};
use sp_core::ed25519;
use sp_runtime::{generic::OpaqueDigestItemId, traits::Header as HeaderT};
use sp_runtime::{generic::OpaqueDigestItemId, traits::Header as HeaderT, RuntimeAppPublic};
use sp_std::prelude::*;

/// A GRANDPA justification for block finality, it includes a commit message and
Expand Down Expand Up @@ -243,20 +243,9 @@ where
H: Encode,
N: Encode,
{
log::trace!(target: "pallet_grandpa", "Justification Message {:?}", (round, set_id));
let buf = (message, round, set_id).encode();

let signature_bytes: &[u8] = signature.as_ref();
let sp_finality_signature: ed25519::Signature = signature_bytes
.try_into()
.map_err(|err| anyhow!("Failed to convert ed25519 signature: {err:#?}"))?;

let id_bytes: &[u8] = id.as_ref();
let pub_key: ed25519::Public = id_bytes
.try_into()
.map_err(|err| anyhow!("Failed to convert public key: {err:#?}"))?;

if !sp_io::crypto::ed25519_verify(&sp_finality_signature, &buf, &pub_key) {
if !id.verify(&buf, signature) {
Err(anyhow!("invalid signature for precommit in grandpa justification"))?
}

Expand Down
2 changes: 1 addition & 1 deletion modules/consensus/grandpa/prover/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ where

Ok(ConsensusState {
current_authorities,
current_set_id: current_set_id + 1,
current_set_id,
latest_height,
latest_hash: hash.into(),
slot_duration,
Expand Down
4 changes: 2 additions & 2 deletions modules/consensus/grandpa/verifier/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "grandpa-verifier"
version = "0.1.1"
version = "0.1.2"
edition = "2021"
authors = ["Polytope Labs <hello@polytope.technology>"]
license = "Apache-2.0"
Expand All @@ -14,7 +14,7 @@ keywords = ["substrate", "polkadot-sdk", "ISMP", "interoperability", "GRANDPA"]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { workspace = true, features = ["derive"]}
codec = { workspace = true, features = ["derive"] }
anyhow = { workspace = true, default-features = false }
finality-grandpa = { version = "0.16.0", features = ["derive-codec"], default-features = false }
serde = { workspace = true, features = ["derive"] }
Expand Down
4 changes: 2 additions & 2 deletions modules/consensus/grandpa/verifier/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async fn follow_grandpa_justifications() {
let relay_ws_url = std::env::var("RELAY_HOST")
.unwrap_or_else(|_| "wss://hyperbridge-paseo-relay.blockops.network:443".to_string());

let para_ids = vec![2000];
let para_ids = vec![1000];

println!("Connecting to relay chain {relay_ws_url}");
let prover = GrandpaProver::<subxt_utils::BlakeSubstrateChain>::new(ProverOptions {
Expand Down Expand Up @@ -85,7 +85,7 @@ async fn follow_grandpa_justifications() {

// slot duration in milliseconds for parachains
let slot_duration = 6000;
let hash = prover.client.rpc().block_hash(Some(10u64.into())).await.unwrap().unwrap();
let hash = prover.client.rpc().finalized_head().await.unwrap();
let mut consensus_state = prover.initialize_consensus_state(slot_duration, hash).await.unwrap();
println!("Grandpa proofs are now available");
while let Some(Ok(_)) = subscription.next().await {
Expand Down
14 changes: 11 additions & 3 deletions modules/ismp/clients/grandpa/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ismp-grandpa"
version = "15.0.0"
version = "15.0.1"
edition = "2021"
authors = ["Polytope Labs <hello@polytope.technology>"]
license = "Apache-2.0"
Expand All @@ -15,9 +15,7 @@ readme = "./README.md"
anyhow = { workspace = true }
codec = { workspace = true, features = ["derive"] }
primitive-types = { workspace = true }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
merkle-mountain-range = { workspace = true }
finality-grandpa = { version = "0.16.0", features = ["derive-codec"], default-features = false }
frame-benchmarking = { workspace = true, optional = true }
sp-std = { workspace = true }

Expand All @@ -39,6 +37,16 @@ sp-core = { workspace = true }
# cumulus
substrate-state-machine = { workspace = true }

[dependencies.scale-info]
version = "2.1.1"
default-features = false
features = ["derive"]

[dependencies.finality-grandpa]
version = "0.16.0"
features = ["derive-codec"]
default-features = false

[features]
default = ["std"]
std = [
Expand Down
21 changes: 10 additions & 11 deletions parachain/runtimes/nexus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ impl Contains<RuntimeCall> for IsTreasurySpend {
fn contains(c: &RuntimeCall) -> bool {
matches!(
c,
RuntimeCall::Treasury(pallet_treasury::Call::spend { .. })
| RuntimeCall::Treasury(pallet_treasury::Call::spend_local { .. })
RuntimeCall::Treasury(pallet_treasury::Call::spend { .. }) |
RuntimeCall::Treasury(pallet_treasury::Call::spend_local { .. })
)
}
}
Expand Down Expand Up @@ -764,20 +764,19 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
fn filter(&self, c: &RuntimeCall) -> bool {
match self {
ProxyType::Any => true,
ProxyType::NonTransfer => {
!matches!(c, RuntimeCall::Balances { .. } | RuntimeCall::Assets { .. })
},
ProxyType::NonTransfer =>
!matches!(c, RuntimeCall::Balances { .. } | RuntimeCall::Assets { .. }),
ProxyType::CancelProxy => matches!(
c,
RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. })
| RuntimeCall::Utility { .. }
| RuntimeCall::Multisig { .. }
RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }) |
RuntimeCall::Utility { .. } |
RuntimeCall::Multisig { .. }
),
ProxyType::Collator => matches!(
c,
RuntimeCall::CollatorSelection { .. }
| RuntimeCall::Utility { .. }
| RuntimeCall::Multisig { .. }
RuntimeCall::CollatorSelection { .. } |
RuntimeCall::Utility { .. } |
RuntimeCall::Multisig { .. }
),
}
}
Expand Down

0 comments on commit f0e85db

Please sign in to comment.