Files
wasmd/x/wasm/Governance.md
pinosu ef9a84dda8 Add StoreAndInstantiateContract gov proposal (#1074)
* Add StoreAndInstantiateContract gov proposal

* Add integration tests

* Bump github.com/prometheus/client_golang from 1.13.0 to 1.14.0

Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.13.0 to 1.14.0.
- [Release notes](https://github.com/prometheus/client_golang/releases)
- [Changelog](https://github.com/prometheus/client_golang/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prometheus/client_golang/compare/v1.13.0...v1.14.0)

---
updated-dependencies:
- dependency-name: github.com/prometheus/client_golang
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Remove exposed functions

* Add tests

* Add Developer's guide and best practices (#1075)

* Add Developer's guide and best practices

* Fix comments

* Change genesis preserving contract history (#1076)

* preserve contract created date on genesis import and add query contract created date

* add validate created

* fix sims test app import export

* add preserve contract history

* Make proto-all only

* Remove ResetFromGenesis

* Add validation

Co-authored-by: Alex Peters <alpe@users.noreply.github.com>

* Return contract history updates

* Bump github.com/spf13/viper from 1.13.0 to 1.14.0 (#1082)

Bumps [github.com/spf13/viper](https://github.com/spf13/viper) from 1.13.0 to 1.14.0.
- [Release notes](https://github.com/spf13/viper/releases)
- [Commits](https://github.com/spf13/viper/compare/v1.13.0...v1.14.0)

---
updated-dependencies:
- dependency-name: github.com/spf13/viper
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Revert "Bump github.com/spf13/viper from 1.13.0 to 1.14.0 (#1082)"

This reverts commit cf81eb8ea6.

* Add cli and refactor code

* Contract authz - redesign (#1077)

* Add contract authz proto

* Implement contract autorization

* Register contract authz

* Add contract-authz tests

* Consume gas for contract authz

* Add contract authz cli

* Update cli usage

* Model spike

* Add max funds limit

* Redesign authz model

* Start e2e test

* Full e2e test

* Test filter and limits

* Test accept

* Fix description

* No linter warning

Co-authored-by: Giancarlos Salas <me@giansalex.dev>

* Add StoreAndInstantiateContract gov proposal

* Add integration tests

* Remove exposed functions

* Add tests

* Add cli and refactor code

* Fix comments

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: GNaD13 <89174180+GNaD13@users.noreply.github.com>
Co-authored-by: Alex Peters <alpe@users.noreply.github.com>
Co-authored-by: Giancarlos Salas <me@giansalex.dev>
2022-11-11 16:04:04 +01:00

6.8 KiB

Governance

This document gives an overview of how the various governance proposals interact with the CosmWasm contract lifecycle. It is a high-level, technical introduction meant to provide context before looking into the code, or constructing proposals.

Proposal Types

We have added 9 new wasm specific proposal types that cover the contract's live cycle and authorization:

  • StoreCodeProposal - upload a wasm binary
  • InstantiateContractProposal - instantiate a wasm contract
  • MigrateContractProposal - migrate a wasm contract to a new code version
  • SudoContractProposal - call into the protected sudo entry point of a contract
  • ExecuteContractProposal - execute a wasm contract as an arbitrary user
  • UpdateAdminProposal - set a new admin for a contract
  • ClearAdminProposal - clear admin for a contract to prevent further migrations
  • PinCodes - pin the given code ids in cache. This trades memory for reduced startup time and lowers gas cost
  • UnpinCodes - unpin the given code ids from the cache. This frees up memory and returns to standard speed and gas cost
  • UpdateInstantiateConfigProposal - update instantiate permissions to a list of given code ids.
  • StoreAndInstantiateContractProposal - upload and instantiate a wasm contract.

For details see the proposal type implementation

Unit tests

Proposal type validations

Proposal Handler

The wasmd proposal_handler implements the gov.Handler function and executes the wasmd proposal types after a successful tally.

The proposal handler uses a GovAuthorizationPolicy to bypass the existing contract's authorization policy.

Tests

Gov Integration

The wasmd proposal handler can be added to the gov router in the abci app to receive proposal execution calls.

govRouter.AddRoute(wasm.RouterKey, wasm.NewWasmProposalHandler(app.wasmKeeper, enabledProposals))

Wasmd Authorization Settings

Settings via sdk params module:

  • code_upload_access - who can upload a wasm binary: Nobody, Everybody, OnlyAddress
  • instantiate_default_permission - platform default, who can instantiate a wasm binary when the code owner has not set it

See params.go

Init Params Via Genesis

    "wasm": {
      "params": {
        "code_upload_access": {
          "permission": "Everybody"
        },
        "instantiate_default_permission": "Everybody"
      }
    },  

The values can be updated via gov proposal implemented in the params module.

Update Params Via ParamChangeProposal

Example to submit a parameter change gov proposal:

wasmd tx gov submit-proposal param-change <proposal-json-file> --from validator --chain-id=testing -b block

Content examples

  • Disable wasm code uploads
{
  "title": "Foo",
  "description": "Bar",
  "changes": [
    {
      "subspace": "wasm",
      "key": "uploadAccess",
      "value": {
        "permission": "Nobody"
      }
    }
  ],
  "deposit": ""
}
  • Allow wasm code uploads for everybody
{
  "title": "Foo",
  "description": "Bar",
  "changes": [
    {
      "subspace": "wasm",
      "key": "uploadAccess",
      "value": {
        "permission": "Everybody"
      }
    }
  ],
  "deposit": ""
}
  • Restrict code uploads to a single address
{
  "title": "Foo",
  "description": "Bar",
  "changes": [
    {
      "subspace": "wasm",
      "key": "uploadAccess",
      "value": {
        "permission": "OnlyAddress",
        "address": "cosmos1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq0fr2sh"
      }
    }
  ],
  "deposit": ""
}
  • Set chain default instantiation settings to nobody
{
  "title": "Foo",
  "description": "Bar",
  "changes": [
    {
      "subspace": "wasm",
      "key": "instantiateAccess",
      "value": "Nobody"
    }
  ],
  "deposit": ""
}
  • Set chain default instantiation settings to everybody
{
  "title": "Foo",
  "description": "Bar",
  "changes": [
    {
      "subspace": "wasm",
      "key": "instantiateAccess",
      "value": "Everybody"
    }
  ],
  "deposit": ""
}

Enable gov proposals at compile time.

As gov proposals bypass the existing authorization policy they are disabled and require to be enabled at compile time.

-X github.com/CosmWasm/wasmd/app.ProposalsEnabled=true - enable all x/wasm governance proposals (default false)
-X github.com/CosmWasm/wasmd/app.EnableSpecificProposals=MigrateContract,UpdateAdmin,ClearAdmin - enable a subset of the x/wasm governance proposal types (overrides ProposalsEnabled)

The ParamChangeProposal is always enabled.

Tests

CLI

  wasmd tx gov submit-proposal [command]

Available Commands:
  wasm-store           Submit a wasm binary proposal
  instantiate-contract Submit an instantiate wasm contract proposal
  migrate-contract     Submit a migrate wasm contract to a new code version proposal
  set-contract-admin   Submit a new admin for a contract proposal
  clear-contract-admin Submit a clear admin for a contract to prevent further migrations proposal
...

Rest

New ProposalHandlers

  • Integration
gov.NewAppModuleBasic(append(wasmclient.ProposalHandlers, paramsclient.ProposalHandler, distr.ProposalHandler, upgradeclient.ProposalHandler)...),

In abci app

Tests

Pull requests