From 770a9bd843b12d7a76212e5fc698220e0836bd7c Mon Sep 17 00:00:00 2001 From: Ganesha Upadhyaya Date: Fri, 24 Mar 2023 01:44:59 -0700 Subject: [PATCH] add signatures and keys to signed header along with signature verification in validate method (#788) Fixes #782 #783 #784 --------- Co-authored-by: Ganesha Upadhyaya --- block/manager.go | 12 +- conv/abci/block.go | 8 +- node/full_client.go | 2 +- node/full_client_test.go | 16 +- proto/rollkit/rollkit.proto | 17 +- state/executor.go | 2 +- state/executor_test.go | 54 +++- types/block.go | 13 +- types/pb/rollkit/rollkit.pb.go | 549 +++++++++++++++++++++++++++------ types/serialization.go | 39 ++- types/serialization_test.go | 11 +- types/validation.go | 55 ++-- 12 files changed, 622 insertions(+), 156 deletions(-) diff --git a/block/manager.go b/block/manager.go index 3e0341560a8..20f026c9e7f 100644 --- a/block/manager.go +++ b/block/manager.go @@ -446,8 +446,6 @@ func (m *Manager) getCommit(header types.Header) (*types.Commit, error) { return nil, err } return &types.Commit{ - Height: uint64(header.Height()), - HeaderHash: header.Hash(), Signatures: []types.Signature{sign}, }, nil } @@ -461,7 +459,7 @@ func (m *Manager) publishBlock(ctx context.Context) error { // this is a special case, when first block is produced - there is no previous commit if newHeight == uint64(m.genesis.InitialHeight) { - lastCommit = &types.Commit{Height: height} + lastCommit = &types.Commit{} } else { lastCommit, err = m.store.LoadCommit(height) if err != nil { @@ -496,6 +494,14 @@ func (m *Manager) publishBlock(ctx context.Context) error { // set the commit to current block's signed header block.SignedHeader.Commit = *commit + // set the validator set using the signer's public key + // TODO(ganesh): need to hook into a module that selects signers + pubKey, err := m.proposerKey.GetPublic().Raw() + if err != nil { + return err + } + block.SignedHeader.Validators = types.ValidatorSet{Validators: []types.Validator{{PublicKey: pubKey}}} + // SaveBlock commits the DB tx err = m.store.SaveBlock(block, commit) if err != nil { diff --git a/conv/abci/block.go b/conv/abci/block.go index 9d672d535db..04e9a36ebe6 100644 --- a/conv/abci/block.go +++ b/conv/abci/block.go @@ -76,7 +76,7 @@ func ToABCIBlock(block *types.Block) (*tmtypes.Block, error) { if err != nil { return nil, err } - abciCommit := ToABCICommit(&block.SignedHeader.Commit) + abciCommit := ToABCICommit(&block.SignedHeader.Commit, block.SignedHeader.Header.BaseHeader.Height, block.SignedHeader.Hash()) // This assumes that we have only one signature if len(abciCommit.Signatures) == 1 { abciCommit.Signatures[0].ValidatorAddress = block.SignedHeader.Header.ProposerAddress @@ -116,12 +116,12 @@ func ToABCIBlockMeta(block *types.Block) (*tmtypes.BlockMeta, error) { // ToABCICommit converts Rollkit commit into commit format defined by ABCI. // This function only converts fields that are available in Rollkit commit. // Other fields (especially ValidatorAddress and Timestamp of Signature) has to be filled by caller. -func ToABCICommit(commit *types.Commit) *tmtypes.Commit { +func ToABCICommit(commit *types.Commit, height uint64, hash types.Hash) *tmtypes.Commit { tmCommit := tmtypes.Commit{ - Height: int64(commit.Height), + Height: int64(height), Round: 0, BlockID: tmtypes.BlockID{ - Hash: tmbytes.HexBytes(commit.HeaderHash), + Hash: tmbytes.HexBytes(hash), PartSetHeader: tmtypes.PartSetHeader{}, }, } diff --git a/node/full_client.go b/node/full_client.go index 8cc379eb8a7..7149cfdd903 100644 --- a/node/full_client.go +++ b/node/full_client.go @@ -493,7 +493,7 @@ func (c *FullClient) Commit(ctx context.Context, height *int64) (*ctypes.ResultC if err != nil { return nil, err } - commit := abciconv.ToABCICommit(com) + commit := abciconv.ToABCICommit(com, heightValue, b.SignedHeader.Hash()) block, err := abciconv.ToABCIBlock(b) if err != nil { return nil, err diff --git a/node/full_client_test.go b/node/full_client_test.go index f74d500b2f7..2b7200489f9 100644 --- a/node/full_client_test.go +++ b/node/full_client_test.go @@ -273,7 +273,7 @@ func TestGetCommit(t *testing.T) { require.NoError(err) for _, b := range blocks { - err = rpc.node.Store.SaveBlock(b, &types.Commit{Height: uint64(b.SignedHeader.Header.Height())}) + err = rpc.node.Store.SaveBlock(b, &types.Commit{}) rpc.node.Store.SetHeight(uint64(b.SignedHeader.Header.Height())) require.NoError(err) } @@ -308,10 +308,7 @@ func TestBlockSearch(t *testing.T) { heights := []int64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} for _, h := range heights { block := getRandomBlock(uint64(h), 5) - err := rpc.node.Store.SaveBlock(block, &types.Commit{ - Height: uint64(h), - HeaderHash: block.SignedHeader.Header.Hash(), - }) + err := rpc.node.Store.SaveBlock(block, &types.Commit{}) require.NoError(err) } indexBlocks(t, rpc, heights) @@ -562,10 +559,7 @@ func TestBlockchainInfo(t *testing.T) { heights := []int64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} for _, h := range heights { block := getRandomBlock(uint64(h), 5) - err := rpc.node.Store.SaveBlock(block, &types.Commit{ - Height: uint64(h), - HeaderHash: block.SignedHeader.Header.Hash(), - }) + err := rpc.node.Store.SaveBlock(block, &types.Commit{}) rpc.node.Store.SetHeight(uint64(block.SignedHeader.Header.Height())) require.NoError(err) } @@ -988,12 +982,12 @@ func TestStatus(t *testing.T) { assert.NotNil(rpc) earliestBlock := getRandomBlockWithProposer(1, 1, validators[0].Address.Bytes()) - err = rpc.node.Store.SaveBlock(earliestBlock, &types.Commit{Height: uint64(earliestBlock.SignedHeader.Header.Height())}) + err = rpc.node.Store.SaveBlock(earliestBlock, &types.Commit{}) rpc.node.Store.SetHeight(uint64(earliestBlock.SignedHeader.Header.Height())) require.NoError(err) latestBlock := getRandomBlockWithProposer(2, 1, validators[1].Address.Bytes()) - err = rpc.node.Store.SaveBlock(latestBlock, &types.Commit{Height: uint64(latestBlock.SignedHeader.Header.Height())}) + err = rpc.node.Store.SaveBlock(latestBlock, &types.Commit{}) rpc.node.Store.SetHeight(uint64(latestBlock.SignedHeader.Header.Height())) require.NoError(err) diff --git a/proto/rollkit/rollkit.proto b/proto/rollkit/rollkit.proto index f959c395439..8dbf301fba5 100644 --- a/proto/rollkit/rollkit.proto +++ b/proto/rollkit/rollkit.proto @@ -49,24 +49,29 @@ message Header { // pubkey can't be recovered by the signature (e.g. ed25519). bytes proposer_address = 10; - // public key of the proposer so we can verify the signature - bytes proposer_public_key = 11; - - // Hash of block aggregator set, at a time of block creation - bytes aggregators_hash = 12; + bytes aggregators_hash = 11; // Chain ID the block belongs to - string chain_id = 13; + string chain_id = 12; } message Commit { repeated bytes signatures = 1; } +message Validator { + bytes public_key = 1; +} + +message ValidatorSet { + repeated Validator validators = 1; +} + message SignedHeader { Header header = 1; Commit commit = 2; + ValidatorSet validators = 3; } message Data { diff --git a/state/executor.go b/state/executor.go index ab825d5d25b..8bf13ce340e 100644 --- a/state/executor.go +++ b/state/executor.go @@ -446,7 +446,7 @@ func (e *BlockExecutor) generateFraudProof(beginBlockRequest *abci.RequestBeginB } func (e *BlockExecutor) getLastCommitHash(lastCommit *types.Commit, header *types.Header) []byte { - lastABCICommit := abciconv.ToABCICommit(lastCommit) + lastABCICommit := abciconv.ToABCICommit(lastCommit, header.BaseHeader.Height, header.Hash()) if len(lastCommit.Signatures) == 1 { lastABCICommit.Signatures[0].ValidatorAddress = e.proposerAddress lastABCICommit.Signatures[0].Timestamp = header.Time() diff --git a/state/executor_test.go b/state/executor_test.go index bb0a9788107..dc3aa4f67c0 100644 --- a/state/executor_test.go +++ b/state/executor_test.go @@ -12,6 +12,7 @@ import ( abci "github.com/tendermint/tendermint/abci/types" cfg "github.com/tendermint/tendermint/config" + "github.com/tendermint/tendermint/crypto/ed25519" "github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/pubsub/query" "github.com/tendermint/tendermint/proxy" @@ -44,7 +45,16 @@ func doTestCreateBlock(t *testing.T, fraudProofsEnabled bool) { state := types.State{} state.ConsensusParams.Block.MaxBytes = 100 state.ConsensusParams.Block.MaxGas = 100000 - state.Validators = tmtypes.NewValidatorSet(nil) + vKey := ed25519.GenPrivKey() + validators := []*tmtypes.Validator{ + { + Address: vKey.PubKey().Address(), + PubKey: vKey.PubKey(), + VotingPower: int64(100), + ProposerPriority: int64(1), + }, + } + state.Validators = tmtypes.NewValidatorSet(validators) // empty block block := executor.CreateBlock(1, &types.Commit{}, []byte{}, state) @@ -124,10 +134,19 @@ func doTestApplyBlock(t *testing.T, fraudProofsEnabled bool) { require.NoError(err) require.NotNil(headerSub) + vKey := ed25519.GenPrivKey() + validators := []*tmtypes.Validator{ + { + Address: vKey.PubKey().Address(), + PubKey: vKey.PubKey(), + VotingPower: int64(100), + ProposerPriority: int64(1), + }, + } state := types.State{ - NextValidators: tmtypes.NewValidatorSet(nil), - Validators: tmtypes.NewValidatorSet(nil), - LastValidators: tmtypes.NewValidatorSet(nil), + NextValidators: tmtypes.NewValidatorSet(validators), + Validators: tmtypes.NewValidatorSet(validators), + LastValidators: tmtypes.NewValidatorSet(validators), } state.InitialHeight = 1 state.LastBlockHeight = 0 @@ -136,11 +155,23 @@ func doTestApplyBlock(t *testing.T, fraudProofsEnabled bool) { _ = mpool.CheckTx([]byte{1, 2, 3, 4}, func(r *abci.Response) {}, mempool.TxInfo{}) require.NoError(err) - block := executor.CreateBlock(1, &types.Commit{}, []byte{}, state) + block := executor.CreateBlock(1, &types.Commit{Signatures: []types.Signature{types.Signature([]byte{1, 1, 1})}}, []byte{}, state) require.NotNil(block) assert.Equal(int64(1), block.SignedHeader.Header.Height()) assert.Len(block.Data.Txs, 1) + // Update the signature on the block to current from last + headerBytes, _ := block.SignedHeader.Header.MarshalBinary() + sig, _ := vKey.Sign(headerBytes) + block.SignedHeader.Commit = types.Commit{ + Signatures: []types.Signature{sig}, + } + block.SignedHeader.Validators = types.ValidatorSet{ + Validators: []types.Validator{{ + PublicKey: vKey.PubKey().Bytes(), + }}, + } + newState, resp, err := executor.ApplyBlock(context.Background(), state, block) require.NoError(err) require.NotNil(newState) @@ -154,11 +185,22 @@ func doTestApplyBlock(t *testing.T, fraudProofsEnabled bool) { require.NoError(mpool.CheckTx([]byte{5, 6, 7, 8, 9}, func(r *abci.Response) {}, mempool.TxInfo{})) require.NoError(mpool.CheckTx([]byte{1, 2, 3, 4, 5}, func(r *abci.Response) {}, mempool.TxInfo{})) require.NoError(mpool.CheckTx(make([]byte, 90), func(r *abci.Response) {}, mempool.TxInfo{})) - block = executor.CreateBlock(2, &types.Commit{}, []byte{}, newState) + block = executor.CreateBlock(2, &types.Commit{Signatures: []types.Signature{types.Signature([]byte{1, 1, 1})}}, []byte{}, newState) require.NotNil(block) assert.Equal(int64(2), block.SignedHeader.Header.Height()) assert.Len(block.Data.Txs, 3) + headerBytes, _ = block.SignedHeader.Header.MarshalBinary() + sig, _ = vKey.Sign(headerBytes) + block.SignedHeader.Commit = types.Commit{ + Signatures: []types.Signature{sig}, + } + block.SignedHeader.Validators = types.ValidatorSet{ + Validators: []types.Validator{{ + PublicKey: vKey.PubKey().Bytes(), + }}, + } + newState, resp, err = executor.ApplyBlock(context.Background(), newState, block) require.NoError(err) require.NotNil(newState) diff --git a/types/block.go b/types/block.go index 9f83ed6d647..ca73b966d18 100644 --- a/types/block.go +++ b/types/block.go @@ -38,17 +38,24 @@ type EvidenceData struct { // Commit contains evidence of block creation. type Commit struct { - Height uint64 - HeaderHash Hash Signatures []Signature // most of the time this is a single signature } +type Validator struct { + PublicKey []byte +} + +type ValidatorSet struct { + Validators []Validator +} + // SignedHeader combines Header and its Commit. // // Used mostly for gossiping. type SignedHeader struct { Header - Commit Commit + Commit Commit + Validators ValidatorSet } // Signature represents signature of block creator. diff --git a/types/pb/rollkit/rollkit.pb.go b/types/pb/rollkit/rollkit.pb.go index 41d5f296027..2df04eee386 100644 --- a/types/pb/rollkit/rollkit.pb.go +++ b/types/pb/rollkit/rollkit.pb.go @@ -106,12 +106,10 @@ type Header struct { // We keep this in case users choose another signature format where the // pubkey can't be recovered by the signature (e.g. ed25519). ProposerAddress []byte `protobuf:"bytes,10,opt,name=proposer_address,json=proposerAddress,proto3" json:"proposer_address,omitempty"` - // public key of the proposer so we can verify the signature - ProposerPublicKey []byte `protobuf:"bytes,11,opt,name=proposer_public_key,json=proposerPublicKey,proto3" json:"proposer_public_key,omitempty"` // Hash of block aggregator set, at a time of block creation - AggregatorsHash []byte `protobuf:"bytes,12,opt,name=aggregators_hash,json=aggregatorsHash,proto3" json:"aggregators_hash,omitempty"` + AggregatorsHash []byte `protobuf:"bytes,11,opt,name=aggregators_hash,json=aggregatorsHash,proto3" json:"aggregators_hash,omitempty"` // Chain ID the block belongs to - ChainId string `protobuf:"bytes,13,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` + ChainId string `protobuf:"bytes,12,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` } func (m *Header) Reset() { *m = Header{} } @@ -217,13 +215,6 @@ func (m *Header) GetProposerAddress() []byte { return nil } -func (m *Header) GetProposerPublicKey() []byte { - if m != nil { - return m.ProposerPublicKey - } - return nil -} - func (m *Header) GetAggregatorsHash() []byte { if m != nil { return m.AggregatorsHash @@ -282,16 +273,105 @@ func (m *Commit) GetSignatures() [][]byte { return nil } +type Validator struct { + PublicKey []byte `protobuf:"bytes,1,opt,name=public_key,json=publicKey,proto3" json:"public_key,omitempty"` +} + +func (m *Validator) Reset() { *m = Validator{} } +func (m *Validator) String() string { return proto.CompactTextString(m) } +func (*Validator) ProtoMessage() {} +func (*Validator) Descriptor() ([]byte, []int) { + return fileDescriptor_ed489fb7f4d78b3f, []int{3} +} +func (m *Validator) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Validator) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Validator.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 *Validator) XXX_Merge(src proto.Message) { + xxx_messageInfo_Validator.Merge(m, src) +} +func (m *Validator) XXX_Size() int { + return m.Size() +} +func (m *Validator) XXX_DiscardUnknown() { + xxx_messageInfo_Validator.DiscardUnknown(m) +} + +var xxx_messageInfo_Validator proto.InternalMessageInfo + +func (m *Validator) GetPublicKey() []byte { + if m != nil { + return m.PublicKey + } + return nil +} + +type ValidatorSet struct { + Validators []*Validator `protobuf:"bytes,1,rep,name=validators,proto3" json:"validators,omitempty"` +} + +func (m *ValidatorSet) Reset() { *m = ValidatorSet{} } +func (m *ValidatorSet) String() string { return proto.CompactTextString(m) } +func (*ValidatorSet) ProtoMessage() {} +func (*ValidatorSet) Descriptor() ([]byte, []int) { + return fileDescriptor_ed489fb7f4d78b3f, []int{4} +} +func (m *ValidatorSet) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ValidatorSet) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ValidatorSet.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 *ValidatorSet) XXX_Merge(src proto.Message) { + xxx_messageInfo_ValidatorSet.Merge(m, src) +} +func (m *ValidatorSet) XXX_Size() int { + return m.Size() +} +func (m *ValidatorSet) XXX_DiscardUnknown() { + xxx_messageInfo_ValidatorSet.DiscardUnknown(m) +} + +var xxx_messageInfo_ValidatorSet proto.InternalMessageInfo + +func (m *ValidatorSet) GetValidators() []*Validator { + if m != nil { + return m.Validators + } + return nil +} + type SignedHeader struct { - Header *Header `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` - Commit *Commit `protobuf:"bytes,2,opt,name=commit,proto3" json:"commit,omitempty"` + Header *Header `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` + Commit *Commit `protobuf:"bytes,2,opt,name=commit,proto3" json:"commit,omitempty"` + Validators *ValidatorSet `protobuf:"bytes,3,opt,name=validators,proto3" json:"validators,omitempty"` } func (m *SignedHeader) Reset() { *m = SignedHeader{} } func (m *SignedHeader) String() string { return proto.CompactTextString(m) } func (*SignedHeader) ProtoMessage() {} func (*SignedHeader) Descriptor() ([]byte, []int) { - return fileDescriptor_ed489fb7f4d78b3f, []int{3} + return fileDescriptor_ed489fb7f4d78b3f, []int{5} } func (m *SignedHeader) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -334,6 +414,13 @@ func (m *SignedHeader) GetCommit() *Commit { return nil } +func (m *SignedHeader) GetValidators() *ValidatorSet { + if m != nil { + return m.Validators + } + return nil +} + type Data struct { Txs [][]byte `protobuf:"bytes,1,rep,name=txs,proto3" json:"txs,omitempty"` IntermediateStateRoots [][]byte `protobuf:"bytes,2,rep,name=intermediate_state_roots,json=intermediateStateRoots,proto3" json:"intermediate_state_roots,omitempty"` @@ -344,7 +431,7 @@ func (m *Data) Reset() { *m = Data{} } func (m *Data) String() string { return proto.CompactTextString(m) } func (*Data) ProtoMessage() {} func (*Data) Descriptor() ([]byte, []int) { - return fileDescriptor_ed489fb7f4d78b3f, []int{4} + return fileDescriptor_ed489fb7f4d78b3f, []int{6} } func (m *Data) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -403,7 +490,7 @@ func (m *Block) Reset() { *m = Block{} } func (m *Block) String() string { return proto.CompactTextString(m) } func (*Block) ProtoMessage() {} func (*Block) Descriptor() ([]byte, []int) { - return fileDescriptor_ed489fb7f4d78b3f, []int{5} + return fileDescriptor_ed489fb7f4d78b3f, []int{7} } func (m *Block) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -450,6 +537,8 @@ func init() { proto.RegisterType((*Version)(nil), "rollkit.Version") proto.RegisterType((*Header)(nil), "rollkit.Header") proto.RegisterType((*Commit)(nil), "rollkit.Commit") + proto.RegisterType((*Validator)(nil), "rollkit.Validator") + proto.RegisterType((*ValidatorSet)(nil), "rollkit.ValidatorSet") proto.RegisterType((*SignedHeader)(nil), "rollkit.SignedHeader") proto.RegisterType((*Data)(nil), "rollkit.Data") proto.RegisterType((*Block)(nil), "rollkit.Block") @@ -458,45 +547,47 @@ func init() { func init() { proto.RegisterFile("rollkit/rollkit.proto", fileDescriptor_ed489fb7f4d78b3f) } var fileDescriptor_ed489fb7f4d78b3f = []byte{ - // 595 bytes of a gzipped FileDescriptorProto -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0xb2, 0xa2, 0xd4, 0x2e, 0x96, 0xdb, 0xf9, 0x3e, 0x74, 0x35, - 0x5b, 0xd2, 0xa0, 0x83, 0x2a, 0xae, 0xfd, 0x08, 0xc6, 0x0b, 0xa2, 0x74, 0x5a, 0xe2, 0x35, 0x69, - 0x49, 0x54, 0x19, 0x74, 0x27, 0x5e, 0x34, 0x4c, 0x76, 0x8d, 0x6e, 0x6f, 0xbf, 0x20, 0xaa, 0x6c, - 0xc8, 0x8c, 0x2f, 0x97, 0x4c, 0x5b, 0x72, 0xeb, 0x81, 0x7c, 0x87, 0x32, 0x92, 0xc7, 0xb0, 0x9d, - 0x13, 0x4d, 0x2c, 0xd2, 0x43, 0x64, 0x60, 0x04, 0x34, 0x9f, 0xc0, 0x6e, 0xc6, 0x2b, 0x45, 0x2b, - 0xb5, 0x52, 0x96, 0xe8, 0x23, 0x31, 0x6a, 0x54, 0xc4, 0x8e, 0x60, 0x40, 0x84, 0xb0, 0xc0, 0x00, - 0x81, 0x3e, 0x11, 0x02, 0xad, 0x13, 0xd8, 0xc7, 0x44, 0x24, 0x55, 0xab, 0x85, 0x76, 0x41, 0xb6, - 0x91, 0xd9, 0x33, 0x46, 0x62, 0x75, 0x64, 0x9f, 0xc1, 0x58, 0x48, 0x2e, 0xb8, 0xa2, 0x32, 0x25, - 0x79, 0x2e, 0xa9, 0x52, 0x01, 0x58, 0xb4, 0xd6, 0xdf, 0x5a, 0xd9, 0x8f, 0xe1, 0xbf, 0x06, 0x15, - 0xab, 0xf9, 0x82, 0x65, 0xe9, 0x15, 0xbd, 0x09, 0x76, 0x90, 0xde, 0xaf, 0xad, 0x4f, 0xe8, 0x7c, - 0xa4, 0x37, 0x26, 0x34, 0x29, 0x0a, 0x49, 0x0b, 0xa2, 0xb9, 0x74, 0x59, 0x0c, 0x6d, 0xe8, 0x96, - 0x5e, 0x17, 0x93, 0x95, 0x84, 0x55, 0x29, 0xcb, 0x83, 0xd1, 0xc4, 0x8b, 0xb6, 0x93, 0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 0xc3, 0x8d, 0xdb, 0x75, 0xb8, 0xf1, 0x7b, 0x1d, 0x6e, 0x7c, 0x79, 0x5e, - 0x30, 0x5d, 0xae, 0xe6, 0x71, 0xc6, 0x97, 0xb3, 0x7f, 0xe6, 0xde, 0xce, 0xf5, 0x4c, 0xcc, 0x6b, - 0x61, 0xde, 0xc3, 0x19, 0x7f, 0xf9, 0x27, 0x00, 0x00, 0xff, 0xff, 0x4a, 0x6d, 0x58, 0xf2, 0x22, - 0x04, 0x00, 0x00, + // 639 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x64, 0x94, 0xcd, 0x6e, 0xd3, 0x4c, + 0x14, 0x86, 0xeb, 0x26, 0xcd, 0xcf, 0xa9, 0xdb, 0xe6, 0x1b, 0x7d, 0xad, 0x5c, 0x2a, 0xac, 0x60, + 0x09, 0x11, 0x8a, 0x94, 0x88, 0xa2, 0x4a, 0x88, 0x1d, 0x85, 0x4a, 0x45, 0xec, 0x26, 0x52, 0x17, + 0x6c, 0xac, 0x89, 0x3d, 0xd8, 0xa3, 0x3a, 0x1e, 0x6b, 0x66, 0x52, 0xd1, 0x4b, 0x60, 0xc7, 0x8e, + 0xdb, 0xe0, 0x32, 0x58, 0x76, 0xc9, 0x12, 0xb5, 0x37, 0x82, 0xe6, 0xc7, 0x8e, 0x0b, 0x9b, 0x64, + 0xce, 0xfb, 0x3e, 0x3e, 0x3e, 0x73, 0x7c, 0x66, 0x60, 0x5f, 0xf0, 0xa2, 0xb8, 0x62, 0x6a, 0xe6, + 0xfe, 0xa7, 0x95, 0xe0, 0x8a, 0xa3, 0xbe, 0x0b, 0x1f, 0x1d, 0x29, 0x5a, 0xa6, 0x54, 0x2c, 0x59, + 0xa9, 0x66, 0x64, 0x91, 0xb0, 0x99, 0xba, 0xa9, 0xa8, 0xb4, 0x54, 0xf4, 0x12, 0xfa, 0x97, 0x54, + 0x48, 0xc6, 0x4b,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x96, 0x4a, 0xff, 0x0a, 0xce, 0x95, 0x0c, 0x36, 0x0d, 0x76, 0xd0, 0xf6, 0xe7, 0xda, 0xc6, 0xda, + 0x45, 0xa7, 0x30, 0xa0, 0xd7, 0x2c, 0xa5, 0x65, 0xa2, 0x07, 0x5e, 0x37, 0xe8, 0x70, 0xba, 0x3e, + 0x9e, 0x53, 0x7d, 0x3c, 0xa7, 0xe7, 0x0e, 0xc0, 0x0d, 0x1a, 0x7d, 0x86, 0xad, 0x33, 0x73, 0x1a, + 0xdf, 0xc0, 0x8e, 0x34, 0xdd, 0x8a, 0x1f, 0x34, 0x69, 0xbd, 0x9d, 0x76, 0x2f, 0xb1, 0x2f, 0xdb, + 0x9d, 0x7d, 0x02, 0x5d, 0x3d, 0xef, 0xae, 0x5d, 0x3b, 0xcd, 0x23, 0x7a, 0x93, 0xd8, 0x58, 0x67, + 0xe7, 0x3f, 0xef, 0x42, 0xef, 0xf6, 0x2e, 0xf4, 0x7e, 0xdf, 0x85, 0xde, 0xb7, 0xfb, 0x70, 0xe3, + 0xf6, 0x3e, 0xdc, 0xf8, 0x75, 0x1f, 0x6e, 0x7c, 0x7a, 0x91, 0x31, 0x95, 0xaf, 0x16, 0xd3, 0x84, + 0x2f, 0x67, 0x7f, 0xdd, 0x37, 0xf6, 0x3e, 0x99, 0x55, 0x8b, 0x5a, 0x58, 0xf4, 0xcc, 0xdd, 0xf2, + 0xea, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x9a, 0xbd, 0xe1, 0x1a, 0x9a, 0x04, 0x00, 0x00, } func (m *Version) Marshal() (dAtA []byte, err error) { @@ -557,20 +648,13 @@ func (m *Header) MarshalToSizedBuffer(dAtA []byte) (int, error) { copy(dAtA[i:], m.ChainId) i = encodeVarintRollkit(dAtA, i, uint64(len(m.ChainId))) i-- - dAtA[i] = 0x6a + dAtA[i] = 0x62 } if len(m.AggregatorsHash) > 0 { i -= len(m.AggregatorsHash) copy(dAtA[i:], m.AggregatorsHash) i = encodeVarintRollkit(dAtA, i, uint64(len(m.AggregatorsHash))) i-- - dAtA[i] = 0x62 - } - if len(m.ProposerPublicKey) > 0 { - i -= len(m.ProposerPublicKey) - copy(dAtA[i:], m.ProposerPublicKey) - i = encodeVarintRollkit(dAtA, i, uint64(len(m.ProposerPublicKey))) - i-- dAtA[i] = 0x5a } if len(m.ProposerAddress) > 0 { @@ -679,6 +763,73 @@ func (m *Commit) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *Validator) 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 *Validator) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Validator) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.PublicKey) > 0 { + i -= len(m.PublicKey) + copy(dAtA[i:], m.PublicKey) + i = encodeVarintRollkit(dAtA, i, uint64(len(m.PublicKey))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *ValidatorSet) 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 *ValidatorSet) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ValidatorSet) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Validators) > 0 { + for iNdEx := len(m.Validators) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Validators[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintRollkit(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + func (m *SignedHeader) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -699,6 +850,18 @@ func (m *SignedHeader) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.Validators != nil { + { + size, err := m.Validators.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintRollkit(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } if m.Commit != nil { { size, err := m.Commit.MarshalToSizedBuffer(dAtA[:i]) @@ -898,10 +1061,6 @@ func (m *Header) Size() (n int) { if l > 0 { n += 1 + l + sovRollkit(uint64(l)) } - l = len(m.ProposerPublicKey) - if l > 0 { - n += 1 + l + sovRollkit(uint64(l)) - } l = len(m.AggregatorsHash) if l > 0 { n += 1 + l + sovRollkit(uint64(l)) @@ -928,6 +1087,34 @@ func (m *Commit) Size() (n int) { return n } +func (m *Validator) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.PublicKey) + if l > 0 { + n += 1 + l + sovRollkit(uint64(l)) + } + return n +} + +func (m *ValidatorSet) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Validators) > 0 { + for _, e := range m.Validators { + l = e.Size() + n += 1 + l + sovRollkit(uint64(l)) + } + } + return n +} + func (m *SignedHeader) Size() (n int) { if m == nil { return 0 @@ -942,6 +1129,10 @@ func (m *SignedHeader) Size() (n int) { l = m.Commit.Size() n += 1 + l + sovRollkit(uint64(l)) } + if m.Validators != nil { + l = m.Validators.Size() + n += 1 + l + sovRollkit(uint64(l)) + } return n } @@ -1426,7 +1617,7 @@ func (m *Header) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 11: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ProposerPublicKey", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field AggregatorsHash", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -1453,16 +1644,16 @@ func (m *Header) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.ProposerPublicKey = append(m.ProposerPublicKey[:0], dAtA[iNdEx:postIndex]...) - if m.ProposerPublicKey == nil { - m.ProposerPublicKey = []byte{} + m.AggregatorsHash = append(m.AggregatorsHash[:0], dAtA[iNdEx:postIndex]...) + if m.AggregatorsHash == nil { + m.AggregatorsHash = []byte{} } iNdEx = postIndex case 12: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AggregatorsHash", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ChainId", wireType) } - var byteLen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowRollkit @@ -1472,31 +1663,79 @@ func (m *Header) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - byteLen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if byteLen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthRollkit } - postIndex := iNdEx + byteLen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthRollkit } if postIndex > l { return io.ErrUnexpectedEOF } - m.AggregatorsHash = append(m.AggregatorsHash[:0], dAtA[iNdEx:postIndex]...) - if m.AggregatorsHash == nil { - m.AggregatorsHash = []byte{} - } + m.ChainId = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 13: + default: + iNdEx = preIndex + skippy, err := skipRollkit(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthRollkit + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Commit) 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 ErrIntOverflowRollkit + } + 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: Commit: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Commit: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ChainId", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Signatures", wireType) } - var stringLen uint64 + var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowRollkit @@ -1506,23 +1745,23 @@ func (m *Header) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + byteLen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if byteLen < 0 { return ErrInvalidLengthRollkit } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + byteLen if postIndex < 0 { return ErrInvalidLengthRollkit } if postIndex > l { return io.ErrUnexpectedEOF } - m.ChainId = string(dAtA[iNdEx:postIndex]) + m.Signatures = append(m.Signatures, make([]byte, postIndex-iNdEx)) + copy(m.Signatures[len(m.Signatures)-1], dAtA[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex @@ -1545,7 +1784,7 @@ func (m *Header) Unmarshal(dAtA []byte) error { } return nil } -func (m *Commit) Unmarshal(dAtA []byte) error { +func (m *Validator) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1568,15 +1807,15 @@ func (m *Commit) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: Commit: wiretype end group for non-group") + return fmt.Errorf("proto: Validator: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: Commit: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: Validator: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Signatures", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field PublicKey", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -1603,8 +1842,94 @@ func (m *Commit) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Signatures = append(m.Signatures, make([]byte, postIndex-iNdEx)) - copy(m.Signatures[len(m.Signatures)-1], dAtA[iNdEx:postIndex]) + m.PublicKey = append(m.PublicKey[:0], dAtA[iNdEx:postIndex]...) + if m.PublicKey == nil { + m.PublicKey = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipRollkit(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthRollkit + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ValidatorSet) 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 ErrIntOverflowRollkit + } + 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: ValidatorSet: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ValidatorSet: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Validators", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRollkit + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthRollkit + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthRollkit + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Validators = append(m.Validators, &Validator{}) + if err := m.Validators[len(m.Validators)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex default: iNdEx = preIndex @@ -1728,6 +2053,42 @@ func (m *SignedHeader) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Validators", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRollkit + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthRollkit + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthRollkit + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Validators == nil { + m.Validators = &ValidatorSet{} + } + if err := m.Validators.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipRollkit(dAtA[iNdEx:]) diff --git a/types/serialization.go b/types/serialization.go index e49bb7e4b13..10c2216938b 100644 --- a/types/serialization.go +++ b/types/serialization.go @@ -63,8 +63,9 @@ func (c *Commit) UnmarshalBinary(data []byte) error { // ToProto converts SignedHeader into protobuf representation and returns it. func (h *SignedHeader) ToProto() *pb.SignedHeader { return &pb.SignedHeader{ - Header: h.Header.ToProto(), - Commit: h.Commit.ToProto(), + Header: h.Header.ToProto(), + Commit: h.Commit.ToProto(), + Validators: h.Validators.ToProto(), } } @@ -79,9 +80,9 @@ func (h *SignedHeader) FromProto(other *pb.SignedHeader) error { return err } - if len(h.Commit.Signatures) > 0 { - h.Commit.HeaderHash = h.Header.Hash() - h.Commit.Height = uint64(h.Header.Height()) + err = h.Validators.FromProto(other.Validators) + if err != nil { + return err } return nil @@ -193,6 +194,18 @@ func (c *Commit) FromProto(other *pb.Commit) error { return nil } +func (vSet *ValidatorSet) ToProto() *pb.ValidatorSet { + return &pb.ValidatorSet{ + Validators: validatorsToProto(vSet.Validators), + } +} + +func (vSet *ValidatorSet) FromProto(other *pb.ValidatorSet) error { + vSet.Validators = validatorsFromProto(other.Validators) + + return nil +} + // ToProto converts State into protobuf representation and returns it. func (s *State) ToProto() (*pb.State, error) { nextValidators, err := s.NextValidators.ToProto() @@ -281,6 +294,22 @@ func byteSlicesToTxs(bytes [][]byte) Txs { return txs } +func validatorsToProto(validators []Validator) []*pb.Validator { + var ret []*pb.Validator + for _, v := range validators { + ret = append(ret, &pb.Validator{PublicKey: v.PublicKey}) + } + return ret +} + +func validatorsFromProto(validators []*pb.Validator) []Validator { + var ret []Validator + for _, v := range validators { + ret = append(ret, Validator{PublicKey: v.PublicKey}) + } + return ret +} + func evidenceToProto(evidence EvidenceData) []*abci.Evidence { var ret []*abci.Evidence for _, e := range evidence.Evidence { diff --git a/types/serialization_test.go b/types/serialization_test.go index 8274b2db18c..afd16ca0ad2 100644 --- a/types/serialization_test.go +++ b/types/serialization_test.go @@ -60,10 +60,15 @@ func TestBlockSerializationRoundTrip(t *testing.T) { SignedHeader: SignedHeader{ Header: h1, Commit: Commit{ - Height: 3, - HeaderHash: h1.Hash(), Signatures: []Signature{Signature([]byte{1, 1, 1}), Signature([]byte{2, 2, 2})}, - }}, + }, + Validators: ValidatorSet{ + Validators: []Validator{ + {PublicKey: []byte{3, 3, 3}}, + {PublicKey: []byte{4, 4, 4}}, + }, + }, + }, Data: Data{ Txs: nil, IntermediateStateRoots: IntermediateStateRoots{RawRootsList: [][]byte{{0x1}}}, diff --git a/types/validation.go b/types/validation.go index 2d99df277b8..bccf37affd9 100644 --- a/types/validation.go +++ b/types/validation.go @@ -1,15 +1,14 @@ package types import ( - "bytes" - "encoding/hex" "errors" - "fmt" + + "github.com/tendermint/tendermint/crypto/ed25519" ) // ValidateBasic performs basic validation of a block. func (b *Block) ValidateBasic() error { - err := b.SignedHeader.Header.ValidateBasic() + err := b.SignedHeader.ValidateBasic() if err != nil { return err } @@ -19,11 +18,6 @@ func (b *Block) ValidateBasic() error { return err } - err = b.SignedHeader.Commit.ValidateBasic() - if err != nil { - return err - } - return nil } @@ -44,30 +38,53 @@ func (d *Data) ValidateBasic() error { // ValidateBasic performs basic validation of a commit. func (c *Commit) ValidateBasic() error { - if c.Height > 0 { - if len(c.Signatures) == 0 { - return errors.New("no signatures") - } + if len(c.Signatures) == 0 { + return errors.New("no signatures") + } + return nil +} + +// ValidateBasic performs basic validation of a validator set +func (vSet *ValidatorSet) ValidateBasic() error { + if len(vSet.Validators) == 0 { + return errors.New("no validators") } return nil } // ValidateBasic performs basic validation of a signed header. func (h *SignedHeader) ValidateBasic() error { - err := h.Commit.ValidateBasic() + err := h.Header.ValidateBasic() if err != nil { return err } - err = h.Header.ValidateBasic() + + err = h.Commit.ValidateBasic() if err != nil { return err } - if h.Commit.Height != uint64(h.Header.Height()) { - return fmt.Errorf("height missmatch - header height: %d, commit height: %d", h.Header.Height(), h.Commit.Height) + err = h.Validators.ValidateBasic() + if err != nil { + return err } - if !bytes.Equal(h.Commit.HeaderHash[:], h.Header.Hash()) { - return fmt.Errorf("hash missmatch - header hash: %s, commit hash: %s", hex.EncodeToString(h.Header.Hash()), hex.EncodeToString(h.Commit.HeaderHash[:])) + + // Make sure there are as many signatures as validators + if len(h.Commit.Signatures) != len(h.Validators.Validators) { + return errors.New("number of signatures and keys don't match") } + + for i, val := range h.Validators.Validators { + sig := h.Commit.Signatures[i] + var pubKey ed25519.PubKey = val.PublicKey + msg, err := h.Header.MarshalBinary() + if err != nil { + return errors.New("signature verification failed, unable to marshal header") + } + if !pubKey.VerifySignature(msg, sig) { + return errors.New("signature verification failed") + } + } + return nil }