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

Feat/evmc6: stEWASMTests fail (internal error -1) #62

Closed
2 tasks done
meowsbits opened this issue Mar 9, 2020 · 9 comments
Closed
2 tasks done

Feat/evmc6: stEWASMTests fail (internal error -1) #62

meowsbits opened this issue Mar 9, 2020 · 9 comments
Assignees
Labels
F4-tests 💻 help wanted Extra attention is needed

Comments

@meowsbits
Copy link
Member

meowsbits commented Mar 9, 2020

Rel #55, #57

System and Version Info

  • OS: Ubuntu 18.04.3 LTS (bionic)
  • Git HEAD: [feat/evmc6] 139dbb5791e46d9c0edea9defd8f9231023fe7cb
go version go1.13.5 linux/amd64
node version: v13.6.0
npm version: 6.13.7
Python 3.6.8

Expected behaviour

Hera and SSVM EWASM libs should be able to pass stEWASMTests.

Actual behaviour

  • SSVM sees:
fatal error: unexpected signal during runtime execution                                
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10291f2ff pc=0x7fde1d4adcf4]

Full log attached: test.ssvm.log

At this point I'm not sure if this is an issue with SSVM, the go-ethereum/evmc CGo bindings, or the core/vm/evmc.go implementation. cc @dm4 Would you be able to help here?

Hera actually seems to throw a comparable error (not sure if on the same specific tests), but doesn't Fatal itself. The code originally caused geth to panic when the EWASMs returned an internal error. Returning the error seems to fix the tests, for hera...

You can make Hera fail the tests by reverting this commit.

Steps to reproduce the behaviour

Backtrace

return_data:                                                                                                                                   [1755/9625]
code_size: 250                                                                                                       
msg->gas: 83865081                                                                
msg->depth: 0                                                                                                         
msg->input_size: 0                                                                
Caller: a94f5374fce5edbc8e2a8697c15331677e6ebf0b                           
CallValue: 0000000000000000000000000000000000000000000000000000000000000000
 Error: Wasm instantiation failed. Code: 4                                
usedGas: 0                                                                                                                                                
return_size: 0                                                            
return_data:                                                                      
code_size: 250                                                                 
msg->gas: 83865081                                                          
msg->depth: 0                                                                           
msg->input_size: 0                                                                                                                                   
Caller: a94f5374fce5edbc8e2a8697c15331677e6ebf0b                                                                                                          
CallValue: 0000000000000000000000000000000000000000000000000000000000000000             
 Error: Wasm instantiation failed. Code: 4                                                 
usedGas: 0                                                                           
return_size: 0                                                                     
return_data:                                                                         
fatal error: unexpected signal during runtime execution                                
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10291f2ff pc=0x7fde1d4adcf4]
                                                                           
runtime stack:                                                            
runtime.throw(0xa7fe53, 0x2a)                                                     
        /home/ia/go1.13.5.linux-amd64/go/src/runtime/panic.go:774 +0x72           
runtime.sigpanic()                                                                
        /home/ia/go1.13.5.linux-amd64/go/src/runtime/signal_unix.go:378 +0x47c    
                                                                                                 
goroutine 5647 [syscall]:                                                          
runtime.cgocall(0x91c560, 0xc000cfb590, 0xc000cfb502)                                        
        /home/ia/go1.13.5.linux-amd64/go/src/runtime/cgocall.go:128 +0x5b fp=0xc000cfb560 sp=0xc000cfb528 pc=0x40654b
github.com/ethereum/go-ethereum/evmc/bindings/go/evmc._Cfunc_execute_wrapper(0x7fde037fe840, 0xa8, 0x4, 0x0, 0x4ffadf9, 0xc000660940, 0xc000660960, 0x0, 0
x0, 0xc000660980, ...)                                                            
        _cgo_gotypes.go:363 +0x68 fp=0xc000cfb590 sp=0xc000cfb560 pc=0x85e448
github.com/ethereum/go-ethereum/evmc/bindings/go/evmc.(*Instance).Execute.func1(0xc0000d6618, 0xa8, 0x4, 0x0, 0x0, 0x0, 0x4ffadf9, 0xc000660940, 0xc000660
960, 0x1175628, ...)                                                              
        /home/ia/go/src/github.com/ethereum/go-ethereum/evmc/bindings/go/evmc/evmc.go:248 +0x17f fp=0xc000cfb660 sp=0xc000cfb590 pc=0x861e2f
github.com/ethereum/go-ethereum/evmc/bindings/go/evmc.(*Instance).Execute(0xc0000d6618, 0xb76820, 0xc000146690, 0x4, 0x0, 0x7fde1dd2b600, 0x0, 0x4ffadf9,
0xcdabcdabcdabcdab, 0xcdabcdabcdabcdab, ...)                                      
        /home/ia/go/src/github.com/ethereum/go-ethereum/evmc/bindings/go/evmc/evmc.go:248 +0x2ab fp=0xc000cfb7d8 sp=0xc000cfb660 pc=0x85fd6b
github.com/ethereum/go-ethereum/core/vm.(*EVMC).Run(0xc0007eea60, 0xc0008460c0, 0x1175628, 0x0, 0x0, 0xc000cfba00, 0x0, 0x0, 0x0, 0x0, ...)
        /home/ia/go/src/github.com/ethereum/go-ethereum/core/vm/evmc.go:360 +0x3ad fp=0xc000cfba70 sp=0xc000cfb7d8 pc=0x86f28d
github.com/ethereum/go-ethereum/core/vm.run(0xc000348000, 0xc0008460c0, 0x1175628, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        /home/ia/go/src/github.com/ethereum/go-ethereum/core/vm/evm.go:64 +0x21a fp=0xc000cfbb00 sp=0xc000cfba70 pc=0x8685da
github.com/ethereum/go-ethereum/core/vm.(*EVM).Call(0xc000348000, 0xb66400, 0xc0007209e0, 0xcdabcdabcdabcdab, 0xcdabcdabcdabcdab, 0xcdabcdab, 0x1175628, 0
x0, 0x0, 0x4ffadf9, ...)                                                   
        /home/ia/go/src/github.com/ethereum/go-ethereum/core/vm/evm.go:228 +0x51a fp=0xc000cfbd50 sp=0xc000cfbb00 pc=0x8694da
github.com/ethereum/go-ethereum/core.(*StateTransition).TransitionDb(0xc000164070, 0xb75280, 0xc000a005a0, 0xc0003987c0, 0xc000164070, 0x989fe0, 0xc000398
7d0, 0xc0003987d0)                                                        
        /home/ia/go/src/github.com/ethereum/go-ethereum/core/state_transition.go:218 +0x4c4 fp=0xc000cfbf28 sp=0xc000cfbd50 pc=0x8ae914
github.com/ethereum/go-ethereum/core.ApplyMessage(0xc000348000, 0xb75280, 0xc000a005a0, 0xc0003987c0, 0x1, 0xc0003987d0, 0x0, 0x1, 0xc28fac6d66bce6e0, 0xb
af97f69, ...)                                                                                        
        /home/ia/go/src/github.com/ethereum/go-ethereum/core/state_transition.go:136 +0x5b fp=0xc000cfbf78 sp=0xc000cfbf28 pc=0x8ade9b
github.com/ethereum/go-ethereum/tests.(*StateTest).RunNoVerify(0xc0008ca000, 0xc000398866, 0x9, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        /home/ia/go/src/github.com/ethereum/go-ethereum/tests/state_test_util.go:217 +0x5ad fp=0xc000cffae8 sp=0xc000cfbf78 pc=0x905d4d
github.com/ethereum/go-ethereum/tests.(*StateTest).Run(0xc0008ca000, 0xc000398866, 0x9, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        /home/ia/go/src/github.com/ethereum/go-ethereum/tests/state_test_util.go:175 +0xa2 fp=0xc000d034a8 sp=0xc000cffae8 pc=0x9052d2
github.com/ethereum/go-ethereum/tests.TestState.func1.1.1(0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)                                          
        /home/ia/go/src/github.com/ethereum/go-ethereum/tests/state_test.go:76 +0xc2 fp=0xc000d06d68 sp=0xc000d034a8 pc=0x915412
github.com/ethereum/go-ethereum/tests.withTrace(0xc000724000, 0x5000001, 0xc000d0df18)
        /home/ia/go/src/github.com/ethereum/go-ethereum/tests/state_test.go:92 +0xe4 fp=0xc000d0dec0 sp=0xc000d06d68 pc=0x910e84                          
github.com/ethereum/go-ethereum/tests.TestState.func1.1(0xc000724000)             
        /home/ia/go/src/github.com/ethereum/go-ethereum/tests/state_test.go:75 +0x178 fp=0xc000d0df70 sp=0xc000d0dec0 pc=0x915618
testing.tRunner(0xc000724000, 0xc00081a600)                                    
        /home/ia/go1.13.5.linux-amd64/go/src/testing/testing.go:909 +0xc9 fp=0xc000d0dfd0 sp=0xc000d0df70 pc=0x505369
runtime.goexit()                                                                  
        /home/ia/go1.13.5.linux-amd64/go/src/runtime/asm_amd64.s:1357 +0x1 fp=0xc000d0dfd8 sp=0xc000d0dfd0 pc=0x4623d1
created by testing.(*T).Run                                                       
        /home/ia/go1.13.5.linux-amd64/go/src/testing/testing.go:960 +0x350 
                                                                           
@meowsbits meowsbits self-assigned this Mar 9, 2020
@meowsbits meowsbits added F4-tests 💻 help wanted Extra attention is needed labels Mar 9, 2020
@triage-new-issues triage-new-issues bot removed the triage label Mar 9, 2020
@meowsbits
Copy link
Member Author

meowsbits commented Mar 9, 2020

With the latest updates in #57 (as of c93eb46), I have:

Hera fails two tests

		st.whitelist(`^stEWASM`)
		if strings.Contains(*testEWASM, "hera") {
			st.skipLoad(`^stEWASMTests/callSenderBalanceExceeds128Bits`)
			st.skipLoad(`^stEWASMTests/ecAddCallDataCopy`)

SSVM seems to fail some (I'm having a tough time isolating the failed test(s)...), but when running the suite continually causes a fatal error: unexpected signal during runtime execution.

> cat .ia/test-ewasm.sh 
#!/usr/bin/env bash

SO_SSVM=/home/ia/dev/second-state/SSVM/build/tools/ssvm-evmc/libssvmEVMC.so 
SO_HERA=/home/ia/dev/ewasm/hera/build/src/libhera.so 

SO_PATH=''

if [[ $1 = ssvm ]]; then 
        SO_PATH="$SO_SSVM"
elif [[ $1 = hera ]]; then
        SO_PATH="$SO_HERA"
fi

[[ -z "$SO_PATH" ]] && echo "Use 'hera' or 'ssvm' as arg1" && exit 1

echo "Running EWASM tests for $SO_PATH"

echo '> go test -v ./tests/... -run TestState -evmc.ewasm='"$SO_PATH" | tee test.$1.log
go test -v ./tests/... -run TestState -evmc.ewasm="$SO_PATH" &> test.$1.log
echo "=> test.$1.log"

# grep -A2 FAIL test.*.log
# grep -B5 -A5 'segementation violation' test.*.log

> t=ssvm; ./.ia/test-ewasm.sh $t; grep -B 10 -A 10 -E '(fatal|FAIL)' test.$t.log || tail -20 test.$t.log
Running EWASM tests for /home/ia/dev/second-state/SSVM/build/tools/ssvm-evmc/libssvmEVMC.so
> go test -v ./tests/... -run TestState -evmc.ewasm=/home/ia/dev/second-state/SSVM/build/tools/ssvm-evmc/libssvmEVMC.so
=> test.ssvm.log
 =================  Statistics  =================
 Total execution time: 14 us
 Wasm instructions execution time: 5 us
 Host functions execution time: 9 us
 Executed wasm instructions count: 19
 Gas costs: 21508
 Instructions per second: 3800000
usedGas: 21508
return_size: 0
return_data:
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x7fb88400a31f pc=0x7fb7b46adc40]

runtime stack:
runtime.throw(0xa80101, 0x2a)
        /home/ia/go1.13.5.linux-amd64/go/src/runtime/panic.go:774 +0x72
runtime.sigpanic()
        /home/ia/go1.13.5.linux-amd64/go/src/runtime/signal_unix.go:378 +0x47c

goroutine 5229 [syscall]:
runtime.cgocall(0x91c7c0, 0xc0009ef640, 0x40faa4)
--
created by testing.(*T).Run
        /home/ia/go1.13.5.linux-amd64/go/src/testing/testing.go:960 +0x350

goroutine 774 [chan send]:
testing.tRunner.func1(0xc00054c700)
        /home/ia/go1.13.5.linux-amd64/go/src/testing/testing.go:904 +0x282
testing.tRunner(0xc00054c700, 0xc000541900)
        /home/ia/go1.13.5.linux-amd64/go/src/testing/testing.go:913 +0xd3
created by testing.(*T).Run
        /home/ia/go1.13.5.linux-amd64/go/src/testing/testing.go:960 +0x350
FAIL    github.com/ethereum/go-ethereum/tests   1.703s
?       github.com/ethereum/go-ethereum/tests/fuzzers/keystore  [no test files]
?       github.com/ethereum/go-ethereum/tests/fuzzers/rlp       [no test files]
?       github.com/ethereum/go-ethereum/tests/fuzzers/trie      [no test files]
?       github.com/ethereum/go-ethereum/tests/fuzzers/txfetcher [no test files]
?       github.com/ethereum/go-ethereum/tests/fuzzers/whisperv6 [no test files]
FAIL

> ^ssvm^hera^
t=hera; ./.ia/test-ewasm.sh $t; grep -B 10 -A 10 -E '(fatal|FAIL)' test.$t.log || tail -20 test.$t.log
Running EWASM tests for /home/ia/dev/ewasm/hera/build/src/libhera.so
> go test -v ./tests/... -run TestState -evmc.ewasm=/home/ia/dev/ewasm/hera/build/src/libhera.so
=> test.hera.log
        --- PASS: TestState/stEWASMTests/createNonzero.json/Byzantium/0 (0.01s)
    --- PASS: TestState/stEWASMTests/validateBytecodeInvalidImportIsInvalid.json (0.00s)
        --- PASS: TestState/stEWASMTests/validateBytecodeInvalidImportIsInvalid.json/Byzantium/0 (0.00s)
    --- PASS: TestState/stEWASMTests/validateBytecodeInvalidImportFromTxIsInvalid.json (0.00s)
        --- PASS: TestState/stEWASMTests/validateBytecodeInvalidImportFromTxIsInvalid.json/Byzantium/0 (0.00s)
    --- PASS: TestState/stEWASMTests/validateBytecodeEmptyInitFromTxIsInvalid.json (0.00s)
        --- PASS: TestState/stEWASMTests/validateBytecodeEmptyInitFromTxIsInvalid.json/Byzantium/0 (0.00s)
    --- PASS: TestState/stEWASMTests/validateBytecodeEmptyInitIsInvalid.json (0.00s)
        --- PASS: TestState/stEWASMTests/validateBytecodeEmptyInitIsInvalid.json/Byzantium/0 (0.00s)
    --- PASS: TestState/stEWASMTests/createFromTransactionExceedGasLimit.json (0.00s)
        --- PASS: TestState/stEWASMTests/createFromTransactionExceedGasLimit.json/Byzantium/0 (0.00s)
    --- PASS: TestState/stEWASMTests/callDepth.json (0.07s)
        --- PASS: TestState/stEWASMTests/callDepth.json/Byzantium/0 (0.07s)
PASS
ok      github.com/ethereum/go-ethereum/tests   0.302s
?       github.com/ethereum/go-ethereum/tests/fuzzers/keystore  [no test files]
?       github.com/ethereum/go-ethereum/tests/fuzzers/rlp       [no test files]
?       github.com/ethereum/go-ethereum/tests/fuzzers/trie      [no test files]
?       github.com/ethereum/go-ethereum/tests/fuzzers/txfetcher [no test files]
?       github.com/ethereum/go-ethereum/tests/fuzzers/whisperv6 [no test files]

@meowsbits meowsbits mentioned this issue Mar 10, 2020
@meowsbits
Copy link
Member Author

As of 88f5c66, there's a way to run the test (files) individually with the --evmc.ewasm=/path/to/ewasm.so flag. #57 (comment)

@meowsbits
Copy link
Member Author

meowsbits commented Mar 10, 2020

#!/usr/bin/env bash


ewasm_sos=(
	/home/ia/dev/second-state/SSVM/build/tools/ssvm-evmc/libssvmEVMC.so
	/home/ia/dev/ewasm/hera/build/src/libhera.so
)

set -e
make evmc
make all
set +e

find tests/testdata/GeneralStateTests/stEWASMTests -type f -name '*json' | while read -r line; do
	for so in "${ewasm_sos[@]}"; do
		resdir="test-ewasm-results/$(basename $so)"
		mkdir -p  "$resdir"
		./build/bin/evm --debug --dump --verbosity 2 statetest --evmc.ewasm="$so" "$line" |& tee "$resdir/$(basename $line)"
	done
done

for so in "${ewasm_sos[@]}"; do
	resfile="test-ewasm-results/batch"
	mkdir -p "$resfile"
	resfile="${resfile}/$(basename $so)"
	go test -v ./tests/ -run TestState -evmc.ewasm="${so}" ./tests |& tee "$resfile"
done

@meowsbits
Copy link
Member Author

As of fc424d7, all tests are passing with Hera.

But something is still clearly broken for SSVM, eg.

> ag panic test-ewasm-results/
libssvmEVMC.so/callStaticVeryLong.json
13:     /home/ia/go1.13.5.linux-amd64/go/src/runtime/panic.go:774 +0x72
14:runtime.sigpanic()

Run the script above to reproduce failures on a test-by-test basis.

@dm4 Can you give a hand here?

@hydai
Copy link
Contributor

hydai commented Mar 11, 2020

Hi, @me020523
I am reproducing this issue and trying to fix SSVM in these test cases.

@hydai
Copy link
Contributor

hydai commented Mar 11, 2020

Update:
https://gist.github.com/hydai/5f9bbbcb7a1227e3e0f55fe00f110e23

It looks like SSVM get lots of wasm module instantiation errors. Please give me a moment to analyze these wasm bytecode.

@hydai
Copy link
Contributor

hydai commented Mar 16, 2020

Update:

You can check out to our master branch to get the latest code.
Git Head: [ master ] ( 8631d4606531981524b347ebb72291cd0b343ab0 ).
Although we've fixed several issues, SSVM still failed on 8 test cases. Luckily, all of these 8 test cases will not create segmentation faults. We are going to the remaining issues in a few weeks.

Commit of fixing Passed Crashed Failed
Original 46 8 172
Delete cost table of wasm instructions in ewasm mode. 103 (+57) 8 115 (-57)
Fix EEI function signature error. 103 8 115
Fix bytecode not set into the ewasm environment. 103 8 115
Complete function import matching. 172 (+69) 8 46 (-69)
Fix state error when call function failed in VM. 175 (+3) 8 43 (-3)
Change out-of-gas case to fail rather than revert. 180 (+5) 8 38 (-5)
Fix error of return value in Call() related EEI functions. 198 (+18) 15 (+7) 13 (-25)
Fix memory resizing policy and bound checking in the memory instance. 198 15 13
Add memory bound checking when loading or storing values from memory in EEI functions. 216 (+18) 0 (-15) 10 (-3)
Add lost checking of flag in StorageStore(). 217 (+1) 0 9 (-1)
Handle overflow of uint128 loading and storing. 218 (+1) 0 8 (-1)

meowsbits added a commit that referenced this issue Mar 16, 2020
Updates SSVM dev to latest as mentioned in
#62 (comment)

SSVM still failing 8 state test cases, but not causing seg fault
anymore.

Signed-off-by: meows <b5c6@protonmail.com>
@hydai
Copy link
Contributor

hydai commented Apr 1, 2020

Hi, @meowsbits,
It's been a long time since last update. SSVM released 0.5.0 just now. In this release, we've resolved all issues. Please update to our latest commit and try again. Thanks 😊

@meowsbits
Copy link
Member Author

Issue indeed resolved with SSVM's 0.5.0! 🎉 See 8354c39.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F4-tests 💻 help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants