Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [\#9011](https://github.com/cosmos/ibc-go/pull/9011) Bump **github.com/cosmos/cosmos-sdk** to **0.55.0**
* [\#9011](https://github.com/cosmos/ibc-go/pull/9011) Bump **github.com/cometbft/cometbft** to **0.40.0**
* [\#9011](https://github.com/cosmos/ibc-go/pull/9011) Bump **Go** to **1.26**
* (light-clients/08-wasm) [\#9175](https://github.com/lfdt-ibc/ibc-go/pull/9175) Replace the GPL-3.0 **github.com/OffchainLabs/prysm/v6** with the Apache-2.0 **github.com/supranational/blst@v0.3.17** in `blsverifier`.

### API Breaking

* (light-clients/08-wasm) [\#9175](https://github.com/lfdt-ibc/ibc-go/pull/9175) `blsverifier.AggregatePublicKeys` returns a `blsverifier.PublicKey` instead of a prysm `bls.PublicKey`. Callers that only use `Marshal()` are unaffected.
Comment thread
dianab-cl marked this conversation as resolved.
Resolved

### State Machine Breaking

* (apps/rate-limiting) [\#8937](https://github.com/cosmos/ibc-go/pull/8937) imp(ratelimit): use collections for pending markers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (s *KeeperTestSuite) TestOnRecvPacket() {
interchainAccountAddr, found := s.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(s.chainB.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID)
s.Require().True(found)

validatorAddr := (sdk.ValAddress)(s.chainB.Vals.Validators[0].Address)
validatorAddr := sdk.ValAddress(s.chainB.Vals.Validators[0].Address)
msg := &stakingtypes.MsgDelegate{
DelegatorAddress: interchainAccountAddr,
ValidatorAddress: validatorAddr.String(),
Expand Down Expand Up @@ -137,7 +137,7 @@ func (s *KeeperTestSuite) TestOnRecvPacket() {
interchainAccountAddr, found := s.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(s.chainB.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID)
s.Require().True(found)

validatorAddr := (sdk.ValAddress)(s.chainB.Vals.Validators[0].Address)
validatorAddr := sdk.ValAddress(s.chainB.Vals.Validators[0].Address)
msgDelegate := &stakingtypes.MsgDelegate{
DelegatorAddress: interchainAccountAddr,
ValidatorAddress: validatorAddr.String(),
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/callbacks/ica_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (s *CallbacksTestSuite) ExecuteICATimeout(icaAddress, memo string) {
// buildICAMsgDelegatePacketData builds a packetData containing a stakingtypes.MsgDelegate to be executed on chainB
func (s *CallbacksTestSuite) buildICAMsgDelegatePacketData(icaAddress string, memo string) icatypes.InterchainAccountPacketData {
// prepare a simple stakingtypes.MsgDelegate to be used as the interchain account msg executed on chainB
validatorAddr := (sdk.ValAddress)(s.chainB.Vals.Validators[0].Address)
validatorAddr := sdk.ValAddress(s.chainB.Vals.Validators[0].Address)
msgDelegate := &stakingtypes.MsgDelegate{
DelegatorAddress: icaAddress,
ValidatorAddress: validatorAddr.String(),
Expand Down
2 changes: 1 addition & 1 deletion modules/core/04-channel/types/acknowledgement.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (ack Acknowledgement) ValidateBasic() error {
// considered successful if it is a ResultAcknowledgement. Otherwise it is
// considered a failed acknowledgement.
func (ack Acknowledgement) Success() bool {
return reflect.TypeOf(ack.Response) == reflect.TypeOf(((*Acknowledgement_Result)(nil)))
return reflect.TypeOf(ack.Response) == reflect.TypeOf((*Acknowledgement_Result)(nil))
Comment thread
dianab-cl marked this conversation as resolved.
Resolved
}

// Acknowledgement implements the Acknowledgement interface. It returns the
Expand Down
74 changes: 69 additions & 5 deletions modules/light-clients/08-wasm/blsverifier/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,83 @@
package blsverifier

import (
"bytes"
"errors"
"fmt"

"github.com/OffchainLabs/prysm/v6/crypto/bls"
blst "github.com/supranational/blst/bindings/go"
)

func AggregatePublicKeys(publicKeys [][]byte) (bls.PublicKey, error) {
return bls.AggregatePublicKeys(publicKeys)
const (
// PublicKeySize is the size of a compressed BLS12-381 G1 public key.
PublicKeySize = blst.BLST_P1_COMPRESS_BYTES
Comment thread
dianab-cl marked this conversation as resolved.
Resolved
// SignatureSize is the size of a compressed BLS12-381 G2 signature.
SignatureSize = blst.BLST_P2_COMPRESS_BYTES
)

// dst is the Ethereum consensus proof-of-possession ciphersuite domain separation tag.
var dst = []byte("BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_")

// PublicKey is a compressed BLS12-381 G1 public key.
type PublicKey []byte
Comment thread
dianab-cl marked this conversation as resolved.
Resolved

// Marshal returns a copy of the compressed public key bytes.
func (pk PublicKey) Marshal() []byte {
return bytes.Clone(pk)
}

// AggregatePublicKeys validates the compressed public keys and returns their aggregate.
func AggregatePublicKeys(publicKeys [][]byte) (PublicKey, error) {
pk, err := aggregatePublicKeys(publicKeys)
if err != nil {
return nil, err
}
return PublicKey(pk.Compress()), nil
}

// VerifySignature verifies a compressed signature over message against the aggregate of publicKeys.
func VerifySignature(signature []byte, message [32]byte, publicKeys [][]byte) (bool, error) {
aggregatedPublicKey, err := AggregatePublicKeys(publicKeys)
pk, err := aggregatePublicKeys(publicKeys)
if err != nil {
return false, fmt.Errorf("failed to aggregate public keys %w", err)
}
return bls.VerifySignature(signature, message, aggregatedPublicKey)

if len(signature) != SignatureSize {
return false, fmt.Errorf("signature must be %d bytes", SignatureSize)
}
sig := new(blst.P2Affine).Uncompress(signature)
if sig == nil {
return false, errors.New("could not unmarshal bytes into signature")
}
// Subgroup check only: an aggregate signature may be the point at infinity.
if !sig.SigValidate(false) {
return false, errors.New("signature not in group")
}

// Signature and key are already validated above.
return sig.Verify(false, pk, false, message[:], dst), nil
}

func aggregatePublicKeys(publicKeys [][]byte) (*blst.P1Affine, error) {
if len(publicKeys) == 0 {
return nil, errors.New("nil or empty public keys")
}

agg := new(blst.P1Aggregate)
for _, bz := range publicKeys {
if len(bz) != PublicKeySize {
return nil, fmt.Errorf("public key must be %d bytes", PublicKeySize)
}
pk := new(blst.P1Affine).Uncompress(bz)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Preserve caching of validated public keys

Successive light-client updates commonly reuse validator keys. Prysm cached validated points, but this loop repeats decompression and subgroup validation on every query. The review benchmark reports 100 recurring keys increasing from ~0.086 ms to ~3.32 ms per aggregation (39× slower). Please preserve reuse through a bounded, concurrency-safe cache populated only after successful validation, and add a repeated-key benchmark.

if pk == nil {
return nil, errors.New("could not unmarshal bytes into public key")
}
// Rejects the point at infinity and points outside the subgroup.
if !pk.KeyValidate() {
return nil, errors.New("received an infinite public key")
}
agg.Add(pk, false)
}

return agg.ToAffine(), nil
}
133 changes: 133 additions & 0 deletions modules/light-clients/08-wasm/blsverifier/crypto_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
// SPDX-License-Identifier: Apache-2.0

package blsverifier_test

import (
"encoding/hex"
"encoding/json"
"testing"

"github.com/stretchr/testify/require"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/lfdt-ibc/ibc-go/modules/light-clients/08-wasm/v11/blsverifier"
)

var (
publicKeys = [][]byte{
mustDecodeHex("84fe268400062ae6255010a421204dad5b0a8bd93522a4abc023037fa7a769f6ef29acc14c7fae8c5c0cd1df21ae1f52"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where do these vectors come from? If prysm or another independent implementation produced them, the success cases prove we match the old behavior; if the new code produced them, they only show it agrees with itself.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// The success vectors were checked against two independent implementations:
// github.com/OffchainLabs/prysm/v6@v6.1.4 crypto/bls, which this package wrapped
// before, and github.com/consensys/gnark-crypto. Both produce aggregatedPublicKey
// from publicKeys and accept aggregatedSignature over message.

mustDecodeHex("8b850e23cf188473e04feaa5d39f40f54b8c0e717f7fccb77d0efb5326802274bda863911efa8775a08674b887e0e766"),
mustDecodeHex("b52684603da6cb2902092310deab2ef3116a0a2b449c0f44d82d1d30bf12f7474492534f518af541ca9da110ee417132"),
}
aggregatedPublicKey = mustDecodeHex("912cf816853d0984e448f065d0bdb34b1e26be1d3c50bbc2f0d39b0ff1c2963a97b5dfd442a496763f3c6e5c54375b1e")
aggregatedSignature = mustDecodeHex("8af25b4a2786b3305f80528520544071a143e80ef4091dfca32e347eeabeef71eeb8673a78e8ff2875883ab5498d8a7b1888a80878bfd82c2d27e93ed74e979014e95d7f2ef55b1d28070a4a2e6ce9df3b8f07c6444c4799c64d654c2810c36d")
message = [32]byte{3, 1, 2, 3}
)

func mustDecodeHex(s string) []byte {
bz, err := hex.DecodeString(s)
if err != nil {
panic(err)
}
return bz
}

// negate flips the sign bit of a compressed point.
func negate(point []byte) []byte {
bz := append([]byte{}, point...)
bz[0] ^= 0x20
return bz
}

func infinityPoint(size int) []byte {
bz := make([]byte, size)
bz[0] = 0xc0
return bz
}

func TestAggregatePublicKeys(t *testing.T) {
testCases := []struct {
name string
publicKeys [][]byte
expected []byte
expErrorMsg string
}{
{"success: single key", publicKeys[:1], publicKeys[0], ""},
{"success: multiple keys", publicKeys, aggregatedPublicKey, ""},
{"failure: no keys", nil, nil, "nil or empty public keys"},
{"failure: wrong length", [][]byte{publicKeys[0][:47]}, nil, "public key must be 48 bytes"},
{"failure: not a curve point", [][]byte{make([]byte, 48)}, nil, "could not unmarshal bytes into public key"},
{"failure: point at infinity", [][]byte{infinityPoint(48)}, nil, "received an infinite public key"},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
pk, err := blsverifier.AggregatePublicKeys(tc.publicKeys)
if tc.expErrorMsg != "" {
require.ErrorContains(t, err, tc.expErrorMsg)
return
}
require.NoError(t, err)
require.Equal(t, tc.expected, pk.Marshal())
})
}
}

func TestVerifySignature(t *testing.T) {
testCases := []struct {
name string
signature []byte
message [32]byte
publicKeys [][]byte
expValid bool
expErrorMsg string
}{
{"success: valid aggregate signature", aggregatedSignature, message, publicKeys, true, ""},
{"invalid: wrong message", aggregatedSignature, [32]byte{9}, publicKeys, false, ""},
{"invalid: missing signer", aggregatedSignature, message, publicKeys[:2], false, ""},
{"invalid: signature at infinity", infinityPoint(96), message, publicKeys, false, ""},
{"failure: wrong signature length", aggregatedSignature[:95], message, publicKeys, false, "signature must be 96 bytes"},
{"failure: signature not a curve point", make([]byte, 96), message, publicKeys, false, "could not unmarshal bytes into signature"},
{"invalid: keys cancel to infinity", infinityPoint(96), message, [][]byte{publicKeys[0], negate(publicKeys[0])}, false, ""},
{"failure: invalid public key", aggregatedSignature, message, [][]byte{infinityPoint(48)}, false, "failed to aggregate public keys"},
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
valid, err := blsverifier.VerifySignature(tc.signature, tc.message, tc.publicKeys)
if tc.expErrorMsg != "" {
require.ErrorContains(t, err, tc.expErrorMsg)
} else {
require.NoError(t, err)
}
require.Equal(t, tc.expValid, valid)
})
}
}

func TestCustomQuerier(t *testing.T) {
querier := blsverifier.CustomQuerier()

request, err := json.Marshal(blsverifier.CustomQuery{
Aggregate: &blsverifier.QueryAggregate{PublicKeys: publicKeys},
})
require.NoError(t, err)
res, err := querier(sdk.Context{}, request)
require.NoError(t, err)
expected, err := json.Marshal(aggregatedPublicKey)
require.NoError(t, err)
require.Equal(t, expected, res)

request, err = json.Marshal(blsverifier.CustomQuery{
AggregateVerify: &blsverifier.QueryAggregateVerify{
PublicKeys: publicKeys,
Signature: aggregatedSignature,
Message: message[:],
},
})
require.NoError(t, err)
res, err = querier(sdk.Context{}, request)
require.NoError(t, err)
require.Equal(t, []byte("true"), res)
}
14 changes: 1 addition & 13 deletions modules/light-clients/08-wasm/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ require (
cosmossdk.io/math v1.5.3
cosmossdk.io/tools/confix v0.1.2
github.com/CosmWasm/wasmvm/v3 v3.0.7
github.com/OffchainLabs/prysm/v6 v6.1.4
github.com/cometbft/cometbft v0.40.0
github.com/cosmos/cosmos-db v1.1.3
github.com/cosmos/cosmos-sdk v0.55.0
Expand All @@ -30,6 +29,7 @@ require (
github.com/spf13/cobra v1.10.2
github.com/spf13/viper v1.21.0
github.com/stretchr/testify v1.12.1
github.com/supranational/blst v0.3.17
google.golang.org/genproto/googleapis/api v0.0.0-20260819154853-08b0e4226688
google.golang.org/grpc v1.84.0
)
Expand Down Expand Up @@ -98,7 +98,6 @@ require (
github.com/cockroachdb/redact v1.1.8 // indirect
github.com/cockroachdb/tokenbucket v0.0.0-20250429170803-42689b6311bb // indirect
github.com/cometbft/cometbft-db v1.0.4 // indirect
github.com/consensys/gnark-crypto v0.18.1 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/btree v1.0.0 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.5 // indirect
Expand All @@ -107,7 +106,6 @@ require (
github.com/cosmos/iavl v1.2.8 // indirect
github.com/cosmos/ics23/go v0.11.0 // indirect
github.com/cosmos/ledger-cosmos-go v1.0.0 // indirect
github.com/crate-crypto/go-eth-kzg v1.5.0 // indirect
github.com/creachadair/atomicfile v0.3.8 // indirect
github.com/creachadair/tomledit v0.0.29 // indirect
github.com/danieljoos/wincred v1.2.3 // indirect
Expand All @@ -124,7 +122,6 @@ require (
github.com/emicklei/dot v1.11.0 // indirect
github.com/envoyproxy/go-control-plane/envoy v1.37.0 // indirect
github.com/envoyproxy/protoc-gen-validate v1.3.3 // indirect
github.com/ethereum/c-kzg-4844/v2 v2.1.8 // indirect
github.com/ethereum/go-ethereum v1.17.8 // indirect
github.com/fatih/color v1.18.0 // indirect
github.com/felixge/httpsnoop v1.1.0 // indirect
Expand Down Expand Up @@ -169,7 +166,6 @@ require (
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/hashicorp/yamux v0.1.2 // indirect
github.com/hdevalence/ed25519consensus v0.2.0 // indirect
github.com/herumi/bls-eth-go-binary v1.31.0 // indirect
github.com/holiman/uint256 v1.3.2 // indirect
github.com/huandu/skiplist v1.2.1 // indirect
github.com/huin/goupnp v1.3.0 // indirect
Expand Down Expand Up @@ -207,8 +203,6 @@ require (
github.com/minio/highwayhash v1.0.4 // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/mr-tron/base58 v1.3.0 // indirect
github.com/mschoch/smat v0.2.0 // indirect
github.com/mtibben/percent v0.2.1 // indirect
Expand Down Expand Up @@ -252,9 +246,6 @@ require (
github.com/prometheus/client_model v0.6.2 // indirect
github.com/prometheus/common v0.70.1 // indirect
github.com/prometheus/procfs v0.21.1 // indirect
github.com/prysmaticlabs/fastssz v0.0.0-20251103153600-259302269bfc // indirect
github.com/prysmaticlabs/go-bitfield v0.0.0-20240328144219-a1caa50c3a1e // indirect
github.com/prysmaticlabs/gohashtree v0.0.5-beta // indirect
github.com/quic-go/qpack v0.6.0 // indirect
github.com/quic-go/quic-go v0.60.0 // indirect
github.com/quic-go/webtransport-go v0.11.1 // indirect
Expand All @@ -266,17 +257,14 @@ require (
github.com/sasha-s/go-deadlock v0.3.9 // indirect
github.com/shamaton/msgpack/v2 v2.4.1 // indirect
github.com/shirou/gopsutil/v4 v4.26.6 // indirect
github.com/sirupsen/logrus v1.9.4 // indirect
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/afero v1.15.0 // indirect
github.com/spf13/pflag v1.0.10 // indirect
github.com/spiffe/go-spiffe/v2 v2.8.1 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/supranational/blst v0.3.16 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
github.com/tendermint/go-amino v0.16.0 // indirect
github.com/thomaso-mirodin/intmath v0.0.0-20160323211736-5dc6d854e46e // indirect
github.com/tidwall/btree v1.8.1 // indirect
github.com/tklauser/go-sysconf v0.4.0 // indirect
github.com/tklauser/numcpus v0.12.0 // indirect
Expand Down
Loading
Loading