8000 feat(privval)!: DO NOT require extension signature by melekes · Pull Request #2496 · cometbft/cometbft · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(privval)!: DO NOT require extension signature #2496

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

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- `[privval]` DO NOT require extension signature from privval if vote
extensions are disabled. Remote signers must ONLY sign the extension if
`sign_extension` flag in `SignVoteRequest` is true.
[\#2496](https://github.com/cometbft/cometbft/pull/2496)
132 changes: 87 additions & 45 deletions api/cometbft/privval/v1/types.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/consensus/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (vs *validatorStub) signVote(
Extension: voteExtension,
}
v := vote.ToProto()
if err = vs.PrivValidator.SignVote(test.DefaultTestChainID, v); err != nil {
if err = vs.PrivValidator.SignVote(test.DefaultTestChainID, v, true); err != nil {
return nil, fmt.Errorf("sign vote failed: %w", err)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/consensus/invalid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func invalidDoPrevoteFunc(t *testing.T, cs *State, sw *p2p.Switch, pv types.Priv
},
8000 }
p := precommit.ToProto()
err = cs.privValidator.SignVote(cs.state.ChainID, p)
err = cs.privValidator.SignVote(cs.state.ChainID, p, true)
if err != nil {
t.Error(err)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/evidence/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,11 +370,11 @@ func TestVerifyDuplicateVoteEvidence(t *testing.T) {
vote1 := types.MakeVoteNoError(t, val, chainID, 0, 10, 2, 1, blockID, defaultEvidenceTime)

v1 := vote1.ToProto()
err := val.SignVote(chainID, v1)
err := val.SignVote(chainID, v1, false)
require.NoError(t, err)
badVote := types.MakeVoteNoError(t, val, chainID, 0, 10, 2, 1, blockID, defaultEvidenceTime)
bv := badVote.ToProto()
err = val2.SignVote(chainID, bv)
err = val2.SignVote(chainID, bv, false)
require.NoError(t, err)

vote1.Signature = v1.Signature
Expand Down
4 changes: 2 additions & 2 deletions internal/state/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,9 @@ func TestValidateBlockCommit(t *testing.T) {
g := goodVote.ToProto()
b := badVote.ToProto()

err = badPrivVal.SignVote(chainID, g)
err = badPrivVal.SignVote(chainID, g, false)
require.NoError(t, err, "height %d", height)
err = badPrivVal.SignVote(chainID, b)
err = badPrivVal.SignVote(chainID, b, false)
require.NoError(t, err, "height %d", height)

goodVote.Signature, badVote.Signature = g.Signature, b.Signature
Expand Down
4 changes: 2 additions & 2 deletions internal/test/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func MakeCommitFromVoteSet(blockID types.BlockID, voteSet *types.VoteSet, valida

v := vote.ToProto()

if err := validators[i].SignVote(voteSet.ChainID(), v); err != nil {
if err := validators[i].SignVote(voteSet.ChainID(), v, false); err != nil {
return nil, err
}
vote.Signature = v.Signature
Expand Down Expand Up @@ -68,7 +68,7 @@ func MakeCommit(blockID types.BlockID, height int64, round int32, valSet *types.

v := vote.ToProto()

if err := privVal.SignVote(chainID, v); err != nil {
if err := privVal.SignVote(chainID, v, false); err != nil {
return nil, err
}

Expand Down
39 changes: 20 additions & 19 deletions privval/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ func (pv *FilePV) GetPubKey() (crypto.PubKey, error) {

// SignVote signs a canonical representation of the vote, along with the
// chainID. Implements PrivValidator.
func (pv *FilePV) SignVote(chainID string, vote *cmtproto.Vote) error {
if err := pv.signVote(chainID, vote); err != nil {
func (pv *FilePV) SignVote(chainID string, vote *cmtproto.Vote, signExtension bool) error {
if err := pv.signVote(chainID, vote, signExtension); err != nil {
return fmt.Errorf("error signing vote: %v", err)
}
return nil
Expand Down Expand Up @@ -312,7 +312,7 @@ func (pv *FilePV) String() string {
// It may need to set the timestamp as well if the vote is otherwise the same as
// a previously signed vote (ie. we crashed after signing but before the vote hit the WAL).
// Extension signatures are always signed for non-nil precommits (even if the data is empty).
func (pv *FilePV) signVote(chainID string, vote *cmtproto.Vote) error {
func (pv *FilePV) signVote(chainID string, vote *cmtproto.Vote, signExtension bool) error {
height, round, step := vote.Height, vote.Round, voteToStep(vote)

lss := pv.LastSignState
Expand All @@ -324,20 +324,24 @@ func (pv *FilePV) signVote(chainID string, vote *cmtproto.Vote) error {

signBytes := types.VoteSignBytes(chainID, vote)

// Vote extensions are non-deterministic, so it is possible that an
// application may have created a different extension. We therefore always
// re-sign the vote extensions of precommits. For prevotes and nil
// precommits, the extension signature will always be empty.
// Even if the signed over data is empty, we still add the signature
var extSig []byte
if vote.Type == types.PrecommitType && !types.ProtoBlockIDIsNil(&vote.BlockID) {
extSignBytes := types.VoteExtensionSignBytes(chainID, vote)
extSig, err = pv.Key.PrivKey.Sign(extSignBytes)
if err != nil {
return err
if signExtension {
// Vote extensions are non-deterministic, so it is possible that an
// application may have created a different extension. We therefore always
// re-sign the vote extensions of precommits. For prevotes and nil
// precommits, the extension signature will always be empty.
// Even if the signed over data is empty, we still add the signature
var extSig []byte
if vote.Type == types.PrecommitType && !types.ProtoBlockIDIsNil(&vote.BlockID) {
extSignBytes := types.VoteExtensionSignBytes(chainID, vote)
extSig, err = pv.Key.PrivKey.Sign(extSignBytes)
if err != nil {
return err
}
} else if len(vote.Extension) > 0 {
return errors.New("unexpected vote extension - extensions are only allowed in non-nil precommits")
}
} else if len(vote.Extension) > 0 {
return errors.New("unexpected vote extension - extensions are only allowed in non-nil precommits")

vote.ExtensionSignature = extSig
}

// We might crash before writing to the wal,
Expand All @@ -357,8 +361,6 @@ func (pv *FilePV) signVote(chainID string, vote *cmtproto.Vote) error {
err = errors.New("conflicting data")
}

vote.ExtensionSignature = extSig

return err
}

Expand All @@ -369,7 +371,6 @@ func (pv *FilePV) signVote(chainID string, vote *cmtproto.Vote) error {
}
pv.saveSigned(height, round, step, signBytes, sig)
vote.Signature = sig
vote.ExtensionSignature = extSig

return nil
}
Expand Down
Loading
0