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(wasm): add contract access control #151

Merged
merged 12 commits into from
May 3, 2021

Conversation

whylee259
Copy link
Contributor

@whylee259 whylee259 commented Apr 27, 2021

Description

closes: #126

Add contract status control and execution rejection logic.

  • Add a permission type ContractStatusAccess which defines access control permission.
    The default value is NoBody and it will be modified using gov

  • The ContractStatus is added in ContractInfo states.
    And it has two options Active and Inactive (Unspecified option will be rejected)

  • Add a message MsgUpdateContractStatus for a qualified permission owner to modify the ContractStatus.

  • If the status Inactive, the contract call will be rejected. (Execution, Migration, UpdateAdmin, ClearAdmin)

#131 must be merged first


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer
  • Review Codecov Report in the comment section below once CI passes

@whylee259 whylee259 marked this pull request as draft April 27, 2021 04:55
@whylee259 whylee259 self-assigned this Apr 27, 2021
@whylee259 whylee259 force-pushed the whylee/v2/feat/contract-access-control branch from 3b8b771 to 97d4c0d Compare April 27, 2021 06:34
Yongwoo Lee added 3 commits April 27, 2021 15:46
- add an enum `ContractStatus`
- add a field `status` into ContractInfo
- add a msg `MsgUpdateContractStatus`
- add handler for it
@whylee259 whylee259 force-pushed the whylee/v2/feat/contract-access-control branch from 97d4c0d to 5f2a0ce Compare April 27, 2021 06:48
@whylee259 whylee259 force-pushed the whylee/v2/feat/contract-access-control branch from 5f2a0ce to c6c6868 Compare April 27, 2021 07:08
@codecov
Copy link

codecov bot commented Apr 27, 2021

Codecov Report

Merging #151 (6620bc5) into v2/develop (1f739c5) will decrease coverage by 1.93%.
The diff coverage is 68.12%.

Impacted file tree graph

@@              Coverage Diff               @@
##           v2/develop     #151      +/-   ##
==============================================
- Coverage       54.99%   53.06%   -1.94%     
==============================================
  Files             812      704     -108     
  Lines           51487    47274    -4213     
==============================================
- Hits            28317    25086    -3231     
+ Misses          20211    19629     -582     
+ Partials         2959     2559     -400     
Impacted Files Coverage Δ
client/grpc/tmservice/query.pb.gw.go 30.06% <ø> (ø)
client/keys/root.go 100.00% <ø> (ø)
client/keys/utils.go 35.29% <ø> (-3.60%) ⬇️
crypto/armor.go 85.89% <ø> (ø)
crypto/keys/ed25519/ed25519.go 67.34% <ø> (ø)
crypto/keys/multisig/codec.go 100.00% <ø> (ø)
crypto/keys/secp256k1/secp256k1.go 86.79% <ø> (ø)
simapp/test_helpers.go 0.49% <0.00%> (-0.01%) ⬇️
types/address.go 65.71% <ø> (ø)
types/config.go 84.61% <ø> (ø)
... and 80 more

@whylee259 whylee259 marked this pull request as ready for review April 27, 2021 07:18
@brew0722
Copy link
Contributor

brew0722 commented Apr 28, 2021

I understood it to be used as Instantiate Auth.

However, There is a part that is suspected of being a problem in the planning that the entity with Instantiate authority can instantiate again the Contract that has made the decision to disuse it.

However, first of all, we are satisfied with the implementation of the planning prototype based on the address, so we do not care about this in this PR.

I understand Blocking/allowing standards for planning via CodeID(CodeInfo).
However, the implementation appears to be a ContractAddress(ContractInfo).

If it is disabled based on address, I think it seems that Instantiate cannot be controlled.

Copy link
Contributor

@brew0722 brew0722 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@loloicci loloicci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not the status of the contract affect Queries?

@@ -40,3 +45,7 @@ func (p GovAuthorizationPolicy) CanInstantiateContract(types.AccessConfig, sdk.A
func (p GovAuthorizationPolicy) CanModifyContract(sdk.AccAddress, sdk.AccAddress) bool {
return true
}

func (p GovAuthorizationPolicy) CanUpdateContractStatus(types.AccessConfig, sdk.AccAddress) bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When is this (and above 3 functions) called and what is this for? Want comment doc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added the comment to the code.

@@ -469,7 +472,8 @@ func TestImportContractWithCodeHistoryReset(t *testing.T) {
"code_id": "1",
"creator": "link1p0yx9c9q4xsnedlcn24gqfry5dcu6e9xkhv9aj",
"admin": "link1qyqszqgpqyqszqgpqyqszqgpqyqszqgp8apuk5",
"label": "ȀĴnZV芢毤"
"label": "ȀĴnZV芢毤",
"status": "Active"
Copy link
Member

@loloicci loloicci Apr 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mixed Tab vs Space in these templates. Want to unify.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have fixed it to use spaces.

@whylee259
Copy link
Contributor Author

Should not the status of the contract affect Queries?

You mean that query responses should not include the status, right?
The original concept of mine was that the status is included for ContractInfo queries.

@brew0722 brew0722 self-requested a review April 29, 2021 04:15
Copy link
Contributor

@shiki-tak shiki-tak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

if contractInfo == nil {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "unknown contract")
}
if contractInfo.Status != status {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can status be nil?

Copy link
Contributor Author

@whylee259 whylee259 Apr 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it is a value type.
It can be ContractStatusUnspecified but it's not a problem.

@whylee259 whylee259 merged commit 62843eb into v2/develop May 3, 2021
@whylee259 whylee259 deleted the whylee/v2/feat/contract-access-control branch May 12, 2021 05:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

VM: Add Contract-Banning Features
4 participants