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

Add check that wasm contract only modifies code hash in migrateContract API #5037

Conversation

chatton
Copy link
Contributor

@chatton chatton commented Nov 7, 2023

Description

closes: #5011

This PR adds checks that verify

  • wasm client is not deleted from the store
  • wasm client is not changed to another type
  • wasm client code hash only changes in MsgMigrateContract usage.

Note: a lot of tests needed to be updated as we were using dummy bytes as clientState (which is no longer valid). These tests were updated to use valid ClientState bytes.


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (see CONTRIBUTING.md).
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards and Go style guide.
  • Wrote unit and integration tests.
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/).
  • Added relevant godoc comments.
  • Provide a commit message to be used for the changelog entry in the PR description for review.
  • Re-reviewed Files changed in the Github PR explorer.
  • Review Codecov Report in the comment section below once CI passes.

@chatton chatton marked this pull request as ready for review November 7, 2023 16:17
Copy link
Contributor

@crodriguezvega crodriguezvega left a comment

Choose a reason for hiding this comment

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

Nice work, @chatton. I left a few comments after a first pass.

modules/light-clients/08-wasm/types/vm.go Outdated Show resolved Hide resolved
@@ -242,6 +249,65 @@ func (suite *TypesTestSuite) TestWasmSudo() {
},
types.ErrWasmInvalidResponseData,
},
{
"failure: invalid clientstate type",
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 add similar tests in TestWasmMigrate (except for the one that changes the code hash)?

modules/light-clients/08-wasm/types/vm.go Outdated Show resolved Hide resolved
modules/light-clients/08-wasm/types/vm.go Outdated Show resolved Hide resolved
modules/light-clients/08-wasm/types/update_test.go Outdated Show resolved Hide resolved
modules/light-clients/08-wasm/types/update_test.go Outdated Show resolved Hide resolved
modules/light-clients/08-wasm/keeper/msg_server_test.go Outdated Show resolved Hide resolved
@crodriguezvega crodriguezvega added the priority PRs that need prompt reviews label Nov 9, 2023
Copy link
Member

@damiannolan damiannolan left a comment

Choose a reason for hiding this comment

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

Excellent, just left some additional tidy up comments.

LGTM! 🚀

modules/light-clients/08-wasm/types/export_test.go Outdated Show resolved Hide resolved
modules/light-clients/08-wasm/types/export_test.go Outdated Show resolved Hide resolved
modules/light-clients/08-wasm/types/vm.go Outdated Show resolved Hide resolved
modules/light-clients/08-wasm/types/vm.go Outdated Show resolved Hide resolved
Copy link
Contributor

@DimitrisJim DimitrisJim left a comment

Choose a reason for hiding this comment

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

pushed a bit to add these checks to instantiate too, lgtm

…wasm-contract-only-modifies-code-hash-in-migratecontract-api
…wasm-contract-only-modifies-code-hash-in-migratecontract-api
Copy link
Member

@damiannolan damiannolan left a comment

Choose a reason for hiding this comment

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

ACK updates

Copy link
Contributor

@crodriguezvega crodriguezvega left a comment

Choose a reason for hiding this comment

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

Excellent work! I just left one comment re-raising one suggestion that @DimitrisJim had that I think makes sense. Happy to do it a follow-up PR.

Comment on lines +167 to +170
// codehash should only be able to be modified during migration.
if !bytes.Equal(codeHash, newClientState.CodeHash) {
return result, errorsmod.Wrapf(ErrWasmInvalidContractModification, "expected code hash %s, got %s", hex.EncodeToString(codeHash), hex.EncodeToString(newClientState.CodeHash))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

@DimitrisJim suggested to do this check also in wasmMigrate and then it could be included in validatePostExecutionClientState, just to make sure the the contract is not doing something we don't expect, even though we set the code hash in 08-wasm after calling wasmMigrate.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yea, didn't push this now. I do agree would be nice to do but without real consequence. Open to pushing this afterwards.

Copy link
Contributor

@charleenfei charleenfei left a comment

Choose a reason for hiding this comment

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

just one nit!

modules/light-clients/08-wasm/types/vm.go Outdated Show resolved Hide resolved
@crodriguezvega
Copy link
Contributor

crodriguezvega commented Nov 13, 2023

I am going to merge this now and tag later today beta.0.

@crodriguezvega crodriguezvega merged commit 1c70944 into feat/wasm-clients Nov 13, 2023
62 checks passed
@crodriguezvega crodriguezvega deleted the cian/issue#5011-add-check-that-wasm-contract-only-modifies-code-hash-in-migratecontract-api branch November 13, 2023 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
08-wasm priority PRs that need prompt reviews
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants