@@ -79,6 +79,7 @@ type Keeper struct {
79
79
messenger Messenger
80
80
// queryGasLimit is the max wasm gas that can be spent on executing a query with a contract
81
81
queryGasLimit uint64
82
+ maxCallDepth uint32
82
83
HomeDir string
83
84
// authZPolicy AuthorizationPolicy
84
85
// paramSpace subspace.Subspace
@@ -144,9 +145,12 @@ func NewKeeper(
144
145
cdc ,
145
146
),
146
147
queryGasLimit : wasmConfig .SmartQueryGasLimit ,
148
+ maxCallDepth : types .DefaultMaxCallDepth ,
147
149
HomeDir : homeDir ,
148
150
LastMsgManager : lastMsgManager ,
149
151
}
152
+ // always wrap the messenger, even if it was replaced by an option
153
+ keeper .messenger = callDepthMessageHandler {keeper .messenger , keeper .maxCallDepth }
150
154
keeper .queryPlugins = DefaultQueryPlugins (govKeeper , distKeeper , mintKeeper , bankKeeper , stakingKeeper , queryRouter , & keeper , channelKeeper ).Merge (customPlugins )
151
155
152
156
return keeper
@@ -754,6 +758,24 @@ func (k Keeper) querySmartImpl(ctx sdk.Context, contractAddress sdk.AccAddress,
754
758
return queryResult , nil
755
759
}
756
760
761
+ func checkAndIncreaseCallDepth (ctx sdk.Context , maxCallDepth uint32 ) (sdk.Context , error ) {
762
+ var callDepth uint32
763
+ if size , ok := types .CallDepth (ctx ); ok {
764
+ callDepth = size
765
+ }
766
+
767
+ // increase
768
+ callDepth ++
769
+
770
+ // did we go too far?
771
+ if callDepth > maxCallDepth {
772
+ return sdk.Context {}, types .ErrExceedMaxCallDepth
773
+ }
774
+
775
+ // set updated stack size
776
+ return types .WithCallDepth (ctx , callDepth ), nil
777
+ }
778
+
757
779
// We don't use this function since we have an encrypted state. It's here for upstream compatibility
758
780
// QueryRaw returns the contract's state for give key. For a `nil` key a empty slice result is returned.
759
781
func (k Keeper ) QueryRaw (ctx sdk.Context , contractAddress sdk.AccAddress , key []byte ) []types.Model {
0 commit comments