Skip to content

Commit

Permalink
imp: add flat fee for queries to VerifyMembership (#5927)
Browse files Browse the repository at this point in the history
Co-authored-by: Damian Nolan <[email protected]>
  • Loading branch information
charleenfei and damiannolan authored Mar 12, 2024
1 parent 3318278 commit 9aa7151
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions modules/core/02-client/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ func (k Keeper) VerifyMembership(c context.Context, req *types.QueryVerifyMember
}

ctx := sdk.UnwrapSDKContext(c)

// cache the context to ensure clientState.VerifyMembership does not change state
cachedCtx, _ := ctx.CacheContext()

Expand All @@ -386,6 +387,13 @@ func (k Keeper) VerifyMembership(c context.Context, req *types.QueryVerifyMember
return nil, status.Error(codes.FailedPrecondition, errorsmod.Wrapf(types.ErrClientNotActive, "cannot verify membership using client (%s) with status %s", req.ClientId, clientStatus).Error())
}

// consume flat gas fee for proof verification queries.
// NOTE: consuming gas prior to method invocation also provides protection against recursive calls reaching stack overflow
ctx.GasMeter().ConsumeGas(
3*ctx.KVGasConfig().ReadCostPerByte*uint64(len(req.Proof)),
"verify membership query",
)

if err := clientState.VerifyMembership(cachedCtx, k.ClientStore(cachedCtx, req.ClientId), k.cdc, req.ProofHeight, req.TimeDelay, req.BlockDelay, req.Proof, req.MerklePath, req.Value); err != nil {
k.Logger(ctx).Debug("proof verification failed", "key", req.MerklePath, "error", err)
return &types.QueryVerifyMembershipResponse{
Expand Down

0 comments on commit 9aa7151

Please sign in to comment.