Skip to content

Commit f030b75

Browse files
SignedSSVMessage and SSVMessage validation (sigp#160)
Co-authored-by: Zachary Holme <zacholme@gmail.com>
1 parent ea73bd0 commit f030b75

File tree

17 files changed

+683
-301
lines changed

17 files changed

+683
-301
lines changed

Cargo.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

anchor/common/qbft/src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,9 @@ where
214214
&self,
215215
wrapped_msg: &WrappedQbftMessage,
216216
) -> Option<(Option<ValidData<D>>, OperatorId)> {
217-
// Validate the wrapped message. This will validate the SignedSsvMessage and the QbftMessage
218-
if !wrapped_msg.validate() {
219-
warn!("Message validation unsuccessful");
217+
// Validate the qbft message
218+
if !wrapped_msg.qbft_message.validate() {
219+
warn!("Invalid qbft_message");
220220
return None;
221221
}
222222

@@ -927,7 +927,8 @@ where
927927
MsgType::SSVConsensusMsgType,
928928
self.identifier.clone(),
929929
qbft_message.as_ssz_bytes(),
930-
);
930+
)
931+
.expect("SSVMessage should be valid."); //TODO revisit this
931932

932933
// Wrap in unsigned SSV message
933934
UnsignedSSVMessage {

anchor/common/qbft/src/qbft_types.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,6 @@ pub struct WrappedQbftMessage {
5050
pub qbft_message: QbftMessage,
5151
}
5252

53-
impl WrappedQbftMessage {
54-
// Validate that the message is well formed
55-
pub fn validate(&self) -> bool {
56-
self.signed_message.validate() && self.qbft_message.validate()
57-
}
58-
}
59-
6053
/// This represents an individual round, these change on regular time intervals
6154
#[derive(Clone, Copy, Debug, Deref, PartialEq, Eq, Hash, PartialOrd, Ord)]
6255
pub struct Round(NonZeroUsize);

anchor/common/qbft/src/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use super::*;
66
use qbft_types::DefaultLeaderFunction;
77
use sha2::{Digest, Sha256};
88
use ssv_types::consensus::UnsignedSSVMessage;
9-
use ssv_types::message::SignedSSVMessage;
9+
use ssv_types::message::{SignedSSVMessage, RSA_SIGNATURE_SIZE};
1010
use ssv_types::OperatorId;
1111
use ssz_derive::{Decode, Encode};
1212
use std::cell::RefCell;
@@ -46,7 +46,7 @@ fn convert_unsigned_to_wrapped(
4646
) -> WrappedQbftMessage {
4747
// Create a signed message containing just this operator
4848
let signed_message = SignedSSVMessage::new(
49-
vec![vec![0; 96]], // Test signature of 96 bytes
49+
vec![vec![0; RSA_SIGNATURE_SIZE]],
5050
vec![OperatorId(*operator_id)],
5151
msg.ssv_message.clone(),
5252
msg.full_data,

anchor/common/ssv_types/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ indexmap = { workspace = true }
1414
openssl = { workspace = true }
1515
rusqlite = { workspace = true }
1616
sha2 = { workspace = true }
17+
thiserror = { workspace = true }
1718
tree_hash = { workspace = true }
1819
tree_hash_derive = { workspace = true }
1920
types = { workspace = true }

anchor/common/ssv_types/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ pub mod partial_sig;
1313
mod share;
1414
mod sql_conversions;
1515
mod util;
16+
17+
pub use share::ENCRYPTED_KEY_LENGTH;

0 commit comments

Comments
 (0)