Skip to content

Commit

Permalink
fix(validation): Fixed wrong validation of proposer hash against head…
Browse files Browse the repository at this point in the history
…er (#1178)

Co-authored-by: Michael Tsitrin <[email protected]>
Co-authored-by: Michael Tsitrin <[email protected]>
  • Loading branch information
3 people authored Nov 7, 2024
1 parent e5e8857 commit 289924d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions types/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ func (b *Block) ValidateWithState(state *State) error {
}

proposerHash := state.GetProposerHash()
if !bytes.Equal(b.Header.NextSequencersHash[:], proposerHash) {
return NewErrInvalidNextSequencersHashFraud([32]byte(proposerHash), b.Header.NextSequencersHash)
if !bytes.Equal(b.Header.SequencerHash[:], proposerHash) {
return NewErrInvalidSequencerHashFraud([32]byte(proposerHash), b.Header.SequencerHash[:])
}

if !bytes.Equal(b.Header.AppHash[:], state.AppHash[:]) {
Expand Down Expand Up @@ -152,7 +152,7 @@ func (c *Commit) ValidateWithHeader(proposerPubKey tmcrypto.PubKey, header *Head
}

if !bytes.Equal(header.SequencerHash[:], proposerHash) {
return NewErrInvalidSequencerHashFraud(header.SequencerHash, proposerHash)
return NewErrInvalidSequencerHashFraud(header.SequencerHash, proposerHash[:])
}

if c.HeaderHash != header.Hash() {
Expand Down
18 changes: 9 additions & 9 deletions types/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ func TestBlock_ValidateWithState(t *testing.T) {
Block: 1,
App: 1,
},
Height: 10,
Time: uint64(currentTime.UnixNano()),
AppHash: [32]byte{1, 2, 3},
LastResultsHash: [32]byte{4, 5, 6},
ProposerAddress: []byte("proposer"),
DataHash: [32]byte{},
LastHeaderHash: [32]byte{7, 8, 9},
ChainID: "chainID",
NextSequencersHash: [32]byte(proposerHash),
Height: 10,
Time: uint64(currentTime.UnixNano()),
AppHash: [32]byte{1, 2, 3},
LastResultsHash: [32]byte{4, 5, 6},
ProposerAddress: []byte("proposer"),
DataHash: [32]byte{},
LastHeaderHash: [32]byte{7, 8, 9},
ChainID: "chainID",
SequencerHash: [32]byte(proposerHash),
},
Data: Data{},
LastCommit: Commit{},
Expand Down

0 comments on commit 289924d

Please sign in to comment.