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

Gov authorization propagation for sub-messages #1482

Merged
merged 2 commits into from
Jul 6, 2023
Merged

Gov authorization propagation for sub-messages #1482

merged 2 commits into from
Jul 6, 2023

Conversation

alpe
Copy link
Contributor

@alpe alpe commented Jul 4, 2023

Resolves #1207

I have focused on instantiate and migrate to propagate to sub-messages. Instantiate is enabled by default as this comes with low risk compared to propagating migrate gov permissions.
This can be enabled/ disabled via the WitGovSubMsgAuthZPropagated option in the app setup.

The sudo call though does not include gov permission propagation for security reasons. It can be enabled for native Go calls by passing an AutorizationPolicy with the sdk.Context. I have added WithSubMsgAuthzPolicy to support this.

@alpe alpe marked this pull request as ready for review July 4, 2023 16:30
@alpe alpe changed the title Pass gov authorization to sub-messages partially Gov authorization propagation for sub-messages Jul 4, 2023
@alpe alpe requested a review from pinosu July 4, 2023 16:41
@@ -54,7 +54,10 @@ func NewKeeper(
gasRegister: NewDefaultWasmGasRegister(),
maxQueryStackSize: types.DefaultMaxQueryStackSize,
acceptedAccountTypes: defaultAcceptedAccountTypes,
authority: authority,
propagateGovAuthorization: map[types.AuthorizationPolicyAction]struct{}{
types.AuthZActionInstantiate: {},
Copy link
Contributor Author

@alpe alpe Jul 4, 2023

Choose a reason for hiding this comment

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

Setting the default: sub-message propagation only for instantiate

@@ -161,6 +161,20 @@ func WithAcceptedAccountTypesOnContractInstantiation(accts ...authtypes.AccountI
})
}

// WitGovSubMsgAuthZPropagated overwrites the default gov authorization policy for sub-messages
func WitGovSubMsgAuthZPropagated(entries ...types.AuthorizationPolicyAction) Option {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Constructor option to modify defaults

return GovAuthorizationPolicy{}
return newGovAuthorizationPolicy(m.keeper.propagateGovAuthorization)
}
if policy, ok := types.SubMsgAuthzPolicy(ctx); ok {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reads policy from context when set

@@ -356,6 +350,7 @@ func (k Keeper) instantiate(
sdk.NewAttribute(types.AttributeKeyCodeID, strconv.FormatUint(codeID, 10)),
))

ctx = types.WithSubMsgAuthzPolicy(ctx, authPolicy.SubMessageAuthorizationPolicy(types.AuthZActionInstantiate))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pass sub-message policy with context

@codecov
Copy link

codecov bot commented Jul 4, 2023

Codecov Report

Merging #1482 (bd1be9a) into main (c158b77) will increase coverage by 0.11%.
The diff coverage is 82.22%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1482      +/-   ##
==========================================
+ Coverage   57.86%   57.98%   +0.11%     
==========================================
  Files          63       64       +1     
  Lines        8344     8401      +57     
==========================================
+ Hits         4828     4871      +43     
- Misses       3112     3126      +14     
  Partials      404      404              
Impacted Files Coverage Δ
x/wasm/types/authz_policy.go 0.00% <0.00%> (ø)
x/wasm/types/context.go 29.41% <29.41%> (ø)
x/wasm/keeper/options.go 76.00% <77.77%> (+0.17%) ⬆️
x/wasm/keeper/authz_policy.go 100.00% <100.00%> (ø)
x/wasm/keeper/contract_keeper.go 95.00% <100.00%> (ø)
x/wasm/keeper/keeper.go 87.05% <100.00%> (+0.28%) ⬆️
x/wasm/keeper/keeper_cgo.go 92.59% <100.00%> (+0.92%) ⬆️
x/wasm/keeper/msg_server.go 61.35% <100.00%> (+0.37%) ⬆️

@@ -550,3 +557,157 @@ func TestDispatchSubMsgConditionalReplyOn(t *testing.T) {
})
}
}

func TestInstantiateGovSubMsgAuthzPropagated(t *testing.T) {
mockWasmVM := &wasmtesting.MockWasmer{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Very nice tests!

Copy link
Contributor

@pinosu pinosu left a comment

Choose a reason for hiding this comment

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

Great work 🥇 LGTM 👍

@alpe alpe merged commit 63f73d3 into main Jul 6, 2023
8 checks passed
@alpe alpe deleted the 1207_gov_context branch July 6, 2023 09:42
@faddat faddat mentioned this pull request Jul 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gov: support contracts that dynamically instantiate other contracts
2 participants