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

Mark wasm queries with module_query_safe #1915

Merged
merged 4 commits into from
Jul 3, 2024
Merged

Conversation

pinosu
Copy link
Contributor

@pinosu pinosu commented Jun 28, 2024

Resolves #1903

@pinosu pinosu requested review from chipshort and webmaster128 June 28, 2024 12:04
Copy link
Collaborator

@chipshort chipshort left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just wondering about the gas

Comment on lines 89 to +91
rpc BuildAddress(QueryBuildAddressRequest)
returns (QueryBuildAddressResponse) {
option (cosmos.query.v1.module_query_safe) = true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This query doesn't charge any gas. The option docs say:

  1. has its gas tracked, to avoid the attack vector where no gas is accounted for on potentially high-computation queries.

I guess this query is so computationally cheap that it's not an issue, but would be good to check somehow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good 👀 ! let's check what @webmaster128 thinks about this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for creating Instantiate2 addresses, right?

I think this query should be removed as the algorithm is stateless and fixed. There are multiple implementations in Rust, TypeScript and Go. I don't see any reason to perform a query to the node for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@webmaster128 should we remove this as part of next release?
I can create a separate pr for it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just create a ticket as this might open a can of worms looking at the code. IMO this is not relevant enough to delay the release. We should get CosmWasm 2.1 and other fixes in wasmd out as soon as possible.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would't it be easy to charge a small amount of gas here for the sake of consistency?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I think it makes sense to charge some gas for this. I will update the pr

Copy link

codecov bot commented Jul 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 54.90%. Comparing base (9ab6498) to head (895e633).
Report is 25 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1915      +/-   ##
==========================================
+ Coverage   54.87%   54.90%   +0.02%     
==========================================
  Files          65       65              
  Lines        9775     9777       +2     
==========================================
+ Hits         5364     5368       +4     
+ Misses       3866     3865       -1     
+ Partials      545      544       -1     
Files Coverage Δ
x/wasm/keeper/querier.go 78.72% <100.00%> (+0.15%) ⬆️

... and 1 file with indirect coverage changes

@webmaster128 webmaster128 modified the milestone: 0.52 Jul 2, 2024
@@ -428,6 +431,11 @@ func (q GrpcQuerier) BuildAddress(c context.Context, req *types.QueryBuildAddres
if len(salt) == 0 {
return nil, status.Error(codes.InvalidArgument, "empty salt")
}

ctx := sdk.UnwrapSDKContext(c)
costBuildAddress := DefaultGasCostBuildAddress * types.DefaultGasMultiplier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this multiplied by the gas multiplier on purpose? To me the code looks like it's just using the cosmos sdk gas meter, so that expects sdk gas as input, not cosmwasm gas.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it makes sense to remove the Multiplier because it is related to CW gas.
I used it to make the cost in line with humanizeAddress operation.
I will update the pr and remove it. @chipshort do you think something like 500_000 is a good value for DefaultGasCostBuildAddress ?

@@ -25,7 +25,7 @@ import (
)

// DefaultGasCostBuildAddress is the SDK gas cost to build a contract address
const DefaultGasCostBuildAddress = 5
const DefaultGasCostBuildAddress = 500_000
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a Cosmos SDK gas value where 100_000-200_00 is the gas range of a full transaction with verification, state changes, events etc. I think we need some much smaller value here.

What about 10?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good! I will update the pr 👍

@pinosu pinosu merged commit 8171d65 into main Jul 3, 2024
16 checks passed
@pinosu pinosu deleted the 1903-mark_module_query_safe branch July 3, 2024 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mark wasmd queries with module_query_safe
3 participants