Commit d66f8532 authored by Inphi's avatar Inphi Committed by GitHub

cannon: Fix parentheses in syscall noop handling (#13470)

* cannon: Fix parentheses in syscall noop handling

* cannon: Add cannon64 test case for the undefined syscall path
parent b6cf8ee2
...@@ -213,7 +213,7 @@ func (m *InstrumentedState) handleSyscall() error { ...@@ -213,7 +213,7 @@ func (m *InstrumentedState) handleSyscall() error {
case arch.SysLseek: case arch.SysLseek:
default: default:
// These syscalls have the same values on 64-bit. So we use if-stmts here to avoid "duplicate case" compiler error for the cannon64 build // These syscalls have the same values on 64-bit. So we use if-stmts here to avoid "duplicate case" compiler error for the cannon64 build
if arch.IsMips32 && syscallNum == arch.SysFstat64 || syscallNum == arch.SysStat64 || syscallNum == arch.SysLlseek { if arch.IsMips32 && (syscallNum == arch.SysFstat64 || syscallNum == arch.SysStat64 || syscallNum == arch.SysLlseek) {
// noop // noop
} else { } else {
m.Traceback() m.Traceback()
......
...@@ -482,3 +482,26 @@ func TestEVM_UnsupportedSyscall64(t *testing.T) { ...@@ -482,3 +482,26 @@ func TestEVM_UnsupportedSyscall64(t *testing.T) {
testUnsupportedSyscall(t, unsupportedSyscalls) testUnsupportedSyscall(t, unsupportedSyscalls)
} }
// Asserts the undefined syscall handling on cannon64 triggers a VM panic
func TestEVM_UndefinedSyscall(t *testing.T) {
// These syscalls all have the same value. We enumerate them here anyways for completeness.
undefinedSyscalls := map[string]uint64{
"SysFstat64": arch.SysFstat64,
"SysStat64": arch.SysStat64,
"SysLlseek": arch.SysLlseek,
}
for name, val := range undefinedSyscalls {
t.Run(name, func(t *testing.T) {
t.Parallel()
goVm, state, contracts := setup(t, int(val), nil)
testutil.StoreInstruction(state.Memory, state.GetPC(), syscallInsn)
state.GetRegistersRef()[2] = Word(val) // Set syscall number
proofData := multiThreadedProofGenerator(t, state)
require.Panics(t, func() { _, _ = goVm.Step(true) })
errorMessage := "unimplemented syscall"
testutil.AssertEVMReverts(t, state, contracts, nil, proofData, testutil.CreateErrorStringMatcher(errorMessage))
})
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment