Skip to content

Commit

Permalink
feat: Misbehavior Reporting and verification on chain (#453)
Browse files Browse the repository at this point in the history
  • Loading branch information
shekohex authored Feb 8, 2024
1 parent 68fca9b commit 19ed43b
Show file tree
Hide file tree
Showing 34 changed files with 2,522 additions and 179 deletions.
427 changes: 389 additions & 38 deletions Cargo.lock

Large diffs are not rendered by default.

105 changes: 67 additions & 38 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,48 @@ repository = "https://github.com/webb-tools/tangle"

[workspace]
members = [
"primitives",
"primitives/crypto",
"primitives/rpc/*",
"primitives/ext",
"client/evm-tracing",
"client/rpc/*",
"client/rpc-core/*",
"client/voter",
"node",
"runtime/testnet",
"runtime/testnet/evm_tracer",
"runtime/mainnet",
"pallets/*",
"pallets/jobs/rpc",
"pallets/jobs/rpc/runtime-api",
"pallets/dkg/frost",
"pallets/dkg/frost/frost-*",
"precompiles/utils",
"precompiles/utils/macro",
"precompiles/utils/tests-external",
"precompiles/pallet-democracy",
"precompiles/batch",
"precompiles/call-permit",
"precompiles/proxy",
"precompiles/preimage",
"precompiles/jobs",
# "relayer-gadget",
# "relayer-gadget/cli",
"primitives",
"primitives/crypto",
"primitives/rpc/*",
"primitives/ext",
"client/evm-tracing",
"client/rpc/*",
"client/rpc-core/*",
"client/voter",
"node",
"runtime/testnet",
"runtime/testnet/evm_tracer",
"runtime/mainnet",
"pallets/*",
"pallets/jobs/rpc",
"pallets/jobs/rpc/runtime-api",
"pallets/dkg/frost",
"pallets/dkg/frost/frost-*",
"precompiles/utils",
"precompiles/utils/macro",
"precompiles/utils/tests-external",
"precompiles/pallet-democracy",
"precompiles/batch",
"precompiles/call-permit",
"precompiles/proxy",
"precompiles/preimage",
"precompiles/jobs",
# "relayer-gadget",
# "relayer-gadget/cli",
]
resolver = "2"

[workspace.dependencies]
smallvec = "1.6.1"
substrate-wasm-builder = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
substrate-build-script-utils = "3.0.0"
subtle = { version = "2.2", default-features = false }
hex-literal = "0.4.1"
log = { version = "0.4.20", default-features = false }
scale-info = { version = "2.9.0", default-features = false, features = ["derive"] }
serde = { version = "1.0.101", default-features = false, features = ["derive"] }
serde_json = "1.0.81"
serde = { version = "1.0", default-features = false, features = ["derive"] }
serde_json = { version = "1.0", default-features = false }
serde_with = { version = "3.6", default-features = false }
serdect = { version = "0.2.0", default-features = false }
static_assertions = "1.1.0"
clap = { version = "4.4.2", features = ["derive"] }
Expand All @@ -56,9 +58,9 @@ rlp = { version = "0.5", default-features = false }
tracing = "0.1.34"
tokio = { version = "1.13" }
futures = { version = "0.3.16" }
rand = "0.7.2"
rand_core = "0.6.4"
smallvec = "1.6.1"
rand_core = { version = "0.6", default-features = false }
rand_chacha = { version = "0.3", default-features = false }
rand = { version = "0.7.2", default-features = false }
async-trait = "0.1.59"
libsecp256k1 = { version = "0.7.0", default-features = false }
rustc-hex = { version = "2.1.0", default-features = false }
Expand All @@ -68,7 +70,9 @@ affix = "0.1.2"
environmental = { version = "1.1.4", default-features = false }
assert_matches = "1.3.0"
impl-trait-for-tuples = "0.2.2"
sha2 = { version = "0.10.1", default-features = false }
sha3 = { version = "0.10.1", default-features = false }
digest = { version = "0.10.1", default-features = false }
similar-asserts = { version = "1.1.0" }
proc-macro2 = "1.0"
quote = "1.0"
Expand All @@ -77,7 +81,7 @@ hex = { version = "0.4.3", default-features = false }
paste = "1.0.6"
slices = "0.2.0"
schnorrkel = { version = "0.9.1", default-features = false }
blst = "0.3.11"
snowbridge-milagro-bls = { git = "https://github.com/Snowfork/milagro_bls", default-features = false, rev = "43a5d480ed6e3b83de4cf54888680d51604199e6" }


tangle-testnet-runtime = { package = "tangle-testnet-runtime", path = "runtime/testnet" }
Expand Down Expand Up @@ -242,13 +246,19 @@ fc-storage = { git = "https://github.com/paritytech/frontier.git", branch = "pol
fc-api = { git = "https://github.com/paritytech/frontier.git", branch = "polkadot-v1.1.0" }

# Frontier Primitive
fp-account = { git = "https://github.com/paritytech/frontier.git", branch = "polkadot-v1.1.0", default-features = false, features = ["serde"] }
fp-account = { git = "https://github.com/paritytech/frontier.git", branch = "polkadot-v1.1.0", default-features = false, features = [
"serde",
] }
fp-consensus = { git = "https://github.com/paritytech/frontier.git", branch = "polkadot-v1.1.0", default-features = false }
fp-dynamic-fee = { git = "https://github.com/paritytech/frontier.git", branch = "polkadot-v1.1.0", default-features = false }
fp-ethereum = { git = "https://github.com/paritytech/frontier.git", branch = "polkadot-v1.1.0", default-features = false }
fp-evm = { git = "https://github.com/paritytech/frontier.git", branch = "polkadot-v1.1.0", default-features = false, features = ["serde"] }
fp-evm = { git = "https://github.com/paritytech/frontier.git", branch = "polkadot-v1.1.0", default-features = false, features = [
"serde",
] }
fp-rpc = { git = "https://github.com/paritytech/frontier.git", branch = "polkadot-v1.1.0", default-features = false }
fp-self-contained = { git = "https://github.com/paritytech/frontier.git", branch = "polkadot-v1.1.0", default-features = false, features = ["serde"] }
fp-self-contained = { git = "https://github.com/paritytech/frontier.git", branch = "polkadot-v1.1.0", default-features = false, features = [
"serde",
] }
fp-storage = { git = "https://github.com/paritytech/frontier.git", branch = "polkadot-v1.1.0", default-features = false }

# Frontier FRAME
Expand Down Expand Up @@ -306,7 +316,10 @@ pallet-eth2-light-client-relayer-gadget-cli = { git = "https://github.com/webb-t
webb-consensus-types = { git = "https://github.com/webb-tools/pallet-eth2-light-client", default-features = false, tag = "v0.5.0" }

webb = { git = "https://github.com/webb-tools/webb-rs.git", default-features = false }
webb-proposals = { git = "https://github.com/webb-tools/webb-rs.git", default-features = false, features = ["scale", "evm"] }
webb-proposals = { git = "https://github.com/webb-tools/webb-rs.git", default-features = false, features = [
"scale",
"evm",
] }

primitives-ext = { path = "primitives/ext", default-features = false }
evm-tracing-events = { path = "primitives/rpc/evm-tracing-events", default-features = false }
Expand All @@ -323,5 +336,21 @@ rpc-trace = { path = "client/rpc/trace" }
rpc-txpool = { path = "client/rpc/txpool" }
evm-tracer = { path = "runtime/testnet/evm_tracer", default-features = false }

# MPC
malachite = { version = "0.4", default-features = false }
postcard = { version = "1", default-features = false }
dfns-cggmp21 = { package = "cggmp21", version = "0.1.1", default-features = false }
udigest = { version = "0.1.0", default-features = false }
generic-ec = { version = "0.1", default-features = false }
generic-ec-zkp = { version = "0.1", default-features = false }
round-based = { version = "0.2", default-features = false }
paillier-zk = { version = "0.1", default-features = false }

[profile.release]
panic = "unwind"

[patch.crates-io]
generic-ec = { git = "https://github.com/webb-tools/generic-ec", branch = "m" }
generic-ec-core = { git = "https://github.com/webb-tools/generic-ec", branch = "m" }
generic-ec-curves = { git = "https://github.com/webb-tools/generic-ec", branch = "m" }
generic-ec-zkp = { git = "https://github.com/webb-tools/generic-ec", branch = "m" }
4 changes: 2 additions & 2 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ sc-transaction-pool = { workspace = true }
sp-consensus-babe = { workspace = true }
sp-keyring = { workspace = true }
sp-trie = { workspace = true }
webb-proposals = { workspace = true, default-features = false }
webb-consensus-types = { workspace = true }
webb-proposals = { workspace = true }

sp-consensus-grandpa = { workspace = true, features = ["default"] }
sp-core = { workspace = true, features = ["default"] }
Expand Down Expand Up @@ -153,4 +153,4 @@ rocksdb = [
sql = ["fc-db/sql", "fc-mapping-sync/sql"]
testnet = ["tangle-testnet-runtime"]
txpool = ["fc-rpc/txpool"]
fast-runtime = ["tangle-testnet-runtime/fast-runtime", "tangle-runtime/fast-runtime"]
fast-runtime = ["tangle-testnet-runtime/fast-runtime", "tangle-runtime/fast-runtime"]
87 changes: 52 additions & 35 deletions pallets/dkg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ frame-support = { workspace = true }
frame-system = { workspace = true }
parity-scale-codec = { workspace = true }
scale-info = { workspace = true }
serde = { workspace = true }
serde = { workspace = true, default-features = false, features = ["derive"] }
serde_with = { workspace = true, default-features = false, features = ["macros"] }
serdect = { workspace = true, features = ["alloc"] }
sp-core = { workspace = true }
sp-io = { workspace = true }
Expand All @@ -22,60 +23,76 @@ sp-std = { workspace = true }
subtle = { workspace = true }
tangle-crypto-primitives = { workspace = true, default-features = false }
tangle-primitives = { workspace = true, default-features = false }
frost-core = { package = "frost-core", workspace = true, default-features = false }
frost-ed25519 = { package = "frost-ed25519", workspace = true, default-features = false }
rand_core = { workspace = true, default-features = false }

# dfns/CGGMP21 specific dependencies
hex = { workspace = true, default-features = false, features = ["serde"] }
postcard = { workspace = true, default-features = false }
sha2 = { workspace = true, default-features = false }
digest = { workspace = true, default-features = false }
udigest = { workspace = true, features = ["derive"] }
generic-ec = { workspace = true, default-features = false, features = ["serde", "udigest", "curve-secp256k1"] }
generic-ec-zkp = { workspace = true, default-features = false, features = ["serde", "udigest", "alloc"] }
frost-core = { workspace = true, default-features = false }
frost-ed25519 = { workspace = true, default-features = false }
elliptic-curve = { version = "0.13", features = ["hash2curve"], default-features = false }
frost-ed448 = { package = "frost-ed448", workspace = true, default-features = false }
frost-ristretto255 = { package = "frost-ristretto255", workspace = true, default-features = false }
frost-secp256k1 = { package = "frost-secp256k1", workspace = true, default-features = false }
frost-p256 = { package = "frost-p256", workspace = true, default-features = false }
frost-p384 = { package = "frost-p384", workspace = true, default-features = false }
blst = { workspace = true, default-features = false, features = ["portable", "no-threads"] }
frost-ed448 = { workspace = true, default-features = false }
frost-ristretto255 = { workspace = true, default-features = false }
frost-secp256k1 = { workspace = true, default-features = false }
frost-p256 = { workspace = true, default-features = false }
frost-p384 = { workspace = true, default-features = false }
snowbridge-milagro-bls = { workspace = true, default-features = false }

# FROST RedJubjub is not yet no_std compatible
# TODO: Update this once it is.
# frost-redjubjub = { package = "frost-redjubjub", workspace = true, default-features = false }

[dev-dependencies]
pallet-balances = { workspace = true }
postcard = { workspace = true, default-features = false, features = ["alloc"] }
smallvec = { workspace = true }
sp-keystore = { workspace = true }
rand_chacha = { workspace = true }
dfns-cggmp21 = { workspace = true, default-features = false, features = ["curve-secp256k1"] }
round-based = { workspace = true, features = ["derive"] }
paillier-zk = { workspace = true, features = ["serde"] }
rand_core = { workspace = true }
frost-core = { workspace = true }
paste = { workspace = true }

[features]
default = ["std"]
std = [
"parity-scale-codec/std",
"scale-info/std",
"sp-runtime/std",
"frame-support/std",
"frame-system/std",
"sp-core/std",
"sp-std/std",
"tangle-primitives/std",
"tangle-crypto-primitives/std",
"pallet-balances/std",
"sp-io/std",
"sp-keystore/std",
"parity-scale-codec/std",
"scale-info/std",
"sp-runtime/std",
"frame-support/std",
"frame-system/std",
"sp-core/std",
"sp-std/std",
"tangle-primitives/std",
"tangle-crypto-primitives/std",
"pallet-balances/std",
"sp-io/std",
"sp-keystore/std",

"frost-core/std",
"frost-ed25519/std",
"elliptic-curve/std",
"frost-ed448/std",
"frost-ristretto255/std",
"frost-secp256k1/std",
"frost-p256/std",
"frost-p384/std",
# "frost-redjubjub/std",
"frost-core/std",
"frost-ed25519/std",
"elliptic-curve/std",
"frost-ed448/std",
"frost-ristretto255/std",
"frost-secp256k1/std",
"frost-p256/std",
"frost-p384/std",
# "frost-redjubjub/std",
"snowbridge-milagro-bls/std",
]
serde = []
try-runtime = ["frame-support/try-runtime"]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
]
32 changes: 3 additions & 29 deletions pallets/dkg/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use sp_core::Get;
use tangle_primitives::jobs::*;

use self::signatures_schemes::{
bls12_381::verify_dkg_signature_bls12_381,
ecdsa::{verify_dkg_signature_ecdsa, verify_generated_dkg_key_ecdsa},
schnorr_frost::verify_dkg_signature_schnorr_frost,
schnorr_sr25519::{
Expand Down Expand Up @@ -146,7 +147,8 @@ impl<T: Config> Pallet<T> {
&data.signature,
&data.signing_key,
),
DigitalSignatureScheme::Bls381 => Self::verify_bls_signature(&data),
DigitalSignatureScheme::Bls381 =>
verify_dkg_signature_bls12_381::<T>(&data.data, &data.signature, &data.signing_key),
DigitalSignatureScheme::SchnorrEd25519 |
DigitalSignatureScheme::SchnorrEd448 |
DigitalSignatureScheme::SchnorrP256 |
Expand Down Expand Up @@ -199,32 +201,4 @@ impl<T: Config> Pallet<T> {
_ => Err(Error::<T>::InvalidSignature.into()), // unimplemented
}
}

/// Verifies the DKG signature result for BLS signatures.
///
/// This function uses the BLS signature algorithm to verify the provided signature
/// based on the message data, signature, and signing key in the DKG signature result.
///
/// # Arguments
///
/// * `data` - The DKG signature result containing the message data, BLS signature, and signing
/// key.
fn verify_bls_signature(
data: &DKGTSSSignatureResult<T::MaxDataLen, T::MaxKeyLen, T::MaxSignatureLen>,
) -> DispatchResult {
let public_key = blst::min_pk::PublicKey::deserialize(&data.signing_key)
.map_err(|_err| Error::<T>::InvalidBlsPublicKey)?;
let signature = blst::min_pk::Signature::deserialize(&data.signature)
.map_err(|_err| Error::<T>::InvalidSignatureData)?;
let dst = &mut [0u8; 48];
let signed_data = &data.data;

if signature.verify(true, signed_data, dst, &[], &public_key, true) !=
blst::BLST_ERROR::BLST_SUCCESS
{
return Err(Error::<T>::InvalidSignature.into())
}

Ok(())
}
}
Loading

0 comments on commit 19ed43b

Please sign in to comment.