Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBFT: Ensure that Committed Seal is not zero value #1118

Merged
merged 14 commits into from
Sep 30, 2021
4 changes: 2 additions & 2 deletions consensus/istanbul/ibft/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ func (c *core) finalizeMessage(msg *ibfttypes.Message) ([]byte, error) {
// Add sender address
msg.Address = c.Address()

// Add proof of consensus
msg.CommittedSeal = []byte{}
// Assign the CommittedSeal if it's a COMMIT message and proposal is not nil
if msg.Code == ibfttypes.MsgCommit && c.current.Proposal() != nil {
msg.CommittedSeal = []byte{}
ricardolyn marked this conversation as resolved.
Show resolved Hide resolved
seal := PrepareCommittedSeal(c.current.Proposal().Hash())
// Add proof of consensus
msg.CommittedSeal, err = c.backend.Sign(seal)
if err != nil {
return nil, err
Expand Down
32 changes: 32 additions & 0 deletions consensus/istanbul/ibft/core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus/istanbul"
ibfttypes "github.com/ethereum/go-ethereum/consensus/istanbul/ibft/types"
"github.com/ethereum/go-ethereum/core/types"
elog "github.com/ethereum/go-ethereum/log"
)
Expand Down Expand Up @@ -95,3 +96,34 @@ func TestQuorumSize(t *testing.T) {
}
}
}

func TestNilCommittedSealWithEmptyProposal(t *testing.T) {
N := uint64(4)
F := uint64(1)

sys := NewTestSystemWithBackend(N, F)
backend := sys.backends[0]
c := backend.engine
// Set the current round state with an empty proposal
preprepare := &istanbul.Preprepare{
View: c.currentView(),
}
c.current.SetPreprepare(preprepare)

// Create a Commit message
subject := &istanbul.Subject{
View: c.currentView(),
Digest: common.StringToHash("1234567890"),
}
subjectPayload, _ := ibfttypes.Encode(subject)
vdamle marked this conversation as resolved.
Show resolved Hide resolved
msg := &ibfttypes.Message{
Code: ibfttypes.MsgCommit,
Msg: subjectPayload,
}

c.finalizeMessage(msg)

if msg.CommittedSeal != nil {
t.Errorf("Unexpected committed seal: %s", msg.CommittedSeal)
}
}