Skip to content

Commit

Permalink
Move DKG message size limit check into SuiTxValidator (#17735)
Browse files Browse the repository at this point in the history
  • Loading branch information
aschran authored May 28, 2024
1 parent 7b19a35 commit 60aed80
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 32 deletions.
40 changes: 12 additions & 28 deletions crates/sui-core/src/authority/authority_per_epoch_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3283,22 +3283,13 @@ impl AuthorityPerEpochStore {
"Received RandomnessDkgMessage from {:?}",
authority.concise()
);
if bytes.len() > dkg::DKG_MESSAGES_MAX_SIZE {
warn!(
"Ignoring RandomnessDkgMessage from {:?} because it is too large",
authority.concise()
);
} else {
match bcs::from_bytes(bytes) {
Ok(message) => {
randomness_manager.add_message(authority, message)?
}
Err(e) => {
warn!(
match bcs::from_bytes(bytes) {
Ok(message) => randomness_manager.add_message(authority, message)?,
Err(e) => {
warn!(
"Failed to deserialize RandomnessDkgMessage from {:?}: {e:?}",
authority.concise(),
);
}
}
}
} else {
Expand All @@ -3325,24 +3316,17 @@ impl AuthorityPerEpochStore {
"Received RandomnessDkgConfirmation from {:?}",
authority.concise()
);
if bytes.len() > dkg::DKG_MESSAGES_MAX_SIZE {
warn!(
"Ignoring RandomnessDkgConfirmation from {:?} because it is too large",
authority.concise()
);
} else {
match bcs::from_bytes(bytes) {
Ok(confirmation) => randomness_manager.add_confirmation(
batch,
authority,
confirmation,
)?,
Err(e) => {
warn!(
match bcs::from_bytes(bytes) {
Ok(confirmation) => randomness_manager.add_confirmation(
batch,
authority,
confirmation,
)?,
Err(e) => {
warn!(
"Failed to deserialize RandomnessDkgMessage from {:?}: {e:?}",
authority.concise(),
);
}
}
}
} else {
Expand Down
22 changes: 18 additions & 4 deletions crates/sui-core/src/consensus_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ use std::sync::Arc;

use consensus_core::{TransactionVerifier, ValidationError};
use eyre::WrapErr;
use fastcrypto_tbls::dkg;
use mysten_metrics::monitored_scope;
use narwhal_types::{validate_batch_version, BatchAPI};
use narwhal_worker::TransactionValidator;
use prometheus::{register_int_counter_with_registry, IntCounter, Registry};
use sui_protocol_config::ProtocolConfig;
use sui_types::messages_consensus::{ConsensusTransaction, ConsensusTransactionKind};
use sui_types::{
error::SuiError,
messages_consensus::{ConsensusTransaction, ConsensusTransactionKind},
};
use tap::TapFallible;
use tracing::{info, warn};

Expand Down Expand Up @@ -69,12 +73,22 @@ impl SuiTxValidator {
ckpt_messages.push(signature.clone());
ckpt_batch.push(signature.summary);
}
ConsensusTransactionKind::RandomnessDkgMessage(_, bytes) => {
if bytes.len() > dkg::DKG_MESSAGES_MAX_SIZE {
warn!("batch verification error: DKG Message too large");
return Err(SuiError::InvalidDkgMessageSize.into());
}
}
ConsensusTransactionKind::RandomnessDkgConfirmation(_, bytes) => {
if bytes.len() > dkg::DKG_MESSAGES_MAX_SIZE {
warn!("batch verification error: DKG Confirmation too large");
return Err(SuiError::InvalidDkgMessageSize.into());
}
}
ConsensusTransactionKind::EndOfPublish(_)
| ConsensusTransactionKind::CapabilityNotification(_)
| ConsensusTransactionKind::NewJWKFetched(_, _, _)
| ConsensusTransactionKind::RandomnessStateUpdate(_, _)
| ConsensusTransactionKind::RandomnessDkgMessage(_, _)
| ConsensusTransactionKind::RandomnessDkgConfirmation(_, _) => {}
| ConsensusTransactionKind::RandomnessStateUpdate(_, _) => {}
}
}

Expand Down
2 changes: 2 additions & 0 deletions crates/sui-types/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,8 @@ pub enum SuiError {

#[error("Invalid digest length. Expected {expected}, got {actual}")]
InvalidDigestLength { expected: usize, actual: usize },
#[error("Invalid DKG message size")]
InvalidDkgMessageSize,

#[error("Unexpected message.")]
UnexpectedMessage,
Expand Down

0 comments on commit 60aed80

Please sign in to comment.