nspcc-dev/neo-go

step n functionality incorrect

Open

#3,676 opened on Nov 13, 2024

 (0 comments) (1 reaction) (0 assignees)Go (108 forks)auto 404
I3S4U3bughelp wantedvm

Repository metrics

Stars
 (132 stars)
PR merge metrics
 (PR metrics pending)

Description

Current Behavior

step n is described as https://github.com/nspcc-dev/neo-go/blob/66fbcb2f0032ae26350bf5b07231419e2195c8d5/cli/vm/cli.go#L287

However, step does a simple increase of ip + n internally, but instructions are not always 1 byte therefore the new address can be invalid. For example

NEO-GO-VM > loadnef /home/erik/code/neo3-boa/stepcontract.nef
READY: loaded 18 instructions
NEO-GO-VM 0 > ops
INDEX    OPCODE      PARAMETER
0        INITSLOT    1 local, 0 arg    <<
3        PUSH10      
4        STLOC0      
5        JMP         11 (6/06)
7        LDLOC0      
8        PUSH1       
9        SUB         
10       STLOC0      
11       LDLOC0      
12       PUSH0       
13       GT          
14       JMPIF       7 (-7/f9)
16       LDLOC0      
17       RET         

NEO-GO-VM 0 > ip
instruction pointer at 0 (INITSLOT)
NEO-GO-VM 0 > step 2
[
    {
        "type": "Integer",
        "value": "0"
    }
]
NEO-GO-VM > ip
Error: VM is not ready: no program loaded
NEO-GO-VM > reset
NEO-GO-VM > loadnef /home/erik/code/neo3-boa/stepcontract.nef
READY: loaded 18 instructions
NEO-GO-VM 0 > step 3
at breakpoint 3 (PUSH10)

Expected Behavior

I expect step 2 to execute INITSLOT + PUSH10, and step 3 to execute the previous 2 + STLOC0.

Possible Solution

run single step's in a loop to the count of n instead of setting a break point relative to ip.

Steps to Reproduce

loadhex 5701001a70220668119f706810b724f96840

Contributor guide