6161 CONTRACT_METHOD_NAME = "invoke"
6262
6363 //max memory size of wasm vm
64- WASM_MEM_LIMITATION uint64 = 10 * 1024 * 1024
65- VM_STEP_LIMIT = 40000000
64+ WASM_MEM_LIMITATION uint64 = 10 * 1024 * 1024
65+ VM_STEP_LIMIT = 40000000
66+ WASM_CALLSTACK_LIMIT = 1024
6667
6768 CodeCache * lru.ARCCache
6869)
@@ -86,7 +87,7 @@ func (this *WasmVmService) Invoke() (interface{}, error) {
8687 return nil , err
8788 }
8889
89- code , err := this .Store . GetContractState (contract .Address )
90+ code , err := this .CacheDB . GetContract (contract .Address )
9091 if err != nil {
9192 return nil , err
9293 }
@@ -103,7 +104,7 @@ func (this *WasmVmService) Invoke() (interface{}, error) {
103104 }
104105
105106 if compiled == nil {
106- compiled , err : = ReadWasmModule (code , false )
107+ compiled , err = ReadWasmModule (code , false )
107108 if err != nil {
108109 return nil , err
109110 }
@@ -121,6 +122,7 @@ func (this *WasmVmService) Invoke() (interface{}, error) {
121122 }
122123 vm .RecoverPanic = true
123124 vm .AvaliableGas = & exec.Gas {GasLimit : this .GasLimit , GasPrice : this .GasPrice }
125+ vm .CallStackDepth = uint32 (WASM_CALLSTACK_LIMIT )
124126
125127 entryName := CONTRACT_METHOD_NAME
126128
@@ -148,6 +150,12 @@ func (this *WasmVmService) Invoke() (interface{}, error) {
148150 this .vm = vm
149151
150152 _ , err = vm .ExecCode (index )
153+
154+ //here sub the sc.Gas.
155+ if ! this .ContextRef .CheckUseGas (this .GasLimit - vm .AvaliableGas .GasLimit ) {
156+ return nil , ERR_GAS_INSUFFICIENT
157+ }
158+
151159 if err != nil {
152160 return nil , errors .NewErr ("[Call]ExecCode error!" + err .Error ())
153161 }
0 commit comments