diff --git a/test/contracts/answer-locals/answer-locals.wat b/test/contracts/answer-locals/answer-locals.wat index 22fd8d03f..02ad07671 100644 --- a/test/contracts/answer-locals/answer-locals.wat +++ b/test/contracts/answer-locals/answer-locals.wat @@ -2,12 +2,14 @@ (type (;0;) (func (param i64))) (type (;1;) (func)) (import "env" "int64finish" (func (;0;) (type 0))) - (func (;1;) (type 1) - (local i64 i64 i64 i64 i64) + (func (;1;) (type 1)) + (func (;2;) (type 1) + (local i64 i64 i64 i64) i64.const 42 call 0) (table (;0;) 1 1 funcref) (memory (;0;) 2) (global (;0;) (mut i32) (i32.const 66560)) (export "memory" (memory 0)) - (export "answer" (func 1))) + (export "init" (func 1)) + (export "answer" (func 2))) diff --git a/test/contracts/answer-locals/output/answer-locals.wasm b/test/contracts/answer-locals/output/answer-locals.wasm index fe42715f7..b6b8d92dc 100644 Binary files a/test/contracts/answer-locals/output/answer-locals.wasm and b/test/contracts/answer-locals/output/answer-locals.wasm differ diff --git a/test/contracts/counter/counter.c b/test/contracts/counter/counter.c index f0c4230fc..91dbac918 100644 --- a/test/contracts/counter/counter.c +++ b/test/contracts/counter/counter.c @@ -7,6 +7,10 @@ void init() { int64storageStore(COUNTER_KEY, COUNTER_KEY_LEN, 1); } +void upgrade() { + int64storageStore(COUNTER_KEY, COUNTER_KEY_LEN, 1); +} + void increment() { i64 counter = int64storageLoad(COUNTER_KEY, COUNTER_KEY_LEN); counter++; diff --git a/test/contracts/counter/counter.export b/test/contracts/counter/counter.export index 91723bf1b..82ad4d916 100644 --- a/test/contracts/counter/counter.export +++ b/test/contracts/counter/counter.export @@ -1,4 +1,5 @@ init +upgrade increment decrement get diff --git a/test/contracts/counter/output/counter.wasm b/test/contracts/counter/output/counter.wasm old mode 100755 new mode 100644 index 4f31dbb4b..97d854c17 Binary files a/test/contracts/counter/output/counter.wasm and b/test/contracts/counter/output/counter.wasm differ diff --git a/test/contracts/counter/output/counter.wat b/test/contracts/counter/output/counter.wat index 50471c3bd..4403b2732 100644 --- a/test/contracts/counter/output/counter.wat +++ b/test/contracts/counter/output/counter.wat @@ -1,56 +1,197 @@ (module - (type $t0 (func (param i32 i32 i64) (result i32))) - (type $t1 (func (param i32 i32) (result i64))) - (type $t2 (func (param i64))) - (type $t3 (func)) - (import "env" "int64storageStore" (func $env.int64storageStore (type $t0))) - (import "env" "int64storageLoad" (func $env.int64storageLoad (type $t1))) - (import "env" "int64finish" (func $env.int64finish (type $t2))) - (func $init (type $t3) + (type (;0;) (func (param i32 i32 i64) (result i32))) + (type (;1;) (func (param i32 i32) (result i64))) + (type (;2;) (func (param i64))) + (type (;3;) (func)) + (import "env" "int64storageStore" (func (;0;) (type 0))) + (import "env" "int64storageLoad" (func (;1;) (type 1))) + (import "env" "int64finish" (func (;2;) (type 2))) + (func (;3;) (type 3) + (local i32 i32 i64) i32.const 1024 + local.set 0 i32.const 7 + local.set 1 i64.const 1 - call $env.int64storageStore - drop) - (func $increment (type $t3) - (local $l0 i64) + local.set 2 + local.get 0 + local.get 1 + local.get 2 + call 0 + drop + return) + (func (;4;) (type 3) + (local i32 i32 i64) i32.const 1024 + local.set 0 i32.const 7 + local.set 1 + i64.const 1 + local.set 2 + local.get 0 + local.get 1 + local.get 2 + call 0 + drop + return) + (func (;5;) (type 3) + (local i32 i32 i32 i32 i32 i64 i64 i64 i64 i64 i64 i32 i32) + global.get 0 + local.set 0 + i32.const 16 + local.set 1 + local.get 0 + local.get 1 + i32.sub + local.set 2 + local.get 2 + global.set 0 i32.const 1024 + local.set 3 i32.const 7 - call $env.int64storageLoad + local.set 4 + local.get 3 + local.get 4 + call 1 + local.set 5 + local.get 2 + local.get 5 + i64.store offset=8 + local.get 2 + i64.load offset=8 + local.set 6 i64.const 1 + local.set 7 + local.get 6 + local.get 7 i64.add - local.tee $l0 - call $env.int64storageStore + local.set 8 + local.get 2 + local.get 8 + i64.store offset=8 + local.get 2 + i64.load offset=8 + local.set 9 + local.get 3 + local.get 4 + local.get 9 + call 0 drop - local.get $l0 - call $env.int64finish) - (func $decrement (type $t3) - (local $l0 i64) - i32.const 1024 - i32.const 7 + local.get 2 + i64.load offset=8 + local.set 10 + local.get 10 + call 2 + i32.const 16 + local.set 11 + local.get 2 + local.get 11 + i32.add + local.set 12 + local.get 12 + global.set 0 + return) + (func (;6;) (type 3) + (local i32 i32 i32 i32 i32 i64 i64 i64 i64 i64 i64 i32 i32) + global.get 0 + local.set 0 + i32.const 16 + local.set 1 + local.get 0 + local.get 1 + i32.sub + local.set 2 + local.get 2 + global.set 0 i32.const 1024 + local.set 3 i32.const 7 - call $env.int64storageLoad + local.set 4 + local.get 3 + local.get 4 + call 1 + local.set 5 + local.get 2 + local.get 5 + i64.store offset=8 + local.get 2 + i64.load offset=8 + local.set 6 i64.const -1 + local.set 7 + local.get 6 + local.get 7 i64.add - local.tee $l0 - call $env.int64storageStore + local.set 8 + local.get 2 + local.get 8 + i64.store offset=8 + local.get 2 + i64.load offset=8 + local.set 9 + local.get 3 + local.get 4 + local.get 9 + call 0 drop - local.get $l0 - call $env.int64finish) - (func $get (type $t3) + local.get 2 + i64.load offset=8 + local.set 10 + local.get 10 + call 2 + i32.const 16 + local.set 11 + local.get 2 + local.get 11 + i32.add + local.set 12 + local.get 12 + global.set 0 + return) + (func (;7;) (type 3) + (local i32 i32 i32 i32 i32 i64 i64 i32 i32) + global.get 0 + local.set 0 + i32.const 16 + local.set 1 + local.get 0 + local.get 1 + i32.sub + local.set 2 + local.get 2 + global.set 0 i32.const 1024 + local.set 3 i32.const 7 - call $env.int64storageLoad - call $env.int64finish) - (table $T0 1 1 funcref) - (memory $memory 2) - (global $g0 (mut i32) (i32.const 66576)) + local.set 4 + local.get 3 + local.get 4 + call 1 + local.set 5 + local.get 2 + local.get 5 + i64.store offset=8 + local.get 2 + i64.load offset=8 + local.set 6 + local.get 6 + call 2 + i32.const 16 + local.set 7 + local.get 2 + local.get 7 + i32.add + local.set 8 + local.get 8 + global.set 0 + return) + (table (;0;) 1 1 funcref) + (memory (;0;) 2) + (global (;0;) (mut i32) (i32.const 66576)) (export "memory" (memory 0)) - (export "init" (func $init)) - (export "increment" (func $increment)) - (export "decrement" (func $decrement)) - (export "get" (func $get)) - (data $d0 (i32.const 1024) "COUNTER\00")) + (export "init" (func 3)) + (export "upgrade" (func 4)) + (export "increment" (func 5)) + (export "decrement" (func 6)) + (export "get" (func 7)) + (data (;0;) (i32.const 1024) "COUNTER\00")) diff --git a/vmhost/hostCore/execution.go b/vmhost/hostCore/execution.go index 51c95912d..64aded75b 100644 --- a/vmhost/hostCore/execution.go +++ b/vmhost/hostCore/execution.go @@ -1150,7 +1150,7 @@ func (host *vmHost) callUpgradeFunction() error { func (host *vmHost) callSCFunction(functionName string) error { runtime := host.Runtime() if !runtime.HasFunction(functionName) { - return nil + return executor.ErrFuncNotFound } err := runtime.CallSCFunction(functionName) diff --git a/vmhost/hosttest/execution_test.go b/vmhost/hosttest/execution_test.go index 4db839d08..fc74f012f 100644 --- a/vmhost/hosttest/execution_test.go +++ b/vmhost/hosttest/execution_test.go @@ -210,7 +210,7 @@ func TestExecution_DeployWASM_Popcnt(t *testing.T) { func TestExecution_DeployWASM_AtMaximumLocals(t *testing.T) { test.BuildInstanceCreatorTest(t). WithInput(test.CreateTestContractCreateInputBuilder(). - WithGasProvided(1000). + WithGasProvided(100000). WithCallValue(88). WithContractCode(makeBytecodeWithLocals(WASMLocalsLimit)). Build()). @@ -3687,8 +3687,9 @@ func TestExecution_Mocked_OnSameFollowedByOnDest(t *testing.T) { // number of i64 locals it instantiates func makeBytecodeWithLocals(numLocals uint64) []byte { originalCode := test.GetTestSCCode("answer-locals", "../../") - firstSlice := originalCode[:0x5B] - secondSlice := originalCode[0x5C:] + + firstSlice := originalCode[:0x66] + secondSlice := originalCode[0x67:] encodedNumLocals := vmhost.U64ToLEB128(numLocals) extraBytes := len(encodedNumLocals) - 1 @@ -3698,8 +3699,8 @@ func makeBytecodeWithLocals(numLocals uint64) []byte { result = append(result, encodedNumLocals...) result = append(result, secondSlice...) - result[0x57] = byte(int(result[0x57]) + extraBytes) - result[0x59] = byte(int(result[0x59]) + extraBytes) + result[0x5F] = byte(int(result[0x5F]) + extraBytes) + result[0x64] = byte(int(result[0x64]) + extraBytes) return result }