Sitelet https://github.com/DAD-Chain/dad-go/commit/c9d6d62d2c9952d0b52db15b7120ef5b247c7a76
Skip to content

Commit c9d6d62

Browse files
committed
add callstackdepth and fix gas fee (#1064)
1 parent 9d937e8 commit c9d6d62

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

‎http/base/common/common.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ func NewNeovmInvokeTransaction(gasPrice, gasLimit uint64, contractAddress common
449449
if err != nil {
450450
return nil, err
451451
}
452-
return NewWasmSmartContractTransaction(gasPrice, gasLimit, invokeCode)
452+
return NewSmartContractTransaction(gasPrice, gasLimit, invokeCode)
453453
}
454454

455455
func NewWasmVMInvokeTransaction(gasPrice, gasLimit uint64, contractAddress common.Address, params []interface{}) (*types.MutableTransaction, error) {

‎smartcontract/service/wasmvm/wasm_service.go‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ var (
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

Comments
 (0)