From 8c7784d291d94eec54510ba1301a055f74384ea3 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Mon, 23 Oct 2023 15:21:03 -0400 Subject: [PATCH] add check to not accept headers if proof type is not supported --- .../keeper/msg_server_add_block_header.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/x/observer/keeper/msg_server_add_block_header.go b/x/observer/keeper/msg_server_add_block_header.go index cfc3e32bcd..bfc49e8199 100644 --- a/x/observer/keeper/msg_server_add_block_header.go +++ b/x/observer/keeper/msg_server_add_block_header.go @@ -2,6 +2,7 @@ package keeper import ( "context" + "fmt" cosmoserrors "cosmossdk.io/errors" @@ -20,6 +21,20 @@ func (k msgServer) AddBlockHeader(goCtx context.Context, msg *types.MsgAddBlockH return nil, types.ErrNotAuthorizedPolicy } + crosschainFlags, found := k.GetCrosschainFlags(ctx) + if !found { + return nil, fmt.Errorf("crosschain flags not found") + } + if crosschainFlags.BlockHeaderVerificationFlags == nil { + return nil, fmt.Errorf("block header verification flags not found") + } + if common.IsBitcoinChain(msg.ChainId) && !crosschainFlags.BlockHeaderVerificationFlags.IsBtcTypeChainEnabled { + return nil, fmt.Errorf("proof verification not enabled for bitcoin chain") + } + if common.IsEVMChain(msg.ChainId) && !crosschainFlags.BlockHeaderVerificationFlags.IsEthTypeChainEnabled { + return nil, fmt.Errorf("proof verification not enabled for evm chain") + } + // add vote to ballot ballot, _, err := k.FindBallot(ctx, msg.Digest(), chain, types.ObservationType_InBoundTx) if err != nil { @@ -37,7 +52,7 @@ func (k msgServer) AddBlockHeader(goCtx context.Context, msg *types.MsgAddBlockH /** * Vote finalized, add block header to store */ - _, found := k.GetBlockHeader(ctx, msg.BlockHash) + _, found = k.GetBlockHeader(ctx, msg.BlockHash) if found { hashString, err := common.HashToString(msg.ChainId, msg.BlockHash) if err != nil {