Skip to content

Commit

Permalink
Merge branch 'wasmd-patch'
Browse files Browse the repository at this point in the history
  • Loading branch information
iKapitonau committed Aug 28, 2024
2 parents 2aad500 823c07f commit 0617649
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 1,10 @@
# CHANGELOG

# 1.14.0

- Fix CWA-2024-005
- Bump ledger-cosmos-go from v0.12.2 to v0.12.4

# 1.13.0

- Support DCAP attestation
Expand Down
2 changes: 2 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 36,7 @@ import (
v1_11 "github.com/scrtlabs/SecretNetwork/app/upgrades/v1.11"
v1_12 "github.com/scrtlabs/SecretNetwork/app/upgrades/v1.12"
v1_13 "github.com/scrtlabs/SecretNetwork/app/upgrades/v1.13"
v1_14 "github.com/scrtlabs/SecretNetwork/app/upgrades/v1.14"
v1_3 "github.com/scrtlabs/SecretNetwork/app/upgrades/v1.3"
v1_4 "github.com/scrtlabs/SecretNetwork/app/upgrades/v1.4"
v1_5 "github.com/scrtlabs/SecretNetwork/app/upgrades/v1.5"
Expand Down Expand Up @@ -109,6 110,7 @@ var (
v1_11.Upgrade,
v1_12.Upgrade,
v1_13.Upgrade,
v1_14.Upgrade,
}
)

Expand Down
36 changes: 36 additions & 0 deletions app/upgrades/v1.14/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 1,36 @@
package v1_14

import (
"fmt"

store "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/scrtlabs/SecretNetwork/app/keepers"
"github.com/scrtlabs/SecretNetwork/app/upgrades"
)

const upgradeName = "v1.14"

var Upgrade = upgrades.Upgrade{
UpgradeName: upgradeName,
CreateUpgradeHandler: createUpgradeHandler,
StoreUpgrades: store.StoreUpgrades{},
}

func createUpgradeHandler(mm *module.Manager, _ *keepers.SecretAppKeepers, configurator module.Configurator,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info(` _ _ _____ _____ _____ _____ ______ `)
ctx.Logger().Info(`| | | | __ \ / ____| __ \ /\ | __ \| ____|`)
ctx.Logger().Info(`| | | | |__) | | __| |__) | / \ | | | | |__ `)
ctx.Logger().Info(`| | | | ___/| | |_ | _ / / /\ \ | | | | __| `)
ctx.Logger().Info(`| |__| | | | |__| | | \ \ / ____ \| |__| | |____ `)
ctx.Logger().Info(` \____/|_| \_____|_| \_\/_/ \_\_____/|______|`)

ctx.Logger().Info(fmt.Sprintf("Running module migrations for %s...", upgradeName))

return mm.RunMigrations(ctx, configurator, vm)
}
}
2 changes: 1 addition & 1 deletion client/docs/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 3,7 @@
"info": {
"title": "Secret Network",
"description": "A REST interface for queries and transactions",
"version": "v1.12"
"version": "v1.14"
},
"apis": [
{
Expand Down
4 changes: 2 additions & 2 deletions client/docs/static/openapi/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/docs/static/openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 2,7 @@ openapi: 3.0.0
info:
title: Secret Network
description: A REST interface for queries and transactions
version: v1.12
version: v1.14
paths:
/cosmos/auth/v1beta1/accounts:
get:
Expand Down
2 changes: 1 addition & 1 deletion client/docs/static/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 2,7 @@ swagger: '2.0'
info:
title: Secret Network
description: A REST interface for queries and transactions
version: v1.12
version: v1.14
paths:
/cosmos/auth/v1beta1/accounts:
get:
Expand Down
2 changes: 1 addition & 1 deletion client/docs/statik/statik.go

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions x/compute/internal/keeper/handler_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 634,21 @@ func (h SDKMessageHandler) handleSdkMessage(ctx sdk.Context, contractAddr sdk.Ad
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "can't route message % v", msg)
}

// callDepthMessageHandler is a wrapper around a Messenger that checks the call depth before dispatching a message.
type callDepthMessageHandler struct {
Messenger
MaxCallDepth uint32
}

func (h callDepthMessageHandler) DispatchMsg(ctx sdk.Context, contractAddr sdk.AccAddress, contractIBCPortID string, msg v1wasmTypes.CosmosMsg) (events []sdk.Event, data [][]byte, err error) {
ctx, err = checkAndIncreaseCallDepth(ctx, h.MaxCallDepth)
if err != nil {
return nil, nil, err
}

return h.Messenger.DispatchMsg(ctx, contractAddr, contractIBCPortID, msg)
}

// convertWasmIBCTimeoutHeightToCosmosHeight converts a wasm type ibc timeout height to ibc module type height
func convertWasmIBCTimeoutHeightToCosmosHeight(ibcTimeoutBlock *v1wasmTypes.IBCTimeoutBlock) ibcclienttypes.Height {
if ibcTimeoutBlock == nil {
Expand Down
22 changes: 22 additions & 0 deletions x/compute/internal/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 79,7 @@ type Keeper struct {
messenger Messenger
// queryGasLimit is the max wasm gas that can be spent on executing a query with a contract
queryGasLimit uint64
maxCallDepth uint32
HomeDir string
// authZPolicy AuthorizationPolicy
// paramSpace subspace.Subspace
Expand Down Expand Up @@ -144,9 145,12 @@ func NewKeeper(
cdc,
),
queryGasLimit: wasmConfig.SmartQueryGasLimit,
maxCallDepth: types.DefaultMaxCallDepth,
HomeDir: homeDir,
LastMsgManager: lastMsgManager,
}
// always wrap the messenger, even if it was replaced by an option
keeper.messenger = callDepthMessageHandler{keeper.messenger, keeper.maxCallDepth}
keeper.queryPlugins = DefaultQueryPlugins(govKeeper, distKeeper, mintKeeper, bankKeeper, stakingKeeper, queryRouter, &keeper, channelKeeper).Merge(customPlugins)

return keeper
Expand Down Expand Up @@ -754,6 758,24 @@ func (k Keeper) querySmartImpl(ctx sdk.Context, contractAddress sdk.AccAddress,
return queryResult, nil
}

func checkAndIncreaseCallDepth(ctx sdk.Context, maxCallDepth uint32) (sdk.Context, error) {
var callDepth uint32
if size, ok := types.CallDepth(ctx); ok {
callDepth = size
}

// increase
callDepth

// did we go too far?
if callDepth > maxCallDepth {
return sdk.Context{}, types.ErrExceedMaxCallDepth
}

// set updated stack size
return types.WithCallDepth(ctx, callDepth), nil
}

// We don't use this function since we have an encrypted state. It's here for upstream compatibility
// QueryRaw returns the contract's state for give key. For a `nil` key a empty slice result is returned.
func (k Keeper) QueryRaw(ctx sdk.Context, contractAddress sdk.AccAddress, key []byte) []types.Model {
Expand Down
16 changes: 16 additions & 0 deletions x/compute/internal/types/context.go
Original file line number Diff line number Diff line change
@@ -0,0 1,16 @@
package types

import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

const contextKeyCallDepth contextKey = iota

func WithCallDepth(ctx sdk.Context, counter uint32) sdk.Context {
return ctx.WithValue(contextKeyCallDepth, counter)
}

func CallDepth(ctx sdk.Context) (uint32, bool) {
val, ok := ctx.Value(contextKeyCallDepth).(uint32)
return val, ok
}
3 changes: 3 additions & 0 deletions x/compute/internal/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 72,9 @@ var (

// ErrMaxIBCChannels error for maximum number of ibc channels reached
ErrMaxIBCChannels = sdkErrors.Register(DefaultCodespace, 22, "max transfer channels")

// ErrExceedMaxCallDepth error if max message stack size is exceeded
ErrExceedMaxCallDepth = sdkErrors.Register(DefaultCodespace, 30, "max call depth exceeded")
)

func IsEncryptedErrorCode(code uint32) bool {
Expand Down
1 change: 1 addition & 0 deletions x/compute/internal/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 17,7 @@ import (
)

const (
DefaultMaxCallDepth = uint32(500)
defaultLRUCacheSize = uint64(0)
defaultEnclaveLRUCacheSize = uint16(100)
defaultQueryGasLimit = uint64(10_000_000)
Expand Down

0 comments on commit 0617649

Please sign in to comment.