diff --git a/go.mod b/go.mod index b039cf48..8665f7d8 100644 --- a/go.mod +++ b/go.mod @@ -24,7 +24,7 @@ require ( github.com/grpc-ecosystem/grpc-gateway v1.16.0 github.com/initia-labs/OPinit v0.1.0-beta.3 // we also need to update `LIBINITIAVM_VERSION` of images/private/Dockerfile#5 - github.com/initia-labs/initiavm v0.1.2-beta.4 + github.com/initia-labs/initiavm v0.1.2-beta.5 github.com/novifinancial/serde-reflection/serde-generate/runtime/golang v0.0.0-20220519162058-e5cd3c3b3f3a github.com/pelletier/go-toml v1.9.5 github.com/pkg/errors v0.9.1 diff --git a/go.sum b/go.sum index 4ae53855..256dedd5 100644 --- a/go.sum +++ b/go.sum @@ -787,8 +787,8 @@ github.com/initia-labs/OPinit v0.1.0-beta.3 h1:DY/ItJTUAujNhqrzjgAFFzSLn/IGrIN1F github.com/initia-labs/OPinit v0.1.0-beta.3/go.mod h1:MPnFU2x4xzeT3L8K3lc0wkOl09o/oekEabPHIwWdqJg= github.com/initia-labs/cosmos-sdk v0.47.7-0.20231208103644-7bba6b092b8c h1:XdQVkEp/PoWGz/ykzQmiKmBK50X8+ToV/briOTz2vT0= github.com/initia-labs/cosmos-sdk v0.47.7-0.20231208103644-7bba6b092b8c/go.mod h1:fIhY9qlXZNvlWz8lAB2YcSRf2dCAi8VEJrq5GY/v2yE= -github.com/initia-labs/initiavm v0.1.2-beta.4 h1:RTBJ2hl8DSwLTi7rWx15beslfaqLm/bnEzaEFxsuGZ8= -github.com/initia-labs/initiavm v0.1.2-beta.4/go.mod h1:aQt4lImZWF9xj7Fm978n0IoeDdKWXTg1CSq6O4WoSD8= +github.com/initia-labs/initiavm v0.1.2-beta.5 h1:/pmtEdgSfNBhuifpQ4VEc/GxBhJCZ8LxzAAhPmnUTT0= +github.com/initia-labs/initiavm v0.1.2-beta.5/go.mod h1:aQt4lImZWF9xj7Fm978n0IoeDdKWXTg1CSq6O4WoSD8= github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= github.com/jedisct1/go-minisign v0.0.0-20190909160543-45766022959e/go.mod h1:G1CVv03EnqU1wYL2dFwXxW2An0az9JTl/ZsqXQeBlkU= github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= diff --git a/images/private/Dockerfile b/images/private/Dockerfile index 0c48055e..9d5ce07c 100644 --- a/images/private/Dockerfile +++ b/images/private/Dockerfile @@ -2,7 +2,7 @@ FROM golang:1.19.1-alpine3.16 AS go-builder #ARG arch=x86_64 # See https://github.com/initia-labs/initiavm/releases -ARG LIBINITIAVM_VERSION=v0.1.2-beta.4 +ARG LIBINITIAVM_VERSION=v0.1.2-beta.5 # this comes from standard alpine nightly file # https://github.com/rust-lang/docker-rust-nightly/blob/master/alpine3.12/Dockerfile diff --git a/proto/initia/move/v1/types.proto b/proto/initia/move/v1/types.proto index 306b2293..0b159550 100644 --- a/proto/initia/move/v1/types.proto +++ b/proto/initia/move/v1/types.proto @@ -30,6 +30,13 @@ message Params { (gogoproto.nullable) = false, (amino.dont_omitempty) = true ]; + + // It is a list of addresses with permission to distribute contracts, + // and an empty list is interpreted as allowing anyone to distribute. + repeated string allowed_publishers = 5 [ + (gogoproto.moretags) = "yaml:\"allowed_publishers\"", + (amino.dont_omitempty) = true + ]; } // RawParams defines the raw params to store. diff --git a/x/bank/keeper/common_test.go b/x/bank/keeper/common_test.go index 82e7b5f3..4448881c 100644 --- a/x/bank/keeper/common_test.go +++ b/x/bank/keeper/common_test.go @@ -367,7 +367,7 @@ func _createTestInput( moduleBytes, err := precompile.ReadStdlib() require.NoError(t, err) - err = moveKeeper.Initialize(ctx, moduleBytes, moveParams.ArbitraryEnabled) + err = moveKeeper.Initialize(ctx, moduleBytes, moveParams.ArbitraryEnabled, moveParams.AllowedPublishers) require.NoError(t, err) faucet := NewTestFaucet(t, ctx, bankKeeper, *moveKeeper, authtypes.Minter, initialTotalSupply()...) diff --git a/x/distribution/keeper/common_test.go b/x/distribution/keeper/common_test.go index a5d673ec..16e5b184 100644 --- a/x/distribution/keeper/common_test.go +++ b/x/distribution/keeper/common_test.go @@ -353,7 +353,7 @@ func _createTestInput( moduleBytes, err := precompile.ReadStdlib() require.NoError(t, err) - err = moveKeeper.Initialize(ctx, moduleBytes, moveParams.ArbitraryEnabled) + err = moveKeeper.Initialize(ctx, moduleBytes, moveParams.ArbitraryEnabled, moveParams.AllowedPublishers) require.NoError(t, err) faucet := NewTestFaucet(t, ctx, bankKeeper, *moveKeeper, authtypes.Minter, initialTotalSupply()...) diff --git a/x/gov/keeper/common_test.go b/x/gov/keeper/common_test.go index 147c8177..77cd9b51 100644 --- a/x/gov/keeper/common_test.go +++ b/x/gov/keeper/common_test.go @@ -382,7 +382,7 @@ func _createTestInput( moduleBytes, err := precompile.ReadStdlib() require.NoError(t, err) - err = moveKeeper.Initialize(ctx, moduleBytes, moveParams.ArbitraryEnabled) + err = moveKeeper.Initialize(ctx, moduleBytes, moveParams.ArbitraryEnabled, moveParams.AllowedPublishers) require.NoError(t, err) faucet := NewTestFaucet(t, ctx, bankKeeper, *moveKeeper, authtypes.Minter, initialTotalSupply()...) diff --git a/x/move/keeper/bank_test.go b/x/move/keeper/bank_test.go index a2136130..a9a8a19b 100644 --- a/x/move/keeper/bank_test.go +++ b/x/move/keeper/bank_test.go @@ -33,6 +33,7 @@ func Test_GetBalance(t *testing.T) { require.NoError(t, err) amount, err = moveBankKeeper.GetBalance(ctx, twoAddr, bondDenom) + require.NoError(t, err) require.Equal(t, mintAmount, amount) } @@ -51,6 +52,8 @@ func Test_AccountCoinStore(t *testing.T) { require.NoError(t, err) coinStore, err := moveBankKeeper.GetUserStores(ctx, twoAddr) + require.NoError(t, err) + iter := coinStore.Iterator(nil, nil) defer iter.Close() @@ -63,6 +66,8 @@ func Test_AccountCoinStore(t *testing.T) { value := iter.Value() storeAddr, err := vmtypes.NewAccountAddressFromBytes(value) + require.NoError(t, err) + mt, amount, err := moveBankKeeper.Balance(ctx, storeAddr) require.NoError(t, err) require.Equal(t, sdk.NewInt(1), amount) @@ -87,6 +92,8 @@ func Test_AccountCoinStore(t *testing.T) { value := iter2.Value() storeAddr, err := vmtypes.NewAccountAddressFromBytes(value) + require.NoError(t, err) + mt, amount, err := moveBankKeeper.Balance(ctx, storeAddr) require.NoError(t, err) require.Equal(t, sdk.NewInt(mintAmount+1), amount) @@ -145,6 +152,8 @@ func Test_GetIssuers(t *testing.T) { } issuers, err := moveBankKeeper.GetIssuers(ctx) + require.NoError(t, err) + iter := issuers.Iterator(nil, nil) defer iter.Close() diff --git a/x/move/keeper/code.go b/x/move/keeper/code.go index 39874fdf..4d788690 100644 --- a/x/move/keeper/code.go +++ b/x/move/keeper/code.go @@ -16,6 +16,21 @@ func NewCodeKeeper(k *Keeper) CodeKeeper { return CodeKeeper{k} } +// Load the code params from the move store +func (k CodeKeeper) GetParams(ctx sdk.Context) (bool, []vmtypes.AccountAddress, error) { + bz, err := k.GetResourceBytes(ctx, vmtypes.StdAddress, vmtypes.StructTag{ + Address: vmtypes.StdAddress, + Module: vmtypes.Identifier(types.MoveModuleNameCode), + Name: vmtypes.Identifier(types.ResourceNameModuleStore), + TypeArgs: []vmtypes.TypeTag{}, + }) + if err != nil { + return false, nil, err + } + + return types.ReadCodeModuleStore(bz) +} + // Load the allow_arbitrary flag from the move store func (k CodeKeeper) GetAllowArbitrary(ctx sdk.Context) (bool, error) { bz, err := k.GetResourceBytes(ctx, vmtypes.StdAddress, vmtypes.StructTag{ @@ -28,7 +43,7 @@ func (k CodeKeeper) GetAllowArbitrary(ctx sdk.Context) (bool, error) { return false, err } - return vmtypes.NewDeserializer(bz).DeserializeBool() + return vmtypes.NewDeserializer(bz[:1]).DeserializeBool() } // Store the allow_arbitrary flag to move store. @@ -51,6 +66,42 @@ func (k CodeKeeper) SetAllowArbitrary(ctx sdk.Context, allow bool) error { ) } +// Load the allowed_publishers from the move store +func (k CodeKeeper) GetAllowedPublishers(ctx sdk.Context) ([]vmtypes.AccountAddress, error) { + bz, err := k.GetResourceBytes(ctx, vmtypes.StdAddress, vmtypes.StructTag{ + Address: vmtypes.StdAddress, + Module: vmtypes.Identifier(types.MoveModuleNameCode), + Name: vmtypes.Identifier(types.ResourceNameModuleStore), + TypeArgs: []vmtypes.TypeTag{}, + }) + if err != nil { + return nil, err + } + + _, allowedPublishers, err := types.ReadCodeModuleStore(bz) + return allowedPublishers, err +} + +// Store the allowed_publishers to move store. +func (k CodeKeeper) SetAllowedPublishers(ctx sdk.Context, allowedPublishers []vmtypes.AccountAddress) error { + bz, err := vmtypes.SerializeAddressVector(allowedPublishers) + if err != nil { + return err + } + + return k.ExecuteEntryFunction( + ctx, + vmtypes.StdAddress, + vmtypes.StdAddress, + types.MoveModuleNameCode, + types.FunctionNameCodeSetAllowedPublishers, + []vmtypes.TypeTag{}, + [][]byte{ + bz, + }, + ) +} + // GetUpgradePolicy reads upgrade policy from the code module. func (k CodeKeeper) GetUpgradePolicy(ctx sdk.Context, addr vmtypes.AccountAddress, name string) (types.UpgradePolicy, error) { st := vmtypes.StructTag{ diff --git a/x/move/keeper/code_test.go b/x/move/keeper/code_test.go new file mode 100644 index 00000000..50246b24 --- /dev/null +++ b/x/move/keeper/code_test.go @@ -0,0 +1,47 @@ +package keeper_test + +import ( + "testing" + + "github.com/initia-labs/initia/x/move/keeper" + "github.com/initia-labs/initia/x/move/types" + vmtypes "github.com/initia-labs/initiavm/types" + + "github.com/stretchr/testify/require" +) + +func Test_CodeKeeper_GetParams(t *testing.T) { + ctx, input := createDefaultTestInput(t) + + allowArbitrary, allowedPublishers, err := keeper.NewCodeKeeper(&input.MoveKeeper).GetParams(ctx) + require.NoError(t, err) + require.Equal(t, types.DefaultArbitraryEnabled, allowArbitrary) + require.Empty(t, allowedPublishers) +} + +func Test_CodeKeeper_SetParams(t *testing.T) { + ctx, input := createDefaultTestInput(t) + codeKeeper := keeper.NewCodeKeeper(&input.MoveKeeper) + + err := codeKeeper.SetAllowArbitrary(ctx, false) + require.NoError(t, err) + + err = codeKeeper.SetAllowedPublishers(ctx, []vmtypes.AccountAddress{vmtypes.StdAddress, vmtypes.TestAddress}) + require.NoError(t, err) + + allowArbitrary, err := codeKeeper.GetAllowArbitrary(ctx) + require.NoError(t, err) + require.False(t, allowArbitrary) + + allowedPublishers, err := codeKeeper.GetAllowedPublishers(ctx) + require.NoError(t, err) + require.Equal(t, []vmtypes.AccountAddress{vmtypes.StdAddress, vmtypes.TestAddress}, allowedPublishers) +} + +func Test_CodeKeeper_MustContains_StdAddr(t *testing.T) { + ctx, input := createDefaultTestInput(t) + codeKeeper := keeper.NewCodeKeeper(&input.MoveKeeper) + + err := codeKeeper.SetAllowedPublishers(ctx, []vmtypes.AccountAddress{vmtypes.TestAddress}) + require.Error(t, err) +} diff --git a/x/move/keeper/common_test.go b/x/move/keeper/common_test.go index 61edd410..2395dd34 100644 --- a/x/move/keeper/common_test.go +++ b/x/move/keeper/common_test.go @@ -391,7 +391,7 @@ func _createTestInput( // append test module moduleBytes = append(moduleBytes, basicCoinModule) - err = moveKeeper.Initialize(ctx, moduleBytes, moveParams.ArbitraryEnabled) + err = moveKeeper.Initialize(ctx, moduleBytes, moveParams.ArbitraryEnabled, moveParams.AllowedPublishers) require.NoError(t, err) faucet := NewTestFaucet(t, ctx, bankKeeper, *moveKeeper, authtypes.Minter, initialTotalSupply()...) diff --git a/x/move/keeper/dex.go b/x/move/keeper/dex.go index e884beca..398d8cfd 100644 --- a/x/move/keeper/dex.go +++ b/x/move/keeper/dex.go @@ -67,8 +67,6 @@ func (k DexKeeper) deleteDexPair( ) { kvStore := ctx.KVStore(k.storeKey) kvStore.Delete(types.GetDexPairKey(metadataQuote)) - - return } // HasDexPair check whether types.DexPair exists or not with diff --git a/x/move/keeper/dex_test.go b/x/move/keeper/dex_test.go index 0ebca124..98fb89aa 100644 --- a/x/move/keeper/dex_test.go +++ b/x/move/keeper/dex_test.go @@ -244,7 +244,9 @@ func TestDexPair(t *testing.T) { require.False(t, found) metadataQuote, err := types.MetadataAddressFromDenom(denom) + require.NoError(t, err) metadataLP, err := types.MetadataAddressFromDenom(denomLP) + require.NoError(t, err) // invalid metadata dexPair := types.DexPair{ diff --git a/x/move/keeper/genesis.go b/x/move/keeper/genesis.go index ce51541a..be80e2a3 100644 --- a/x/move/keeper/genesis.go +++ b/x/move/keeper/genesis.go @@ -15,6 +15,7 @@ func (k Keeper) Initialize( ctx sdk.Context, moduleBytes [][]byte, allowArbitrary bool, + allowedPublishers []string, ) error { ctx = ctx.WithTxBytes(make([]byte, 32)) @@ -30,10 +31,20 @@ func (k Keeper) Initialize( modules[i] = vmtypes.NewModule(moduleBz) } + _allowedPublishers := make([]vmtypes.AccountAddress, len(allowedPublishers)) + for i, addr := range allowedPublishers { + addr, err := types.AccAddressFromString(addr) + if err != nil { + return err + } + + _allowedPublishers[i] = addr + } + // The default upgrade policy is compatible when it's not set, // so skip the registration at initialize. kvStore := prefix.NewStore(ctx.KVStore(k.storeKey), types.PrefixKeyVMStore) - if err := k.moveVM.Initialize(kvStore, api, env, vmtypes.NewModuleBundle(modules...), allowArbitrary); err != nil { + if err := k.moveVM.Initialize(kvStore, api, env, vmtypes.NewModuleBundle(modules...), allowArbitrary, _allowedPublishers); err != nil { return err } @@ -51,7 +62,7 @@ func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) ([]abc k.SetExecutionCounter(ctx, genState.ExecutionCounter) if len(genState.GetModules()) == 0 { - if err := k.Initialize(ctx, genState.GetStdlibs(), params.ArbitraryEnabled); err != nil { + if err := k.Initialize(ctx, genState.GetStdlibs(), params.ArbitraryEnabled, params.AllowedPublishers); err != nil { return nil, err } } diff --git a/x/move/keeper/handler.go b/x/move/keeper/handler.go index 05b625d0..44f6bb97 100644 --- a/x/move/keeper/handler.go +++ b/x/move/keeper/handler.go @@ -154,10 +154,8 @@ func (k Keeper) ExecuteEntryFunctionWithMultiSenders( } sendersStr := make([]string, len(senders)) - signers := make([][]byte, len(senders)) - for i, signer := range senders { - signers[i] = signer[:] - sendersStr[i] = signer.String() + for i, sender := range senders { + sendersStr[i] = sender.String() } api := NewApi(k, ctx) @@ -172,7 +170,7 @@ func (k Keeper) ExecuteEntryFunctionWithMultiSenders( api, env, gasForRuntime, - signers, + senders, payload, ) @@ -200,14 +198,14 @@ func (k Keeper) ExecuteEntryFunctionWithMultiSenders( func (k Keeper) ExecuteScript( ctx sdk.Context, - sender sdk.AccAddress, + sender vmtypes.AccountAddress, byteCodes []byte, typeArgs []vmtypes.TypeTag, args [][]byte, ) error { return k.ExecuteScriptWithMultiSenders( ctx, - []sdk.AccAddress{sender}, + []vmtypes.AccountAddress{sender}, byteCodes, typeArgs, args, @@ -216,7 +214,7 @@ func (k Keeper) ExecuteScript( func (k Keeper) ExecuteScriptWithMultiSenders( ctx sdk.Context, - senders []sdk.AccAddress, + senders []vmtypes.AccountAddress, byteCodes []byte, typeArgs []vmtypes.TypeTag, args [][]byte, @@ -251,10 +249,8 @@ func (k Keeper) ExecuteScriptWithMultiSenders( } sendersStr := make([]string, len(senders)) - signers := make([][]byte, len(senders)) - for i, signer := range senders { - signers[i] = signer - sendersStr[i] = signer.String() + for i, sender := range senders { + sendersStr[i] = sender.String() } api := NewApi(k, ctx) @@ -269,7 +265,7 @@ func (k Keeper) ExecuteScriptWithMultiSenders( api, env, gasForRuntime, - signers, + senders, payload, ) diff --git a/x/move/keeper/handler_test.go b/x/move/keeper/handler_test.go index 669e757f..0c01b6af 100644 --- a/x/move/keeper/handler_test.go +++ b/x/move/keeper/handler_test.go @@ -1,7 +1,6 @@ package keeper_test import ( - "encoding/hex" "fmt" "testing" @@ -44,6 +43,24 @@ func TestPublishModuleBundle_ArbitraryNotEnabled(t *testing.T) { require.NoError(t, err) } +func TestPublishModuleBundle_AllowedPublishers(t *testing.T) { + ctx, input := createDefaultTestInput(t) + + // limit only vmtypes.StdAddr can publish the code. + err := input.MoveKeeper.SetAllowedPublishers(ctx, []vmtypes.AccountAddress{vmtypes.StdAddress}) + require.NoError(t, err) + + err = input.MoveKeeper.PublishModuleBundle(ctx, vmtypes.TestAddress, vmtypes.NewModuleBundle(vmtypes.NewModule(tableGeneratorModule)), types.UpgradePolicy_COMPATIBLE) + require.Error(t, err) + + // add vmtypes.TestAddr to the allowed list + err = input.MoveKeeper.SetAllowedPublishers(ctx, []vmtypes.AccountAddress{vmtypes.StdAddress, vmtypes.TestAddress}) + require.NoError(t, err) + + err = input.MoveKeeper.PublishModuleBundle(ctx, vmtypes.TestAddress, vmtypes.NewModuleBundle(vmtypes.NewModule(tableGeneratorModule)), types.UpgradePolicy_COMPATIBLE) + require.NoError(t, err) +} + func TestExecuteEntryFunction(t *testing.T) { ctx, input := createDefaultTestInput(t) @@ -68,11 +85,7 @@ func TestExecuteEntryFunction(t *testing.T) { func TestExecuteScript(t *testing.T) { ctx, input := createDefaultTestInput(t) - bz, err := hex.DecodeString("0000000000000000000000000000000000000002") - require.NoError(t, err) - twoAddr := sdk.AccAddress(bz) - - err = input.MoveKeeper.ExecuteScript(ctx, twoAddr, + err := input.MoveKeeper.ExecuteScript(ctx, vmtypes.TestAddress, basicCoinMintScript, []vmtypes.TypeTag{MustConvertStringToTypeTag("0x1::BasicCoin::Initia"), MustConvertStringToTypeTag("bool")}, [][]byte{}, @@ -126,6 +139,7 @@ func TestDispatchFundCommunityPoolMessage(t *testing.T) { depositor := addrs[0] depositorAddr, err := vmtypes.NewAccountAddressFromBytes(addrs[0]) + require.NoError(t, err) denom := bondDenom amount := sdk.NewInt(100) @@ -158,6 +172,7 @@ func TestDispatchTransferMessage(t *testing.T) { sender := addrs[0] senderAddr, err := vmtypes.NewAccountAddressFromBytes(addrs[0]) + require.NoError(t, err) receiver := valAddrs[0] denom := bondDenom amount := sdk.NewInt(100) @@ -232,6 +247,7 @@ func TestDispatchPayFeeMessage(t *testing.T) { sender := addrs[0] senderAddr, err := vmtypes.NewAccountAddressFromBytes(addrs[0]) + require.NoError(t, err) recvFeeDenom := testDenoms[0] recvFeeAmount := sdk.NewInt(100) ackFeeDenom := testDenoms[1] diff --git a/x/move/keeper/keeper_test.go b/x/move/keeper/keeper_test.go index 041b8d4f..f11e1b83 100644 --- a/x/move/keeper/keeper_test.go +++ b/x/move/keeper/keeper_test.go @@ -58,6 +58,7 @@ func TestGetAndSetResource(t *testing.T) { testDenom := testDenoms[0] testDenomMetadata, err := types.MetadataAddressFromDenom(testDenom) + require.NoError(t, err) structTagStr := "0x1::fungible_asset::FungibleStore" structTag, err := vmapi.ParseStructTag(structTagStr) diff --git a/x/move/keeper/msg_server.go b/x/move/keeper/msg_server.go index 3882cc99..7fd6e732 100644 --- a/x/move/keeper/msg_server.go +++ b/x/move/keeper/msg_server.go @@ -94,7 +94,7 @@ func (ms MsgServer) Script(context context.Context, req *types.MsgScript) (*type defer telemetry.MeasureSince(time.Now(), "move", "msg", "script") ctx := sdk.UnwrapSDKContext(context) - sender, err := sdk.AccAddressFromBech32(req.Sender) + sender, err := types.AccAddressFromString(req.Sender) if err != nil { return nil, err } @@ -199,7 +199,7 @@ func (ms MsgServer) GovScript(context context.Context, req *types.MsgGovScript) ctx := sdk.UnwrapSDKContext(context) - sender, err := sdk.AccAddressFromBech32(req.Sender) + sender, err := types.AccAddressFromString(req.Sender) if err != nil { return nil, err } diff --git a/x/move/keeper/params.go b/x/move/keeper/params.go index e29779eb..045a5e79 100644 --- a/x/move/keeper/params.go +++ b/x/move/keeper/params.go @@ -4,6 +4,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/initia-labs/initia/x/move/types" + vmtypes "github.com/initia-labs/initiavm/types" ) // BaseDenom - base denom of native move dex @@ -21,11 +22,21 @@ func (k Keeper) ArbitraryEnabled(ctx sdk.Context) (bool, error) { return NewCodeKeeper(&k).GetAllowArbitrary(ctx) } +// AllowedPublishers - allowed publishers +func (k Keeper) AllowedPublishers(ctx sdk.Context) ([]vmtypes.AccountAddress, error) { + return NewCodeKeeper(&k).GetAllowedPublishers(ctx) +} + // SetArbitraryEnabled - update arbitrary enabled flag func (k Keeper) SetArbitraryEnabled(ctx sdk.Context, arbitraryEnabled bool) error { return NewCodeKeeper(&k).SetAllowArbitrary(ctx, arbitraryEnabled) } +// SetAllowedPublishers - update allowed publishers +func (k Keeper) SetAllowedPublishers(ctx sdk.Context, allowedPublishers []vmtypes.AccountAddress) error { + return NewCodeKeeper(&k).SetAllowedPublishers(ctx, allowedPublishers) +} + // ContractSharedRevenueRatio - percentage of fees distributed to developers func (k Keeper) ContractSharedRevenueRatio(ctx sdk.Context) sdk.Dec { return k.GetParams(ctx).ContractSharedRevenueRatio @@ -55,12 +66,17 @@ func (k Keeper) GetParams(ctx sdk.Context) types.Params { rawParams := types.RawParams{} k.cdc.MustUnmarshal(bz, &rawParams) - allow, err := NewCodeKeeper(&k).GetAllowArbitrary(ctx) + allowArbitrary, allowedPublishers, err := NewCodeKeeper(&k).GetParams(ctx) if err != nil { panic(err) } - return rawParams.ToParams(allow) + _allowedPublishers := make([]string, len(allowedPublishers)) + for i, addr := range allowedPublishers { + _allowedPublishers[i] = addr.String() + } + + return rawParams.ToParams(allowArbitrary, _allowedPublishers) } // SetRawParams stores raw params to store. diff --git a/x/move/keeper/staking_test.go b/x/move/keeper/staking_test.go index 9e6a33f9..245c7770 100644 --- a/x/move/keeper/staking_test.go +++ b/x/move/keeper/staking_test.go @@ -305,6 +305,7 @@ func TestApplyStakingDeltas(t *testing.T) { require.Equal(t, unbondingShare, sdk.NewInt(25_000_000)) _, unbondingAmount, err := keeper.NewMoveBankKeeper(&input.MoveKeeper).Balance(ctx, unbondingCoinStore) + require.NoError(t, err) require.Equal(t, unbondingAmount, sdk.NewInt(25_000_000)) } @@ -410,6 +411,7 @@ func Test_SlashUnbondingDelegations(t *testing.T) { require.NoError(t, err) _, unbondingAmount, err := keeper.NewMoveBankKeeper(&input.MoveKeeper).Balance(ctx, unbondingCoinStore) + require.NoError(t, err) require.Equal(t, unbondingAmount, sdk.NewInt(23_750_000)) require.Equal(t, unbondingShare, sdk.NewInt(25_000_000)) } diff --git a/x/move/types/connector.go b/x/move/types/connector.go index 20798d63..a817b085 100644 --- a/x/move/types/connector.go +++ b/x/move/types/connector.go @@ -63,9 +63,10 @@ const ( FunctionNameObjectTransfer = "transfer" // function names for code - FunctionNameCodePublish = "publish" - FunctionNameCodeInitGenesis = "init_genesis" - FunctionNameCodeSetAllowArbitrary = "set_allow_arbitrary" + FunctionNameCodePublish = "publish" + FunctionNameCodeInitGenesis = "init_genesis" + FunctionNameCodeSetAllowArbitrary = "set_allow_arbitrary" + FunctionNameCodeSetAllowedPublishers = "set_allowed_publishers" // resource names ResourceNameFungibleStore = "FungibleStore" @@ -549,6 +550,29 @@ func ReadStakingStatesTableHandleFromModuleStore(bz []byte) (vmtypes.AccountAddr return ReadTableHandleFromTable(bz[cursor : cursor+AddressBytesLength+8]) } +func ReadCodeModuleStore(bz []byte) (bool, []vmtypes.AccountAddress, error) { + cursor := int(0) + + allowArbitrary := bz[cursor] == 1 + cursor += 1 + + addrsLen, len := readULEB128(bz[cursor:]) + cursor += len + + allowedPublishers := make([]vmtypes.AccountAddress, addrsLen) + for i := 0; i < addrsLen; i++ { + var err error + allowedPublishers[i], err = vmtypes.NewAccountAddressFromBytes(bz[cursor : cursor+AddressBytesLength]) + if err != nil { + return false, nil, err + } + + cursor += AddressBytesLength + } + + return allowArbitrary, allowedPublishers, nil +} + // readULEB128 converts a uleb128-encoded byte array into an int. func readULEB128(r []byte) (total int, len int) { var shift uint64 diff --git a/x/move/types/keys.go b/x/move/types/keys.go index e705dc94..404fb722 100644 --- a/x/move/types/keys.go +++ b/x/move/types/keys.go @@ -53,7 +53,6 @@ func GetDelegatorModuleAddress(val sdk.ValAddress) sdk.AccAddress { // 0x1 address var StdAddr = sdk.AccAddress(vmtypes.StdAddress[:]) -// 0x2 address var TestAddr = sdk.AccAddress(vmtypes.TestAddress[:]) // Keys for move store diff --git a/x/move/types/params.go b/x/move/types/params.go index cf055fc2..9f5ab8f8 100644 --- a/x/move/types/params.go +++ b/x/move/types/params.go @@ -35,6 +35,7 @@ func DefaultParams() Params { BaseMinGasPrice: DefaultBaseMinGasPrice, ArbitraryEnabled: DefaultArbitraryEnabled, ContractSharedRevenueRatio: DefaultContractSharedRevenueRatio, + AllowedPublishers: nil, } } @@ -64,6 +65,10 @@ func (p Params) Validate() error { return errors.Wrap(err, "invalid shared_revenue_ratio") } + if err := validateAllowedPublishers(p.AllowedPublishers); err != nil { + return errors.Wrap(err, "invalid allowed_publishers") + } + return nil } @@ -77,12 +82,13 @@ func (p Params) ToRaw() RawParams { } // ToParams return Params from the RawParams -func (p RawParams) ToParams(allowArbitrary bool) Params { +func (p RawParams) ToParams(allowArbitrary bool, allowedPublishers []string) Params { return Params{ BaseDenom: p.BaseDenom, BaseMinGasPrice: p.BaseMinGasPrice, ArbitraryEnabled: allowArbitrary, ContractSharedRevenueRatio: p.ContractSharedRevenueRatio, + AllowedPublishers: allowedPublishers, } } @@ -137,3 +143,18 @@ func validateContractSharedRatio(i interface{}) error { return nil } + +func validateAllowedPublishers(i interface{}) error { + allowedPublishers, ok := i.([]string) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + for _, addr := range allowedPublishers { + if _, err := AccAddressFromString(addr); err != nil { + return err + } + } + + return nil +} diff --git a/x/move/types/params_test.go b/x/move/types/params_test.go index b4bffb63..844487c7 100644 --- a/x/move/types/params_test.go +++ b/x/move/types/params_test.go @@ -24,6 +24,11 @@ func TestParams(t *testing.T) { p3.BaseMinGasPrice = sdk.OneDec().Neg() err = p3.Validate() require.Error(t, err) + + p4 := DefaultParams() + p4.AllowedPublishers = []string{"abc"} + err = p4.Validate() + require.Error(t, err) } func TestRawParams(t *testing.T) { @@ -36,7 +41,7 @@ func TestRawParams(t *testing.T) { require.NoError(t, p1.Validate()) rp := p1.ToRaw() - p2 := rp.ToParams(p1.ArbitraryEnabled) + p2 := rp.ToParams(p1.ArbitraryEnabled, p1.AllowedPublishers) require.NoError(t, p2.Validate()) require.Equal(t, p1, p2) } diff --git a/x/move/types/types.pb.go b/x/move/types/types.pb.go index 8b00b8b1..5572cae8 100644 --- a/x/move/types/types.pb.go +++ b/x/move/types/types.pb.go @@ -72,6 +72,9 @@ type Params struct { ArbitraryEnabled bool `protobuf:"varint,3,opt,name=arbitrary_enabled,json=arbitraryEnabled,proto3" json:"arbitrary_enabled,omitempty"` // CSR: Percentage of fees distributed to developers ContractSharedRevenueRatio github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,4,opt,name=contract_shared_revenue_ratio,json=contractSharedRevenueRatio,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"contract_shared_revenue_ratio" yaml:"contract_shared_revenue_ratio"` + // It is a list of addresses with permission to distribute contracts, + // and an empty list is interpreted as allowing anyone to distribute. + AllowedPublishers []string `protobuf:"bytes,5,rep,name=allowed_publishers,json=allowedPublishers,proto3" json:"allowed_publishers,omitempty" yaml:"allowed_publishers"` } func (m *Params) Reset() { *m = Params{} } @@ -451,60 +454,62 @@ func init() { func init() { proto.RegisterFile("initia/move/v1/types.proto", fileDescriptor_5ab4b0783858a3a5) } var fileDescriptor_5ab4b0783858a3a5 = []byte{ - // 840 bytes of a gzipped FileDescriptorProto + // 874 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x55, 0xbf, 0x8f, 0x1b, 0x45, - 0x18, 0xf5, 0x9c, 0x73, 0x3f, 0xf6, 0xbb, 0xd8, 0x38, 0xab, 0x14, 0x9b, 0x43, 0xe7, 0x3d, 0x2d, - 0x3f, 0x74, 0xba, 0x28, 0xb6, 0x02, 0xa2, 0x89, 0x44, 0x61, 0x73, 0x27, 0x64, 0x71, 0x06, 0x33, - 0x38, 0x05, 0x50, 0xac, 0xc6, 0xbb, 0x13, 0xdf, 0xca, 0xde, 0x1d, 0x33, 0x33, 0xeb, 0xbb, 0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1, 0x93, 0x81, 0x07, 0x0b, 0xc9, 0x49, + 0xe6, 0x7e, 0x8f, 0xc0, 0x39, 0x3e, 0xa7, 0x41, 0x2e, 0x69, 0x27, 0x97, 0xa7, 0x8c, 0x47, 0x5f, + 0xa9, 0xab, 0x9f, 0xf6, 0x24, 0x4d, 0xf4, 0xa1, 0xe6, 0x4a, 0x2d, 0x67, 0x5a, 0x35, 0x68, 0xe7, + 0xba, 0x37, 0xef, 0x0e, 0xd4, 0x1e, 0xe5, 0x69, 0xa0, 0xea, 0x6a, 0x89, 0x70, 0xca, 0x7a, 0xfa, + 0xdd, 0xb8, 0x98, 0x35, 0x91, 0x57, 0x5d, 0x70, 0x4a, 0x2b, 0x0e, 0xdf, 0x87, 0xea, 0x52, 0x1a, + 0xb8, 0x0a, 0x95, 0x8e, 0xd7, 0xed, 0x0d, 0xbd, 0x8e, 0xf7, 0x59, 0xbd, 0x84, 0x6b, 0x00, 0x1f, + 0x7c, 0xd2, 0x1f, 0x74, 0x86, 0xbd, 0xee, 0xc9, 0x71, 0x1d, 0x29, 0xba, 0xd7, 0xef, 0x3f, 0x1c, + 0x76, 0xd4, 0x76, 0xad, 0x7b, 0x72, 0xf1, 0xbc, 0x51, 0x7a, 0x32, 0x6f, 0xa0, 0x8b, 0x79, 0x03, + 0x3d, 0x9b, 0x37, 0xd0, 0xef, 0xf3, 0x06, 0xfa, 0xe1, 0xb2, 0x51, 0x7a, 0x76, 0xd9, 0x28, 0xfd, + 0x7a, 0xd9, 0x28, 0x7d, 0x7e, 0xf8, 0xd2, 0x18, 0x31, 0x6d, 0xb8, 0x1b, 0x93, 0x91, 0xb0, 0xeb, + 0xf6, 0xb9, 0xf9, 0xe8, 0xea, 0x71, 0x32, 0xda, 0xd0, 0x5f, 0xce, 0x77, 0xff, 0x0a, 0x00, 0x00, + 0xff, 0xff, 0x66, 0x91, 0x0a, 0x8b, 0x90, 0x07, 0x00, 0x00, } func (this *Params) Equal(that interface{}) bool { @@ -538,6 +543,14 @@ func (this *Params) Equal(that interface{}) bool { if !this.ContractSharedRevenueRatio.Equal(that1.ContractSharedRevenueRatio) { return false } + if len(this.AllowedPublishers) != len(that1.AllowedPublishers) { + return false + } + for i := range this.AllowedPublishers { + if this.AllowedPublishers[i] != that1.AllowedPublishers[i] { + return false + } + } return true } func (this *RawParams) Equal(that interface{}) bool { @@ -811,6 +824,15 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.AllowedPublishers) > 0 { + for iNdEx := len(m.AllowedPublishers) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.AllowedPublishers[iNdEx]) + copy(dAtA[i:], m.AllowedPublishers[iNdEx]) + i = encodeVarintTypes(dAtA, i, uint64(len(m.AllowedPublishers[iNdEx]))) + i-- + dAtA[i] = 0x2a + } + } { size := m.ContractSharedRevenueRatio.Size() i -= size @@ -1249,6 +1271,12 @@ func (m *Params) Size() (n int) { } l = m.ContractSharedRevenueRatio.Size() n += 1 + l + sovTypes(uint64(l)) + if len(m.AllowedPublishers) > 0 { + for _, s := range m.AllowedPublishers { + l = len(s) + n += 1 + l + sovTypes(uint64(l)) + } + } return n } @@ -1579,6 +1607,38 @@ func (m *Params) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AllowedPublishers", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.AllowedPublishers = append(m.AllowedPublishers, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTypes(dAtA[iNdEx:]) diff --git a/x/move/types/vm_engine.go b/x/move/types/vm_engine.go index ddc45447..7da87ebb 100644 --- a/x/move/types/vm_engine.go +++ b/x/move/types/vm_engine.go @@ -13,6 +13,7 @@ type VMEngine interface { env vmtypes.Env, moduleBundle vmtypes.ModuleBundle, allowArbitrary bool, + allowedPublishers []vmtypes.AccountAddress, ) error Destroy() ExecuteViewFunction( @@ -27,7 +28,7 @@ type VMEngine interface { goApi api.GoAPI, env vmtypes.Env, gasLimit uint64, - senders [][]byte, + senders []vmtypes.AccountAddress, payload vmtypes.EntryFunction, ) (vmtypes.ExecutionResult, error) ExecuteScript( @@ -35,7 +36,7 @@ type VMEngine interface { goApi api.GoAPI, env vmtypes.Env, gasLimit uint64, - senders [][]byte, + senders []vmtypes.AccountAddress, payload vmtypes.Script, ) (vmtypes.ExecutionResult, error) MarkLoaderCacheAsInvalid() error diff --git a/x/mstaking/keeper/common_test.go b/x/mstaking/keeper/common_test.go index ca675251..4c45f553 100644 --- a/x/mstaking/keeper/common_test.go +++ b/x/mstaking/keeper/common_test.go @@ -386,7 +386,7 @@ func _createTestInput( moduleBytes, err := precompile.ReadStdlib() require.NoError(t, err) - err = moveKeeper.Initialize(ctx, moduleBytes, moveParams.ArbitraryEnabled) + err = moveKeeper.Initialize(ctx, moduleBytes, moveParams.ArbitraryEnabled, moveParams.AllowedPublishers) require.NoError(t, err) faucet := NewTestFaucet(t, ctx, bankKeeper, *moveKeeper, authtypes.Minter, initialTotalSupply()...) diff --git a/x/reward/keeper/common_test.go b/x/reward/keeper/common_test.go index 4744e267..82f1a7c9 100644 --- a/x/reward/keeper/common_test.go +++ b/x/reward/keeper/common_test.go @@ -355,7 +355,7 @@ func _createTestInput( moduleBytes, err := precompile.ReadStdlib() require.NoError(t, err) - err = moveKeeper.Initialize(ctx, moduleBytes, moveParams.ArbitraryEnabled) + err = moveKeeper.Initialize(ctx, moduleBytes, moveParams.ArbitraryEnabled, moveParams.AllowedPublishers) require.NoError(t, err) faucet := NewTestFaucet(t, ctx, bankKeeper, *moveKeeper, authtypes.Minter, initialTotalSupply()...) diff --git a/x/slashing/keeper/common_test.go b/x/slashing/keeper/common_test.go index 8277923b..604cdcef 100644 --- a/x/slashing/keeper/common_test.go +++ b/x/slashing/keeper/common_test.go @@ -383,7 +383,7 @@ func _createTestInput( moduleBytes, err := precompile.ReadStdlib() require.NoError(t, err) - err = moveKeeper.Initialize(ctx, moduleBytes, moveParams.ArbitraryEnabled) + err = moveKeeper.Initialize(ctx, moduleBytes, moveParams.ArbitraryEnabled, moveParams.AllowedPublishers) require.NoError(t, err) faucet := NewTestFaucet(t, ctx, bankKeeper, *moveKeeper, authtypes.Minter, initialTotalSupply()...)