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

can not run smart contract script, the vm throw FAULT message. #96

Closed
shelmesky opened this issue Sep 10, 2018 · 9 comments
Closed

can not run smart contract script, the vm throw FAULT message. #96

shelmesky opened this issue Sep 10, 2018 · 9 comments
Labels
I2 Regular impact vm VM tasks/bugs/issues
Milestone

Comments

@shelmesky
Copy link

shelmesky commented Sep 10, 2018

First i start local neo node by run this command: make run, then i try to run smart contract script token_sale.go:

NEO-GO-VM > loadgo token_sale.go
READY: loaded 2996 instructions
NEO-GO-VM > run
NEO-GO-VM > error encountered at instruction 9 (Oroll)
NEO-GO-VM > runtime error: invalid memory address or nil pointer dereference
FAULT
NEO-GO-VM > error encountered at instruction 10 (Osetitem)
NEO-GO-VM > interface conversion: interface {} is []vm.StackItem, not []uint8
FAULT
NEO-GO-VM 10 >

@anthdm
Copy link

anthdm commented Sep 12, 2018

@shelmesky Thanks for your bug report, The old neo-go VM have some issues on new API's I implemented. I'm currently rewriting the VM to be compatible with the new APIS that are in neo-storm. This will not take longer then a week. I will keep you posted on this issue when its completed. The improved VM will also house in the neo-storm repository. Thanks for your understanding.

@shelmesky
Copy link
Author

Thank you @anthdm . I have check the neo-storm repository, but i can not find a virtual machine in there. Can you tell me where to find a runnable virtual machine and written by golang? thanks a lot!

@anthdm
Copy link

anthdm commented Sep 25, 2018

@shelmesky I'm currently working on it :) should not take to long. 2 weeks max.

@hal0x2328
Copy link
Contributor

@anthdm Is this completed?

@im-kulikov
Copy link
Contributor

@hal0x2328 nope, I test that yesterday

@hal0x2328 hal0x2328 added the I2 Regular impact label Feb 25, 2019
@roman-khimov
Copy link
Member

Reproducible on current master:

$ go run cli/main.go vm

    _   ____________        __________      _    ____  ___
   / | / / ____/ __ \      / ____/ __ \    | |  / /  |/  /
  /  |/ / __/ / / / /_____/ / __/ / / /____| | / / /|_/ / 
 / /|  / /___/ /_/ /_____/ /_/ / /_/ /_____/ |/ / /  / /  
/_/ |_/_____/\____/      \____/\____/      |___/_/  /_/   


NEO-GO-VM > loadgo examples/token-sale/token_sale.go
READY: loaded 3017 instructions
NEO-GO-VM > run
NEO-GO-VM > error encountered at instruction 9 (Oroll)
NEO-GO-VM > runtime error: invalid memory address or nil pointer dereference
FAULT
NEO-GO-VM > error encountered at instruction 10 (Osetitem)
NEO-GO-VM > interface conversion: interface {} is []vm.StackItem, not []uint8
FAULT

@roman-khimov roman-khimov added this to the v0.5.0 milestone Aug 26, 2019
@roman-khimov roman-khimov added the compiler Go smart contract compiler label Aug 30, 2019
@roman-khimov
Copy link
Member

I think the problem actually is in the codegen, it can be simplified to this one

$ cat h.go
package tokensale

func Main(operation string, args []interface{}) interface{} {
        return true
}
$ ./bin/neo-go vm

    _   ____________        __________      _    ____  ___
   / | / / ____/ __ \      / ____/ __ \    | |  / /  |/  /
  /  |/ / __/ / / / /_____/ / __/ / / /____| | / / /|_/ / 
 / /|  / /___/ /_/ /_____/ /_/ / /_/ /_____/ |/ / /  / /  
/_/ |_/_____/\____/      \____/\____/      |___/_/  /_/   


NEO-GO-VM > loadgo h.go
READY: loaded 17 instructions
NEO-GO-VM > ops
INDEX    OPCODE    DESC               
0        0x53      PUSH3              
1        0xc5      NEWARRAY           
2        0x6b      TOALTSTACK         
3        0x6a      DUPFROMALTSTACK    
4        0x 0      PUSH0              
5        0x52      PUSH2              
6        0x7a      ROLL               
7        0xc4      SETITEM            
8        0x6a      DUPFROMALTSTACK    
9        0x51      PUSH1              
10       0x52      PUSH2              
11       0x7a      ROLL               
12       0xc4      SETITEM            
13       0x51      PUSH1              
14       0x6c      FROMALTSTACK       
15       0x75      DROP               
16       0x66      RET                
NEO-GO-VM > run
NEO-GO-VM > error encountered at instruction 6 (ROLL)
NEO-GO-VM > runtime error: invalid memory address or nil pointer dereference
FAULT
NEO-GO-VM > error encountered at instruction 7 (SETITEM)
NEO-GO-VM > interface conversion: interface {} is []vm.StackItem, not []uint8
FAULT

It tries to get the stack item with index number 2 with ROLL, but it doesn't exist. But there are also some issues in the VM: nil pointer dereference (instead of error detection and messaging) and execution of the next instruction in FAULT state.

@roman-khimov
Copy link
Member

Or it's not an issue on the compiler side at all, because it can be reduced even further to:

package tokensale

func Main(operation int) interface{} {
 return true
}

And in all these examples Main() has some parameters that it expects to be passed into it while we're not actually passing (putting on the stack) anything, so it breaks. What we're missing at the moment is the possibility to pass parameters to the VM script from CLI (also true for testinvoke contract functionality).

@roman-khimov roman-khimov added vm VM tasks/bugs/issues and removed compiler Go smart contract compiler labels Aug 30, 2019
roman-khimov added a commit that referenced this issue Aug 31, 2019
Current VM implementation doesn't return errors for many operations, so the
only way to handle it here is to check for NULL. Refs. #96.
roman-khimov added a commit that referenced this issue Aug 31, 2019
Fixes one more instruction being ran when VM FAULTs:

NEO-GO-VM > run
NEO-GO-VM > error encountered at instruction 6 (ROLL)
NEO-GO-VM > runtime error: invalid memory address or nil pointer dereference
FAULT
NEO-GO-VM > error encountered at instruction 7 (SETITEM)
NEO-GO-VM > interface conversion: interface {} is []vm.StackItem, not []uint8

Refs. #96.
roman-khimov added a commit that referenced this issue Aug 31, 2019
This fixes two minor things observed in #96:

    running VM twice, which leads to instruction execution attempt for VM in FAULT state
    panicing with nil dereference (it's better to show some error message)

Before this patchset:

NEO-GO-VM > run
NEO-GO-VM > error encountered at instruction 6 (ROLL)
NEO-GO-VM > runtime error: invalid memory address or nil pointer dereference
FAULT
NEO-GO-VM > error encountered at instruction 7 (SETITEM)
NEO-GO-VM > interface conversion: interface {} is []vm.StackItem, not []uint8

After this patchset:

NEO-GO-VM > run
NEO-GO-VM > error encountered at instruction 6 (ROLL)
NEO-GO-VM > bad index
FAULT
@roman-khimov
Copy link
Member

Closing this one, minor problems were fixed in #331 and parameters are subject of #332.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I2 Regular impact vm VM tasks/bugs/issues
Projects
None yet
Development

No branches or pull requests

5 participants