Skip to content

Commit

Permalink
Verify IBFT preprepare proposal block number matches sequence number (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Asa Oines authored and celo-ci-bot-user committed Nov 20, 2019
1 parent 39695bb commit 6ff30e7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
6 changes: 6 additions & 0 deletions consensus/istanbul/core/preprepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ func (c *core) handlePreprepare(msg *istanbul.Message) error {
return errNotFromProposer
}

// Verify that the proposal is for the sequence number of the view we verified.
if preprepare.View.Sequence.Cmp(preprepare.Proposal.Number()) != 0 {
logger.Warn("Received preprepare with invalid block number", "number", preprepare.Proposal.Number(), "view_seq", preprepare.View.Sequence)
return errInvalidProposal
}

// Verify the proposal we received
if duration, err := c.backend.Verify(preprepare.Proposal); err != nil {
logger.Warn("Failed to verify proposal", "err", err, "duration", duration)
Expand Down
36 changes: 27 additions & 9 deletions consensus/istanbul/core/preprepare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,27 @@ func TestHandlePreprepare(t *testing.T) {
nil,
false,
},
{
// proposal sequence doesn't match message sequence
func() *testSystem {
sys := NewTestSystemWithBackend(N, F)

for i, backend := range sys.backends {
c := backend.engine.(*core)
c.valSet = backend.peers
if i != 0 {
c.state = StateAcceptRequest
}
}
return sys
}(),
func(_ *testSystem) istanbul.RoundChangeCertificate {
return istanbul.RoundChangeCertificate{}
},
makeBlock(3),
errInvalidProposal,
false,
},
{
// non-proposer
func() *testSystem {
Expand Down Expand Up @@ -116,14 +137,12 @@ func TestHandlePreprepare(t *testing.T) {
func() *testSystem {
sys := NewTestSystemWithBackend(N, F)

for i, backend := range sys.backends {
for _, backend := range sys.backends {
c := backend.engine.(*core)
c.valSet = backend.peers
if i != 0 {
c.state = StatePreprepared
c.current.SetSequence(big.NewInt(10))
c.current.SetRound(big.NewInt(10))
}
c.state = StatePreprepared
c.current.SetSequence(big.NewInt(10))
c.current.SetRound(big.NewInt(10))
}
return sys
}(),
Expand Down Expand Up @@ -244,7 +263,6 @@ func TestHandlePreprepare(t *testing.T) {
errInvalidPreparedCertificateDigestMismatch,
false,
},

{
// ROUND CHANGE certificate for N+1 round with valid PREPARED certificates
// Round is N+1 to match the correct proposer.
Expand All @@ -262,11 +280,11 @@ func TestHandlePreprepare(t *testing.T) {
return sys
}(),
func(sys *testSystem) istanbul.RoundChangeCertificate {
preparedCertificate := sys.getPreparedCertificate(t, []istanbul.View{*(sys.backends[0].engine.(*core).current.View())}, makeBlock(0))
preparedCertificate := sys.getPreparedCertificate(t, []istanbul.View{*(sys.backends[0].engine.(*core).current.View())}, makeBlock(1))
roundChangeCertificate := sys.getRoundChangeCertificate(t, *(sys.backends[0].engine.(*core).current.View()), preparedCertificate)
return roundChangeCertificate
},
makeBlock(0),
makeBlock(1),
nil,
false,
},
Expand Down

0 comments on commit 6ff30e7

Please sign in to comment.