From bac69e72c03aab09746e8f037700c70e6b14440c Mon Sep 17 00:00:00 2001 From: Charly Date: Tue, 5 Mar 2024 16:56:18 +0100 Subject: [PATCH 1/3] add flat fee for queries to verifymembership --- modules/core/02-client/keeper/grpc_query.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/core/02-client/keeper/grpc_query.go b/modules/core/02-client/keeper/grpc_query.go index 9ba5241fe57..aae9ad5b537 100644 --- a/modules/core/02-client/keeper/grpc_query.go +++ b/modules/core/02-client/keeper/grpc_query.go @@ -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() @@ -386,6 +387,12 @@ 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 queries to this rpc to read consensus state bytes from store + 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{ From a959a5865a825ddda5a5a121a260846d7e258114 Mon Sep 17 00:00:00 2001 From: Charly Date: Thu, 7 Mar 2024 11:26:34 +0100 Subject: [PATCH 2/3] update inline docs re: pr review --- modules/core/02-client/keeper/grpc_query.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/02-client/keeper/grpc_query.go b/modules/core/02-client/keeper/grpc_query.go index aae9ad5b537..a1d691bc1e1 100644 --- a/modules/core/02-client/keeper/grpc_query.go +++ b/modules/core/02-client/keeper/grpc_query.go @@ -387,7 +387,7 @@ 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 queries to this rpc to read consensus state bytes from store + // consume flat gas fee for proof verification queries ctx.GasMeter().ConsumeGas( 3*ctx.KVGasConfig().ReadCostPerByte*uint64(len(req.Proof)), "verify membership query", From e57aa4acbaa462167d2e711d43816dd060417958 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Mon, 11 Mar 2024 10:05:46 +0100 Subject: [PATCH 3/3] Update modules/core/02-client/keeper/grpc_query.go --- modules/core/02-client/keeper/grpc_query.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/core/02-client/keeper/grpc_query.go b/modules/core/02-client/keeper/grpc_query.go index a1d691bc1e1..3646abdcb79 100644 --- a/modules/core/02-client/keeper/grpc_query.go +++ b/modules/core/02-client/keeper/grpc_query.go @@ -387,7 +387,8 @@ 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 + // 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",