Skip to content

Commit

Permalink
Merge pull request #181 from Fairblock/nil-poniter-checks
Browse files Browse the repository at this point in the history
Nil poniter checks
  • Loading branch information
p0p3yee authored Aug 6, 2024
2 parents c4d7c2b + 7c0d46b commit 9af7227
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
11 changes: 9 additions & 2 deletions x/keyshare/keeper/process_queues.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ 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())
continue
// return errors.New("estimated delay has not been set")
}
delay := req.EstimatedDelay
blockDelay := uint64(math.Ceil(delay.Seconds() / types.AvgBlockTime))
currentHeight := uint64(ctx.BlockHeight())
Expand All @@ -26,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)
}
Expand Down
4 changes: 4 additions & 0 deletions x/pep/keeper/msg_request_general_key_share.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 15 additions & 6 deletions x/pep/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 9af7227

Please sign in to comment.