From 7053b588935e1a3d018c4f8ab8b573e8b872c600 Mon Sep 17 00:00:00 2001 From: ap0calypse644 Date: Mon, 5 Aug 2024 19:24:04 +0530 Subject: [PATCH 1/3] fixing nil pointer issues --- x/pep/keeper/msg_request_general_key_share.go | 4 ++++ x/pep/module/module.go | 21 +++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/x/pep/keeper/msg_request_general_key_share.go b/x/pep/keeper/msg_request_general_key_share.go index 56a8e87a..f0b3d2ae 100644 --- a/x/pep/keeper/msg_request_general_key_share.go +++ b/x/pep/keeper/msg_request_general_key_share.go @@ -25,6 +25,10 @@ func (k msgServer) RequestGeneralKeyshare(goCtx context.Context, msg *types.MsgR reqCount, _ := strconv.ParseUint(reqCountString, 10, 64) reqCount = reqCount + 1 + if msg.EstimatedDelay == nil { + return &types.MsgRequestGeneralKeyshareResponse{}, errors.New("could not parse estimated delay") + } + if params.IsSourceChain { entry := commontypes.RequestAggrKeyshare{ Creator: msg.Creator, diff --git a/x/pep/module/module.go b/x/pep/module/module.go index 0c0f946f..fd8da779 100644 --- a/x/pep/module/module.go +++ b/x/pep/module/module.go @@ -3,13 +3,17 @@ package pep import ( "bytes" "context" - "cosmossdk.io/core/appmodule" - cosmosmath "cosmossdk.io/math" - txsigning "cosmossdk.io/x/tx/signing" "encoding/hex" "encoding/json" "errors" "fmt" + "math" + "strconv" + "strings" + + "cosmossdk.io/core/appmodule" + cosmosmath "cosmossdk.io/math" + txsigning "cosmossdk.io/x/tx/signing" enc "github.com/FairBlock/DistributedIBE/encryption" commontypes "github.com/Fairblock/fairyring/x/common/types" "github.com/cosmos/cosmos-sdk/baseapp" @@ -22,9 +26,6 @@ import ( bls "github.com/drand/kyber-bls12381" "github.com/drand/kyber/pairing" "google.golang.org/protobuf/types/known/anypb" - "math" - "strconv" - "strings" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" @@ -462,6 +463,10 @@ func convertGenEncTxToDecryptionTx(tx types.GeneralEncryptedTx) DecryptionTx { func (am AppModule) handleGasConsumption(ctx sdk.Context, recipient sdk.AccAddress, gasUsed cosmosmath.Int, gasCharged *sdk.Coin) { creatorAccount := am.accountKeeper.GetAccount(ctx, recipient) + if gasCharged == nil { + gasCharged = &sdk.Coin{} + } + if gasUsed.GT(gasCharged.Amount) { deductFeeErr := ante.DeductFees( am.bankKeeper, @@ -789,6 +794,10 @@ func (am AppModule) decryptAndExecuteTx( txFee[0].Amount.Quo(gasProvided).Mul(gasUsedInBig), ) + if eachTx.ChargedGas == nil { + eachTx.ChargedGas = &sdk.Coin{} + } + if usedGasFee.Denom != eachTx.ChargedGas.Denom { am.processFailedEncryptedTx(ctx, eachTx, fmt.Sprintf("underlying tx gas denom does not match charged gas denom, got: %s, expect: %s", usedGasFee.Denom, eachTx.ChargedGas.Denom), startConsumedGas) return errors.New("underlying tx gas denom does not match charged gas denom") From ba724ec0921571f0fc90465ae6ce8a121ed5b46e Mon Sep 17 00:00:00 2001 From: ap0calypse644 Date: Tue, 6 Aug 2024 14:04:36 +0530 Subject: [PATCH 2/3] add redundant nil-pointer check for faulty txs already in proposal --- x/keyshare/keeper/process_queues.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/x/keyshare/keeper/process_queues.go b/x/keyshare/keeper/process_queues.go index 7108259c..14e033f0 100644 --- a/x/keyshare/keeper/process_queues.go +++ b/x/keyshare/keeper/process_queues.go @@ -18,6 +18,10 @@ func (k Keeper) ProcessPepRequestQueue(ctx sdk.Context) error { reqs := k.pepKeeper.GetAllGenEncTxReqQueueEntry(ctx) for _, req := range reqs { + if req.EstimatedDelay == nil { + k.pepKeeper.RemoveReqQueueEntry(ctx, req.GetRequestId()) + return errors.New("estimated delay has not been set") + } delay := req.EstimatedDelay blockDelay := uint64(math.Ceil(delay.Seconds() / types.AvgBlockTime)) currentHeight := uint64(ctx.BlockHeight()) From 7c0d46b2924d69dccaa9a3359d2c160a0ffbde02 Mon Sep 17 00:00:00 2001 From: ap0calypse644 Date: Tue, 6 Aug 2024 20:32:56 +0530 Subject: [PATCH 3/3] remove misplaced returns --- x/keyshare/keeper/process_queues.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/x/keyshare/keeper/process_queues.go b/x/keyshare/keeper/process_queues.go index 14e033f0..87d48727 100644 --- a/x/keyshare/keeper/process_queues.go +++ b/x/keyshare/keeper/process_queues.go @@ -20,7 +20,8 @@ func (k Keeper) ProcessPepRequestQueue(ctx sdk.Context) error { for _, req := range reqs { if req.EstimatedDelay == nil { k.pepKeeper.RemoveReqQueueEntry(ctx, req.GetRequestId()) - return errors.New("estimated delay has not been set") + continue + // return errors.New("estimated delay has not been set") } delay := req.EstimatedDelay blockDelay := uint64(math.Ceil(delay.Seconds() / types.AvgBlockTime)) @@ -30,11 +31,13 @@ func (k Keeper) ProcessPepRequestQueue(ctx sdk.Context) error { queuedPubKey, found := k.GetQueuedPubKey(ctx) if !found { k.pepKeeper.RemoveReqQueueEntry(ctx, req.GetRequestId()) - return errors.New("estimated delay too long") + continue + // return errors.New("estimated delay too long") } if executionHeight > queuedPubKey.Expiry { k.pepKeeper.RemoveReqQueueEntry(ctx, req.GetRequestId()) - return errors.New("estimated delay too long") + continue + // return errors.New("estimated delay too long") } activePubKey = types.ActivePubKey(queuedPubKey) }