Skip to content

Commit

Permalink
Use canonical(borsh) serialization when checking block body size
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash-L2L committed Nov 25, 2024
1 parent 6e7a433 commit 3f31b56
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 0 additions & 2 deletions lib/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ pub enum Error {
AmountUnderflow(#[from] AmountUnderflowError),
#[error("archive error")]
Archive(#[from] archive::Error),
#[error("bincode error")]
Bincode(#[from] bincode::Error),
#[error("CUSF mainchain proto error")]
CusfMainchain(#[from] proto::Error),
#[error("heed error")]
Expand Down
8 changes: 5 additions & 3 deletions lib/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ pub enum Error {
AmountOverflow(#[from] AmountOverflowError),
#[error(transparent)]
AmountUnderflow(#[from] AmountUnderflowError),
#[error("binvode error")]
Bincode(#[from] bincode::Error),
#[error("body too large")]
BodyTooLarge,
#[error(transparent)]
BorshSerialize(borsh::io::Error),
#[error("invalid body: expected merkle root {expected}, but computed {computed}")]
InvalidBody {
expected: MerkleRoot,
Expand Down Expand Up @@ -505,7 +505,9 @@ impl State {
if body.authorizations.len() > Self::body_sigops_limit(height) {
return Err(Error::TooManySigops);
}
if bincode::serialize(&body)?.len() > Self::body_size_limit(height) {
let body_size =
borsh::object_length(&body).map_err(Error::BorshSerialize)?;
if body_size > Self::body_size_limit(height) {
return Err(Error::BodyTooLarge);
}
let mut accumulator = self
Expand Down
2 changes: 1 addition & 1 deletion lib/types/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ pub struct AuthorizedTransaction {
pub authorizations: Vec<Authorization>,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[derive(BorshSerialize, Clone, Debug, Deserialize, Serialize)]
pub struct Body {
pub coinbase: Vec<Output>,
pub transactions: Vec<Transaction>,
Expand Down

0 comments on commit 3f31b56

Please sign in to comment.