Skip to content

Commit

Permalink
feat: remove contract activation control by actor (#470)
Browse files Browse the repository at this point in the history
* feat: remove contract access control by actor

* feat: remove contract status access config

* test: re-add inactive contract tests using gov proposal

* docs: add changelog

* chore: update swagger

* chore: apply review
  • Loading branch information
Jiyong Ha authored Mar 23, 2022
1 parent 393d1fc commit 7075790
Show file tree
Hide file tree
Showing 21 changed files with 282 additions and 1,130 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
## [Unreleased](https://github.com/line/lbm-sdk/compare/v0.45.0-rc0...HEAD)

### Features
* (x/wasm) [\#470](https://github.com/line/lbm-sdk/pull/470) remove contract activation control by actor

### Improvements

Expand Down
6 changes: 4 additions & 2 deletions client/docs/statik/statik.go

Large diffs are not rendered by default.

31 changes: 0 additions & 31 deletions docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -848,8 +848,6 @@
- [MsgStoreCodeResponse](#lbm.wasm.v1.MsgStoreCodeResponse)
- [MsgUpdateAdmin](#lbm.wasm.v1.MsgUpdateAdmin)
- [MsgUpdateAdminResponse](#lbm.wasm.v1.MsgUpdateAdminResponse)
- [MsgUpdateContractStatus](#lbm.wasm.v1.MsgUpdateContractStatus)
- [MsgUpdateContractStatusResponse](#lbm.wasm.v1.MsgUpdateContractStatusResponse)

- [Msg](#lbm.wasm.v1.Msg)

Expand Down Expand Up @@ -12044,7 +12042,6 @@ Params defines the set of wasm parameters.
| ----- | ---- | ----- | ----------- |
| `code_upload_access` | [AccessConfig](#lbm.wasm.v1.AccessConfig) | | |
| `instantiate_default_permission` | [AccessType](#lbm.wasm.v1.AccessType) | | |
| `contract_status_access` | [AccessConfig](#lbm.wasm.v1.AccessConfig) | | |
| `max_wasm_code_size` | [uint64](#uint64) | | |
| `gas_multiplier` | [uint64](#uint64) | | |
| `instance_cost` | [uint64](#uint64) | | |
Expand Down Expand Up @@ -12337,33 +12334,6 @@ MsgUpdateAdminResponse returns empty data




<a name="lbm.wasm.v1.MsgUpdateContractStatus"></a>

### MsgUpdateContractStatus
MsgUpdateContractStatus sets a new status for a smart contract


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `sender` | [string](#string) | | Sender is the that actor that signed the messages |
| `contract` | [string](#string) | | Contract is the address of the smart contract |
| `status` | [ContractStatus](#lbm.wasm.v1.ContractStatus) | | Status to be set |






<a name="lbm.wasm.v1.MsgUpdateContractStatusResponse"></a>

### MsgUpdateContractStatusResponse
MsgUpdateContractStatusResponse returns empty data





<!-- end messages -->

<!-- end enums -->
Expand All @@ -12385,7 +12355,6 @@ Msg defines the wasm Msg service.
| `MigrateContract` | [MsgMigrateContract](#lbm.wasm.v1.MsgMigrateContract) | [MsgMigrateContractResponse](#lbm.wasm.v1.MsgMigrateContractResponse) | Migrate runs a code upgrade/ downgrade for a smart contract | |
| `UpdateAdmin` | [MsgUpdateAdmin](#lbm.wasm.v1.MsgUpdateAdmin) | [MsgUpdateAdminResponse](#lbm.wasm.v1.MsgUpdateAdminResponse) | UpdateAdmin sets a new admin for a smart contract | |
| `ClearAdmin` | [MsgClearAdmin](#lbm.wasm.v1.MsgClearAdmin) | [MsgClearAdminResponse](#lbm.wasm.v1.MsgClearAdminResponse) | ClearAdmin removes any admin stored for a smart contract | |
| `UpdateContractStatus` | [MsgUpdateContractStatus](#lbm.wasm.v1.MsgUpdateContractStatus) | [MsgUpdateContractStatusResponse](#lbm.wasm.v1.MsgUpdateContractStatusResponse) | UpdateContractStatus sets a new status for a smart contract | |

<!-- end services -->

Expand Down
15 changes: 0 additions & 15 deletions proto/lbm/wasm/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ service Msg {
rpc UpdateAdmin(MsgUpdateAdmin) returns (MsgUpdateAdminResponse);
// ClearAdmin removes any admin stored for a smart contract
rpc ClearAdmin(MsgClearAdmin) returns (MsgClearAdminResponse);
// UpdateContractStatus sets a new status for a smart contract
rpc UpdateContractStatus(MsgUpdateContractStatus) returns (MsgUpdateContractStatusResponse);
}

// MsgStoreCode submit Wasm code to the system
Expand Down Expand Up @@ -162,16 +160,3 @@ message MsgClearAdmin {

// MsgClearAdminResponse returns empty data
message MsgClearAdminResponse {}

// MsgUpdateContractStatus sets a new status for a smart contract
message MsgUpdateContractStatus {
// Sender is the that actor that signed the messages
string sender = 1;
// Contract is the address of the smart contract
string contract = 2;
// Status to be set
ContractStatus status = 3;
}

// MsgUpdateContractStatusResponse returns empty data
message MsgUpdateContractStatusResponse {}
12 changes: 5 additions & 7 deletions proto/lbm/wasm/v1/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,11 @@ message Params {
option (gogoproto.goproto_stringer) = false;
AccessConfig code_upload_access = 1
[(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"code_upload_access\""];
AccessType instantiate_default_permission = 2 [(gogoproto.moretags) = "yaml:\"instantiate_default_permission\""];
AccessConfig contract_status_access = 3
[(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"contract_status_access\""];
uint64 max_wasm_code_size = 4 [(gogoproto.moretags) = "yaml:\"max_wasm_code_size\""];
uint64 gas_multiplier = 5 [(gogoproto.moretags) = "yaml:\"max_gas\""];
uint64 instance_cost = 6 [(gogoproto.moretags) = "yaml:\"instance_cost\""];
uint64 compile_cost = 7 [(gogoproto.moretags) = "yaml:\"compile_cost\""];
AccessType instantiate_default_permission = 2 [(gogoproto.moretags) = "yaml:\"instantiate_default_permission\""];
uint64 max_wasm_code_size = 3 [(gogoproto.moretags) = "yaml:\"max_wasm_code_size\""];
uint64 gas_multiplier = 4 [(gogoproto.moretags) = "yaml:\"max_gas\""];
uint64 instance_cost = 5 [(gogoproto.moretags) = "yaml:\"instance_cost\""];
uint64 compile_cost = 6 [(gogoproto.moretags) = "yaml:\"compile_cost\""];
}

// CodeInfo is data for the uploaded contract WASM code
Expand Down
32 changes: 0 additions & 32 deletions x/wasm/client/cli/new_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,35 +117,3 @@ func ClearContractAdminCmd() *cobra.Command {
flags.AddTxFlagsToCmd(cmd)
return cmd
}

// UpdateContractStatusCmd clears an admin for a contract
func UpdateContractStatusCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "update-contract-status [contract_addr_bech32] [status(Active|Inactive)]",
Short: "Clears admin for a contract to prevent further migrations",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

status := types.ContractStatusUnspecified
if err := (&status).UnmarshalText([]byte(args[1])); err != nil {
return err
}

msg := types.MsgUpdateContractStatus{
Sender: clientCtx.GetFromAddress().String(),
Contract: args[0],
Status: status,
}
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}
1 change: 0 additions & 1 deletion x/wasm/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func GetTxCmd() *cobra.Command {
MigrateContractCmd(),
UpdateContractAdminCmd(),
ClearContractAdminCmd(),
UpdateContractStatusCmd(),
)
return txCmd
}
Expand Down
2 changes: 0 additions & 2 deletions x/wasm/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ func NewHandler(k types.ContractOpsKeeper) sdk.Handler {
res, err = msgServer.UpdateAdmin(sdk.WrapSDKContext(ctx), msg)
case *MsgClearAdmin:
res, err = msgServer.ClearAdmin(sdk.WrapSDKContext(ctx), msg)
case *types.MsgUpdateContractStatus:
res, err = msgServer.UpdateContractStatus(sdk.WrapSDKContext(ctx), msg)
default:
errMsg := fmt.Sprintf("unrecognized wasm message type: %T", msg)
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg)
Expand Down
10 changes: 5 additions & 5 deletions x/wasm/keeper/authz_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type AuthorizationPolicy interface {
CanCreateCode(c types.AccessConfig, creator sdk.AccAddress) bool
CanInstantiateContract(c types.AccessConfig, actor sdk.AccAddress) bool
CanModifyContract(admin, actor sdk.AccAddress) bool
CanUpdateContractStatus(c types.AccessConfig, actor sdk.AccAddress) bool
CanUpdateContractStatus() bool
}

type DefaultAuthorizationPolicy struct {
Expand All @@ -27,8 +27,8 @@ func (p DefaultAuthorizationPolicy) CanModifyContract(admin, actor sdk.AccAddres
return admin != "" && admin.Equals(actor)
}

func (p DefaultAuthorizationPolicy) CanUpdateContractStatus(config types.AccessConfig, actor sdk.AccAddress) bool {
return config.Allowed(actor)
func (p DefaultAuthorizationPolicy) CanUpdateContractStatus() bool {
return false
}

// GovAuthorizationPolicy is for the gov handler(proposal_handler.go) authorities
Expand All @@ -50,7 +50,7 @@ func (p GovAuthorizationPolicy) CanModifyContract(sdk.AccAddress, sdk.AccAddress
return true
}

func (p GovAuthorizationPolicy) CanUpdateContractStatus(types.AccessConfig, sdk.AccAddress) bool {
// The gov handler can update contract status regardless of the current access config
func (p GovAuthorizationPolicy) CanUpdateContractStatus() bool {
// The gov handler can update contract status
return true
}
3 changes: 0 additions & 3 deletions x/wasm/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,9 +458,6 @@ func TestImportContractWithCodeHistoryReset(t *testing.T) {
"permission": "Everybody"
},
"instantiate_default_permission": "Everybody",
"contract_status_access": {
"permission": "Nobody"
},
"max_wasm_code_size": 500000,
"gas_multiplier": 100,
"instance_cost": 40000,
Expand Down
8 changes: 1 addition & 7 deletions x/wasm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,6 @@ func (k Keeper) getInstantiateAccessConfig(ctx sdk.Context) types.AccessType {
return a
}

func (k Keeper) getContractStatusAccessConfig(ctx sdk.Context) types.AccessConfig {
var a types.AccessConfig
k.paramSpace.Get(ctx, types.ParamStoreKeyContractStatusAccess, &a)
return a
}

func (k Keeper) getMaxWasmCodeSize(ctx sdk.Context) uint64 {
var a uint64
k.paramSpace.Get(ctx, types.ParamStoreKeyMaxWasmCodeSize, &a)
Expand Down Expand Up @@ -619,7 +613,7 @@ func (k Keeper) IterateContractsByCode(ctx sdk.Context, codeID uint64, cb func(a
}

func (k Keeper) setContractStatus(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, status types.ContractStatus, authZ AuthorizationPolicy) error {
if !authZ.CanUpdateContractStatus(k.getContractStatusAccessConfig(ctx), caller) {
if !authZ.CanUpdateContractStatus() {
return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "can not update contract status")
}

Expand Down
Loading

0 comments on commit 7075790

Please sign in to comment.