diff --git a/app/app.go b/app/app.go index b0b76f0c6..4467bb5ab 100644 --- a/app/app.go +++ b/app/app.go @@ -327,7 +327,7 @@ func NewBabylonApp( // TODO for now use mocks, as soon as Checkpoining and lightClient will have correct interfaces // change to correct implementations app.BtcCheckpointKeeper = btccheckpointkeeper.NewKeeper(appCodec, keys[btccheckpointtypes.StoreKey], keys[btccheckpointtypes.MemStoreKey], app.GetSubspace(btccheckpointtypes.ModuleName), btccheckpointtypes.MockBTCLightClientKeeper{}, btccheckpointtypes.MockCheckpointingKeeper{}) - app.CheckpointingKeeper = checkpointingkeeper.NewKeeper(appCodec, keys[checkpointingtypes.StoreKey], keys[checkpointingtypes.MemStoreKey], app.GetSubspace(checkpointingtypes.ModuleName)) + app.CheckpointingKeeper = checkpointingkeeper.NewKeeper(appCodec, keys[checkpointingtypes.StoreKey], keys[checkpointingtypes.MemStoreKey], app.EpochingKeeper, app.GetSubspace(checkpointingtypes.ModuleName)) // create evidence keeper with router evidenceKeeper := evidencekeeper.NewKeeper( appCodec, keys[evidencetypes.StoreKey], &app.StakingKeeper, app.SlashingKeeper, diff --git a/crypto/bls12381/types.go b/crypto/bls12381/types.go index 1d622e7b4..52ae3de3a 100644 --- a/crypto/bls12381/types.go +++ b/crypto/bls12381/types.go @@ -1,6 +1,7 @@ package bls12381 import ( + "errors" blst "github.com/supranational/blst/bindings/go" ) @@ -25,10 +26,85 @@ var DST = []byte("BLS_SIG_BLS12381G1_XMD:SHA-256_SSWU_RO_NUL_") type Signature []byte type PublicKey []byte +const SignatureLen = 48 +const PublicKeyLen = 96 + +func (sig Signature) Marshal() ([]byte, error) { + return sig, nil +} + +func (sig Signature) MustMarshal() []byte { + bz, err := sig.Marshal() + if err != nil { + panic(err) + } + + return bz +} + +func (sig Signature) MarshalTo(data []byte) (int, error) { + copy(data, sig) + return len(data), nil +} + +func (sig Signature) Size() int { + bz, _ := sig.Marshal() + return len(bz) +} + +func (sig *Signature) Unmarshal(data []byte) error { + if len(data) != SignatureLen { + return errors.New("Invalid signature length") + } + + *sig = data + return nil +} + func (sig Signature) Byte() []byte { return sig } +func (sig Signature) Equal(s Signature) bool { + return string(sig) == string(s) +} + +func (pk PublicKey) Marshal() ([]byte, error) { + return pk, nil +} + +func (pk PublicKey) MustMarshal() []byte { + bz, err := pk.Marshal() + if err != nil { + panic(err) + } + + return bz +} + +func (pk PublicKey) MarshalTo(data []byte) (int, error) { + copy(data, pk) + return len(data), nil +} + +func (pk PublicKey) Size() int { + bz, _ := pk.Marshal() + return len(bz) +} + +func (pk *PublicKey) Unmarshal(data []byte) error { + if len(data) != PublicKeyLen { + return errors.New("Invalid public key length") + } + + *pk = data + return nil +} + +func (pk PublicKey) Equal(k PublicKey) bool { + return string(pk) == string(k) +} + func (pk PublicKey) Byte() []byte { return pk } diff --git a/proto/babylon/checkpointing/bls_key.proto b/proto/babylon/checkpointing/bls_key.proto new file mode 100644 index 000000000..6d64058cd --- /dev/null +++ b/proto/babylon/checkpointing/bls_key.proto @@ -0,0 +1,25 @@ +syntax = "proto3"; +package babylon.checkpointing.v1; + +import "gogoproto/gogo.proto"; + +option go_package = "github.com/babylonchain/babylon/x/checkpointing/types"; + +// BlsKey wraps BLS public key with PoP +message BlsKey { + // pubkey is the BLS public key of a validator + bytes pubkey = 1 [ + (gogoproto.customtype) = "github.com/babylonchain/babylon/crypto/bls12381.PublicKey" + ]; + + // pop is the proof-of-possession of the BLS key + ProofOfPossession pop = 2; +} + +// ProofOfPossession defines proof for the ownership of Ed25519 and BLS private keys +message ProofOfPossession { + // bls_sig is calculated by encrypt(key = BLS_sk, data = encrypt(key = Ed25519_sk, data = Secp256k1_pk)) + bytes bls_sig = 1 [ + (gogoproto.customtype) = "github.com/babylonchain/babylon/crypto/bls12381.Signature" + ]; +} diff --git a/proto/babylon/checkpointing/checkpoint.proto b/proto/babylon/checkpointing/checkpoint.proto index eea6c7443..2c5888dde 100644 --- a/proto/babylon/checkpointing/checkpoint.proto +++ b/proto/babylon/checkpointing/checkpoint.proto @@ -18,7 +18,9 @@ message RawCheckpoint { // bitmap defines the bitmap that indicates the signers of the bls multi sig bytes bitmap = 3; // bls_multi_sig defines the multi sig that is aggregated from individual bls sigs - bytes bls_multi_sig = 4; + bytes bls_multi_sig = 4 [ + (gogoproto.customtype) = "github.com/babylonchain/babylon/crypto/bls12381.Signature" + ]; } // RawCheckpointWithMeta wraps the raw checkpoint with meta data. @@ -42,12 +44,16 @@ enum CheckpointStatus { // BlsSig wraps the bls sig with meta data. message BlsSig { + option (gogoproto.equal) = false; + // epoch_num defines the epoch number that the bls sig is signed on uint64 epoch_num = 1; // last_commit_hash defines the 'LastCommitHash' that the bls sig is signed on bytes last_commit_hash = 2; // bls_sig defines the actual bls sig - bytes bls_sig = 3; + bytes bls_sig = 3 [ + (gogoproto.customtype) = "github.com/babylonchain/babylon/crypto/bls12381.Signature" + ]; // can't find cosmos_proto.scalar when compiling due to cosmos v0.45.4 does not support scalar // string signer_address = 5 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // the signer_address defines the address of the signer diff --git a/proto/babylon/checkpointing/tx.proto b/proto/babylon/checkpointing/tx.proto index 7e2ae0a3a..a6c89b28a 100644 --- a/proto/babylon/checkpointing/tx.proto +++ b/proto/babylon/checkpointing/tx.proto @@ -3,12 +3,18 @@ package babylon.checkpointing.v1; import "gogoproto/gogo.proto"; import "babylon/checkpointing/checkpoint.proto"; +import "babylon/checkpointing/bls_key.proto"; +import "cosmos/staking/v1beta1/tx.proto"; option go_package = "github.com/babylonchain/babylon/x/checkpointing/types"; // Msg defines the checkpointing Msg service. service Msg { + // AddBlsSig defines a method for accumulating BLS signatures rpc AddBlsSig(MsgAddBlsSig) returns (MsgAddBlsSigResponse); + + // WrappedCreateValidator defines a method for registering a new validator + rpc WrappedCreateValidator(MsgWrappedCreateValidator) returns (MsgWrappedCreateValidatorResponse); } // MsgAddBlsSig defines a message to add a bls signature from a @@ -22,3 +28,15 @@ message MsgAddBlsSig { // MsgAddBlsSigResponse defines the MsgAddBlsSig response type. message MsgAddBlsSigResponse {} + +// MsgWrappedCreateValidator defines a wrapped message to create a validator +message MsgWrappedCreateValidator { + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + BlsKey key = 1; + cosmos.staking.v1beta1.MsgCreateValidator msg_create_validator = 2; +} + +// MsgWrappedCreateValidatorResponse defines the MsgWrappedCreateValidator response type +message MsgWrappedCreateValidatorResponse {} diff --git a/x/checkpointing/keeper/blssig_state.go b/x/checkpointing/keeper/blssig_state.go index be76da30a..772858f85 100644 --- a/x/checkpointing/keeper/blssig_state.go +++ b/x/checkpointing/keeper/blssig_state.go @@ -18,25 +18,25 @@ func (k Keeper) BlsSigsState(ctx sdk.Context) BlsSigsState { store := ctx.KVStore(k.storeKey) return BlsSigsState{ cdc: k.cdc, - blsSigs: prefix.NewStore(store, types.BlsSigsPrefix), + blsSigs: prefix.NewStore(store, types.BlsSigsObjectPrefix), hashToEpoch: prefix.NewStore(store, types.BlsSigsHashToEpochPrefix), } } -// CreateBlsSig inserts the bls sig into the hash->epoch and (epoch, hash)->bls sig storage +// CreateBlsSig inserts the BLS sig into the hash->epoch and (epoch, hash)->bls sig storage func (bs BlsSigsState) CreateBlsSig(sig *types.BlsSig) { epoch := sig.GetEpochNum() sigHash := sig.Hash() blsSigsKey := types.BlsSigsObjectKey(epoch, sigHash) epochKey := types.BlsSigsEpochKey(sigHash) - // save concrete bls sig object + // save concrete BLS sig object bs.blsSigs.Set(blsSigsKey, types.BlsSigToBytes(bs.cdc, sig)) // map bls sig to epoch bs.hashToEpoch.Set(epochKey, sdk.Uint64ToBigEndian(epoch)) } -// GetBlsSigsByEpoch retrieves bls sigs by their epoch +// GetBlsSigsByEpoch retrieves BLS sigs by their epoch func (bs BlsSigsState) GetBlsSigsByEpoch(epoch uint64, f func(sig *types.BlsSig) bool) error { store := prefix.NewStore(bs.blsSigs, sdk.Uint64ToBigEndian(epoch)) iter := store.Iterator(nil, nil) @@ -56,7 +56,7 @@ func (bs BlsSigsState) GetBlsSigsByEpoch(epoch uint64, f func(sig *types.BlsSig) return nil } -// Exists Check whether a bls sig is maintained in storage +// Exists Checks whether a BLS sig is maintained in storage func (bs BlsSigsState) Exists(hash types.BlsSigHash) bool { store := prefix.NewStore(bs.hashToEpoch, types.BlsSigsHashToEpochPrefix) return store.Has(hash.Bytes()) diff --git a/x/checkpointing/keeper/keeper.go b/x/checkpointing/keeper/keeper.go index 179d68552..02d3ba250 100644 --- a/x/checkpointing/keeper/keeper.go +++ b/x/checkpointing/keeper/keeper.go @@ -2,22 +2,22 @@ package keeper import ( "fmt" - - "github.com/tendermint/tendermint/libs/log" - + "github.com/babylonchain/babylon/crypto/bls12381" "github.com/babylonchain/babylon/x/checkpointing/types" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/tendermint/tendermint/libs/log" ) type ( Keeper struct { - cdc codec.BinaryCodec - storeKey sdk.StoreKey - memKey sdk.StoreKey - hooks types.CheckpointingHooks - paramstore paramtypes.Subspace + cdc codec.BinaryCodec + storeKey sdk.StoreKey + memKey sdk.StoreKey + epochingKeeper types.EpochingKeeper + hooks types.CheckpointingHooks + paramstore paramtypes.Subspace } ) @@ -25,6 +25,7 @@ func NewKeeper( cdc codec.BinaryCodec, storeKey, memKey sdk.StoreKey, + ek types.EpochingKeeper, ps paramtypes.Subspace, ) Keeper { // set KeyTable if it has not already been set @@ -33,11 +34,12 @@ func NewKeeper( } return Keeper{ - cdc: cdc, - storeKey: storeKey, - memKey: memKey, - paramstore: ps, - hooks: nil, + cdc: cdc, + storeKey: storeKey, + memKey: memKey, + epochingKeeper: ek, + paramstore: ps, + hooks: nil, } } @@ -99,3 +101,7 @@ func (k Keeper) UpdateCkptStatus(ctx sdk.Context, rawCkptBytes []byte, status ty } return k.CheckpointsState(ctx).UpdateCkptStatus(ckpt, status) } + +func (k Keeper) CreateRegistration(ctx sdk.Context, blsPubKey bls12381.PublicKey, valAddr types.ValidatorAddress) error { + return k.RegistrationState(ctx).CreateRegistration(blsPubKey, valAddr) +} diff --git a/x/checkpointing/keeper/msg_server.go b/x/checkpointing/keeper/msg_server.go index ca4a587e8..fce696916 100644 --- a/x/checkpointing/keeper/msg_server.go +++ b/x/checkpointing/keeper/msg_server.go @@ -2,6 +2,8 @@ package keeper import ( "context" + epochingtypes "github.com/babylonchain/babylon/x/epoching/types" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/babylonchain/babylon/x/checkpointing/types" ) @@ -10,11 +12,6 @@ type msgServer struct { k Keeper } -func (m msgServer) AddBlsSig(ctx context.Context, header *types.MsgAddBlsSig) (*types.MsgAddBlsSigResponse, error) { - //TODO implement me - panic("implement me") -} - // NewMsgServerImpl returns an implementation of the MsgServer interface // for the provided Keeper. func NewMsgServerImpl(keeper Keeper) types.MsgServer { @@ -22,3 +19,30 @@ func NewMsgServerImpl(keeper Keeper) types.MsgServer { } var _ types.MsgServer = msgServer{} + +func (m msgServer) AddBlsSig(goCtx context.Context, header *types.MsgAddBlsSig) (*types.MsgAddBlsSigResponse, error) { + panic("TODO: implement me") +} + +// WrappedCreateValidator stores validator's BLS public key as well as corresponding MsgCreateValidator message +func (m msgServer) WrappedCreateValidator(goCtx context.Context, msg *types.MsgWrappedCreateValidator) (*types.MsgWrappedCreateValidatorResponse, error) { + // TODO: verify pop, should be done in ValidateBasic() + ctx := sdk.UnwrapSDKContext(goCtx) + + err := m.k.CreateRegistration(ctx, *msg.Key.Pubkey, types.ValidatorAddress(msg.MsgCreateValidator.ValidatorAddress)) + if err != nil { + return nil, err + } + + // enqueue the msg into the epoching module + queueMsg := epochingtypes.QueuedMessage{ + Msg: &epochingtypes.QueuedMessage_MsgCreateValidator{MsgCreateValidator: msg.MsgCreateValidator}, + } + + err = m.k.epochingKeeper.EnqueueMsg(ctx, queueMsg) + if err != nil { + return nil, err + } + + return &types.MsgWrappedCreateValidatorResponse{}, err +} diff --git a/x/checkpointing/keeper/registration_state.go b/x/checkpointing/keeper/registration_state.go new file mode 100644 index 000000000..53e4eeed7 --- /dev/null +++ b/x/checkpointing/keeper/registration_state.go @@ -0,0 +1,70 @@ +package keeper + +import ( + "github.com/babylonchain/babylon/crypto/bls12381" + "github.com/babylonchain/babylon/x/checkpointing/types" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +type RegistrationState struct { + cdc codec.BinaryCodec + // addrToBlsKeys maps validator addresses to BLS public keys + addrToBlsKeys sdk.KVStore + // blsKeysToAddr maps BLS public keys to validator addresses + blsKeysToAddr sdk.KVStore +} + +func (k Keeper) RegistrationState(ctx sdk.Context) RegistrationState { + // Build the RegistrationState storage + store := ctx.KVStore(k.storeKey) + return RegistrationState{ + cdc: k.cdc, + addrToBlsKeys: prefix.NewStore(store, types.AddrToBlsKeyPrefix), + blsKeysToAddr: prefix.NewStore(store, types.BlsKeyToAddrPrefix), + } +} + +// CreateRegistration inserts the BLS key into the addr -> key and key -> addr storage +func (rs RegistrationState) CreateRegistration(key bls12381.PublicKey, valAddr types.ValidatorAddress) error { + blsPubKey, err := rs.GetBlsPubKey(valAddr) + + // we should disallow a validator to register with different BLS public keys + if err == nil && !blsPubKey.Equal(key) { + return types.ErrBlsKeyAlreadyExist.Wrapf("the validator has registered a BLS public key") + } + + // we should disallow the same BLS public key is registered by different validators + bkToAddrKey := types.BlsKeyToAddrKey(key) + rawAddr := rs.blsKeysToAddr.Get(bkToAddrKey) + if rawAddr != nil && types.BytesToValAddr(rawAddr) != valAddr { + return types.ErrBlsKeyAlreadyExist.Wrapf("same BLS public key is registered by another validator") + } + + // save concrete BLS public key object + blsPkKey := types.AddrToBlsKeyKey(valAddr) + rs.addrToBlsKeys.Set(blsPkKey, key) + rs.blsKeysToAddr.Set(bkToAddrKey, types.ValAddrToBytes(valAddr)) + + return nil +} + +// GetBlsPubKey retrieves BLS public key by validator's address +func (rs RegistrationState) GetBlsPubKey(addr types.ValidatorAddress) (bls12381.PublicKey, error) { + pkKey := types.AddrToBlsKeyKey(addr) + rawBytes := rs.addrToBlsKeys.Get(pkKey) + if rawBytes == nil { + return nil, types.ErrBlsKeyDoesNotExist.Wrapf("BLS public key does not exist with address %s", addr) + } + pk := new(bls12381.PublicKey) + err := pk.Unmarshal(rawBytes) + + return *pk, err +} + +// Exists checks whether a BLS key exists +func (rs RegistrationState) Exists(addr types.ValidatorAddress) bool { + pkKey := types.AddrToBlsKeyKey(addr) + return rs.addrToBlsKeys.Has(pkKey) +} diff --git a/x/checkpointing/types/bls_key.pb.go b/x/checkpointing/types/bls_key.pb.go new file mode 100644 index 000000000..a7db272db --- /dev/null +++ b/x/checkpointing/types/bls_key.pb.go @@ -0,0 +1,563 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: babylon/checkpointing/bls_key.proto + +package types + +import ( + fmt "fmt" + github_com_babylonchain_babylon_crypto_bls12381 "github.com/babylonchain/babylon/crypto/bls12381" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// BlsKey wraps BLS public key with PoP +type BlsKey struct { + // pubkey is the BLS public key of a validator + Pubkey *github_com_babylonchain_babylon_crypto_bls12381.PublicKey `protobuf:"bytes,1,opt,name=pubkey,proto3,customtype=github.com/babylonchain/babylon/crypto/bls12381.PublicKey" json:"pubkey,omitempty"` + // pop is the proof-of-possession of the BLS key + Pop *ProofOfPossession `protobuf:"bytes,2,opt,name=pop,proto3" json:"pop,omitempty"` +} + +func (m *BlsKey) Reset() { *m = BlsKey{} } +func (m *BlsKey) String() string { return proto.CompactTextString(m) } +func (*BlsKey) ProtoMessage() {} +func (*BlsKey) Descriptor() ([]byte, []int) { + return fileDescriptor_a7e926461cc70111, []int{0} +} +func (m *BlsKey) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *BlsKey) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_BlsKey.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *BlsKey) XXX_Merge(src proto.Message) { + xxx_messageInfo_BlsKey.Merge(m, src) +} +func (m *BlsKey) XXX_Size() int { + return m.Size() +} +func (m *BlsKey) XXX_DiscardUnknown() { + xxx_messageInfo_BlsKey.DiscardUnknown(m) +} + +var xxx_messageInfo_BlsKey proto.InternalMessageInfo + +func (m *BlsKey) GetPop() *ProofOfPossession { + if m != nil { + return m.Pop + } + return nil +} + +// ProofOfPossession defines proof for the ownership of Ed25519 and BLS private keys +type ProofOfPossession struct { + // bls_sig is calculated by encrypt(key = BLS_sk, data = encrypt(key = Ed25519_sk, data = Secp256k1_pk)) + BlsSig *github_com_babylonchain_babylon_crypto_bls12381.Signature `protobuf:"bytes,1,opt,name=bls_sig,json=blsSig,proto3,customtype=github.com/babylonchain/babylon/crypto/bls12381.Signature" json:"bls_sig,omitempty"` +} + +func (m *ProofOfPossession) Reset() { *m = ProofOfPossession{} } +func (m *ProofOfPossession) String() string { return proto.CompactTextString(m) } +func (*ProofOfPossession) ProtoMessage() {} +func (*ProofOfPossession) Descriptor() ([]byte, []int) { + return fileDescriptor_a7e926461cc70111, []int{1} +} +func (m *ProofOfPossession) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ProofOfPossession) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ProofOfPossession.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ProofOfPossession) XXX_Merge(src proto.Message) { + xxx_messageInfo_ProofOfPossession.Merge(m, src) +} +func (m *ProofOfPossession) XXX_Size() int { + return m.Size() +} +func (m *ProofOfPossession) XXX_DiscardUnknown() { + xxx_messageInfo_ProofOfPossession.DiscardUnknown(m) +} + +var xxx_messageInfo_ProofOfPossession proto.InternalMessageInfo + +func init() { + proto.RegisterType((*BlsKey)(nil), "babylon.checkpointing.v1.BlsKey") + proto.RegisterType((*ProofOfPossession)(nil), "babylon.checkpointing.v1.ProofOfPossession") +} + +func init() { + proto.RegisterFile("babylon/checkpointing/bls_key.proto", fileDescriptor_a7e926461cc70111) +} + +var fileDescriptor_a7e926461cc70111 = []byte{ + // 284 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x4e, 0x4a, 0x4c, 0xaa, + 0xcc, 0xc9, 0xcf, 0xd3, 0x4f, 0xce, 0x48, 0x4d, 0xce, 0x2e, 0xc8, 0xcf, 0xcc, 0x2b, 0xc9, 0xcc, + 0x4b, 0xd7, 0x4f, 0xca, 0x29, 0x8e, 0xcf, 0x4e, 0xad, 0xd4, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, + 0x92, 0x80, 0x2a, 0xd2, 0x43, 0x51, 0xa4, 0x57, 0x66, 0x28, 0x25, 0x92, 0x9e, 0x9f, 0x9e, 0x0f, + 0x56, 0xa4, 0x0f, 0x62, 0x41, 0xd4, 0x2b, 0xcd, 0x63, 0xe4, 0x62, 0x73, 0xca, 0x29, 0xf6, 0x4e, + 0xad, 0x14, 0x0a, 0xe5, 0x62, 0x2b, 0x28, 0x4d, 0xca, 0x4e, 0xad, 0x94, 0x60, 0x54, 0x60, 0xd4, + 0xe0, 0x71, 0xb2, 0xbd, 0x75, 0x4f, 0xde, 0x32, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, + 0x3f, 0x57, 0x1f, 0x6a, 0x72, 0x72, 0x46, 0x62, 0x66, 0x9e, 0x3e, 0xdc, 0x2d, 0x45, 0x95, 0x05, + 0x25, 0xf9, 0x20, 0x47, 0x18, 0x1a, 0x19, 0x5b, 0x18, 0xea, 0x05, 0x94, 0x26, 0xe5, 0x64, 0x26, + 0x7b, 0xa7, 0x56, 0x06, 0x41, 0x0d, 0x13, 0xb2, 0xe5, 0x62, 0x2e, 0xc8, 0x2f, 0x90, 0x60, 0x52, + 0x60, 0xd4, 0xe0, 0x36, 0xd2, 0xd6, 0xc3, 0xe5, 0x3e, 0xbd, 0x80, 0xa2, 0xfc, 0xfc, 0x34, 0xff, + 0xb4, 0x80, 0xfc, 0xe2, 0xe2, 0xd4, 0xe2, 0xe2, 0xcc, 0xfc, 0xbc, 0x20, 0x90, 0x3e, 0xa5, 0x6c, + 0x2e, 0x41, 0x0c, 0x19, 0xa1, 0x30, 0x2e, 0x76, 0x90, 0xb7, 0x8b, 0x33, 0xd3, 0x29, 0x71, 0x6b, + 0x70, 0x66, 0x7a, 0x5e, 0x62, 0x49, 0x69, 0x51, 0x6a, 0x10, 0x5b, 0x52, 0x4e, 0x71, 0x70, 0x66, + 0xba, 0x93, 0xff, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, + 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x44, 0x99, 0x12, 0x32, + 0xbc, 0x02, 0x2d, 0x5a, 0x4a, 0x2a, 0x0b, 0x52, 0x8b, 0x93, 0xd8, 0xc0, 0xa1, 0x6c, 0x0c, 0x08, + 0x00, 0x00, 0xff, 0xff, 0x88, 0x85, 0x5d, 0xf5, 0xbc, 0x01, 0x00, 0x00, +} + +func (m *BlsKey) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *BlsKey) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *BlsKey) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pop != nil { + { + size, err := m.Pop.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintBlsKey(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if m.Pubkey != nil { + { + size := m.Pubkey.Size() + i -= size + if _, err := m.Pubkey.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintBlsKey(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *ProofOfPossession) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ProofOfPossession) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ProofOfPossession) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.BlsSig != nil { + { + size := m.BlsSig.Size() + i -= size + if _, err := m.BlsSig.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintBlsKey(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintBlsKey(dAtA []byte, offset int, v uint64) int { + offset -= sovBlsKey(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *BlsKey) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Pubkey != nil { + l = m.Pubkey.Size() + n += 1 + l + sovBlsKey(uint64(l)) + } + if m.Pop != nil { + l = m.Pop.Size() + n += 1 + l + sovBlsKey(uint64(l)) + } + return n +} + +func (m *ProofOfPossession) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.BlsSig != nil { + l = m.BlsSig.Size() + n += 1 + l + sovBlsKey(uint64(l)) + } + return n +} + +func sovBlsKey(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozBlsKey(x uint64) (n int) { + return sovBlsKey(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *BlsKey) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBlsKey + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: BlsKey: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: BlsKey: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pubkey", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBlsKey + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthBlsKey + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthBlsKey + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var v github_com_babylonchain_babylon_crypto_bls12381.PublicKey + m.Pubkey = &v + if err := m.Pubkey.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pop", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBlsKey + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthBlsKey + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthBlsKey + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pop == nil { + m.Pop = &ProofOfPossession{} + } + if err := m.Pop.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipBlsKey(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthBlsKey + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ProofOfPossession) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBlsKey + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ProofOfPossession: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ProofOfPossession: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BlsSig", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBlsKey + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthBlsKey + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthBlsKey + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var v github_com_babylonchain_babylon_crypto_bls12381.Signature + m.BlsSig = &v + if err := m.BlsSig.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipBlsKey(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthBlsKey + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipBlsKey(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowBlsKey + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowBlsKey + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowBlsKey + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthBlsKey + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupBlsKey + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthBlsKey + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthBlsKey = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowBlsKey = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupBlsKey = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/checkpointing/types/checkpoint.pb.go b/x/checkpointing/types/checkpoint.pb.go index 1d860a278..c9ecb8047 100644 --- a/x/checkpointing/types/checkpoint.pb.go +++ b/x/checkpointing/types/checkpoint.pb.go @@ -6,6 +6,7 @@ package types import ( bytes "bytes" fmt "fmt" + github_com_babylonchain_babylon_crypto_bls12381 "github.com/babylonchain/babylon/crypto/bls12381" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" _ "github.com/regen-network/cosmos-proto" @@ -67,7 +68,7 @@ type RawCheckpoint struct { // bitmap defines the bitmap that indicates the signers of the bls multi sig Bitmap []byte `protobuf:"bytes,3,opt,name=bitmap,proto3" json:"bitmap,omitempty"` // bls_multi_sig defines the multi sig that is aggregated from individual bls sigs - BlsMultiSig []byte `protobuf:"bytes,4,opt,name=bls_multi_sig,json=blsMultiSig,proto3" json:"bls_multi_sig,omitempty"` + BlsMultiSig *github_com_babylonchain_babylon_crypto_bls12381.Signature `protobuf:"bytes,4,opt,name=bls_multi_sig,json=blsMultiSig,proto3,customtype=github.com/babylonchain/babylon/crypto/bls12381.Signature" json:"bls_multi_sig,omitempty"` } func (m *RawCheckpoint) Reset() { *m = RawCheckpoint{} } @@ -124,13 +125,6 @@ func (m *RawCheckpoint) GetBitmap() []byte { return nil } -func (m *RawCheckpoint) GetBlsMultiSig() []byte { - if m != nil { - return m.BlsMultiSig - } - return nil -} - // RawCheckpointWithMeta wraps the raw checkpoint with meta data. type RawCheckpointWithMeta struct { Ckpt *RawCheckpoint `protobuf:"bytes,1,opt,name=ckpt,proto3" json:"ckpt,omitempty"` @@ -192,7 +186,7 @@ type BlsSig struct { // last_commit_hash defines the 'LastCommitHash' that the bls sig is signed on LastCommitHash []byte `protobuf:"bytes,2,opt,name=last_commit_hash,json=lastCommitHash,proto3" json:"last_commit_hash,omitempty"` // bls_sig defines the actual bls sig - BlsSig []byte `protobuf:"bytes,3,opt,name=bls_sig,json=blsSig,proto3" json:"bls_sig,omitempty"` + BlsSig *github_com_babylonchain_babylon_crypto_bls12381.Signature `protobuf:"bytes,3,opt,name=bls_sig,json=blsSig,proto3,customtype=github.com/babylonchain/babylon/crypto/bls12381.Signature" json:"bls_sig,omitempty"` // can't find cosmos_proto.scalar when compiling due to cosmos v0.45.4 does not support scalar // string signer_address = 5 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // the signer_address defines the address of the signer @@ -246,13 +240,6 @@ func (m *BlsSig) GetLastCommitHash() []byte { return nil } -func (m *BlsSig) GetBlsSig() []byte { - if m != nil { - return m.BlsSig - } - return nil -} - func (m *BlsSig) GetSignerAddress() string { if m != nil { return m.SignerAddress @@ -272,40 +259,42 @@ func init() { } var fileDescriptor_63ff05f0a47b36f7 = []byte{ - // 517 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x53, 0x41, 0x6f, 0xd3, 0x3e, - 0x1c, 0xad, 0xf7, 0xef, 0xbf, 0x50, 0x97, 0x96, 0xca, 0x62, 0x2c, 0x04, 0x29, 0x8b, 0x2a, 0x01, - 0xd5, 0x84, 0x12, 0x51, 0xc4, 0x05, 0x4e, 0x6b, 0x56, 0xb4, 0x69, 0x6a, 0x3b, 0xa5, 0xad, 0x90, - 0xb8, 0x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0x51, 0x1d, 0xa8, - 0x77, 0xa7, 0x33, 0xbd, 0x32, 0x8a, 0x3d, 0x16, 0x9f, 0x93, 0x09, 0xf5, 0xc7, 0xa8, 0x09, 0x77, - 0xaf, 0xab, 0xd7, 0xda, 0x1d, 0xb5, 0x3a, 0x9d, 0xe9, 0x65, 0x6b, 0xa5, 0x54, 0x8b, 0x1f, 0xbf, - 0x69, 0x85, 0x76, 0xff, 0xc7, 0x5c, 0x03, 0x57, 0x73, 0x0d, 0xfc, 0x9a, 0x6b, 0xe0, 0xf3, 0x42, - 0x2b, 0x5c, 0x2d, 0xb4, 0xc2, 0xcf, 0x85, 0x56, 0x78, 0xfb, 0x22, 0x20, 0x22, 0x4c, 0x5d, 0xc3, - 0x63, 0xd4, 0x5c, 0x1e, 0x88, 0x17, 0x62, 0x12, 0xaf, 0x80, 0xf9, 0x61, 0xeb, 0xd9, 0x88, 0xcb, - 0xc4, 0xe7, 0x6e, 0x49, 0x5e, 0xe3, 0xe7, 0x7f, 0x02, 0x00, 0x00, 0xff, 0xff, 0x99, 0x75, 0xc9, - 0xc2, 0x5c, 0x03, 0x00, 0x00, + // 558 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x93, 0x5f, 0x6b, 0xd3, 0x50, + 0x18, 0xc6, 0x73, 0xb6, 0x5a, 0xdd, 0x99, 0xad, 0x25, 0x38, 0x8d, 0x11, 0xd2, 0x50, 0x50, 0xcb, + 0x90, 0x84, 0x76, 0x08, 0xfe, 0xc1, 0x8b, 0x35, 0xab, 0x6c, 0x8c, 0xb6, 0x23, 0x69, 0x15, 0xbc, + 0x09, 0x27, 0x69, 0x96, 0x1c, 0x96, 0xe4, 0x84, 0x9c, 0x13, 0xb5, 0xdf, 0x40, 0x7a, 0xe5, 0xa5, + 0x37, 0x05, 0x41, 0x3f, 0x8c, 0x97, 0xbb, 0x10, 0x14, 0x2f, 0x44, 0xda, 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 0x6f, 0xef, 0x55, 0x38, 0x91, 0x1f, 0x4f, + 0xe4, 0xf2, 0x20, 0x5c, 0xc8, 0x73, 0x86, 0xfc, 0x43, 0x78, 0x7b, 0x85, 0xe9, 0x75, 0x5f, 0x1c, + 0xe8, 0x9d, 0xf6, 0x5e, 0x05, 0x88, 0x37, 0xc6, 0x13, 0x79, 0x73, 0x10, 0xda, 0x24, 0x3c, 0xc6, + 0x71, 0xe0, 0x0c, 0xf9, 0x3a, 0xdc, 0x3a, 0xdf, 0x5e, 0x74, 0xd7, 0xc4, 0xd2, 0x78, 0x22, 0x6f, + 0x68, 0xff, 0x9a, 0x62, 0xe1, 0xfd, 0x67, 0x89, 0x6b, 0xf5, 0xbe, 0x4e, 0x25, 0x70, 0x3a, 0x95, + 0xc0, 0xef, 0xa9, 0x04, 0x3e, 0xcc, 0x24, 0xee, 0x74, 0x26, 0x71, 0x3f, 0x66, 0x12, 0xf7, 0xfa, + 0xd1, 0xff, 0x84, 0xbd, 0x5b, 0xb9, 0xba, 0x6c, 0x14, 0x39, 0xd4, 0x2a, 0x66, 0x57, 0x69, 0xe7, + 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xf1, 0xf9, 0xdf, 0x5c, 0xe0, 0x03, 0x00, 0x00, } func (this *RawCheckpoint) Equal(that interface{}) bool { @@ -336,7 +325,11 @@ func (this *RawCheckpoint) Equal(that interface{}) bool { if !bytes.Equal(this.Bitmap, that1.Bitmap) { return false } - if !bytes.Equal(this.BlsMultiSig, that1.BlsMultiSig) { + if that1.BlsMultiSig == nil { + if this.BlsMultiSig != nil { + return false + } + } else if !this.BlsMultiSig.Equal(*that1.BlsMultiSig) { return false } return true @@ -361,10 +354,15 @@ func (m *RawCheckpoint) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.BlsMultiSig) > 0 { - i -= len(m.BlsMultiSig) - copy(dAtA[i:], m.BlsMultiSig) - i = encodeVarintCheckpoint(dAtA, i, uint64(len(m.BlsMultiSig))) + if m.BlsMultiSig != nil { + { + size := m.BlsMultiSig.Size() + i -= size + if _, err := m.BlsMultiSig.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintCheckpoint(dAtA, i, uint64(size)) + } i-- dAtA[i] = 0x22 } @@ -457,10 +455,15 @@ func (m *BlsSig) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x2a } - if len(m.BlsSig) > 0 { - i -= len(m.BlsSig) - copy(dAtA[i:], m.BlsSig) - i = encodeVarintCheckpoint(dAtA, i, uint64(len(m.BlsSig))) + if m.BlsSig != nil { + { + size := m.BlsSig.Size() + i -= size + if _, err := m.BlsSig.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintCheckpoint(dAtA, i, uint64(size)) + } i-- dAtA[i] = 0x1a } @@ -507,8 +510,8 @@ func (m *RawCheckpoint) Size() (n int) { if l > 0 { n += 1 + l + sovCheckpoint(uint64(l)) } - l = len(m.BlsMultiSig) - if l > 0 { + if m.BlsMultiSig != nil { + l = m.BlsMultiSig.Size() n += 1 + l + sovCheckpoint(uint64(l)) } return n @@ -543,8 +546,8 @@ func (m *BlsSig) Size() (n int) { if l > 0 { n += 1 + l + sovCheckpoint(uint64(l)) } - l = len(m.BlsSig) - if l > 0 { + if m.BlsSig != nil { + l = m.BlsSig.Size() n += 1 + l + sovCheckpoint(uint64(l)) } l = len(m.SignerAddress) @@ -705,9 +708,10 @@ func (m *RawCheckpoint) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.BlsMultiSig = append(m.BlsMultiSig[:0], dAtA[iNdEx:postIndex]...) - if m.BlsMultiSig == nil { - m.BlsMultiSig = []byte{} + var v github_com_babylonchain_babylon_crypto_bls12381.Signature + m.BlsMultiSig = &v + if err := m.BlsMultiSig.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err } iNdEx = postIndex default: @@ -947,9 +951,10 @@ func (m *BlsSig) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.BlsSig = append(m.BlsSig[:0], dAtA[iNdEx:postIndex]...) - if m.BlsSig == nil { - m.BlsSig = []byte{} + var v github_com_babylonchain_babylon_crypto_bls12381.Signature + m.BlsSig = &v + if err := m.BlsSig.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err } iNdEx = postIndex case 5: diff --git a/x/checkpointing/types/codec.go b/x/checkpointing/types/codec.go index 4bb325044..cd1a2a495 100644 --- a/x/checkpointing/types/codec.go +++ b/x/checkpointing/types/codec.go @@ -15,6 +15,7 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { // Register messages registry.RegisterImplementations((*sdk.Msg)(nil), &MsgAddBlsSig{}, + &MsgWrappedCreateValidator{}, ) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } diff --git a/x/checkpointing/types/errors.go b/x/checkpointing/types/errors.go index 70c1aa380..d19169605 100644 --- a/x/checkpointing/types/errors.go +++ b/x/checkpointing/types/errors.go @@ -4,7 +4,9 @@ import sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" // x/checkpointing module sentinel errors var ( - ErrCkptDoesNotExist = sdkerrors.Register(ModuleName, 1201, "raw checkpoint does not exist") - ErrCkptAlreadyExist = sdkerrors.Register(ModuleName, 1202, "raw checkpoint already exists") - ErrCkptHashNotEqual = sdkerrors.Register(ModuleName, 1203, "hash does not equal to raw checkpoint") + ErrCkptDoesNotExist = sdkerrors.Register(ModuleName, 1201, "raw checkpoint does not exist") + ErrCkptAlreadyExist = sdkerrors.Register(ModuleName, 1202, "raw checkpoint already exists") + ErrCkptHashNotEqual = sdkerrors.Register(ModuleName, 1203, "hash does not equal to raw checkpoint") + ErrBlsKeyDoesNotExist = sdkerrors.Register(ModuleName, 1204, "BLS public key does not exist") + ErrBlsKeyAlreadyExist = sdkerrors.Register(ModuleName, 1205, "BLS public key already exists") ) diff --git a/x/checkpointing/types/expected_keepers.go b/x/checkpointing/types/expected_keepers.go index ae5f1d865..ce1fa0d5a 100644 --- a/x/checkpointing/types/expected_keepers.go +++ b/x/checkpointing/types/expected_keepers.go @@ -1,6 +1,7 @@ package types import ( + epochingtypes "github.com/babylonchain/babylon/x/epoching/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/types" ) @@ -24,7 +25,8 @@ type StakingKeeper interface { // EpochingKeeper defines the expected interface needed to retrieve epoch info type EpochingKeeper interface { - GetCurrentEpoch(ctx sdk.Context) sdk.Uint + GetEpochNumber(ctx sdk.Context) (sdk.Uint, error) + EnqueueMsg(ctx sdk.Context, msg epochingtypes.QueuedMessage) error } // Event Hooks diff --git a/x/checkpointing/types/keys.go b/x/checkpointing/types/keys.go index 7ffd74232..835f92aaa 100644 --- a/x/checkpointing/types/keys.go +++ b/x/checkpointing/types/keys.go @@ -1,6 +1,7 @@ package types import ( + "github.com/babylonchain/babylon/crypto/bls12381" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -22,13 +23,17 @@ const ( ) var ( - BlsSigsPrefix = []byte{0x0} // reserve this namespace for bls sigs - CheckpointsPrefix = []byte{0x1} // reserve this namespace for checkpoints + BlsSigsPrefix = []byte{0x0} // reserve this namespace for BLS sigs + CheckpointsPrefix = []byte{0x1} // reserve this namespace for checkpoints + RegistrationPrefix = []byte{0x2} // reserve this namespace for BLS keys - BlsSigsObjectPrefix = append(BlsSigsPrefix, 0x0) // where we save the concrete bls sig bytes + BlsSigsObjectPrefix = append(BlsSigsPrefix, 0x0) // where we save the concrete BLS sig bytes BlsSigsHashToEpochPrefix = append(BlsSigsPrefix, 0x1) // where we map hash to epoch - CkptsObjectPrefix = append(CheckpointsPrefix, 0x0) // where we save the concrete bls sig bytes + CkptsObjectPrefix = append(CheckpointsPrefix, 0x0) // where we save the concrete BLS sig bytes + + AddrToBlsKeyPrefix = append(RegistrationPrefix, 0x0) // where we save the concrete BLS public keys + BlsKeyToAddrPrefix = append(RegistrationPrefix, 0x1) // where we save BLS key set ) // BlsSigsObjectKey defines epoch + hash @@ -38,6 +43,7 @@ func BlsSigsObjectKey(epoch uint64, hash BlsSigHash) []byte { return append(epochPrefix, hash...) } +// BlsSigsEpochKey defines BLS sig hash func BlsSigsEpochKey(hash BlsSigHash) []byte { return append(BlsSigsHashToEpochPrefix, hash...) } @@ -47,6 +53,16 @@ func CkptsObjectKey(epoch uint64) []byte { return append(CkptsObjectPrefix, sdk.Uint64ToBigEndian(epoch)...) } +// AddrToBlsKeyKey defines validator address +func AddrToBlsKeyKey(valAddr ValidatorAddress) []byte { + return append(AddrToBlsKeyPrefix, []byte(valAddr)...) +} + +// BlsKeyToAddrKey defines BLS public key +func BlsKeyToAddrKey(pk bls12381.PublicKey) []byte { + return append(BlsKeyToAddrPrefix, pk...) +} + func KeyPrefix(p string) []byte { return []byte(p) } diff --git a/x/checkpointing/types/msgs.go b/x/checkpointing/types/msgs.go index 2f3f41439..517f7a830 100644 --- a/x/checkpointing/types/msgs.go +++ b/x/checkpointing/types/msgs.go @@ -27,3 +27,14 @@ func (m *MsgAddBlsSig) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{signer} } + +func (m *MsgWrappedCreateValidator) ValidateBasic() error { + // This function validates stateless message elements + // TODO: verify bls sig + + return m.MsgCreateValidator.ValidateBasic() +} + +func (m *MsgWrappedCreateValidator) GetSigners() []sdk.AccAddress { + return m.MsgCreateValidator.GetSigners() +} diff --git a/x/checkpointing/types/tx.pb.go b/x/checkpointing/types/tx.pb.go index 908a59b13..2fab4a133 100644 --- a/x/checkpointing/types/tx.pb.go +++ b/x/checkpointing/types/tx.pb.go @@ -6,6 +6,7 @@ package types import ( context "context" fmt "fmt" + types "github.com/cosmos/cosmos-sdk/x/staking/types" _ "github.com/gogo/protobuf/gogoproto" grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" @@ -104,31 +105,118 @@ func (m *MsgAddBlsSigResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgAddBlsSigResponse proto.InternalMessageInfo +// MsgWrappedCreateValidator defines a wrapped message to create a validator +type MsgWrappedCreateValidator struct { + Key *BlsKey `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + MsgCreateValidator *types.MsgCreateValidator `protobuf:"bytes,2,opt,name=msg_create_validator,json=msgCreateValidator,proto3" json:"msg_create_validator,omitempty"` +} + +func (m *MsgWrappedCreateValidator) Reset() { *m = MsgWrappedCreateValidator{} } +func (m *MsgWrappedCreateValidator) String() string { return proto.CompactTextString(m) } +func (*MsgWrappedCreateValidator) ProtoMessage() {} +func (*MsgWrappedCreateValidator) Descriptor() ([]byte, []int) { + return fileDescriptor_24b023a97b92daa6, []int{2} +} +func (m *MsgWrappedCreateValidator) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgWrappedCreateValidator) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgWrappedCreateValidator.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgWrappedCreateValidator) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgWrappedCreateValidator.Merge(m, src) +} +func (m *MsgWrappedCreateValidator) XXX_Size() int { + return m.Size() +} +func (m *MsgWrappedCreateValidator) XXX_DiscardUnknown() { + xxx_messageInfo_MsgWrappedCreateValidator.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgWrappedCreateValidator proto.InternalMessageInfo + +// MsgWrappedCreateValidatorResponse defines the MsgWrappedCreateValidator response type +type MsgWrappedCreateValidatorResponse struct { +} + +func (m *MsgWrappedCreateValidatorResponse) Reset() { *m = MsgWrappedCreateValidatorResponse{} } +func (m *MsgWrappedCreateValidatorResponse) String() string { return proto.CompactTextString(m) } +func (*MsgWrappedCreateValidatorResponse) ProtoMessage() {} +func (*MsgWrappedCreateValidatorResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_24b023a97b92daa6, []int{3} +} +func (m *MsgWrappedCreateValidatorResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgWrappedCreateValidatorResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgWrappedCreateValidatorResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgWrappedCreateValidatorResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgWrappedCreateValidatorResponse.Merge(m, src) +} +func (m *MsgWrappedCreateValidatorResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgWrappedCreateValidatorResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgWrappedCreateValidatorResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgWrappedCreateValidatorResponse proto.InternalMessageInfo + func init() { proto.RegisterType((*MsgAddBlsSig)(nil), "babylon.checkpointing.v1.MsgAddBlsSig") proto.RegisterType((*MsgAddBlsSigResponse)(nil), "babylon.checkpointing.v1.MsgAddBlsSigResponse") + proto.RegisterType((*MsgWrappedCreateValidator)(nil), "babylon.checkpointing.v1.MsgWrappedCreateValidator") + proto.RegisterType((*MsgWrappedCreateValidatorResponse)(nil), "babylon.checkpointing.v1.MsgWrappedCreateValidatorResponse") } func init() { proto.RegisterFile("babylon/checkpointing/tx.proto", fileDescriptor_24b023a97b92daa6) } var fileDescriptor_24b023a97b92daa6 = []byte{ - // 246 bytes of a gzipped FileDescriptorProto + // 399 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x4b, 0x4a, 0x4c, 0xaa, 0xcc, 0xc9, 0xcf, 0xd3, 0x4f, 0xce, 0x48, 0x4d, 0xce, 0x2e, 0xc8, 0xcf, 0xcc, 0x2b, 0xc9, 0xcc, 0x4b, 0xd7, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x80, 0xca, 0xeb, 0xa1, 0xc8, 0xeb, 0x95, 0x19, 0x4a, 0x89, 0xa4, 0xe7, 0xa7, 0xe7, 0x83, 0x15, 0xe9, 0x83, 0x58, 0x10, - 0xf5, 0x52, 0x6a, 0xd8, 0xcd, 0x43, 0xf0, 0x20, 0xea, 0x94, 0x82, 0xb9, 0x78, 0x7c, 0x8b, 0xd3, - 0x1d, 0x53, 0x52, 0x9c, 0x72, 0x8a, 0x83, 0x33, 0xd3, 0x85, 0x2c, 0xb9, 0xd8, 0x93, 0x72, 0x8a, - 0xe3, 0x8b, 0x33, 0xd3, 0x25, 0x18, 0x15, 0x18, 0x35, 0xb8, 0x8d, 0x14, 0xf4, 0x70, 0xd9, 0xac, - 0x07, 0xd1, 0x12, 0xc4, 0x96, 0x04, 0xa6, 0xad, 0x38, 0x3a, 0x16, 0xc8, 0x33, 0xbc, 0x58, 0x20, - 0xcf, 0xa0, 0x24, 0xc6, 0x25, 0x82, 0x6c, 0x68, 0x50, 0x6a, 0x71, 0x41, 0x7e, 0x5e, 0x71, 0xaa, - 0x51, 0x16, 0x17, 0xb3, 0x6f, 0x71, 0xba, 0x50, 0x32, 0x17, 0x27, 0xc2, 0x42, 0x35, 0xdc, 0xe6, - 0x23, 0x9b, 0x21, 0xa5, 0x47, 0x9c, 0x3a, 0x98, 0x5d, 0x4e, 0xfe, 0x27, 0x1e, 0xc9, 0x31, 0x5e, - 0x78, 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, - 0xdc, 0x78, 0x2c, 0xc7, 0x10, 0x65, 0x9a, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, - 0xab, 0x0f, 0x35, 0x33, 0x39, 0x23, 0x31, 0x33, 0x0f, 0xc6, 0xd1, 0xaf, 0x40, 0x8f, 0x84, 0xca, - 0x82, 0xd4, 0xe2, 0x24, 0x36, 0x70, 0x80, 0x19, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x32, 0xaf, - 0xd1, 0xd8, 0xaa, 0x01, 0x00, 0x00, + 0xf5, 0x52, 0x6a, 0xd8, 0xcd, 0x43, 0xf0, 0xa0, 0xea, 0x94, 0xb1, 0xab, 0x4b, 0xca, 0x29, 0x8e, + 0xcf, 0x4e, 0xad, 0x84, 0x2a, 0x92, 0x4f, 0xce, 0x2f, 0xce, 0xcd, 0x2f, 0xd6, 0x2f, 0x2e, 0x49, + 0xcc, 0x06, 0xc9, 0x96, 0x19, 0x26, 0xa5, 0x96, 0x24, 0x1a, 0xc2, 0x5d, 0xa7, 0x14, 0xcc, 0xc5, + 0xe3, 0x5b, 0x9c, 0xee, 0x98, 0x92, 0xe2, 0x94, 0x53, 0x1c, 0x9c, 0x99, 0x2e, 0x64, 0xc9, 0xc5, + 0x0e, 0x32, 0xa1, 0x38, 0x33, 0x5d, 0x82, 0x51, 0x81, 0x51, 0x83, 0xdb, 0x48, 0x41, 0x0f, 0x97, + 0xfb, 0xf5, 0x20, 0x5a, 0x82, 0xd8, 0x92, 0xc0, 0xb4, 0x15, 0x47, 0xc7, 0x02, 0x79, 0x86, 0x17, + 0x0b, 0xe4, 0x19, 0x94, 0xc4, 0xb8, 0x44, 0x90, 0x0d, 0x0d, 0x4a, 0x2d, 0x2e, 0xc8, 0xcf, 0x2b, + 0x4e, 0x55, 0xda, 0xce, 0xc8, 0x25, 0xe9, 0x5b, 0x9c, 0x1e, 0x5e, 0x94, 0x58, 0x50, 0x90, 0x9a, + 0xe2, 0x5c, 0x94, 0x9a, 0x58, 0x92, 0x1a, 0x96, 0x98, 0x93, 0x99, 0x92, 0x58, 0x92, 0x5f, 0x24, + 0x64, 0xc4, 0xc5, 0x9c, 0x9d, 0x5a, 0x49, 0x94, 0xb5, 0xde, 0xa9, 0x95, 0x41, 0x20, 0xc5, 0x42, + 0x31, 0x5c, 0x22, 0xb9, 0xc5, 0xe9, 0xf1, 0xc9, 0x60, 0xa3, 0xe2, 0xcb, 0x60, 0x66, 0x49, 0x30, + 0x81, 0x0d, 0xd1, 0xd2, 0x83, 0x78, 0x5f, 0x0f, 0xea, 0x7d, 0x3d, 0xa8, 0xf7, 0xf5, 0x7c, 0x8b, + 0xd3, 0xd1, 0x6c, 0x0f, 0x12, 0xca, 0xc5, 0x10, 0x43, 0xf2, 0x91, 0x32, 0x97, 0x22, 0x4e, 0x87, + 0xc3, 0xbc, 0x67, 0xf4, 0x9d, 0x91, 0x8b, 0xd9, 0xb7, 0x38, 0x5d, 0x28, 0x99, 0x8b, 0x13, 0x11, + 0xa0, 0x6a, 0xb8, 0x3d, 0x82, 0x1c, 0x46, 0x52, 0x7a, 0xc4, 0xa9, 0x83, 0x59, 0x26, 0xd4, 0xc5, + 0xc8, 0x25, 0x86, 0x23, 0x20, 0x8d, 0xf1, 0x1a, 0x85, 0x5d, 0x93, 0x94, 0x35, 0x19, 0x9a, 0x60, + 0x8e, 0x71, 0xf2, 0x3f, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, + 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0xd3, 0xf4, + 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0x7d, 0xa8, 0x05, 0xc9, 0x19, 0x89, 0x99, + 0x79, 0x30, 0x8e, 0x7e, 0x05, 0x7a, 0xbe, 0xa9, 0x2c, 0x48, 0x2d, 0x4e, 0x62, 0x03, 0xa7, 0x4e, + 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x0a, 0xe9, 0x81, 0x51, 0x5d, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -143,7 +231,10 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type MsgClient interface { + // AddBlsSig defines a method for accumulating BLS signatures AddBlsSig(ctx context.Context, in *MsgAddBlsSig, opts ...grpc.CallOption) (*MsgAddBlsSigResponse, error) + // WrappedCreateValidator defines a method for registering a new validator + WrappedCreateValidator(ctx context.Context, in *MsgWrappedCreateValidator, opts ...grpc.CallOption) (*MsgWrappedCreateValidatorResponse, error) } type msgClient struct { @@ -163,9 +254,21 @@ func (c *msgClient) AddBlsSig(ctx context.Context, in *MsgAddBlsSig, opts ...grp return out, nil } +func (c *msgClient) WrappedCreateValidator(ctx context.Context, in *MsgWrappedCreateValidator, opts ...grpc.CallOption) (*MsgWrappedCreateValidatorResponse, error) { + out := new(MsgWrappedCreateValidatorResponse) + err := c.cc.Invoke(ctx, "/babylon.checkpointing.v1.Msg/WrappedCreateValidator", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { + // AddBlsSig defines a method for accumulating BLS signatures AddBlsSig(context.Context, *MsgAddBlsSig) (*MsgAddBlsSigResponse, error) + // WrappedCreateValidator defines a method for registering a new validator + WrappedCreateValidator(context.Context, *MsgWrappedCreateValidator) (*MsgWrappedCreateValidatorResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -175,6 +278,9 @@ type UnimplementedMsgServer struct { func (*UnimplementedMsgServer) AddBlsSig(ctx context.Context, req *MsgAddBlsSig) (*MsgAddBlsSigResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method AddBlsSig not implemented") } +func (*UnimplementedMsgServer) WrappedCreateValidator(ctx context.Context, req *MsgWrappedCreateValidator) (*MsgWrappedCreateValidatorResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method WrappedCreateValidator not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -198,6 +304,24 @@ func _Msg_AddBlsSig_Handler(srv interface{}, ctx context.Context, dec func(inter return interceptor(ctx, in, info, handler) } +func _Msg_WrappedCreateValidator_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgWrappedCreateValidator) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).WrappedCreateValidator(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/babylon.checkpointing.v1.Msg/WrappedCreateValidator", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).WrappedCreateValidator(ctx, req.(*MsgWrappedCreateValidator)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "babylon.checkpointing.v1.Msg", HandlerType: (*MsgServer)(nil), @@ -206,6 +330,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "AddBlsSig", Handler: _Msg_AddBlsSig_Handler, }, + { + MethodName: "WrappedCreateValidator", + Handler: _Msg_WrappedCreateValidator_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "babylon/checkpointing/tx.proto", @@ -269,6 +397,76 @@ func (m *MsgAddBlsSigResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *MsgWrappedCreateValidator) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgWrappedCreateValidator) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgWrappedCreateValidator) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.MsgCreateValidator != nil { + { + size, err := m.MsgCreateValidator.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if m.Key != nil { + { + size, err := m.Key.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgWrappedCreateValidatorResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgWrappedCreateValidatorResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgWrappedCreateValidatorResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + func encodeVarintTx(dAtA []byte, offset int, v uint64) int { offset -= sovTx(v) base := offset @@ -302,6 +500,32 @@ func (m *MsgAddBlsSigResponse) Size() (n int) { return n } +func (m *MsgWrappedCreateValidator) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Key != nil { + l = m.Key.Size() + n += 1 + l + sovTx(uint64(l)) + } + if m.MsgCreateValidator != nil { + l = m.MsgCreateValidator.Size() + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgWrappedCreateValidatorResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -444,6 +668,178 @@ func (m *MsgAddBlsSigResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgWrappedCreateValidator) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgWrappedCreateValidator: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgWrappedCreateValidator: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Key == nil { + m.Key = &BlsKey{} + } + if err := m.Key.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MsgCreateValidator", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.MsgCreateValidator == nil { + m.MsgCreateValidator = &types.MsgCreateValidator{} + } + if err := m.MsgCreateValidator.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgWrappedCreateValidatorResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgWrappedCreateValidatorResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgWrappedCreateValidatorResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/checkpointing/types/types.go b/x/checkpointing/types/types.go index 20679b531..758a8d16b 100644 --- a/x/checkpointing/types/types.go +++ b/x/checkpointing/types/types.go @@ -5,10 +5,20 @@ import ( "github.com/cosmos/cosmos-sdk/codec" ) +type ValidatorAddress string + type BlsSigHash []byte type RawCkptHash []byte +func BytesToValAddr(data []byte) ValidatorAddress { + return ValidatorAddress(data) +} + +func ValAddrToBytes(address ValidatorAddress) []byte { + return []byte(address) +} + func NewCheckpointWithMeta(ckpt *RawCheckpoint, status CheckpointStatus) *RawCheckpointWithMeta { return &RawCheckpointWithMeta{ Ckpt: ckpt, diff --git a/x/checkpointing/types/utils.go b/x/checkpointing/types/utils.go index 01099b1c5..8d2016bd5 100644 --- a/x/checkpointing/types/utils.go +++ b/x/checkpointing/types/utils.go @@ -9,7 +9,7 @@ func (m BlsSig) Hash() BlsSigHash { fields := [][]byte{ sdk.Uint64ToBigEndian(m.EpochNum), m.LastCommitHash, - m.BlsSig, + m.BlsSig.MustMarshal(), []byte(m.SignerAddress), } return hash(fields) @@ -19,7 +19,7 @@ func (m RawCheckpoint) Hash() RawCkptHash { fields := [][]byte{ sdk.Uint64ToBigEndian(m.EpochNum), m.LastCommitHash, - m.BlsMultiSig, + m.BlsMultiSig.MustMarshal(), m.Bitmap, } return hash(fields)