From 04cfab307f26fc63736f5fba1dc07a995d65cc3f Mon Sep 17 00:00:00 2001 From: Fangyu Gai Date: Mon, 4 Jul 2022 17:38:33 +0800 Subject: [PATCH 1/6] add bls key proto and state --- proto/babylon/checkpointing/bls_key.proto | 25 + proto/babylon/checkpointing/tx.proto | 30 + x/checkpointing/keeper/blskey_state.go | 59 ++ x/checkpointing/keeper/blssig_state.go | 8 +- x/checkpointing/keeper/msg_server.go | 17 +- x/checkpointing/types/bls_key.pb.go | 661 +++++++++++++++++ x/checkpointing/types/errors.go | 8 +- x/checkpointing/types/keys.go | 13 +- x/checkpointing/types/tx.pb.go | 838 +++++++++++++++++++++- x/checkpointing/types/types.go | 10 + 10 files changed, 1635 insertions(+), 34 deletions(-) create mode 100644 proto/babylon/checkpointing/bls_key.proto create mode 100644 x/checkpointing/keeper/blskey_state.go create mode 100644 x/checkpointing/types/bls_key.pb.go diff --git a/proto/babylon/checkpointing/bls_key.proto b/proto/babylon/checkpointing/bls_key.proto new file mode 100644 index 000000000..e6b5a322c --- /dev/null +++ b/proto/babylon/checkpointing/bls_key.proto @@ -0,0 +1,25 @@ +syntax = "proto3"; +package babylon.checkpointing.v1; + +option go_package = "github.com/babylonchain/babylon/x/checkpointing/types"; + +// BlsPubKey wraps BLS public key with meta data +message BlsPubKey { + // key is the BLS public key of a validator + bytes key = 1; + + // address is validator's address + string address = 2; +} + +// ProofOfPossession defines proof for the ownership of Ed25519 and BLS private keys +message ProofOfPossession { + // ed25519_pk is the Ed25519 public key of the validator + bytes ed25519_pk = 1; + + // bls_sig is the BLS signature over ed25519_pk + bytes bls_sig = 2; + + // ed25519_sig is the Ed25519 signature over bls_sig + bytes ed25519_sig = 3; +} diff --git a/proto/babylon/checkpointing/tx.proto b/proto/babylon/checkpointing/tx.proto index 7e2ae0a3a..e6e514087 100644 --- a/proto/babylon/checkpointing/tx.proto +++ b/proto/babylon/checkpointing/tx.proto @@ -3,12 +3,21 @@ 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); + + // CreateBlsKey defines a method for registering a BLS key for a validator + rpc CreateBlsKey(MsgCreateBlsKey) returns (MsgCreateBlsKeyResponse); + + // 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 +31,24 @@ message MsgAddBlsSig { // MsgAddBlsSigResponse defines the MsgAddBlsSig response type. message MsgAddBlsSigResponse {} + +// MsgCreateBlsKey defines a message to create a BLS key for a validator +message MsgCreateBlsKey { + BlsPubKey pubkey = 1; + ProofOfPossession pop = 2; +} + +// MsgCreateBlsKeyResponse defines the MsgCreateBlsKey response type +message MsgCreateBlsKeyResponse {} + +// MsgWrappedCreateValidator defines a wrapped message to create a validator +message MsgWrappedCreateValidator { + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + cosmos.staking.v1beta1.MsgCreateValidator msg_staking = 1; + MsgCreateBlsKey msg_checkpointing = 2; +} + +// MsgWrappedCreateValidatorResponse defines the MsgWrappedCreateValidator response type +message MsgWrappedCreateValidatorResponse {} diff --git a/x/checkpointing/keeper/blskey_state.go b/x/checkpointing/keeper/blskey_state.go new file mode 100644 index 000000000..3927f8cab --- /dev/null +++ b/x/checkpointing/keeper/blskey_state.go @@ -0,0 +1,59 @@ +package keeper + +import ( + "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 BlsKeysState struct { + cdc codec.BinaryCodec + blsKeys sdk.KVStore +} + +func (k Keeper) BlsKeysState(ctx sdk.Context) BlsKeysState { + // Build the BlsKeysState storage + store := ctx.KVStore(k.storeKey) + return BlsKeysState{ + cdc: k.cdc, + blsKeys: prefix.NewStore(store, types.BlsKeysPrefix), + } +} + +// CreateBlsKey inserts the BLS key into the address->bls_key storage +func (bk BlsKeysState) CreateBlsKey(key *types.BlsPubKey) error { + if bk.Exists(key.Address) { + return types.ErrBlsKeyAlreadyExist.Wrapf("existed public key: %x", key.Key) + } + blsKeysKey := types.BlsKeysObjectKey(key.Address) + // save concrete BLS public key object + bk.blsKeys.Set(blsKeysKey, types.BlsPubKeyToBytes(bk.cdc, key)) + return nil +} + +// GetBlsPubKey retrieves BLS public key by validator's address +func (bk BlsKeysState) GetBlsPubKey(addr string) (*types.BlsPubKey, error) { + pubKeyKey := types.BlsKeysObjectKey(addr) + rawBytes := bk.blsKeys.Get(pubKeyKey) + if rawBytes == nil { + return nil, types.ErrBlsKeyDoesNotExist.Wrapf("BLS public key does not exist with address %s", addr) + } + + return types.BytesToBlsPubKey(bk.cdc, rawBytes) +} + +// RemoveBlsPubKey removes a BLS public key +func (bk BlsKeysState) RemoveBlsPubKey(addr string) error { + if !bk.Exists(addr) { + return types.ErrBlsKeyDoesNotExist.Wrapf("BLS public key does not exist with address %s", addr) + } + // delete BLS public key from storage + bk.blsKeys.Delete(types.BlsKeysObjectKey(addr)) + return nil +} + +func (bk BlsKeysState) Exists(addr string) bool { + blsKeysKey := types.BlsKeysObjectKey(addr) + return bk.blsKeys.Has(blsKeysKey) +} diff --git a/x/checkpointing/keeper/blssig_state.go b/x/checkpointing/keeper/blssig_state.go index be76da30a..f579e2f0f 100644 --- a/x/checkpointing/keeper/blssig_state.go +++ b/x/checkpointing/keeper/blssig_state.go @@ -23,20 +23,20 @@ func (k Keeper) BlsSigsState(ctx sdk.Context) BlsSigsState { } } -// 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/msg_server.go b/x/checkpointing/keeper/msg_server.go index ca4a587e8..9901b30a0 100644 --- a/x/checkpointing/keeper/msg_server.go +++ b/x/checkpointing/keeper/msg_server.go @@ -10,11 +10,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 +17,15 @@ func NewMsgServerImpl(keeper Keeper) types.MsgServer { } var _ types.MsgServer = msgServer{} + +func (m msgServer) AddBlsSig(ctx context.Context, header *types.MsgAddBlsSig) (*types.MsgAddBlsSigResponse, error) { + panic("TODO: implement me") +} + +func (m msgServer) CreateBlsKey(ctx context.Context, msg *types.MsgCreateBlsKey) (*types.MsgCreateBlsKeyResponse, error) { + panic("TODO: implement me") +} + +func (m msgServer) WrappedCreateValidator(ctx context.Context, msg *types.MsgWrappedCreateValidator) (*types.MsgWrappedCreateValidatorResponse, error) { + panic("TODO: implement me") +} diff --git a/x/checkpointing/types/bls_key.pb.go b/x/checkpointing/types/bls_key.pb.go new file mode 100644 index 000000000..faedc9a57 --- /dev/null +++ b/x/checkpointing/types/bls_key.pb.go @@ -0,0 +1,661 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: babylon/checkpointing/bls_key.proto + +package types + +import ( + fmt "fmt" + 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 + +// BlsPubKey wraps BLS public key with meta data +type BlsPubKey struct { + // key is the BLS public key of a validator + Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + // address is validator's address + Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` +} + +func (m *BlsPubKey) Reset() { *m = BlsPubKey{} } +func (m *BlsPubKey) String() string { return proto.CompactTextString(m) } +func (*BlsPubKey) ProtoMessage() {} +func (*BlsPubKey) Descriptor() ([]byte, []int) { + return fileDescriptor_a7e926461cc70111, []int{0} +} +func (m *BlsPubKey) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *BlsPubKey) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_BlsPubKey.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 *BlsPubKey) XXX_Merge(src proto.Message) { + xxx_messageInfo_BlsPubKey.Merge(m, src) +} +func (m *BlsPubKey) XXX_Size() int { + return m.Size() +} +func (m *BlsPubKey) XXX_DiscardUnknown() { + xxx_messageInfo_BlsPubKey.DiscardUnknown(m) +} + +var xxx_messageInfo_BlsPubKey proto.InternalMessageInfo + +func (m *BlsPubKey) GetKey() []byte { + if m != nil { + return m.Key + } + return nil +} + +func (m *BlsPubKey) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + +// ProofOfPossession defines proof for the ownership of Ed25519 and BLS private keys +type ProofOfPossession struct { + // ed25519_pk is the Ed25519 public key of the validator + Ed25519Pk []byte `protobuf:"bytes,1,opt,name=ed25519_pk,json=ed25519Pk,proto3" json:"ed25519_pk,omitempty"` + // bls_sig is the BLS signature over ed25519_pk + BlsSig []byte `protobuf:"bytes,2,opt,name=bls_sig,json=blsSig,proto3" json:"bls_sig,omitempty"` + // ed25519_sig is the Ed25519 signature over bls_sig + Ed25519Sig []byte `protobuf:"bytes,3,opt,name=ed25519_sig,json=ed25519Sig,proto3" json:"ed25519_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 (m *ProofOfPossession) GetEd25519Pk() []byte { + if m != nil { + return m.Ed25519Pk + } + return nil +} + +func (m *ProofOfPossession) GetBlsSig() []byte { + if m != nil { + return m.BlsSig + } + return nil +} + +func (m *ProofOfPossession) GetEd25519Sig() []byte { + if m != nil { + return m.Ed25519Sig + } + return nil +} + +func init() { + proto.RegisterType((*BlsPubKey)(nil), "babylon.checkpointing.v1.BlsPubKey") + proto.RegisterType((*ProofOfPossession)(nil), "babylon.checkpointing.v1.ProofOfPossession") +} + +func init() { + proto.RegisterFile("babylon/checkpointing/bls_key.proto", fileDescriptor_a7e926461cc70111) +} + +var fileDescriptor_a7e926461cc70111 = []byte{ + // 262 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x90, 0x31, 0x4f, 0xc3, 0x30, + 0x10, 0x85, 0x6b, 0x2a, 0xb5, 0x8a, 0xe9, 0x00, 0x5e, 0xc8, 0x82, 0xa9, 0xca, 0xd2, 0x29, 0x51, + 0x41, 0x11, 0x62, 0xed, 0xca, 0xd0, 0x28, 0xdd, 0x58, 0xaa, 0x38, 0x71, 0x1d, 0xcb, 0xc6, 0x8e, + 0x72, 0x29, 0xc2, 0xff, 0x82, 0x9f, 0xc5, 0xd8, 0x91, 0x11, 0x25, 0x7f, 0x04, 0x25, 0x4a, 0x06, + 0xd8, 0xfc, 0xfc, 0xde, 0x7d, 0xba, 0x7b, 0xf8, 0x9e, 0xa5, 0xcc, 0x69, 0x6b, 0xc2, 0xac, 0xe0, + 0x99, 0x2a, 0xad, 0x34, 0xb5, 0x34, 0x22, 0x64, 0x1a, 0x0e, 0x8a, 0xbb, 0xa0, 0xac, 0x6c, 0x6d, + 0x89, 0x3f, 0x84, 0x82, 0x3f, 0xa1, 0xe0, 0x7d, 0xb3, 0x7a, 0xc2, 0xde, 0x56, 0x43, 0x7c, 0x62, + 0x2f, 0xdc, 0x91, 0x2b, 0x3c, 0x55, 0xdc, 0xf9, 0x68, 0x89, 0xd6, 0x8b, 0xa4, 0x7b, 0x12, 0x1f, + 0xcf, 0xd3, 0x3c, 0xaf, 0x38, 0x80, 0x7f, 0xb1, 0x44, 0x6b, 0x2f, 0x19, 0xe5, 0x4a, 0xe3, 0xeb, + 0xb8, 0xb2, 0xf6, 0xb8, 0x3b, 0xc6, 0x16, 0x80, 0x03, 0x48, 0x6b, 0xc8, 0x2d, 0xc6, 0x3c, 0x7f, + 0x88, 0xa2, 0xcd, 0xf3, 0xa1, 0x54, 0x03, 0xc7, 0x1b, 0x7e, 0x62, 0x45, 0x6e, 0xf0, 0xbc, 0xdb, + 0x0b, 0xa4, 0xe8, 0x69, 0x8b, 0x64, 0xc6, 0x34, 0xec, 0xa5, 0x20, 0x77, 0xf8, 0x72, 0x9c, 0xeb, + 0xcc, 0x69, 0x6f, 0x8e, 0xa8, 0xbd, 0x14, 0xdb, 0xdd, 0x57, 0x43, 0xd1, 0xb9, 0xa1, 0xe8, 0xa7, + 0xa1, 0xe8, 0xb3, 0xa5, 0x93, 0x73, 0x4b, 0x27, 0xdf, 0x2d, 0x9d, 0xbc, 0x46, 0x42, 0xd6, 0xc5, + 0x89, 0x05, 0x99, 0x7d, 0x0b, 0x87, 0x2b, 0xb3, 0x22, 0x95, 0x66, 0x14, 0xe1, 0xc7, 0xbf, 0x66, + 0x6a, 0x57, 0x72, 0x60, 0xb3, 0xbe, 0x98, 0xc7, 0xdf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x3e, 0x05, + 0xe2, 0xdc, 0x3f, 0x01, 0x00, 0x00, +} + +func (m *BlsPubKey) 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 *BlsPubKey) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *BlsPubKey) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintBlsKey(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0x12 + } + if len(m.Key) > 0 { + i -= len(m.Key) + copy(dAtA[i:], m.Key) + i = encodeVarintBlsKey(dAtA, i, uint64(len(m.Key))) + 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 len(m.Ed25519Sig) > 0 { + i -= len(m.Ed25519Sig) + copy(dAtA[i:], m.Ed25519Sig) + i = encodeVarintBlsKey(dAtA, i, uint64(len(m.Ed25519Sig))) + i-- + dAtA[i] = 0x1a + } + if len(m.BlsSig) > 0 { + i -= len(m.BlsSig) + copy(dAtA[i:], m.BlsSig) + i = encodeVarintBlsKey(dAtA, i, uint64(len(m.BlsSig))) + i-- + dAtA[i] = 0x12 + } + if len(m.Ed25519Pk) > 0 { + i -= len(m.Ed25519Pk) + copy(dAtA[i:], m.Ed25519Pk) + i = encodeVarintBlsKey(dAtA, i, uint64(len(m.Ed25519Pk))) + 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 *BlsPubKey) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Key) + if l > 0 { + n += 1 + l + sovBlsKey(uint64(l)) + } + l = len(m.Address) + if l > 0 { + n += 1 + l + sovBlsKey(uint64(l)) + } + return n +} + +func (m *ProofOfPossession) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Ed25519Pk) + if l > 0 { + n += 1 + l + sovBlsKey(uint64(l)) + } + l = len(m.BlsSig) + if l > 0 { + n += 1 + l + sovBlsKey(uint64(l)) + } + l = len(m.Ed25519Sig) + if l > 0 { + 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 *BlsPubKey) 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: BlsPubKey: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: BlsPubKey: 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 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 + } + m.Key = append(m.Key[:0], dAtA[iNdEx:postIndex]...) + if m.Key == nil { + m.Key = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBlsKey + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthBlsKey + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthBlsKey + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + 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 Ed25519Pk", 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 + } + m.Ed25519Pk = append(m.Ed25519Pk[:0], dAtA[iNdEx:postIndex]...) + if m.Ed25519Pk == nil { + m.Ed25519Pk = []byte{} + } + iNdEx = postIndex + case 2: + 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 + } + m.BlsSig = append(m.BlsSig[:0], dAtA[iNdEx:postIndex]...) + if m.BlsSig == nil { + m.BlsSig = []byte{} + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Ed25519Sig", 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 + } + m.Ed25519Sig = append(m.Ed25519Sig[:0], dAtA[iNdEx:postIndex]...) + if m.Ed25519Sig == nil { + m.Ed25519Sig = []byte{} + } + 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/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/keys.go b/x/checkpointing/types/keys.go index 7ffd74232..5def7a7da 100644 --- a/x/checkpointing/types/keys.go +++ b/x/checkpointing/types/keys.go @@ -22,13 +22,16 @@ const ( ) var ( - BlsSigsPrefix = []byte{0x0} // reserve this namespace for bls sigs + BlsSigsPrefix = []byte{0x0} // reserve this namespace for BLS sigs CheckpointsPrefix = []byte{0x1} // reserve this namespace for checkpoints + BlsKeysPrefix = []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 + + BlsKeysObjectPrefix = append(BlsKeysPrefix, 0x0) // where we save the concrete BLS public keys ) // BlsSigsObjectKey defines epoch + hash @@ -47,6 +50,10 @@ func CkptsObjectKey(epoch uint64) []byte { return append(CkptsObjectPrefix, sdk.Uint64ToBigEndian(epoch)...) } +func BlsKeysObjectKey(valAddress string) []byte { + return append(BlsKeysObjectPrefix, []byte(valAddress)...) +} + func KeyPrefix(p string) []byte { return []byte(p) } diff --git a/x/checkpointing/types/tx.pb.go b/x/checkpointing/types/tx.pb.go index 908a59b13..66152cf64 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,216 @@ func (m *MsgAddBlsSigResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgAddBlsSigResponse proto.InternalMessageInfo +// MsgCreateBlsKey defines a message to create a BLS key for a validator +type MsgCreateBlsKey struct { + Pubkey *BlsPubKey `protobuf:"bytes,1,opt,name=pubkey,proto3" json:"pubkey,omitempty"` + Pop *ProofOfPossession `protobuf:"bytes,2,opt,name=pop,proto3" json:"pop,omitempty"` +} + +func (m *MsgCreateBlsKey) Reset() { *m = MsgCreateBlsKey{} } +func (m *MsgCreateBlsKey) String() string { return proto.CompactTextString(m) } +func (*MsgCreateBlsKey) ProtoMessage() {} +func (*MsgCreateBlsKey) Descriptor() ([]byte, []int) { + return fileDescriptor_24b023a97b92daa6, []int{2} +} +func (m *MsgCreateBlsKey) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgCreateBlsKey) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgCreateBlsKey.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 *MsgCreateBlsKey) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCreateBlsKey.Merge(m, src) +} +func (m *MsgCreateBlsKey) XXX_Size() int { + return m.Size() +} +func (m *MsgCreateBlsKey) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCreateBlsKey.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgCreateBlsKey proto.InternalMessageInfo + +func (m *MsgCreateBlsKey) GetPubkey() *BlsPubKey { + if m != nil { + return m.Pubkey + } + return nil +} + +func (m *MsgCreateBlsKey) GetPop() *ProofOfPossession { + if m != nil { + return m.Pop + } + return nil +} + +// MsgCreateBlsKeyResponse defines the MsgCreateBlsKey response type +type MsgCreateBlsKeyResponse struct { +} + +func (m *MsgCreateBlsKeyResponse) Reset() { *m = MsgCreateBlsKeyResponse{} } +func (m *MsgCreateBlsKeyResponse) String() string { return proto.CompactTextString(m) } +func (*MsgCreateBlsKeyResponse) ProtoMessage() {} +func (*MsgCreateBlsKeyResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_24b023a97b92daa6, []int{3} +} +func (m *MsgCreateBlsKeyResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgCreateBlsKeyResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgCreateBlsKeyResponse.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 *MsgCreateBlsKeyResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCreateBlsKeyResponse.Merge(m, src) +} +func (m *MsgCreateBlsKeyResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgCreateBlsKeyResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCreateBlsKeyResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgCreateBlsKeyResponse proto.InternalMessageInfo + +// MsgWrappedCreateValidator defines a wrapped message to create a validator +type MsgWrappedCreateValidator struct { + MsgStaking *types.MsgCreateValidator `protobuf:"bytes,1,opt,name=msg_staking,json=msgStaking,proto3" json:"msg_staking,omitempty"` + MsgCheckpointing *MsgCreateBlsKey `protobuf:"bytes,2,opt,name=msg_checkpointing,json=msgCheckpointing,proto3" json:"msg_checkpointing,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{4} +} +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{5} +} +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((*MsgCreateBlsKey)(nil), "babylon.checkpointing.v1.MsgCreateBlsKey") + proto.RegisterType((*MsgCreateBlsKeyResponse)(nil), "babylon.checkpointing.v1.MsgCreateBlsKeyResponse") + 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 - 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, + // 486 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x54, 0xcd, 0x6a, 0xdb, 0x40, + 0x10, 0xb6, 0x12, 0x70, 0xdb, 0x49, 0xa0, 0xad, 0x08, 0xa9, 0xa3, 0x83, 0x9c, 0xda, 0x10, 0xfa, + 0x03, 0x2b, 0x9c, 0xd0, 0x43, 0x1b, 0x7a, 0xa8, 0x73, 0x34, 0x26, 0x46, 0x86, 0x14, 0x7a, 0x09, + 0x5a, 0x79, 0xb3, 0x16, 0x96, 0xb4, 0x8b, 0x46, 0x0e, 0xd1, 0x1b, 0x94, 0x42, 0xa1, 0x8f, 0x90, + 0xc7, 0x29, 0x3d, 0xe5, 0xd8, 0x63, 0xb1, 0x29, 0xf4, 0x31, 0x8a, 0xac, 0x95, 0x62, 0x1b, 0xcb, + 0x98, 0x9c, 0xa4, 0xd5, 0x7c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x25, 0xae, 0x08, 0x2c, 0x65, 0xe0, 0x0e, 0x1d, 0x2f, 0xcc, 0x17, 0xd6, 0xcd, 0xf2, 0x1d, + 0x93, 0x48, 0x86, 0xb4, 0x3a, 0xfb, 0x93, 0x4f, 0xfe, 0x07, 0x00, 0x00, 0xff, 0xff, 0x23, 0x97, + 0xb6, 0xb3, 0x89, 0x04, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -143,7 +329,12 @@ 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) + // CreateBlsKey defines a method for registering a BLS key for a validator + CreateBlsKey(ctx context.Context, in *MsgCreateBlsKey, opts ...grpc.CallOption) (*MsgCreateBlsKeyResponse, 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 +354,32 @@ func (c *msgClient) AddBlsSig(ctx context.Context, in *MsgAddBlsSig, opts ...grp return out, nil } +func (c *msgClient) CreateBlsKey(ctx context.Context, in *MsgCreateBlsKey, opts ...grpc.CallOption) (*MsgCreateBlsKeyResponse, error) { + out := new(MsgCreateBlsKeyResponse) + err := c.cc.Invoke(ctx, "/babylon.checkpointing.v1.Msg/CreateBlsKey", in, out, opts...) + if err != nil { + return nil, err + } + 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) + // CreateBlsKey defines a method for registering a BLS key for a validator + CreateBlsKey(context.Context, *MsgCreateBlsKey) (*MsgCreateBlsKeyResponse, 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 +389,12 @@ 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) CreateBlsKey(ctx context.Context, req *MsgCreateBlsKey) (*MsgCreateBlsKeyResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method CreateBlsKey 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 +418,42 @@ func _Msg_AddBlsSig_Handler(srv interface{}, ctx context.Context, dec func(inter return interceptor(ctx, in, info, handler) } +func _Msg_CreateBlsKey_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgCreateBlsKey) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).CreateBlsKey(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/babylon.checkpointing.v1.Msg/CreateBlsKey", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).CreateBlsKey(ctx, req.(*MsgCreateBlsKey)) + } + 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 +462,14 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "AddBlsSig", Handler: _Msg_AddBlsSig_Handler, }, + { + MethodName: "CreateBlsKey", + Handler: _Msg_CreateBlsKey_Handler, + }, + { + MethodName: "WrappedCreateValidator", + Handler: _Msg_WrappedCreateValidator_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "babylon/checkpointing/tx.proto", @@ -269,6 +533,146 @@ func (m *MsgAddBlsSigResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *MsgCreateBlsKey) 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 *MsgCreateBlsKey) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgCreateBlsKey) 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 = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if m.Pubkey != nil { + { + size, err := m.Pubkey.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 *MsgCreateBlsKeyResponse) 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 *MsgCreateBlsKeyResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgCreateBlsKeyResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + 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.MsgCheckpointing != nil { + { + size, err := m.MsgCheckpointing.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if m.MsgStaking != nil { + { + size, err := m.MsgStaking.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,8 +706,60 @@ func (m *MsgAddBlsSigResponse) Size() (n int) { return n } -func sovTx(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 +func (m *MsgCreateBlsKey) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Pubkey != nil { + l = m.Pubkey.Size() + n += 1 + l + sovTx(uint64(l)) + } + if m.Pop != nil { + l = m.Pop.Size() + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgCreateBlsKeyResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgWrappedCreateValidator) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.MsgStaking != nil { + l = m.MsgStaking.Size() + n += 1 + l + sovTx(uint64(l)) + } + if m.MsgCheckpointing != nil { + l = m.MsgCheckpointing.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 } func sozTx(x uint64) (n int) { return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) @@ -444,6 +900,350 @@ func (m *MsgAddBlsSigResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgCreateBlsKey) 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: MsgCreateBlsKey: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCreateBlsKey: 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 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.Pubkey == nil { + m.Pubkey = &BlsPubKey{} + } + 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 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.Pop == nil { + m.Pop = &ProofOfPossession{} + } + if err := m.Pop.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 *MsgCreateBlsKeyResponse) 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: MsgCreateBlsKeyResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCreateBlsKeyResponse: 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 (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 MsgStaking", 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.MsgStaking == nil { + m.MsgStaking = &types.MsgCreateValidator{} + } + if err := m.MsgStaking.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MsgCheckpointing", 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.MsgCheckpointing == nil { + m.MsgCheckpointing = &MsgCreateBlsKey{} + } + if err := m.MsgCheckpointing.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..58dec831a 100644 --- a/x/checkpointing/types/types.go +++ b/x/checkpointing/types/types.go @@ -46,6 +46,16 @@ func BytesToBlsSig(cdc codec.BinaryCodec, bz []byte) (*BlsSig, error) { return blsSig, err } +func BlsPubKeyToBytes(cdc codec.BinaryCodec, key *BlsPubKey) []byte { + return cdc.MustMarshal(key) +} + +func BytesToBlsPubKey(cdc codec.BinaryCodec, bz []byte) (*BlsPubKey, error) { + key := new(BlsPubKey) + err := cdc.Unmarshal(bz, key) + return key, err +} + func (m RawCkptHash) Equals(h RawCkptHash) bool { if bytes.Compare(m.Bytes(), h.Bytes()) == 0 { return true From e7e8e5130039af7486d6a454be97b243cbd32332 Mon Sep 17 00:00:00 2001 From: Fangyu Gai Date: Tue, 5 Jul 2022 10:24:39 +0800 Subject: [PATCH 2/6] add MsgCreateValidator store --- proto/babylon/checkpointing/tx.proto | 17 +- x/checkpointing/keeper/blskey_state.go | 59 --- x/checkpointing/keeper/blssig_state.go | 2 +- x/checkpointing/keeper/keeper.go | 6 +- x/checkpointing/keeper/msg_server.go | 18 +- x/checkpointing/keeper/registration_state.go | 76 ++++ x/checkpointing/types/keys.go | 20 +- x/checkpointing/types/tx.pb.go | 445 ++----------------- 8 files changed, 159 insertions(+), 484 deletions(-) delete mode 100644 x/checkpointing/keeper/blskey_state.go create mode 100644 x/checkpointing/keeper/registration_state.go diff --git a/proto/babylon/checkpointing/tx.proto b/proto/babylon/checkpointing/tx.proto index e6e514087..6fa9a53da 100644 --- a/proto/babylon/checkpointing/tx.proto +++ b/proto/babylon/checkpointing/tx.proto @@ -13,9 +13,6 @@ service Msg { // AddBlsSig defines a method for accumulating BLS signatures rpc AddBlsSig(MsgAddBlsSig) returns (MsgAddBlsSigResponse); - // CreateBlsKey defines a method for registering a BLS key for a validator - rpc CreateBlsKey(MsgCreateBlsKey) returns (MsgCreateBlsKeyResponse); - // WrappedCreateValidator defines a method for registering a new validator rpc WrappedCreateValidator(MsgWrappedCreateValidator) returns (MsgWrappedCreateValidatorResponse); } @@ -32,22 +29,14 @@ message MsgAddBlsSig { // MsgAddBlsSigResponse defines the MsgAddBlsSig response type. message MsgAddBlsSigResponse {} -// MsgCreateBlsKey defines a message to create a BLS key for a validator -message MsgCreateBlsKey { - BlsPubKey pubkey = 1; - ProofOfPossession pop = 2; -} - -// MsgCreateBlsKeyResponse defines the MsgCreateBlsKey response type -message MsgCreateBlsKeyResponse {} - // MsgWrappedCreateValidator defines a wrapped message to create a validator message MsgWrappedCreateValidator { option (gogoproto.equal) = false; option (gogoproto.goproto_getters) = false; - cosmos.staking.v1beta1.MsgCreateValidator msg_staking = 1; - MsgCreateBlsKey msg_checkpointing = 2; + BlsPubKey pubkey = 1; + ProofOfPossession pop = 2; + cosmos.staking.v1beta1.MsgCreateValidator msg_staking = 3; } // MsgWrappedCreateValidatorResponse defines the MsgWrappedCreateValidator response type diff --git a/x/checkpointing/keeper/blskey_state.go b/x/checkpointing/keeper/blskey_state.go deleted file mode 100644 index 3927f8cab..000000000 --- a/x/checkpointing/keeper/blskey_state.go +++ /dev/null @@ -1,59 +0,0 @@ -package keeper - -import ( - "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 BlsKeysState struct { - cdc codec.BinaryCodec - blsKeys sdk.KVStore -} - -func (k Keeper) BlsKeysState(ctx sdk.Context) BlsKeysState { - // Build the BlsKeysState storage - store := ctx.KVStore(k.storeKey) - return BlsKeysState{ - cdc: k.cdc, - blsKeys: prefix.NewStore(store, types.BlsKeysPrefix), - } -} - -// CreateBlsKey inserts the BLS key into the address->bls_key storage -func (bk BlsKeysState) CreateBlsKey(key *types.BlsPubKey) error { - if bk.Exists(key.Address) { - return types.ErrBlsKeyAlreadyExist.Wrapf("existed public key: %x", key.Key) - } - blsKeysKey := types.BlsKeysObjectKey(key.Address) - // save concrete BLS public key object - bk.blsKeys.Set(blsKeysKey, types.BlsPubKeyToBytes(bk.cdc, key)) - return nil -} - -// GetBlsPubKey retrieves BLS public key by validator's address -func (bk BlsKeysState) GetBlsPubKey(addr string) (*types.BlsPubKey, error) { - pubKeyKey := types.BlsKeysObjectKey(addr) - rawBytes := bk.blsKeys.Get(pubKeyKey) - if rawBytes == nil { - return nil, types.ErrBlsKeyDoesNotExist.Wrapf("BLS public key does not exist with address %s", addr) - } - - return types.BytesToBlsPubKey(bk.cdc, rawBytes) -} - -// RemoveBlsPubKey removes a BLS public key -func (bk BlsKeysState) RemoveBlsPubKey(addr string) error { - if !bk.Exists(addr) { - return types.ErrBlsKeyDoesNotExist.Wrapf("BLS public key does not exist with address %s", addr) - } - // delete BLS public key from storage - bk.blsKeys.Delete(types.BlsKeysObjectKey(addr)) - return nil -} - -func (bk BlsKeysState) Exists(addr string) bool { - blsKeysKey := types.BlsKeysObjectKey(addr) - return bk.blsKeys.Has(blsKeysKey) -} diff --git a/x/checkpointing/keeper/blssig_state.go b/x/checkpointing/keeper/blssig_state.go index f579e2f0f..772858f85 100644 --- a/x/checkpointing/keeper/blssig_state.go +++ b/x/checkpointing/keeper/blssig_state.go @@ -18,7 +18,7 @@ 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), } } diff --git a/x/checkpointing/keeper/keeper.go b/x/checkpointing/keeper/keeper.go index 179d68552..9f8c2a154 100644 --- a/x/checkpointing/keeper/keeper.go +++ b/x/checkpointing/keeper/keeper.go @@ -2,7 +2,7 @@ package keeper import ( "fmt" - + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/tendermint/tendermint/libs/log" "github.com/babylonchain/babylon/x/checkpointing/types" @@ -99,3 +99,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 *types.BlsPubKey, msg *stakingtypes.MsgCreateValidator) error { + return k.RegistrationState(ctx).CreateRegistration(blsPubKey, msg) +} diff --git a/x/checkpointing/keeper/msg_server.go b/x/checkpointing/keeper/msg_server.go index 9901b30a0..9b584a9b3 100644 --- a/x/checkpointing/keeper/msg_server.go +++ b/x/checkpointing/keeper/msg_server.go @@ -2,6 +2,7 @@ package keeper import ( "context" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/babylonchain/babylon/x/checkpointing/types" ) @@ -18,14 +19,19 @@ func NewMsgServerImpl(keeper Keeper) types.MsgServer { var _ types.MsgServer = msgServer{} -func (m msgServer) AddBlsSig(ctx context.Context, header *types.MsgAddBlsSig) (*types.MsgAddBlsSigResponse, error) { +func (m msgServer) AddBlsSig(goCtx context.Context, header *types.MsgAddBlsSig) (*types.MsgAddBlsSigResponse, error) { panic("TODO: implement me") } -func (m msgServer) CreateBlsKey(ctx context.Context, msg *types.MsgCreateBlsKey) (*types.MsgCreateBlsKeyResponse, 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 + ctx := sdk.UnwrapSDKContext(goCtx) -func (m msgServer) WrappedCreateValidator(ctx context.Context, msg *types.MsgWrappedCreateValidator) (*types.MsgWrappedCreateValidatorResponse, error) { - panic("TODO: implement me") + err := m.k.CreateRegistration(ctx, msg.Pubkey, msg.MsgStaking) + if err != nil { + return nil, err + } + + return &types.MsgWrappedCreateValidatorResponse{}, nil } diff --git a/x/checkpointing/keeper/registration_state.go b/x/checkpointing/keeper/registration_state.go new file mode 100644 index 000000000..09a70a45a --- /dev/null +++ b/x/checkpointing/keeper/registration_state.go @@ -0,0 +1,76 @@ +package keeper + +import ( + "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" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" +) + +type RegistrationState struct { + cdc codec.BinaryCodec + blsKeys sdk.KVStore + msgCreateValidators sdk.KVStore +} + +func (k Keeper) RegistrationState(ctx sdk.Context) RegistrationState { + // Build the RegistrationState storage + store := ctx.KVStore(k.storeKey) + return RegistrationState{ + cdc: k.cdc, + blsKeys: prefix.NewStore(store, types.BlsKeysObjectPrefix), + msgCreateValidators: prefix.NewStore(store, types.MsgCreateValidatorsPrefix), + } +} + +// CreateRegistration inserts the BLS key as well as a corresponding MsgCreateValidator message into the storage +func (rs RegistrationState) CreateRegistration(key *types.BlsPubKey, msg *stakingtypes.MsgCreateValidator) error { + if rs.Exists(key.Address) { + return types.ErrBlsKeyAlreadyExist.Wrapf("existed public key: %x", key.Key) + } + + blsKeysKey := types.BlsKeysObjectKey(key.Address) + msgKey := types.MsgCreateValidatorsKey(key.Address) + + // save concrete BLS public key object and msgCreateValidator + rs.blsKeys.Set(blsKeysKey, types.BlsPubKeyToBytes(rs.cdc, key)) + rs.msgCreateValidators.Set(msgKey, rs.cdc.MustMarshal(msg)) + + return nil +} + +// GetBlsPubKey retrieves BLS public key by validator's address +func (rs RegistrationState) GetBlsPubKey(addr string) (*types.BlsPubKey, error) { + pubKeyKey := types.BlsKeysObjectKey(addr) + rawBytes := rs.blsKeys.Get(pubKeyKey) + if rawBytes == nil { + return nil, types.ErrBlsKeyDoesNotExist.Wrapf("BLS public key does not exist with address %s", addr) + } + + return types.BytesToBlsPubKey(rs.cdc, rawBytes) +} + +// RemoveBlsPubKey removes a BLS public key +func (rs RegistrationState) RemoveBlsPubKey(addr string) error { + if !rs.Exists(addr) { + return types.ErrBlsKeyDoesNotExist.Wrapf("BLS public key does not exist with address %s", addr) + } + + // delete BLS public key and corresponding msgCreateValidator from storage + rs.blsKeys.Delete(types.BlsKeysObjectKey(addr)) + rs.msgCreateValidators.Delete(types.MsgCreateValidatorsKey(addr)) + + return nil +} + +// RemoveMsgCreateValidator removes a MsgCreateValidator +func (rs RegistrationState) RemoveMsgCreateValidator(addr string) { + rs.msgCreateValidators.Delete(types.MsgCreateValidatorsKey(addr)) +} + +// Exists checks whether a BLS key exists +func (rs RegistrationState) Exists(addr string) bool { + blsKeysKey := types.BlsKeysObjectKey(addr) + return rs.blsKeys.Has(blsKeysKey) +} diff --git a/x/checkpointing/types/keys.go b/x/checkpointing/types/keys.go index 5def7a7da..29a033acb 100644 --- a/x/checkpointing/types/keys.go +++ b/x/checkpointing/types/keys.go @@ -22,16 +22,17 @@ const ( ) var ( - BlsSigsPrefix = []byte{0x0} // reserve this namespace for BLS sigs - CheckpointsPrefix = []byte{0x1} // reserve this namespace for checkpoints - BlsKeysPrefix = []byte{0x2} // reserve this namespace for BLS keys + 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 BlsSigsHashToEpochPrefix = append(BlsSigsPrefix, 0x1) // where we map hash to epoch CkptsObjectPrefix = append(CheckpointsPrefix, 0x0) // where we save the concrete BLS sig bytes - BlsKeysObjectPrefix = append(BlsKeysPrefix, 0x0) // where we save the concrete BLS public keys + BlsKeysObjectPrefix = append(RegistrationPrefix, 0x0) // where we save the concrete BLS public keys + MsgCreateValidatorsPrefix = append(RegistrationPrefix, 0x1) // where we save MsgCreateValidators ) // BlsSigsObjectKey defines epoch + hash @@ -41,6 +42,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...) } @@ -50,8 +52,14 @@ func CkptsObjectKey(epoch uint64) []byte { return append(CkptsObjectPrefix, sdk.Uint64ToBigEndian(epoch)...) } -func BlsKeysObjectKey(valAddress string) []byte { - return append(BlsKeysObjectPrefix, []byte(valAddress)...) +// BlsKeysObjectKey defines validator address +func BlsKeysObjectKey(valAddr string) []byte { + return append(BlsKeysObjectPrefix, []byte(valAddr)...) +} + +// MsgCreateValidatorsKey defines validator address +func MsgCreateValidatorsKey(valAddr string) []byte { + return append(MsgCreateValidatorsPrefix, []byte(valAddr)...) } func KeyPrefix(p string) []byte { diff --git a/x/checkpointing/types/tx.pb.go b/x/checkpointing/types/tx.pb.go index 66152cf64..98ec616bd 100644 --- a/x/checkpointing/types/tx.pb.go +++ b/x/checkpointing/types/tx.pb.go @@ -105,107 +105,18 @@ func (m *MsgAddBlsSigResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgAddBlsSigResponse proto.InternalMessageInfo -// MsgCreateBlsKey defines a message to create a BLS key for a validator -type MsgCreateBlsKey struct { - Pubkey *BlsPubKey `protobuf:"bytes,1,opt,name=pubkey,proto3" json:"pubkey,omitempty"` - Pop *ProofOfPossession `protobuf:"bytes,2,opt,name=pop,proto3" json:"pop,omitempty"` -} - -func (m *MsgCreateBlsKey) Reset() { *m = MsgCreateBlsKey{} } -func (m *MsgCreateBlsKey) String() string { return proto.CompactTextString(m) } -func (*MsgCreateBlsKey) ProtoMessage() {} -func (*MsgCreateBlsKey) Descriptor() ([]byte, []int) { - return fileDescriptor_24b023a97b92daa6, []int{2} -} -func (m *MsgCreateBlsKey) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *MsgCreateBlsKey) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_MsgCreateBlsKey.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 *MsgCreateBlsKey) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgCreateBlsKey.Merge(m, src) -} -func (m *MsgCreateBlsKey) XXX_Size() int { - return m.Size() -} -func (m *MsgCreateBlsKey) XXX_DiscardUnknown() { - xxx_messageInfo_MsgCreateBlsKey.DiscardUnknown(m) -} - -var xxx_messageInfo_MsgCreateBlsKey proto.InternalMessageInfo - -func (m *MsgCreateBlsKey) GetPubkey() *BlsPubKey { - if m != nil { - return m.Pubkey - } - return nil -} - -func (m *MsgCreateBlsKey) GetPop() *ProofOfPossession { - if m != nil { - return m.Pop - } - return nil -} - -// MsgCreateBlsKeyResponse defines the MsgCreateBlsKey response type -type MsgCreateBlsKeyResponse struct { -} - -func (m *MsgCreateBlsKeyResponse) Reset() { *m = MsgCreateBlsKeyResponse{} } -func (m *MsgCreateBlsKeyResponse) String() string { return proto.CompactTextString(m) } -func (*MsgCreateBlsKeyResponse) ProtoMessage() {} -func (*MsgCreateBlsKeyResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_24b023a97b92daa6, []int{3} -} -func (m *MsgCreateBlsKeyResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *MsgCreateBlsKeyResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_MsgCreateBlsKeyResponse.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 *MsgCreateBlsKeyResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgCreateBlsKeyResponse.Merge(m, src) -} -func (m *MsgCreateBlsKeyResponse) XXX_Size() int { - return m.Size() -} -func (m *MsgCreateBlsKeyResponse) XXX_DiscardUnknown() { - xxx_messageInfo_MsgCreateBlsKeyResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_MsgCreateBlsKeyResponse proto.InternalMessageInfo - // MsgWrappedCreateValidator defines a wrapped message to create a validator type MsgWrappedCreateValidator struct { - MsgStaking *types.MsgCreateValidator `protobuf:"bytes,1,opt,name=msg_staking,json=msgStaking,proto3" json:"msg_staking,omitempty"` - MsgCheckpointing *MsgCreateBlsKey `protobuf:"bytes,2,opt,name=msg_checkpointing,json=msgCheckpointing,proto3" json:"msg_checkpointing,omitempty"` + Pubkey *BlsPubKey `protobuf:"bytes,1,opt,name=pubkey,proto3" json:"pubkey,omitempty"` + Pop *ProofOfPossession `protobuf:"bytes,2,opt,name=pop,proto3" json:"pop,omitempty"` + MsgStaking *types.MsgCreateValidator `protobuf:"bytes,3,opt,name=msg_staking,json=msgStaking,proto3" json:"msg_staking,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{4} + return fileDescriptor_24b023a97b92daa6, []int{2} } func (m *MsgWrappedCreateValidator) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -242,7 +153,7 @@ func (m *MsgWrappedCreateValidatorResponse) Reset() { *m = MsgWrappedCre func (m *MsgWrappedCreateValidatorResponse) String() string { return proto.CompactTextString(m) } func (*MsgWrappedCreateValidatorResponse) ProtoMessage() {} func (*MsgWrappedCreateValidatorResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_24b023a97b92daa6, []int{5} + return fileDescriptor_24b023a97b92daa6, []int{3} } func (m *MsgWrappedCreateValidatorResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -274,8 +185,6 @@ 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((*MsgCreateBlsKey)(nil), "babylon.checkpointing.v1.MsgCreateBlsKey") - proto.RegisterType((*MsgCreateBlsKeyResponse)(nil), "babylon.checkpointing.v1.MsgCreateBlsKeyResponse") proto.RegisterType((*MsgWrappedCreateValidator)(nil), "babylon.checkpointing.v1.MsgWrappedCreateValidator") proto.RegisterType((*MsgWrappedCreateValidatorResponse)(nil), "babylon.checkpointing.v1.MsgWrappedCreateValidatorResponse") } @@ -283,38 +192,34 @@ func init() { func init() { proto.RegisterFile("babylon/checkpointing/tx.proto", fileDescriptor_24b023a97b92daa6) } var fileDescriptor_24b023a97b92daa6 = []byte{ - // 486 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x54, 0xcd, 0x6a, 0xdb, 0x40, - 0x10, 0xb6, 0x12, 0x70, 0xdb, 0x49, 0xa0, 0xad, 0x08, 0xa9, 0xa3, 0x83, 0x9c, 0xda, 0x10, 0xfa, - 0x03, 0x2b, 0x9c, 0xd0, 0x43, 0x1b, 0x7a, 0xa8, 0x73, 0x34, 0x26, 0x46, 0x86, 0x14, 0x7a, 0x09, - 0x5a, 0x79, 0xb3, 0x16, 0x96, 0xb4, 0x8b, 0x46, 0x0e, 0xd1, 0x1b, 0x94, 0x42, 0xa1, 0x8f, 0x90, - 0xc7, 0x29, 0x3d, 0xe5, 0xd8, 0x63, 0xb1, 0x29, 0xf4, 0x31, 0x8a, 0xac, 0x95, 0x62, 0x1b, 0xcb, - 0x98, 0x9c, 0xa4, 0xd5, 0x7c, 0x7f, 0x33, 0xbb, 0x5a, 0x30, 0xa9, 0x43, 0x13, 0x5f, 0x84, 0x96, - 0x3b, 0x64, 0xee, 0x48, 0x0a, 0x2f, 0x8c, 0xbd, 0x90, 0x5b, 0xf1, 0x0d, 0x91, 0x91, 0x88, 0x85, - 0x5e, 0x53, 0x75, 0xb2, 0x50, 0x27, 0xd7, 0x2d, 0x63, 0x8f, 0x0b, 0x2e, 0x66, 0x20, 0x2b, 0x7d, - 0xcb, 0xf0, 0xc6, 0xd1, 0x6a, 0xbd, 0xfb, 0x95, 0xc2, 0x35, 0x57, 0xe3, 0xa8, 0x8f, 0x97, 0x23, - 0x96, 0x28, 0x50, 0xdd, 0x15, 0x18, 0x08, 0xb4, 0x30, 0x76, 0x46, 0x69, 0xf5, 0xba, 0x45, 0x59, - 0xec, 0xb4, 0x8a, 0x74, 0x8d, 0x3e, 0xec, 0x76, 0x91, 0x7f, 0x1a, 0x0c, 0x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, 0x67, 0xf3, 0xa0, 0xb9, 0xfd, 0x68, 0xc2, 0xcb, 0xd2, 0x5e, 0xf2, 0x8e, 0x8f, 0xff, - 0x6e, 0xc1, 0x76, 0x17, 0xb9, 0xee, 0xc2, 0x93, 0xfb, 0xe3, 0x70, 0xb4, 0x36, 0x40, 0x81, 0x33, - 0xc8, 0x66, 0xb8, 0xdc, 0x4c, 0xf7, 0x61, 0x77, 0xe1, 0x14, 0x6c, 0xde, 0xa8, 0xd1, 0xda, 0x7c, - 0x26, 0xb9, 0xdb, 0x37, 0x0d, 0xf6, 0x4b, 0x76, 0xf2, 0x64, 0xad, 0xda, 0x6a, 0x92, 0x71, 0xfa, - 0x00, 0x52, 0x1e, 0xa6, 0x7d, 0xfe, 0x73, 0x62, 0x6a, 0x77, 0x13, 0x53, 0xfb, 0x33, 0x31, 0xb5, - 0x1f, 0x53, 0xb3, 0x72, 0x37, 0x35, 0x2b, 0xbf, 0xa7, 0x66, 0xe5, 0xcb, 0x3b, 0xee, 0xc5, 0xc3, - 0x31, 0x25, 0xae, 0x08, 0x2c, 0x65, 0xe0, 0x0e, 0x1d, 0x2f, 0xcc, 0x17, 0xd6, 0xcd, 0xf2, 0x1d, - 0x93, 0x48, 0x86, 0xb4, 0x3a, 0xfb, 0x93, 0x4f, 0xfe, 0x07, 0x00, 0x00, 0xff, 0xff, 0x23, 0x97, - 0xb6, 0xb3, 0x89, 0x04, 0x00, 0x00, + // 432 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x53, 0x3f, 0x6f, 0xd3, 0x40, + 0x14, 0xf7, 0x11, 0x29, 0xc0, 0x95, 0xc9, 0xaa, 0xaa, 0x90, 0xc1, 0x29, 0x89, 0x54, 0x21, 0x90, + 0xce, 0x4a, 0x2b, 0x06, 0xa8, 0x18, 0x28, 0x63, 0x15, 0x35, 0x72, 0x24, 0x90, 0x58, 0xaa, 0x3b, + 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 0x59, 0x7c, + 0xd4, 0x47, 0x7f, 0x02, 0x00, 0x00, 0xff, 0xff, 0x77, 0x54, 0xbd, 0x28, 0x94, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -331,8 +236,6 @@ const _ = grpc.SupportPackageIsVersion4 type MsgClient interface { // AddBlsSig defines a method for accumulating BLS signatures AddBlsSig(ctx context.Context, in *MsgAddBlsSig, opts ...grpc.CallOption) (*MsgAddBlsSigResponse, error) - // CreateBlsKey defines a method for registering a BLS key for a validator - CreateBlsKey(ctx context.Context, in *MsgCreateBlsKey, opts ...grpc.CallOption) (*MsgCreateBlsKeyResponse, error) // WrappedCreateValidator defines a method for registering a new validator WrappedCreateValidator(ctx context.Context, in *MsgWrappedCreateValidator, opts ...grpc.CallOption) (*MsgWrappedCreateValidatorResponse, error) } @@ -354,15 +257,6 @@ func (c *msgClient) AddBlsSig(ctx context.Context, in *MsgAddBlsSig, opts ...grp return out, nil } -func (c *msgClient) CreateBlsKey(ctx context.Context, in *MsgCreateBlsKey, opts ...grpc.CallOption) (*MsgCreateBlsKeyResponse, error) { - out := new(MsgCreateBlsKeyResponse) - err := c.cc.Invoke(ctx, "/babylon.checkpointing.v1.Msg/CreateBlsKey", in, out, opts...) - if err != nil { - return nil, err - } - 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...) @@ -376,8 +270,6 @@ func (c *msgClient) WrappedCreateValidator(ctx context.Context, in *MsgWrappedCr type MsgServer interface { // AddBlsSig defines a method for accumulating BLS signatures AddBlsSig(context.Context, *MsgAddBlsSig) (*MsgAddBlsSigResponse, error) - // CreateBlsKey defines a method for registering a BLS key for a validator - CreateBlsKey(context.Context, *MsgCreateBlsKey) (*MsgCreateBlsKeyResponse, error) // WrappedCreateValidator defines a method for registering a new validator WrappedCreateValidator(context.Context, *MsgWrappedCreateValidator) (*MsgWrappedCreateValidatorResponse, error) } @@ -389,9 +281,6 @@ 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) CreateBlsKey(ctx context.Context, req *MsgCreateBlsKey) (*MsgCreateBlsKeyResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method CreateBlsKey not implemented") -} func (*UnimplementedMsgServer) WrappedCreateValidator(ctx context.Context, req *MsgWrappedCreateValidator) (*MsgWrappedCreateValidatorResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method WrappedCreateValidator not implemented") } @@ -418,24 +307,6 @@ func _Msg_AddBlsSig_Handler(srv interface{}, ctx context.Context, dec func(inter return interceptor(ctx, in, info, handler) } -func _Msg_CreateBlsKey_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgCreateBlsKey) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(MsgServer).CreateBlsKey(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/babylon.checkpointing.v1.Msg/CreateBlsKey", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).CreateBlsKey(ctx, req.(*MsgCreateBlsKey)) - } - 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 { @@ -462,10 +333,6 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "AddBlsSig", Handler: _Msg_AddBlsSig_Handler, }, - { - MethodName: "CreateBlsKey", - Handler: _Msg_CreateBlsKey_Handler, - }, { MethodName: "WrappedCreateValidator", Handler: _Msg_WrappedCreateValidator_Handler, @@ -533,7 +400,7 @@ func (m *MsgAddBlsSigResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *MsgCreateBlsKey) Marshal() (dAtA []byte, err error) { +func (m *MsgWrappedCreateValidator) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -543,31 +410,19 @@ func (m *MsgCreateBlsKey) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgCreateBlsKey) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgWrappedCreateValidator) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgCreateBlsKey) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgWrappedCreateValidator) 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 = encodeVarintTx(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - if m.Pubkey != nil { + if m.MsgStaking != nil { { - size, err := m.Pubkey.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.MsgStaking.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -575,57 +430,11 @@ func (m *MsgCreateBlsKey) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintTx(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0xa + dAtA[i] = 0x1a } - return len(dAtA) - i, nil -} - -func (m *MsgCreateBlsKeyResponse) 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 *MsgCreateBlsKeyResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *MsgCreateBlsKeyResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - 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.MsgCheckpointing != nil { + if m.Pop != nil { { - size, err := m.MsgCheckpointing.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.Pop.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -635,9 +444,9 @@ func (m *MsgWrappedCreateValidator) MarshalToSizedBuffer(dAtA []byte) (int, erro i-- dAtA[i] = 0x12 } - if m.MsgStaking != nil { + if m.Pubkey != nil { { - size, err := m.MsgStaking.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.Pubkey.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -706,7 +515,7 @@ func (m *MsgAddBlsSigResponse) Size() (n int) { return n } -func (m *MsgCreateBlsKey) Size() (n int) { +func (m *MsgWrappedCreateValidator) Size() (n int) { if m == nil { return 0 } @@ -720,32 +529,10 @@ func (m *MsgCreateBlsKey) Size() (n int) { l = m.Pop.Size() n += 1 + l + sovTx(uint64(l)) } - return n -} - -func (m *MsgCreateBlsKeyResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - return n -} - -func (m *MsgWrappedCreateValidator) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l if m.MsgStaking != nil { l = m.MsgStaking.Size() n += 1 + l + sovTx(uint64(l)) } - if m.MsgCheckpointing != nil { - l = m.MsgCheckpointing.Size() - n += 1 + l + sovTx(uint64(l)) - } return n } @@ -900,7 +687,7 @@ func (m *MsgAddBlsSigResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgCreateBlsKey) Unmarshal(dAtA []byte) error { +func (m *MsgWrappedCreateValidator) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -923,10 +710,10 @@ func (m *MsgCreateBlsKey) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgCreateBlsKey: wiretype end group for non-group") + return fmt.Errorf("proto: MsgWrappedCreateValidator: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgCreateBlsKey: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgWrappedCreateValidator: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -1001,107 +788,7 @@ func (m *MsgCreateBlsKey) Unmarshal(dAtA []byte) error { 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 *MsgCreateBlsKeyResponse) 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: MsgCreateBlsKeyResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MsgCreateBlsKeyResponse: 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 (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: + case 3: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field MsgStaking", wireType) } @@ -1137,42 +824,6 @@ func (m *MsgWrappedCreateValidator) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MsgCheckpointing", 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.MsgCheckpointing == nil { - m.MsgCheckpointing = &MsgCreateBlsKey{} - } - if err := m.MsgCheckpointing.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:]) From d78df0ffe36932b93f7f2f88e62419e7a99f8b6a Mon Sep 17 00:00:00 2001 From: Fangyu Gai Date: Tue, 5 Jul 2022 10:38:12 +0800 Subject: [PATCH 3/6] fix ci --- x/checkpointing/types/codec.go | 1 + x/checkpointing/types/msgs.go | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) 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/msgs.go b/x/checkpointing/types/msgs.go index 2f3f41439..f46017d64 100644 --- a/x/checkpointing/types/msgs.go +++ b/x/checkpointing/types/msgs.go @@ -27,3 +27,24 @@ func (m *MsgAddBlsSig) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{signer} } + +func (m *MsgWrappedCreateValidator) ValidateBasic() error { + // This function validates stateless message elements + _, err := sdk.AccAddressFromBech32(m.Pubkey.Address) + if err != nil { + return err + } + + // TODO: verify bls sig + + return nil +} + +func (m *MsgWrappedCreateValidator) GetSigners() []sdk.AccAddress { + signer, err := sdk.AccAddressFromBech32(m.Pubkey.Address) + if err != nil { + panic(err) + } + + return []sdk.AccAddress{signer} +} From c3d9e59cb714fc36637f7ece492c9290aed36fcc Mon Sep 17 00:00:00 2001 From: Fangyu Gai Date: Wed, 6 Jul 2022 12:23:35 +0800 Subject: [PATCH 4/6] address comments --- crypto/bls12381/types.go | 54 ++++ proto/babylon/checkpointing/bls_key.proto | 28 +- proto/babylon/checkpointing/checkpoint.proto | 8 +- proto/babylon/checkpointing/tx.proto | 5 +- x/checkpointing/keeper/keeper.go | 32 +- x/checkpointing/keeper/msg_server.go | 15 +- x/checkpointing/keeper/registration_state.go | 64 ++-- x/checkpointing/types/bls_key.pb.go | 308 +++++++------------ x/checkpointing/types/checkpoint.pb.go | 143 ++++----- x/checkpointing/types/expected_keepers.go | 4 +- x/checkpointing/types/keys.go | 13 +- x/checkpointing/types/msgs.go | 4 +- x/checkpointing/types/tx.pb.go | 143 +++------ x/checkpointing/types/types.go | 20 +- 14 files changed, 387 insertions(+), 454 deletions(-) diff --git a/crypto/bls12381/types.go b/crypto/bls12381/types.go index 1d622e7b4..159775404 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,63 @@ 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) 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 (pk PublicKey) Marshal() ([]byte, error) { + return pk, nil +} + +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) Equals(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 index e6b5a322c..6d64058cd 100644 --- a/proto/babylon/checkpointing/bls_key.proto +++ b/proto/babylon/checkpointing/bls_key.proto @@ -1,25 +1,25 @@ syntax = "proto3"; package babylon.checkpointing.v1; +import "gogoproto/gogo.proto"; + option go_package = "github.com/babylonchain/babylon/x/checkpointing/types"; -// BlsPubKey wraps BLS public key with meta data -message BlsPubKey { - // key is the BLS public key of a validator - bytes key = 1; +// 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" + ]; - // address is validator's address - string address = 2; + // 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 { - // ed25519_pk is the Ed25519 public key of the validator - bytes ed25519_pk = 1; - - // bls_sig is the BLS signature over ed25519_pk - bytes bls_sig = 2; - - // ed25519_sig is the Ed25519 signature over bls_sig - bytes ed25519_sig = 3; + // 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..2dd8d5a53 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. @@ -47,7 +49,9 @@ message BlsSig { // 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 6fa9a53da..a6c89b28a 100644 --- a/proto/babylon/checkpointing/tx.proto +++ b/proto/babylon/checkpointing/tx.proto @@ -34,9 +34,8 @@ message MsgWrappedCreateValidator { option (gogoproto.equal) = false; option (gogoproto.goproto_getters) = false; - BlsPubKey pubkey = 1; - ProofOfPossession pop = 2; - cosmos.staking.v1beta1.MsgCreateValidator msg_staking = 3; + BlsKey key = 1; + cosmos.staking.v1beta1.MsgCreateValidator msg_create_validator = 2; } // MsgWrappedCreateValidatorResponse defines the MsgWrappedCreateValidator response type diff --git a/x/checkpointing/keeper/keeper.go b/x/checkpointing/keeper/keeper.go index 9f8c2a154..02d3ba250 100644 --- a/x/checkpointing/keeper/keeper.go +++ b/x/checkpointing/keeper/keeper.go @@ -2,22 +2,22 @@ package keeper import ( "fmt" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "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, } } @@ -100,6 +102,6 @@ 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 *types.BlsPubKey, msg *stakingtypes.MsgCreateValidator) error { - return k.RegistrationState(ctx).CreateRegistration(blsPubKey, msg) +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 9b584a9b3..aae98ead1 100644 --- a/x/checkpointing/keeper/msg_server.go +++ b/x/checkpointing/keeper/msg_server.go @@ -2,6 +2,7 @@ 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" @@ -28,10 +29,20 @@ func (m msgServer) WrappedCreateValidator(goCtx context.Context, msg *types.MsgW // TODO: verify pop ctx := sdk.UnwrapSDKContext(goCtx) - err := m.k.CreateRegistration(ctx, msg.Pubkey, msg.MsgStaking) + err := m.k.CreateRegistration(ctx, *msg.Key.Pubkey, types.ValidatorAddress(msg.MsgCreateValidator.ValidatorAddress)) if err != nil { return nil, err } - return &types.MsgWrappedCreateValidatorResponse{}, nil + // 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 index 09a70a45a..10c6a9240 100644 --- a/x/checkpointing/keeper/registration_state.go +++ b/x/checkpointing/keeper/registration_state.go @@ -1,76 +1,84 @@ 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" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) type RegistrationState struct { - cdc codec.BinaryCodec - blsKeys sdk.KVStore - msgCreateValidators sdk.KVStore + cdc codec.BinaryCodec + blsKeys sdk.KVStore + // keySet maps BLS public keys to validator addresses + keySet sdk.KVStore } func (k Keeper) RegistrationState(ctx sdk.Context) RegistrationState { // Build the RegistrationState storage store := ctx.KVStore(k.storeKey) return RegistrationState{ - cdc: k.cdc, - blsKeys: prefix.NewStore(store, types.BlsKeysObjectPrefix), - msgCreateValidators: prefix.NewStore(store, types.MsgCreateValidatorsPrefix), + cdc: k.cdc, + blsKeys: prefix.NewStore(store, types.BlsKeysObjectPrefix), + keySet: prefix.NewStore(store, types.BlsKeySetPrefix), } } -// CreateRegistration inserts the BLS key as well as a corresponding MsgCreateValidator message into the storage -func (rs RegistrationState) CreateRegistration(key *types.BlsPubKey, msg *stakingtypes.MsgCreateValidator) error { - if rs.Exists(key.Address) { - return types.ErrBlsKeyAlreadyExist.Wrapf("existed public key: %x", key.Key) +// 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.Equals(key) { + return types.ErrBlsKeyAlreadyExist.Wrapf("the validator has registered a BLS public key") } - blsKeysKey := types.BlsKeysObjectKey(key.Address) - msgKey := types.MsgCreateValidatorsKey(key.Address) + // we should disallow the same BLS public key is registered by different validators + blsKeySetKey := types.BlsKeySetKey(key) + rawAddr := rs.keySet.Get(blsKeySetKey) + 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 and msgCreateValidator - rs.blsKeys.Set(blsKeysKey, types.BlsPubKeyToBytes(rs.cdc, key)) - rs.msgCreateValidators.Set(msgKey, rs.cdc.MustMarshal(msg)) + blsKeysKey := types.BlsKeysObjectKey(valAddr) + rs.blsKeys.Set(blsKeysKey, key) + rs.keySet.Set(blsKeySetKey, types.ValAddrToBytes(valAddr)) return nil } // GetBlsPubKey retrieves BLS public key by validator's address -func (rs RegistrationState) GetBlsPubKey(addr string) (*types.BlsPubKey, error) { +func (rs RegistrationState) GetBlsPubKey(addr types.ValidatorAddress) (bls12381.PublicKey, error) { pubKeyKey := types.BlsKeysObjectKey(addr) rawBytes := rs.blsKeys.Get(pubKeyKey) 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 types.BytesToBlsPubKey(rs.cdc, rawBytes) + return *pk, err } -// RemoveBlsPubKey removes a BLS public key -func (rs RegistrationState) RemoveBlsPubKey(addr string) error { - if !rs.Exists(addr) { +// RemoveBlsKey removes a BLS public key +// this should be called when a validator is removed +func (rs RegistrationState) RemoveBlsKey(addr types.ValidatorAddress) error { + blsPubKey, err := rs.GetBlsPubKey(addr) + if err != nil { return types.ErrBlsKeyDoesNotExist.Wrapf("BLS public key does not exist with address %s", addr) } - // delete BLS public key and corresponding msgCreateValidator from storage + // delete BLS public key and corresponding key set from storage rs.blsKeys.Delete(types.BlsKeysObjectKey(addr)) - rs.msgCreateValidators.Delete(types.MsgCreateValidatorsKey(addr)) + rs.keySet.Delete(types.BlsKeySetKey(blsPubKey)) return nil } -// RemoveMsgCreateValidator removes a MsgCreateValidator -func (rs RegistrationState) RemoveMsgCreateValidator(addr string) { - rs.msgCreateValidators.Delete(types.MsgCreateValidatorsKey(addr)) -} - // Exists checks whether a BLS key exists -func (rs RegistrationState) Exists(addr string) bool { +func (rs RegistrationState) Exists(addr types.ValidatorAddress) bool { blsKeysKey := types.BlsKeysObjectKey(addr) return rs.blsKeys.Has(blsKeysKey) } diff --git a/x/checkpointing/types/bls_key.pb.go b/x/checkpointing/types/bls_key.pb.go index faedc9a57..a7db272db 100644 --- a/x/checkpointing/types/bls_key.pb.go +++ b/x/checkpointing/types/bls_key.pb.go @@ -5,6 +5,8 @@ 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" @@ -22,26 +24,26 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// BlsPubKey wraps BLS public key with meta data -type BlsPubKey struct { - // key is the BLS public key of a validator - Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` - // address is validator's address - Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` +// 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 *BlsPubKey) Reset() { *m = BlsPubKey{} } -func (m *BlsPubKey) String() string { return proto.CompactTextString(m) } -func (*BlsPubKey) ProtoMessage() {} -func (*BlsPubKey) Descriptor() ([]byte, []int) { +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 *BlsPubKey) XXX_Unmarshal(b []byte) error { +func (m *BlsKey) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *BlsPubKey) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *BlsKey) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_BlsPubKey.Marshal(b, m, deterministic) + return xxx_messageInfo_BlsKey.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -51,40 +53,29 @@ func (m *BlsPubKey) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { return b[:n], nil } } -func (m *BlsPubKey) XXX_Merge(src proto.Message) { - xxx_messageInfo_BlsPubKey.Merge(m, src) +func (m *BlsKey) XXX_Merge(src proto.Message) { + xxx_messageInfo_BlsKey.Merge(m, src) } -func (m *BlsPubKey) XXX_Size() int { +func (m *BlsKey) XXX_Size() int { return m.Size() } -func (m *BlsPubKey) XXX_DiscardUnknown() { - xxx_messageInfo_BlsPubKey.DiscardUnknown(m) +func (m *BlsKey) XXX_DiscardUnknown() { + xxx_messageInfo_BlsKey.DiscardUnknown(m) } -var xxx_messageInfo_BlsPubKey proto.InternalMessageInfo +var xxx_messageInfo_BlsKey proto.InternalMessageInfo -func (m *BlsPubKey) GetKey() []byte { +func (m *BlsKey) GetPop() *ProofOfPossession { if m != nil { - return m.Key + return m.Pop } return nil } -func (m *BlsPubKey) GetAddress() string { - if m != nil { - return m.Address - } - return "" -} - // ProofOfPossession defines proof for the ownership of Ed25519 and BLS private keys type ProofOfPossession struct { - // ed25519_pk is the Ed25519 public key of the validator - Ed25519Pk []byte `protobuf:"bytes,1,opt,name=ed25519_pk,json=ed25519Pk,proto3" json:"ed25519_pk,omitempty"` - // bls_sig is the BLS signature over ed25519_pk - BlsSig []byte `protobuf:"bytes,2,opt,name=bls_sig,json=blsSig,proto3" json:"bls_sig,omitempty"` - // ed25519_sig is the Ed25519 signature over bls_sig - Ed25519Sig []byte `protobuf:"bytes,3,opt,name=ed25519_sig,json=ed25519Sig,proto3" json:"ed25519_sig,omitempty"` + // 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{} } @@ -120,29 +111,8 @@ func (m *ProofOfPossession) XXX_DiscardUnknown() { var xxx_messageInfo_ProofOfPossession proto.InternalMessageInfo -func (m *ProofOfPossession) GetEd25519Pk() []byte { - if m != nil { - return m.Ed25519Pk - } - return nil -} - -func (m *ProofOfPossession) GetBlsSig() []byte { - if m != nil { - return m.BlsSig - } - return nil -} - -func (m *ProofOfPossession) GetEd25519Sig() []byte { - if m != nil { - return m.Ed25519Sig - } - return nil -} - func init() { - proto.RegisterType((*BlsPubKey)(nil), "babylon.checkpointing.v1.BlsPubKey") + proto.RegisterType((*BlsKey)(nil), "babylon.checkpointing.v1.BlsKey") proto.RegisterType((*ProofOfPossession)(nil), "babylon.checkpointing.v1.ProofOfPossession") } @@ -151,27 +121,28 @@ func init() { } var fileDescriptor_a7e926461cc70111 = []byte{ - // 262 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x90, 0x31, 0x4f, 0xc3, 0x30, - 0x10, 0x85, 0x6b, 0x2a, 0xb5, 0x8a, 0xe9, 0x00, 0x5e, 0xc8, 0x82, 0xa9, 0xca, 0xd2, 0x29, 0x51, - 0x41, 0x11, 0x62, 0xed, 0xca, 0xd0, 0x28, 0xdd, 0x58, 0xaa, 0x38, 0x71, 0x1d, 0xcb, 0xc6, 0x8e, - 0x72, 0x29, 0xc2, 0xff, 0x82, 0x9f, 0xc5, 0xd8, 0x91, 0x11, 0x25, 0x7f, 0x04, 0x25, 0x4a, 0x06, - 0xd8, 0xfc, 0xfc, 0xde, 0x7d, 0xba, 0x7b, 0xf8, 0x9e, 0xa5, 0xcc, 0x69, 0x6b, 0xc2, 0xac, 0xe0, - 0x99, 0x2a, 0xad, 0x34, 0xb5, 0x34, 0x22, 0x64, 0x1a, 0x0e, 0x8a, 0xbb, 0xa0, 0xac, 0x6c, 0x6d, - 0x89, 0x3f, 0x84, 0x82, 0x3f, 0xa1, 0xe0, 0x7d, 0xb3, 0x7a, 0xc2, 0xde, 0x56, 0x43, 0x7c, 0x62, - 0x2f, 0xdc, 0x91, 0x2b, 0x3c, 0x55, 0xdc, 0xf9, 0x68, 0x89, 0xd6, 0x8b, 0xa4, 0x7b, 0x12, 0x1f, - 0xcf, 0xd3, 0x3c, 0xaf, 0x38, 0x80, 0x7f, 0xb1, 0x44, 0x6b, 0x2f, 0x19, 0xe5, 0x4a, 0xe3, 0xeb, - 0xb8, 0xb2, 0xf6, 0xb8, 0x3b, 0xc6, 0x16, 0x80, 0x03, 0x48, 0x6b, 0xc8, 0x2d, 0xc6, 0x3c, 0x7f, - 0x88, 0xa2, 0xcd, 0xf3, 0xa1, 0x54, 0x03, 0xc7, 0x1b, 0x7e, 0x62, 0x45, 0x6e, 0xf0, 0xbc, 0xdb, - 0x0b, 0xa4, 0xe8, 0x69, 0x8b, 0x64, 0xc6, 0x34, 0xec, 0xa5, 0x20, 0x77, 0xf8, 0x72, 0x9c, 0xeb, - 0xcc, 0x69, 0x6f, 0x8e, 0xa8, 0xbd, 0x14, 0xdb, 0xdd, 0x57, 0x43, 0xd1, 0xb9, 0xa1, 0xe8, 0xa7, - 0xa1, 0xe8, 0xb3, 0xa5, 0x93, 0x73, 0x4b, 0x27, 0xdf, 0x2d, 0x9d, 0xbc, 0x46, 0x42, 0xd6, 0xc5, - 0x89, 0x05, 0x99, 0x7d, 0x0b, 0x87, 0x2b, 0xb3, 0x22, 0x95, 0x66, 0x14, 0xe1, 0xc7, 0xbf, 0x66, - 0x6a, 0x57, 0x72, 0x60, 0xb3, 0xbe, 0x98, 0xc7, 0xdf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x3e, 0x05, - 0xe2, 0xdc, 0x3f, 0x01, 0x00, 0x00, + // 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 *BlsPubKey) Marshal() (dAtA []byte, err error) { +func (m *BlsKey) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -181,27 +152,37 @@ func (m *BlsPubKey) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *BlsPubKey) MarshalTo(dAtA []byte) (int, error) { +func (m *BlsKey) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *BlsPubKey) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *BlsKey) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - if len(m.Address) > 0 { - i -= len(m.Address) - copy(dAtA[i:], m.Address) - i = encodeVarintBlsKey(dAtA, i, uint64(len(m.Address))) + 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 len(m.Key) > 0 { - i -= len(m.Key) - copy(dAtA[i:], m.Key) - i = encodeVarintBlsKey(dAtA, i, uint64(len(m.Key))) + 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 } @@ -228,24 +209,15 @@ func (m *ProofOfPossession) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.Ed25519Sig) > 0 { - i -= len(m.Ed25519Sig) - copy(dAtA[i:], m.Ed25519Sig) - i = encodeVarintBlsKey(dAtA, i, uint64(len(m.Ed25519Sig))) - i-- - dAtA[i] = 0x1a - } - if len(m.BlsSig) > 0 { - i -= len(m.BlsSig) - copy(dAtA[i:], m.BlsSig) - i = encodeVarintBlsKey(dAtA, i, uint64(len(m.BlsSig))) - i-- - dAtA[i] = 0x12 - } - if len(m.Ed25519Pk) > 0 { - i -= len(m.Ed25519Pk) - copy(dAtA[i:], m.Ed25519Pk) - i = encodeVarintBlsKey(dAtA, i, uint64(len(m.Ed25519Pk))) + 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 } @@ -263,18 +235,18 @@ func encodeVarintBlsKey(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *BlsPubKey) Size() (n int) { +func (m *BlsKey) Size() (n int) { if m == nil { return 0 } var l int _ = l - l = len(m.Key) - if l > 0 { + if m.Pubkey != nil { + l = m.Pubkey.Size() n += 1 + l + sovBlsKey(uint64(l)) } - l = len(m.Address) - if l > 0 { + if m.Pop != nil { + l = m.Pop.Size() n += 1 + l + sovBlsKey(uint64(l)) } return n @@ -286,16 +258,8 @@ func (m *ProofOfPossession) Size() (n int) { } var l int _ = l - l = len(m.Ed25519Pk) - if l > 0 { - n += 1 + l + sovBlsKey(uint64(l)) - } - l = len(m.BlsSig) - if l > 0 { - n += 1 + l + sovBlsKey(uint64(l)) - } - l = len(m.Ed25519Sig) - if l > 0 { + if m.BlsSig != nil { + l = m.BlsSig.Size() n += 1 + l + sovBlsKey(uint64(l)) } return n @@ -307,7 +271,7 @@ func sovBlsKey(x uint64) (n int) { func sozBlsKey(x uint64) (n int) { return sovBlsKey(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *BlsPubKey) Unmarshal(dAtA []byte) error { +func (m *BlsKey) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -330,15 +294,15 @@ func (m *BlsPubKey) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: BlsPubKey: wiretype end group for non-group") + return fmt.Errorf("proto: BlsKey: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: BlsPubKey: illegal tag %d (wire type %d)", fieldNum, wire) + 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 Key", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Pubkey", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -365,16 +329,17 @@ func (m *BlsPubKey) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Key = append(m.Key[:0], dAtA[iNdEx:postIndex]...) - if m.Key == nil { - m.Key = []byte{} + 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 Address", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Pop", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowBlsKey @@ -384,23 +349,27 @@ func (m *BlsPubKey) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthBlsKey } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthBlsKey } if postIndex > l { return io.ErrUnexpectedEOF } - m.Address = string(dAtA[iNdEx:postIndex]) + if m.Pop == nil { + m.Pop = &ProofOfPossession{} + } + if err := m.Pop.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex default: iNdEx = preIndex @@ -453,40 +422,6 @@ func (m *ProofOfPossession) Unmarshal(dAtA []byte) error { } switch fieldNum { case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Ed25519Pk", 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 - } - m.Ed25519Pk = append(m.Ed25519Pk[:0], dAtA[iNdEx:postIndex]...) - if m.Ed25519Pk == nil { - m.Ed25519Pk = []byte{} - } - iNdEx = postIndex - case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field BlsSig", wireType) } @@ -515,43 +450,10 @@ func (m *ProofOfPossession) 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{} - } - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Ed25519Sig", 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 - } - m.Ed25519Sig = append(m.Ed25519Sig[:0], dAtA[iNdEx:postIndex]...) - if m.Ed25519Sig == nil { - m.Ed25519Sig = []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 default: diff --git a/x/checkpointing/types/checkpoint.pb.go b/x/checkpointing/types/checkpoint.pb.go index 1d860a278..8a36e435f 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, 0x44, 0x4e, 0x9a, 0x25, 0xd6, 0xe2, 0x38, 0xaa, 0x1d, 0x60, 0xdf, 0x00, 0xf5, 0x02, 0x47, - 0x2e, 0x95, 0x90, 0xe0, 0xc3, 0x70, 0xdc, 0x91, 0x23, 0x6a, 0x2f, 0x7c, 0x0c, 0x14, 0xa7, 0xa5, - 0x6b, 0xa5, 0xdd, 0xb8, 0xe5, 0xbd, 0xdf, 0x7b, 0xf1, 0xf3, 0x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, 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, + // 554 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x93, 0x4f, 0x8b, 0xd3, 0x40, + 0x18, 0xc6, 0x3b, 0xbb, 0xb5, 0xda, 0xa9, 0xad, 0x25, 0xb8, 0x1a, 0x23, 0xa4, 0xa1, 0xa0, 0x96, + 0x45, 0x12, 0xda, 0x45, 0xf0, 0x0f, 0x1e, 0xb6, 0xd9, 0xca, 0x2e, 0x4b, 0xdb, 0x25, 0x69, 0x15, + 0xbc, 0x84, 0x49, 0x9a, 0x4d, 0x86, 0x4d, 0x32, 0x21, 0x33, 0x51, 0xfb, 0x0d, 0xa4, 0x27, 0x8f, + 0x5e, 0x0a, 0x82, 0x7e, 0x18, 0x4f, 0xb2, 0x37, 0xc5, 0x83, 0x48, 0x7b, 0xf1, 0x63, 0x48, 0x92, + 0xba, 0xdd, 0x16, 0x16, 0x2f, 0x7b, 0xcb, 0xfb, 0xcc, 0xf3, 0x4b, 0xf2, 0xfe, 0x60, 0xe0, 0x7d, + 0x13, 0x99, 0x63, 0x8f, 0x04, 0x8a, 0xe5, 0xda, 0xd6, 0x49, 0x48, 0x70, 0xc0, 0x70, 0xe0, 0x9c, + 0x9b, 0xe4, 0x30, 0x22, 0x8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 0x35, 0xe0, 0xd6, 0xf9, 0xf6, 0xb2, 0xbb, 0x21, 0x94, 0x27, 0x53, 0xa9, 0xa8, 0xfe, 0x6b, 0x0a, + 0xf9, 0xf7, 0x9f, 0xc5, 0x5c, 0xbb, 0xff, 0x75, 0x26, 0x82, 0xd3, 0x99, 0x08, 0x7e, 0xcf, 0x44, + 0xf0, 0x61, 0x2e, 0xe6, 0x4e, 0xe7, 0x62, 0xee, 0xc7, 0x5c, 0xcc, 0xbd, 0x7e, 0xf4, 0x3f, 0x55, + 0xef, 0xd6, 0x2e, 0x2d, 0x1b, 0x87, 0x36, 0x35, 0x0b, 0xe9, 0x25, 0xda, 0xf9, 0x1b, 0x00, 0x00, + 0xff, 0xff, 0x36, 0x21, 0xf6, 0x40, 0xda, 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/expected_keepers.go b/x/checkpointing/types/expected_keepers.go index ae5f1d865..60a9bfd34 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 + 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 29a033acb..cb12ffb24 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" ) @@ -31,8 +32,8 @@ var ( CkptsObjectPrefix = append(CheckpointsPrefix, 0x0) // where we save the concrete BLS sig bytes - BlsKeysObjectPrefix = append(RegistrationPrefix, 0x0) // where we save the concrete BLS public keys - MsgCreateValidatorsPrefix = append(RegistrationPrefix, 0x1) // where we save MsgCreateValidators + BlsKeysObjectPrefix = append(RegistrationPrefix, 0x0) // where we save the concrete BLS public keys + BlsKeySetPrefix = append(RegistrationPrefix, 0x1) // where we save BLS key set ) // BlsSigsObjectKey defines epoch + hash @@ -53,13 +54,13 @@ func CkptsObjectKey(epoch uint64) []byte { } // BlsKeysObjectKey defines validator address -func BlsKeysObjectKey(valAddr string) []byte { +func BlsKeysObjectKey(valAddr ValidatorAddress) []byte { return append(BlsKeysObjectPrefix, []byte(valAddr)...) } -// MsgCreateValidatorsKey defines validator address -func MsgCreateValidatorsKey(valAddr string) []byte { - return append(MsgCreateValidatorsPrefix, []byte(valAddr)...) +// BlsKeySetKey defines BLS public key +func BlsKeySetKey(pk bls12381.PublicKey) []byte { + return append(BlsKeySetPrefix, pk...) } func KeyPrefix(p string) []byte { diff --git a/x/checkpointing/types/msgs.go b/x/checkpointing/types/msgs.go index f46017d64..bcd3d7031 100644 --- a/x/checkpointing/types/msgs.go +++ b/x/checkpointing/types/msgs.go @@ -30,7 +30,7 @@ func (m *MsgAddBlsSig) GetSigners() []sdk.AccAddress { func (m *MsgWrappedCreateValidator) ValidateBasic() error { // This function validates stateless message elements - _, err := sdk.AccAddressFromBech32(m.Pubkey.Address) + _, err := sdk.AccAddressFromBech32(m.MsgCreateValidator.ValidatorAddress) if err != nil { return err } @@ -41,7 +41,7 @@ func (m *MsgWrappedCreateValidator) ValidateBasic() error { } func (m *MsgWrappedCreateValidator) GetSigners() []sdk.AccAddress { - signer, err := sdk.AccAddressFromBech32(m.Pubkey.Address) + signer, err := sdk.AccAddressFromBech32(m.MsgCreateValidator.ValidatorAddress) if err != nil { panic(err) } diff --git a/x/checkpointing/types/tx.pb.go b/x/checkpointing/types/tx.pb.go index 98ec616bd..2fab4a133 100644 --- a/x/checkpointing/types/tx.pb.go +++ b/x/checkpointing/types/tx.pb.go @@ -107,9 +107,8 @@ var xxx_messageInfo_MsgAddBlsSigResponse proto.InternalMessageInfo // MsgWrappedCreateValidator defines a wrapped message to create a validator type MsgWrappedCreateValidator struct { - Pubkey *BlsPubKey `protobuf:"bytes,1,opt,name=pubkey,proto3" json:"pubkey,omitempty"` - Pop *ProofOfPossession `protobuf:"bytes,2,opt,name=pop,proto3" json:"pop,omitempty"` - MsgStaking *types.MsgCreateValidator `protobuf:"bytes,3,opt,name=msg_staking,json=msgStaking,proto3" json:"msg_staking,omitempty"` + 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{} } @@ -192,34 +191,32 @@ func init() { func init() { proto.RegisterFile("babylon/checkpointing/tx.proto", fileDescriptor_24b023a97b92daa6) } var fileDescriptor_24b023a97b92daa6 = []byte{ - // 432 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x53, 0x3f, 0x6f, 0xd3, 0x40, - 0x14, 0xf7, 0x11, 0x29, 0xc0, 0x95, 0xc9, 0xaa, 0xaa, 0x90, 0xc1, 0x29, 0x89, 0x54, 0x21, 0x90, - 0xce, 0x4a, 0x2b, 0x06, 0xa8, 0x18, 0x28, 0x63, 0x15, 0x35, 0x72, 0x24, 0x90, 0x58, 0xaa, 0x3b, - 0xe7, 0x7a, 0x39, 0x25, 0xf1, 0x3b, 0xf9, 0x5d, 0xaa, 0xfa, 0x1b, 0x20, 0x26, 0x3e, 0x42, 0x3f, - 0x0e, 0x63, 0x47, 0x46, 0x94, 0x2c, 0x4c, 0xac, 0xac, 0xc8, 0xf6, 0x99, 0x86, 0x2a, 0x8e, 0x50, - 0x27, 0xfb, 0xfc, 0x7e, 0xff, 0xde, 0xcf, 0x36, 0x0d, 0x04, 0x17, 0xd9, 0x0c, 0x92, 0x30, 0x9e, - 0xc8, 0x78, 0x6a, 0x40, 0x27, 0x56, 0x27, 0x2a, 0xb4, 0x57, 0xcc, 0xa4, 0x60, 0xc1, 0x6f, 0xb9, - 0x39, 0xfb, 0x67, 0xce, 0x2e, 0xfb, 0xed, 0x5d, 0x05, 0x0a, 0x0a, 0x50, 0x98, 0xdf, 0x95, 0xf8, - 0xf6, 0xc1, 0x66, 0xbd, 0xdb, 0x93, 0xc3, 0xf5, 0x36, 0xe3, 0xc4, 0x0c, 0xcf, 0xa7, 0x32, 0x73, - 0xa0, 0x4e, 0x0c, 0x38, 0x07, 0x0c, 0xd1, 0xf2, 0x69, 0x3e, 0xbd, 0xec, 0x0b, 0x69, 0x79, 0xff, - 0x6f, 0xba, 0xee, 0x88, 0x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0xab, 0xcc, 0xfc, 0x2f, 0x84, - 0xee, 0xd5, 0xf4, 0x7f, 0xb4, 0x55, 0x6a, 0x33, 0xa9, 0x7d, 0x7c, 0x0f, 0x52, 0x15, 0xe6, 0xe4, - 0xec, 0xdb, 0x32, 0x20, 0x37, 0xcb, 0x80, 0xfc, 0x58, 0x06, 0xe4, 0xeb, 0x2a, 0xf0, 0x6e, 0x56, - 0x81, 0xf7, 0x7d, 0x15, 0x78, 0x9f, 0x5e, 0x29, 0x6d, 0x27, 0x0b, 0xc1, 0x62, 0x98, 0x87, 0xce, - 0x20, 0x9e, 0x70, 0x9d, 0x54, 0x87, 0xf0, 0xea, 0xee, 0xef, 0x96, 0x19, 0x89, 0xa2, 0x59, 0x7c, - 0xd4, 0x47, 0x7f, 0x02, 0x00, 0x00, 0xff, 0xff, 0x77, 0x54, 0xbd, 0x28, 0x94, 0x03, 0x00, 0x00, + // 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, 0xa0, 0xea, 0x94, 0xb1, 0xab, 0x4b, 0xca, 0x29, 0x8e, + 0xcf, 0x4e, 0xad, 0x84, 0x2a, 0x92, 0x4f, 0xce, 0x2f, 0xce, 0xcd, 0x2f, 0xd6, 0x2f, 0x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, 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. @@ -420,21 +417,9 @@ func (m *MsgWrappedCreateValidator) MarshalToSizedBuffer(dAtA []byte) (int, erro _ = i var l int _ = l - if m.MsgStaking != nil { + if m.MsgCreateValidator != nil { { - size, err := m.MsgStaking.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTx(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - } - if m.Pop != nil { - { - size, err := m.Pop.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.MsgCreateValidator.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -444,9 +429,9 @@ func (m *MsgWrappedCreateValidator) MarshalToSizedBuffer(dAtA []byte) (int, erro i-- dAtA[i] = 0x12 } - if m.Pubkey != nil { + if m.Key != nil { { - size, err := m.Pubkey.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.Key.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -521,16 +506,12 @@ func (m *MsgWrappedCreateValidator) Size() (n int) { } var l int _ = l - if m.Pubkey != nil { - l = m.Pubkey.Size() - n += 1 + l + sovTx(uint64(l)) - } - if m.Pop != nil { - l = m.Pop.Size() + if m.Key != nil { + l = m.Key.Size() n += 1 + l + sovTx(uint64(l)) } - if m.MsgStaking != nil { - l = m.MsgStaking.Size() + if m.MsgCreateValidator != nil { + l = m.MsgCreateValidator.Size() n += 1 + l + sovTx(uint64(l)) } return n @@ -718,7 +699,7 @@ func (m *MsgWrappedCreateValidator) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Pubkey", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -745,52 +726,16 @@ func (m *MsgWrappedCreateValidator) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.Pubkey == nil { - m.Pubkey = &BlsPubKey{} + if m.Key == nil { + m.Key = &BlsKey{} } - if err := m.Pubkey.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + 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 Pop", 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.Pop == nil { - m.Pop = &ProofOfPossession{} - } - if err := m.Pop.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MsgStaking", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field MsgCreateValidator", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -817,10 +762,10 @@ func (m *MsgWrappedCreateValidator) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.MsgStaking == nil { - m.MsgStaking = &types.MsgCreateValidator{} + if m.MsgCreateValidator == nil { + m.MsgCreateValidator = &types.MsgCreateValidator{} } - if err := m.MsgStaking.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.MsgCreateValidator.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/x/checkpointing/types/types.go b/x/checkpointing/types/types.go index 58dec831a..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, @@ -46,16 +56,6 @@ func BytesToBlsSig(cdc codec.BinaryCodec, bz []byte) (*BlsSig, error) { return blsSig, err } -func BlsPubKeyToBytes(cdc codec.BinaryCodec, key *BlsPubKey) []byte { - return cdc.MustMarshal(key) -} - -func BytesToBlsPubKey(cdc codec.BinaryCodec, bz []byte) (*BlsPubKey, error) { - key := new(BlsPubKey) - err := cdc.Unmarshal(bz, key) - return key, err -} - func (m RawCkptHash) Equals(h RawCkptHash) bool { if bytes.Compare(m.Bytes(), h.Bytes()) == 0 { return true From 44c44ff80a7e699d0a74f54efbabc81937e3541a Mon Sep 17 00:00:00 2001 From: Fangyu Gai Date: Wed, 6 Jul 2022 12:33:52 +0800 Subject: [PATCH 5/6] fix ci --- app/app.go | 2 +- crypto/bls12381/types.go | 24 ++++++- proto/babylon/checkpointing/checkpoint.proto | 2 + x/checkpointing/keeper/registration_state.go | 2 +- x/checkpointing/types/checkpoint.pb.go | 72 ++++++++++---------- x/checkpointing/types/expected_keepers.go | 2 +- x/checkpointing/types/utils.go | 4 +- 7 files changed, 66 insertions(+), 42 deletions(-) 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 159775404..52ae3de3a 100644 --- a/crypto/bls12381/types.go +++ b/crypto/bls12381/types.go @@ -33,6 +33,15 @@ 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 @@ -56,10 +65,23 @@ 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 @@ -79,7 +101,7 @@ func (pk *PublicKey) Unmarshal(data []byte) error { return nil } -func (pk PublicKey) Equals(k PublicKey) bool { +func (pk PublicKey) Equal(k PublicKey) bool { return string(pk) == string(k) } diff --git a/proto/babylon/checkpointing/checkpoint.proto b/proto/babylon/checkpointing/checkpoint.proto index 2dd8d5a53..2c5888dde 100644 --- a/proto/babylon/checkpointing/checkpoint.proto +++ b/proto/babylon/checkpointing/checkpoint.proto @@ -44,6 +44,8 @@ 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 diff --git a/x/checkpointing/keeper/registration_state.go b/x/checkpointing/keeper/registration_state.go index 10c6a9240..9d29294a3 100644 --- a/x/checkpointing/keeper/registration_state.go +++ b/x/checkpointing/keeper/registration_state.go @@ -30,7 +30,7 @@ func (rs RegistrationState) CreateRegistration(key bls12381.PublicKey, valAddr t blsPubKey, err := rs.GetBlsPubKey(valAddr) // we should disallow a validator to register with different BLS public keys - if err == nil && !blsPubKey.Equals(key) { + if err == nil && !blsPubKey.Equal(key) { return types.ErrBlsKeyAlreadyExist.Wrapf("the validator has registered a BLS public key") } diff --git a/x/checkpointing/types/checkpoint.pb.go b/x/checkpointing/types/checkpoint.pb.go index 8a36e435f..c9ecb8047 100644 --- a/x/checkpointing/types/checkpoint.pb.go +++ b/x/checkpointing/types/checkpoint.pb.go @@ -259,42 +259,42 @@ func init() { } var fileDescriptor_63ff05f0a47b36f7 = []byte{ - // 554 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x93, 0x4f, 0x8b, 0xd3, 0x40, - 0x18, 0xc6, 0x3b, 0xbb, 0xb5, 0xda, 0xa9, 0xad, 0x25, 0xb8, 0x1a, 0x23, 0xa4, 0xa1, 0xa0, 0x96, - 0x45, 0x12, 0xda, 0x45, 0xf0, 0x0f, 0x1e, 0xb6, 0xd9, 0xca, 0x2e, 0x4b, 0xdb, 0x25, 0x69, 0x15, - 0xbc, 0x84, 0x49, 0x9a, 0x4d, 0x86, 0x4d, 0x32, 0x21, 0x33, 0x51, 0xfb, 0x0d, 0xa4, 0x27, 0x8f, - 0x5e, 0x0a, 0x82, 0x7e, 0x18, 0x4f, 0xb2, 0x37, 0xc5, 0x83, 0x48, 0x7b, 0xf1, 0x63, 0x48, 0x92, - 0xba, 0xdd, 0x16, 0x16, 0x2f, 0x7b, 0xcb, 0xfb, 0xcc, 0xf3, 0x4b, 0xf2, 0xfe, 0x60, 0xe0, 0x7d, - 0x13, 0x99, 0x63, 0x8f, 0x04, 0x8a, 0xe5, 0xda, 0xd6, 0x49, 0x48, 0x70, 0xc0, 0x70, 0xe0, 0x9c, - 0x9b, 0xe4, 0x30, 0x22, 0x8c, 0x70, 0xfc, 0xa2, 0x27, 0xaf, 0xf4, 0xe4, 0x37, 0x4d, 0xe1, 0x8e, - 0x45, 0xa8, 0x4f, 0xa8, 0x91, 0xf6, 0x94, 0x6c, 0xc8, 0x20, 0xe1, 0xa6, 0x43, 0x1c, 0x92, 0xe5, - 0xc9, 0xd3, 0x22, 0xad, 0x39, 0x84, 0x38, 0x9e, 0xad, 0xa4, 0x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e7, 0x62, 0xee, 0xc7, 0x5c, 0xcc, 0xbd, 0x7e, 0xf4, 0x3f, 0x55, - 0xef, 0xd6, 0x2e, 0x2d, 0x1b, 0x87, 0x36, 0x35, 0x0b, 0xe9, 0x25, 0xda, 0xf9, 0x1b, 0x00, 0x00, - 0xff, 0xff, 0x36, 0x21, 0xf6, 0x40, 0xda, 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, 0x1b, 0x3f, 0x86, 0x24, + 0xa9, 0xeb, 0x5a, 0x18, 0xde, 0xec, 0x2e, 0xef, 0x73, 0x9e, 0x5f, 0x92, 0xf7, 0x07, 0x07, 0xde, + 0xb7, 0x90, 0x35, 0xf2, 0x49, 0xa8, 0xda, 0x9e, 0x63, 0x9f, 0x44, 0x04, 0x87, 0x0c, 0x87, 0xee, + 0xb9, 0x49, 0x89, 0x62, 0xc2, 0x08, 0x2f, 0xcc, 0x7b, 0xca, 0x52, 0x4f, 0x79, 0xd3, 0x10, 0xef, + 0xd8, 0x84, 0x06, 0x84, 0x9a, 0x59, 0x4f, 0xcd, 0x87, 0x1c, 0x12, 0x6f, 0xba, 0xc4, 0x25, 0x79, + 0x9e, 0x3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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 { diff --git a/x/checkpointing/types/expected_keepers.go b/x/checkpointing/types/expected_keepers.go index 60a9bfd34..ce1fa0d5a 100644 --- a/x/checkpointing/types/expected_keepers.go +++ b/x/checkpointing/types/expected_keepers.go @@ -25,7 +25,7 @@ type StakingKeeper interface { // EpochingKeeper defines the expected interface needed to retrieve epoch info type EpochingKeeper interface { - GetEpochNumber(ctx sdk.Context) sdk.Uint + GetEpochNumber(ctx sdk.Context) (sdk.Uint, error) EnqueueMsg(ctx sdk.Context, msg epochingtypes.QueuedMessage) error } 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) From 00d3e9003b6b85ade37960323c42b3a6d83ed05d Mon Sep 17 00:00:00 2001 From: Fangyu Gai Date: Wed, 6 Jul 2022 16:56:47 +0800 Subject: [PATCH 6/6] update according to comments --- x/checkpointing/keeper/msg_server.go | 2 +- x/checkpointing/keeper/registration_state.go | 50 +++++++------------- x/checkpointing/types/keys.go | 16 +++---- x/checkpointing/types/msgs.go | 14 +----- 4 files changed, 29 insertions(+), 53 deletions(-) diff --git a/x/checkpointing/keeper/msg_server.go b/x/checkpointing/keeper/msg_server.go index aae98ead1..fce696916 100644 --- a/x/checkpointing/keeper/msg_server.go +++ b/x/checkpointing/keeper/msg_server.go @@ -26,7 +26,7 @@ func (m msgServer) AddBlsSig(goCtx context.Context, header *types.MsgAddBlsSig) // 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 + // 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)) diff --git a/x/checkpointing/keeper/registration_state.go b/x/checkpointing/keeper/registration_state.go index 9d29294a3..53e4eeed7 100644 --- a/x/checkpointing/keeper/registration_state.go +++ b/x/checkpointing/keeper/registration_state.go @@ -9,19 +9,20 @@ import ( ) type RegistrationState struct { - cdc codec.BinaryCodec - blsKeys sdk.KVStore - // keySet maps BLS public keys to validator addresses - keySet sdk.KVStore + 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, - blsKeys: prefix.NewStore(store, types.BlsKeysObjectPrefix), - keySet: prefix.NewStore(store, types.BlsKeySetPrefix), + cdc: k.cdc, + addrToBlsKeys: prefix.NewStore(store, types.AddrToBlsKeyPrefix), + blsKeysToAddr: prefix.NewStore(store, types.BlsKeyToAddrPrefix), } } @@ -35,24 +36,24 @@ func (rs RegistrationState) CreateRegistration(key bls12381.PublicKey, valAddr t } // we should disallow the same BLS public key is registered by different validators - blsKeySetKey := types.BlsKeySetKey(key) - rawAddr := rs.keySet.Get(blsKeySetKey) + 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 and msgCreateValidator - blsKeysKey := types.BlsKeysObjectKey(valAddr) - rs.blsKeys.Set(blsKeysKey, key) - rs.keySet.Set(blsKeySetKey, types.ValAddrToBytes(valAddr)) + // 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) { - pubKeyKey := types.BlsKeysObjectKey(addr) - rawBytes := rs.blsKeys.Get(pubKeyKey) + 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) } @@ -62,23 +63,8 @@ func (rs RegistrationState) GetBlsPubKey(addr types.ValidatorAddress) (bls12381. return *pk, err } -// RemoveBlsKey removes a BLS public key -// this should be called when a validator is removed -func (rs RegistrationState) RemoveBlsKey(addr types.ValidatorAddress) error { - blsPubKey, err := rs.GetBlsPubKey(addr) - if err != nil { - return types.ErrBlsKeyDoesNotExist.Wrapf("BLS public key does not exist with address %s", addr) - } - - // delete BLS public key and corresponding key set from storage - rs.blsKeys.Delete(types.BlsKeysObjectKey(addr)) - rs.keySet.Delete(types.BlsKeySetKey(blsPubKey)) - - return nil -} - // Exists checks whether a BLS key exists func (rs RegistrationState) Exists(addr types.ValidatorAddress) bool { - blsKeysKey := types.BlsKeysObjectKey(addr) - return rs.blsKeys.Has(blsKeysKey) + pkKey := types.AddrToBlsKeyKey(addr) + return rs.addrToBlsKeys.Has(pkKey) } diff --git a/x/checkpointing/types/keys.go b/x/checkpointing/types/keys.go index cb12ffb24..835f92aaa 100644 --- a/x/checkpointing/types/keys.go +++ b/x/checkpointing/types/keys.go @@ -32,8 +32,8 @@ var ( CkptsObjectPrefix = append(CheckpointsPrefix, 0x0) // where we save the concrete BLS sig bytes - BlsKeysObjectPrefix = append(RegistrationPrefix, 0x0) // where we save the concrete BLS public keys - BlsKeySetPrefix = append(RegistrationPrefix, 0x1) // where we save BLS key set + 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 @@ -53,14 +53,14 @@ func CkptsObjectKey(epoch uint64) []byte { return append(CkptsObjectPrefix, sdk.Uint64ToBigEndian(epoch)...) } -// BlsKeysObjectKey defines validator address -func BlsKeysObjectKey(valAddr ValidatorAddress) []byte { - return append(BlsKeysObjectPrefix, []byte(valAddr)...) +// AddrToBlsKeyKey defines validator address +func AddrToBlsKeyKey(valAddr ValidatorAddress) []byte { + return append(AddrToBlsKeyPrefix, []byte(valAddr)...) } -// BlsKeySetKey defines BLS public key -func BlsKeySetKey(pk bls12381.PublicKey) []byte { - return append(BlsKeySetPrefix, pk...) +// BlsKeyToAddrKey defines BLS public key +func BlsKeyToAddrKey(pk bls12381.PublicKey) []byte { + return append(BlsKeyToAddrPrefix, pk...) } func KeyPrefix(p string) []byte { diff --git a/x/checkpointing/types/msgs.go b/x/checkpointing/types/msgs.go index bcd3d7031..517f7a830 100644 --- a/x/checkpointing/types/msgs.go +++ b/x/checkpointing/types/msgs.go @@ -30,21 +30,11 @@ func (m *MsgAddBlsSig) GetSigners() []sdk.AccAddress { func (m *MsgWrappedCreateValidator) ValidateBasic() error { // This function validates stateless message elements - _, err := sdk.AccAddressFromBech32(m.MsgCreateValidator.ValidatorAddress) - if err != nil { - return err - } - // TODO: verify bls sig - return nil + return m.MsgCreateValidator.ValidateBasic() } func (m *MsgWrappedCreateValidator) GetSigners() []sdk.AccAddress { - signer, err := sdk.AccAddressFromBech32(m.MsgCreateValidator.ValidatorAddress) - if err != nil { - panic(err) - } - - return []sdk.AccAddress{signer} + return m.MsgCreateValidator.GetSigners() }