Skip to content

Commit

Permalink
refactor: remove prefix from uncompressed public key in validator tree
Browse files Browse the repository at this point in the history
  • Loading branch information
hacheigriega committed Oct 16, 2024
1 parent b94e85a commit b8a7d54
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions x/batching/keeper/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ func Test_ConstructValidatorTree(t *testing.T) {
parsedPowers := make([]uint32, len(entries))
for i, entry := range entries {
require.Equal(t, []byte{utils.SEDASeparatorSecp256k1}, entry[:1])
parsedPKs[i] = entry[1:66]
parsedPowers[i] = binary.BigEndian.Uint32(entry[66:])
parsedPKs[i] = entry[1:65]
parsedPowers[i] = binary.BigEndian.Uint32(entry[65:])

uncompressedPKs[i] = decompressPubKey(t, pks[i])
}
Expand Down Expand Up @@ -144,14 +144,14 @@ func addBatchSigningValidators(t *testing.T, f *fixture, num int) ([]sdk.AccAddr
}

// decompressPubKey decompresses a 33-byte long compressed public key
// into a 65-byte long uncompressed format.
// into a 64-byte long uncompressed format.
func decompressPubKey(t *testing.T, pubKey []byte) []byte {
t.Helper()
pk, err := dcrdsecp256k1.ParsePubKey(pubKey)
if err != nil {
panic(err)
}
return pk.SerializeUncompressed()
return pk.SerializeUncompressed()[1:]
}

// generateDataResults returns a given number of randomly-generated
Expand Down
6 changes: 3 additions & 3 deletions x/batching/keeper/endblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,12 @@ func (k Keeper) ConstructValidatorTree(ctx sdk.Context) ([][]byte, []byte, error
}

// decompressPubKey decompresses a public key in 33-byte compressed
// format into the one in 65-byte uncompressed format.
// format into the one in 64-byte uncompressed format.
func decompressPubKey(pubKey []byte) ([]byte, error) {
x, y := secp256k1.DecompressPubkey(pubKey)
if x == nil || y == nil {
return nil, types.ErrInvalidPublicKey
}
// 65-byte format: 0x04 | x-coordinate | y-coordinate
return append([]byte{0x04}, append(x.Bytes(), y.Bytes()...)...), nil
// 64-byte format: x-coordinate | y-coordinate
return append(x.Bytes(), y.Bytes()...), nil
}

0 comments on commit b8a7d54

Please sign in to comment.