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

feat: wasmd size increase and restricts wasmd uploads to known accounts #394

Merged
merged 11 commits into from
Jan 1, 2024
3 changes: 2 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
version4 "github.com/notional-labs/composable/v6/app/upgrades/v4"
version5 "github.com/notional-labs/composable/v6/app/upgrades/v5"
version6 "github.com/notional-labs/composable/v6/app/upgrades/v6"
version7 "github.com/notional-labs/composable/v6/app/upgrades/v7"
custombankmodule "github.com/notional-labs/composable/v6/custom/bank"
"github.com/notional-labs/composable/v6/x/mint"
minttypes "github.com/notional-labs/composable/v6/x/mint/types"
Expand Down Expand Up @@ -117,7 +118,7 @@ const (
)

var (
Upgrades = []upgrades.Upgrade{version4.Upgrade, version5.Upgrade, version6.Upgrade}
Upgrades = []upgrades.Upgrade{version4.Upgrade, version5.Upgrade, version6.Upgrade, version7.Upgrade}
Forks = []upgrades.Fork{}
)

Expand Down
88 changes: 46 additions & 42 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,6 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
)
appKeepers.IBCHooksKeeper = &hooksKeeper

composablePrefix := sdk.GetConfig().GetBech32AccountAddrPrefix()
wasmHooks := ibchooks.NewWasmHooks(&hooksKeeper, nil, composablePrefix) // The contract keeper needs to be set later
appKeepers.Ics20WasmHooks = &wasmHooks
appKeepers.HooksICS4Wrapper = ibchooks.NewICS4Middleware(
appKeepers.IBCKeeper.ChannelKeeper,
appKeepers.Ics20WasmHooks,
)

appKeepers.TransferMiddlewareKeeper = transfermiddlewarekeeper.NewKeeper(
appKeepers.keys[transfermiddlewaretypes.StoreKey],
appKeepers.GetSubspace(transfermiddlewaretypes.ModuleName),
Expand Down Expand Up @@ -299,14 +291,58 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
appKeepers.IBCKeeper.ChannelKeeper,
)

composablePrefix := sdk.GetConfig().GetBech32AccountAddrPrefix()

wasmDir := filepath.Join(homePath, "wasm")
blasrodri marked this conversation as resolved.
Show resolved Hide resolved
wasmConfig, err := wasm.ReadWasmConfig(appOpts)
if err != nil {
panic(fmt.Sprintf("error while reading wasm config: %s", err))
}

// increase default wasm size in all wasmd related codes (as on Neutorn/Osmosis)
wasmtypes.MaxWasmSize *= 2
blasrodri marked this conversation as resolved.
Show resolved Hide resolved

// The last arguments can contain custom message handlers, and custom query handlers,
// if we want to allow any custom callbacks
availableCapabilities := strings.Join(AllCapabilities(), ",")
wasmKeeper := wasmkeeper.NewKeeper(
appCodec,
appKeepers.keys[wasmtypes.StoreKey],
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
appKeepers.StakingKeeper,
distrkeeper.NewQuerier(appKeepers.DistrKeeper),
appKeepers.IBCKeeper.ChannelKeeper, // ISC4 Wrapper: fee IBC middleware
appKeepers.IBCKeeper.ChannelKeeper,
&appKeepers.IBCKeeper.PortKeeper,
appKeepers.ScopedWasmKeeper,
appKeepers.TransferKeeper,
bApp.MsgServiceRouter(),
bApp.GRPCQueryRouter(),
wasmDir,
wasmConfig,
availableCapabilities,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
wasmOpts...,
)

wasmHooks := ibchooks.NewWasmHooks(&hooksKeeper, &wasmKeeper, composablePrefix)
hooksICS4Wrapper := ibchooks.NewICS4Middleware(
appKeepers.IBCKeeper.ChannelKeeper,
wasmHooks,
)
appKeepers.Ics20WasmHooks = &wasmHooks
appKeepers.HooksICS4Wrapper = hooksICS4Wrapper
appKeepers.WasmKeeper = wasmKeeper

appKeepers.RatelimitKeeper = *ratelimitmodulekeeper.NewKeeper(
appCodec,
appKeepers.keys[ratelimitmoduletypes.StoreKey],
appKeepers.GetSubspace(ratelimitmoduletypes.ModuleName),
appKeepers.BankKeeper,
appKeepers.IBCKeeper.ChannelKeeper,
// TODO: Implement ICS4Wrapper in Records and pass records keeper here
&appKeepers.HooksICS4Wrapper, // ICS4Wrapper
&hooksICS4Wrapper,
appKeepers.TransferMiddlewareKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
Expand Down Expand Up @@ -340,7 +376,7 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
routerkeeper.DefaultRefundTransferPacketTimeoutTimestamp,
)
ratelimitMiddlewareStack := ratelimitmodule.NewIBCMiddleware(appKeepers.RatelimitKeeper, ibcMiddlewareStack)
hooksTransferMiddleware := ibchooks.NewIBCMiddleware(ratelimitMiddlewareStack, &appKeepers.HooksICS4Wrapper)
hooksTransferMiddleware := ibchooks.NewIBCMiddleware(ratelimitMiddlewareStack, &hooksICS4Wrapper)

// Create evidence Keeper for to register the IBC light client misbehaviour evidence route
evidenceKeeper := evidencekeeper.NewKeeper(
Expand All @@ -349,38 +385,6 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
// If evidence needs to be handled for the app, set routes in router here and seal
appKeepers.EvidenceKeeper = *evidenceKeeper

wasmDir := filepath.Join(homePath, "wasm")
wasmConfig, err := wasm.ReadWasmConfig(appOpts)
if err != nil {
panic(fmt.Sprintf("error while reading wasm config: %s", err))
}

// The last arguments can contain custom message handlers, and custom query handlers,
// if we want to allow any custom callbacks
availableCapabilities := strings.Join(AllCapabilities(), ",")
appKeepers.WasmKeeper = wasmkeeper.NewKeeper(
appCodec,
appKeepers.keys[wasmtypes.StoreKey],
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
appKeepers.StakingKeeper,
distrkeeper.NewQuerier(appKeepers.DistrKeeper),
appKeepers.IBCKeeper.ChannelKeeper, // ISC4 Wrapper: fee IBC middleware
appKeepers.IBCKeeper.ChannelKeeper,
&appKeepers.IBCKeeper.PortKeeper,
appKeepers.ScopedWasmKeeper,
appKeepers.TransferKeeper,
bApp.MsgServiceRouter(),
bApp.GRPCQueryRouter(),
wasmDir,
wasmConfig,
availableCapabilities,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
wasmOpts...,
)

appKeepers.Ics20WasmHooks.ContractKeeper = &appKeepers.WasmKeeper

// Register Gov (must be registered after stakeibc)
govRouter := govtypesv1beta1.NewRouter()
govRouter.AddRoute(govtypes.RouterKey, govtypesv1beta1.ProposalHandler).
Expand Down
17 changes: 17 additions & 0 deletions app/upgrades/v7/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package v6

import (
"github.com/notional-labs/composable/v6/app/upgrades"

store "github.com/cosmos/cosmos-sdk/store/types"
)

const (
UpgradeName = "v7"
)

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler,
StoreUpgrades: store.StoreUpgrades{},
}
38 changes: 38 additions & 0 deletions app/upgrades/v7/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package v6

import (
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/notional-labs/composable/v6/app/keepers"
"github.com/notional-labs/composable/v6/app/upgrades"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
_ upgrades.BaseAppParamManager,
cdc codec.Codec,
keepers *keepers.AppKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
allowed := []string{
keepers.AccountKeeper.GetModuleAddress(wasmtypes.ModuleName).String(),
keepers.AccountKeeper.GetModuleAddress(govtypes.ModuleName).String(),
"centauri1u2sr0p2j75fuezu92nfxg5wm46gu22ywfgul6k", // "dzmitry lahoda CVM/MANTIS dev
}
wasmdParams := keepers.WasmKeeper.GetParams(ctx)
wasmdParams.CodeUploadAccess.Permission = wasmtypes.AccessTypeAnyOfAddresses
wasmdParams.CodeUploadAccess.Addresses = append(wasmdParams.CodeUploadAccess.Addresses, allowed...)

err := keepers.WasmKeeper.SetParams(ctx, wasmdParams)
if err != nil {
return nil, err
}
return mm.RunMigrations(ctx, configurator, vm)
}
}
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
perSystem = { config, self', inputs', pkgs, system, ... }: {
devShells = {
default = pkgs.mkShell {
buildInputs = with pkgs; [ pkgs.go pkgs.gnumake ];
buildInputs = with pkgs; [ pkgs.go pkgs.gnumake pkgs.gotools pkgs.golangci-lint pkgs.gci ];
};
};
};
Expand Down
Loading