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

[EVM] add wasmd precompile #1139

Merged
merged 5 commits into from
Nov 14, 2023
Merged

[EVM] add wasmd precompile #1139

merged 5 commits into from
Nov 14, 2023

Conversation

codchen
Copy link
Collaborator

@codchen codchen commented Nov 13, 2023

Describe your changes and provide context

Add a wasmd precompile that allows EVM contracts to access the following CosmWasm functions for any CW contract:

  • instantiate
  • execute
  • query

Testing performed to validate your change

unit test

@codchen codchen changed the title Evm wasmd [EVM] add wasmd precompile Nov 13, 2023
Comment on lines +63 to +72
for name, m := range newAbi.Methods {
switch name {
case "instantiate":
p.InstantiateID = m.ID
case "execute":
p.ExecuteID = m.ID
case "query":
p.QueryID = m.ID
}
}

Check warning

Code scanning / CodeQL

Iteration over map

Iteration over map may be a possible source of non-determinism
Copy link

codecov bot commented Nov 13, 2023

Codecov Report

Merging #1139 (297fb67) into evm (7934261) will decrease coverage by 0.11%.
The diff coverage is 86.79%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##              evm    #1139      +/-   ##
==========================================
- Coverage   65.45%   65.34%   -0.11%     
==========================================
  Files         323      325       +2     
  Lines       20578    20742     +164     
==========================================
+ Hits        13469    13554      +85     
- Misses       6417     6490      +73     
- Partials      692      698       +6     
Files Coverage Δ
precompiles/common/precompiles.go 11.53% <100.00%> (ø)
x/evm/keeper/keeper.go 91.25% <100.00%> (+0.11%) ⬆️
evmrpc/state.go 26.37% <0.00%> (-28.08%) ⬇️
app/test_helpers.go 48.55% <66.66%> (+0.01%) ⬆️
app/app.go 75.87% <73.68%> (-0.15%) ⬇️
precompiles/wasmd/wasmd.go 89.84% <89.84%> (ø)

... and 5 files with indirect coverage changes

@@ -193,46 +191,3 @@ func TestGetStorageAt(t *testing.T) {
})
}
}

func TestGetProof(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why was this deleted?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

there was a bug in how stores in tests were initialized that were fixed in this PR, and apparently GetProof would only work with the presence of that bug, so GetProof is in reality broken. I've added a comment in GetProof to fix it in a later PR given this one is already too large.

Comment on lines -32 to -37
evmStoreKey := sdk.NewKVStoreKey(types.StoreKey)
authStoreKey := sdk.NewKVStoreKey(authtypes.StoreKey)
bankStoreKey := sdk.NewKVStoreKey(banktypes.StoreKey)
stakingStoreKey := sdk.NewKVStoreKey(stakingtypes.StoreKey)
keyParams := sdk.NewKVStoreKey(typesparams.StoreKey)
tKeyParams := sdk.NewTransientStoreKey(typesparams.TStoreKey)
Copy link
Contributor

Choose a reason for hiding this comment

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

why are these no longer needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

they are initialized more properly via testApp := Setup(false) above

Copy link
Contributor

@jewei1997 jewei1997 left a comment

Choose a reason for hiding this comment

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

very cool, LGTM!

return nil
}

// This function modifies global variable in `vm` module. It should only be called once
Copy link
Contributor

Choose a reason for hiding this comment

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

should we follow a singleton pattern here to ensure it's only initialized once (or something like baseapp.sealed where it panics if called multiple times)?

Copy link
Collaborator Author

@codchen codchen Nov 14, 2023

Choose a reason for hiding this comment

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

made it panic if already initialized

require.Nil(t, err)
require.Equal(t, 1, len(outputs))
require.Equal(t, "{\"message\":\"query test\"}", string(outputs[0].([]byte)))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

thoughts on adding more test cases around failure/edge cases? Most of these look happy path, and the added tests would help ensure wasmd.go doesn't have different behavior when we modify

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah we should

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added

@codchen codchen force-pushed the evm-wasmd branch 2 times, most recently from d0547aa to 01d12c7 Compare November 14, 2023 05:23
@codchen codchen merged commit c80fa34 into evm Nov 14, 2023
@codchen codchen deleted the evm-wasmd branch November 14, 2023 08:48
codchen added a commit that referenced this pull request Jan 5, 2024
* [EVM] several bug fixes

* [EVM] add wasmd precompiles

* [EVM] wasmd precompile

* query method

* add tests
codchen added a commit that referenced this pull request Jan 8, 2024
* [EVM] several bug fixes

* [EVM] add wasmd precompiles

* [EVM] wasmd precompile

* query method

* add tests
udpatil pushed a commit that referenced this pull request Jan 31, 2024
* [EVM] several bug fixes

* [EVM] add wasmd precompiles

* [EVM] wasmd precompile

* query method

* add tests
udpatil pushed a commit that referenced this pull request Feb 28, 2024
* [EVM] several bug fixes

* [EVM] add wasmd precompiles

* [EVM] wasmd precompile

* query method

* add tests
udpatil pushed a commit that referenced this pull request Feb 28, 2024
* [EVM] several bug fixes

* [EVM] add wasmd precompiles

* [EVM] wasmd precompile

* query method

* add tests
udpatil pushed a commit that referenced this pull request Feb 28, 2024
* [EVM] several bug fixes

* [EVM] add wasmd precompiles

* [EVM] wasmd precompile

* query method

* add tests
udpatil pushed a commit that referenced this pull request Mar 4, 2024
* [EVM] several bug fixes

* [EVM] add wasmd precompiles

* [EVM] wasmd precompile

* query method

* add tests
udpatil pushed a commit that referenced this pull request Mar 4, 2024
* [EVM] several bug fixes

* [EVM] add wasmd precompiles

* [EVM] wasmd precompile

* query method

* add tests
udpatil pushed a commit that referenced this pull request Mar 11, 2024
* [EVM] several bug fixes

* [EVM] add wasmd precompiles

* [EVM] wasmd precompile

* query method

* add tests
udpatil pushed a commit that referenced this pull request Mar 26, 2024
* [EVM] several bug fixes

* [EVM] add wasmd precompiles

* [EVM] wasmd precompile

* query method

* add tests
udpatil pushed a commit that referenced this pull request Apr 17, 2024
* [EVM] several bug fixes

* [EVM] add wasmd precompiles

* [EVM] wasmd precompile

* query method

* add tests
udpatil pushed a commit that referenced this pull request Apr 17, 2024
* [EVM] several bug fixes

* [EVM] add wasmd precompiles

* [EVM] wasmd precompile

* query method

* add tests
udpatil pushed a commit that referenced this pull request Apr 17, 2024
* [EVM] several bug fixes

* [EVM] add wasmd precompiles

* [EVM] wasmd precompile

* query method

* add tests
udpatil pushed a commit that referenced this pull request Apr 18, 2024
* [EVM] several bug fixes

* [EVM] add wasmd precompiles

* [EVM] wasmd precompile

* query method

* add tests
udpatil pushed a commit that referenced this pull request Apr 19, 2024
* [EVM] several bug fixes

* [EVM] add wasmd precompiles

* [EVM] wasmd precompile

* query method

* add tests
udpatil pushed a commit that referenced this pull request Apr 19, 2024
* [EVM] several bug fixes

* [EVM] add wasmd precompiles

* [EVM] wasmd precompile

* query method

* add tests
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.

3 participants