Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imp: add flat fee for queries to VerifyMembership #5927

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
Loading