Skip to content

Commit

Permalink
fix(abci): remove double keccak256 in signing
Browse files Browse the repository at this point in the history
  • Loading branch information
mariocao committed Oct 31, 2024
1 parent 2ed853d commit 5cc14cc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 2 additions & 4 deletions app/abci/vote_extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ func (m *mockSigner) Sign(input []byte, _ utils.SEDAKeyIndex) ([]byte, error) {
if err != nil {
return nil, err
}
hash := crypto.Keccak256Hash(input)
signature, err := crypto.Sign(hash.Bytes(), privKey)
signature, err := crypto.Sign(input, privKey)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -101,8 +100,7 @@ func TestExtendVerifyVoteHandlers(t *testing.T) {
require.NoError(t, err)

// Recover and verify public key
hash := crypto.Keccak256Hash(mockBatch.BatchId)
sigPubKey, err := crypto.Ecrecover(hash.Bytes(), evRes.VoteExtension)
sigPubKey, err := crypto.Ecrecover(mockBatch.BatchId, evRes.VoteExtension)
require.NoError(t, err)
require.Equal(t, expPubKey, sigPubKey)

Expand Down
6 changes: 4 additions & 2 deletions app/utils/seda_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,16 @@ func LoadSEDASigner(loadPath string) (SEDASigner, error) {
return &sedaKeys{keys: keys}, nil
}

// Sign returns the signature for the a given hashed input using the
// key at the given index.
func (s *sedaKeys) Sign(input []byte, index SEDAKeyIndex) ([]byte, error) {
privKey, err := ethcrypto.ToECDSA(s.keys[index].PrivKey.Bytes())
if err != nil {
return nil, err
}

hash := ethcrypto.Keccak256Hash(input)
signature, err := ethcrypto.Sign(hash.Bytes(), privKey)
// ethcrypto library already checks if input is 32 bytes (digest length)
signature, err := ethcrypto.Sign(input, privKey)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 5cc14cc

Please sign in to comment.