Skip to content

fix: handle Marshal error in CertificateResult.Hash() - #592

Open
yasinlex wants to merge 1 commit into
canopy-network:mainfrom
yasinlex:fix/unchecked-marshal-error-in-certificate-hash
Open

fix: handle Marshal error in CertificateResult.Hash()#592
yasinlex wants to merge 1 commit into
canopy-network:mainfrom
yasinlex:fix/unchecked-marshal-error-in-certificate-hash

Conversation

@yasinlex

@yasinlex yasinlex commented Sep 5, 2026

Copy link
Copy Markdown

Problem

CertificateResult.Hash() silently ignored the error from Marshal():

func (x *CertificateResult) Hash() []byte {
    bz, _ := Marshal(x)  // error ignored!
    return crypto.Hash(bz)
}

If marshaling fails, this returns a hash of nil bytes, which could lead to incorrect consensus decisions in the BFT protocol.

Changes

lib/certificate.go

  • Hash() now returns ([]byte, ErrorI) instead of []byte
  • Error from Marshal() is properly propagated

bft/bft.go (6 call sites)

  • StartProposePhase(): compute hash before struct literal, return on error
  • StartProposeVotePhase(): compute hash before sending vote
  • StartPrecommitPhase(): compute hash before sending precommit
  • StartPrecommitVotePhase(): compute hash before sending vote
  • StartCommitPhase(): compute hash before sending commit
  • CheckProposerAndProposal(): handle error when comparing hashes
  • SafeNode(): handle error when validating HighQC

bft/msg.go

  • GetValidateMessageParams(): handle error when computing results hash

controller/consensus.go

  • Handle error when populating consensus summary

Impact

  • Before: Marshal failure → hash of nil bytes → potential consensus divergence
  • After: Marshal failure → error propagated → BFT handles gracefully

Previously, CertificateResult.Hash() silently ignored the error from
Marshal(), which could return a hash of nil bytes if marshaling failed.
This could lead to incorrect consensus decisions.

Changes:
- Hash() now returns ([]byte, ErrorI) instead of []byte
- Updated all callers in bft/bft.go, bft/msg.go, and controller/consensus.go
- Errors are properly propagated to callers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants