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

set wasm permissions #1125

Merged
merged 5 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions app/upgrades/v19/upgrades.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v19

import (
errorsmod "cosmossdk.io/errors"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/cosmos/cosmos-sdk/codec"
Expand All @@ -11,6 +12,8 @@ import (

const (
UpgradeName = "v19"

WasmAdmin = "stride159smvptpq6evq0x6jmca6t8y7j8xmwj6kxapyh"
)

// CreateUpgradeHandler creates an SDK upgrade handler for v19
Expand All @@ -30,17 +33,24 @@ func CreateUpgradeHandler(
return newVm, err
}

// Update wasm params so that contracts can only be uploaded through governance
wasmParams := wasmKeeper.GetParams(ctx)
wasmParams.CodeUploadAccess = wasmtypes.AccessConfig{
Permission: wasmtypes.AccessTypeNobody,
Addresses: []string{},
}
wasmParams.InstantiateDefaultPermission = wasmtypes.AccessTypeNobody
if err := wasmKeeper.SetParams(ctx, wasmParams); err != nil {
return newVm, err
if err := SetWasmPermissions(ctx, wasmKeeper); err != nil {
return newVm, errorsmod.Wrapf(err, "unable to set wasm permissions")
}

return newVm, nil
}
}

// Update wasm params so that contracts can only be uploaded through governance
func SetWasmPermissions(ctx sdk.Context, wk wasmkeeper.Keeper) error {
wasmParams := wk.GetParams(ctx)
wasmParams.CodeUploadAccess = wasmtypes.AccessConfig{
Permission: wasmtypes.AccessTypeAnyOfAddresses,
Addresses: []string{WasmAdmin},
}
wasmParams.InstantiateDefaultPermission = wasmtypes.AccessTypeNobody
if err := wk.SetParams(ctx, wasmParams); err != nil {
return err
}
return nil
}
40 changes: 40 additions & 0 deletions app/upgrades/v19/upgrades_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package v19_test

import (
"testing"

wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/stretchr/testify/suite"

"github.com/Stride-Labs/stride/v18/app/apptesting"
v19 "github.com/Stride-Labs/stride/v18/app/upgrades/v19"
)

type UpgradeTestSuite struct {
apptesting.AppTestHelper
}

func TestKeeperTestSuite(t *testing.T) {
suite.Run(t, new(UpgradeTestSuite))
}

func (s *UpgradeTestSuite) SetupTest() {
s.Setup()
}

func (s *UpgradeTestSuite) TestUpgrade() {
dummyUpgradeHeight := int64(5)

// Run through upgrade
s.ConfirmUpgradeSucceededs("v19", dummyUpgradeHeight)

// Check state after upgrade
s.CheckWasmPerms()
}

func (s *UpgradeTestSuite) CheckWasmPerms() {
wasmParams := s.App.WasmKeeper.GetParams(s.Ctx)
s.Require().Equal(wasmtypes.AccessTypeAnyOfAddresses, wasmParams.CodeUploadAccess.Permission, "upload permission")
s.Require().Equal(v19.WasmAdmin, wasmParams.CodeUploadAccess.Addresses[0], "upload address")
s.Require().Equal(wasmtypes.AccessTypeNobody, wasmParams.InstantiateDefaultPermission, "instantiate permission")
sampocs marked this conversation as resolved.
Show resolved Hide resolved
}
Loading