Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge master into rc170 2023.10.11 #788

Merged
merged 17 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions test/contracts/answer-locals/answer-locals.wat
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Binary file modified test/contracts/answer-locals/output/answer-locals.wasm
Binary file not shown.
2 changes: 2 additions & 0 deletions test/contracts/answer/answer.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "../mxvm/context.h"

void init() {}

void answer() {
int64finish(42);
}
1 change: 1 addition & 0 deletions test/contracts/answer/answer.export
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
answer
init
Binary file added test/contracts/bad-extra/output/bad-extra.wasm
Binary file not shown.
4 changes: 4 additions & 0 deletions test/contracts/counter/counter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down
1 change: 1 addition & 0 deletions test/contracts/counter/counter.export
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
init
upgrade
increment
decrement
get
Binary file modified test/contracts/counter/output/counter.wasm
100755 → 100644
Binary file not shown.
215 changes: 178 additions & 37 deletions test/contracts/counter/output/counter.wat
Original file line number Diff line number Diff line change
@@ -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"))
2 changes: 1 addition & 1 deletion vmhost/hostCore/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
44 changes: 44 additions & 0 deletions vmhost/hosttest/bad_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package hostCoretest

import (
"context"
"testing"
"time"

"github.com/multiversx/mx-chain-vm-go/executor"
contextmock "github.com/multiversx/mx-chain-vm-go/mock/context"
test "github.com/multiversx/mx-chain-vm-go/testcommon"
"github.com/multiversx/mx-chain-vm-go/vmhost"
"github.com/multiversx/mx-chain-vm-go/wasmer"
"github.com/multiversx/mx-chain-vm-go/wasmer2"
"github.com/stretchr/testify/require"
)

func TestBadContract_NoPanic_Memoryfault(t *testing.T) {
Expand Down Expand Up @@ -251,3 +256,42 @@ func TestBadContract_NoPanic_NonExistingFunction(t *testing.T) {
HasRuntimeErrorAndInfo(executor.ErrInvalidFunction.Error(), "thisDoesNotExist")
})
}

func TestBadContractExtra_LongIntLoop_Wasmer1(t *testing.T) {
testBadContractExtraLongIntLoop(t, wasmer.ExecutorFactory())
}

func TestBadContractExtra_LongIntLoop_Wasmer2(t *testing.T) {
testBadContractExtraLongIntLoop(t, wasmer2.ExecutorFactory())
}

func testBadContractExtraLongIntLoop(t *testing.T, executorFactory executor.ExecutorAbstractFactory) {
testCase := test.BuildInstanceCallTest(t).WithContracts(
test.CreateInstanceContract(test.ParentAddress).
WithCode(test.GetTestSCCode("bad-extra", "../../"))).
WithInput(test.CreateTestContractCallInputBuilder().
WithRecipientAddr(test.ParentAddress).
WithGasProvided(test.GasProvided).
WithFunction("bigLoop").
Build()).
WithExecutorFactory(executorFactory).
WithWasmerSIGSEGVPassthrough(false)

ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

done := make(chan struct{})
go func() {
testCase.AndAssertResults(func(_ vmhost.VMHost, _ *contextmock.BlockchainHookStub, verify *test.VMOutputVerifier) {
verify.OutOfGas()
})
close(done)
}()

select {
case <-done:
return
case <-ctx.Done():
require.FailNow(t, "test timed out")
}
}
11 changes: 6 additions & 5 deletions vmhost/hosttest/execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,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()).
Expand Down Expand Up @@ -3692,8 +3692,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
Expand All @@ -3703,8 +3704,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
}
Expand Down
Binary file modified wasmer/libwasmer_darwin_amd64.dylib
Binary file not shown.
Binary file modified wasmer2/libvmexeccapi.dylib
Binary file not shown.
Binary file modified wasmer2/libvmexeccapi.so
Binary file not shown.
Loading