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

Prevent migration to a restricted code #900

Merged
merged 1 commit into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion x/wasm/keeper/contract_keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (p PermissionedKeeper) UnpinCode(ctx sdk.Context, codeID uint64) error {
return p.nested.unpinCode(ctx, codeID)
}

// SetExtraContractAttributes updates the extra attributes that can be stored with the contract info
// SetContractInfoExtension updates the extra attributes that can be stored with the contract info
func (p PermissionedKeeper) SetContractInfoExtension(ctx sdk.Context, contract sdk.AccAddress, extra types.ContractInfoExtension) error {
return p.nested.setContractInfoExtension(ctx, contract, extra)
}
Expand Down
4 changes: 4 additions & 0 deletions x/wasm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,10 @@ func (k Keeper) migrate(ctx sdk.Context, contractAddress sdk.AccAddress, caller
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "unknown code")
}

if !authZ.CanInstantiateContract(newCodeInfo.InstantiateConfig, caller) {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "to use new code")
}

// check for IBC flag
switch report, err := k.wasmVM.AnalyzeCode(newCodeInfo.CodeHash); {
case err != nil:
Expand Down
13 changes: 13 additions & 0 deletions x/wasm/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,10 @@ func TestMigrate(t *testing.T) {
ibcCodeID := StoreIBCReflectContract(t, ctx, keepers).CodeID
require.NotEqual(t, originalCodeID, newCodeID)

restrictedCodeID := StoreHackatomExampleContract(t, ctx, keepers).CodeID
keeper.SetAccessConfig(ctx, restrictedCodeID, types.AllowNobody)
require.NotEqual(t, originalCodeID, restrictedCodeID)

anyAddr := RandomAccountAddress(t)
newVerifierAddr := RandomAccountAddress(t)
initMsgBz := HackatomExampleInitMsg{
Expand Down Expand Up @@ -952,6 +956,15 @@ func TestMigrate(t *testing.T) {
toCodeID: originalCodeID,
expErr: sdkerrors.ErrUnauthorized,
},
"prevent migration when new code is restricted": {
admin: creator,
caller: creator,
initMsg: initMsgBz,
fromCodeID: originalCodeID,
toCodeID: restrictedCodeID,
migrateMsg: migMsgBz,
expErr: sdkerrors.ErrUnauthorized,
},
"fail with non existing code id": {
admin: creator,
caller: creator,
Expand Down