Skip to content

Commit

Permalink
fix: no keccak double hashing when verifying batch signature
Browse files Browse the repository at this point in the history
  • Loading branch information
hacheigriega committed Oct 31, 2024
1 parent 5cc14cc commit 228b963
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 1 addition & 2 deletions app/abci/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,7 @@ func (h *Handlers) verifyBatchSignatures(ctx sdk.Context, batchID, voteExtension
return err
}
pubKeyBytes := crypto.FromECDSAPub(pubKeyECDSA)
hash := crypto.Keccak256Hash(batchID)
sigPubKey, err := crypto.Ecrecover(hash.Bytes(), voteExtension[:65])
sigPubKey, err := crypto.Ecrecover(batchID, voteExtension[:65])
if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion app/abci/vote_extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/rs/zerolog"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
"golang.org/x/crypto/sha3"

cometabci "github.com/cometbft/cometbft/abci/types"

Expand Down Expand Up @@ -64,8 +65,11 @@ func TestExtendVerifyVoteHandlers(t *testing.T) {
mockPubKeyKeeper := testutil.NewMockPubKeyKeeper(ctrl)
mockStakingKeeper := testutil.NewMockStakingKeeper(ctrl)

hasher := sha3.NewLegacyKeccak256()
hasher.Write([]byte("Message for ECDSA signing"))
batchID := hasher.Sum(nil)
mockBatch := batchingtypes.Batch{
BatchId: []byte("Message for ECDSA signing"),
BatchId: batchID,
BlockHeight: 100, // created from the previous block
}

Expand Down

0 comments on commit 228b963

Please sign in to comment.