Commit graph

80 commits

Author SHA1 Message Date
Roman Khimov
8d4dd2d2e1 vm: move opcodes into their own package
This allows easier reuse of opcodes and in some cases allows to eliminate
dependencies on the whole vm package, like in compiler that only needs opcodes
and doesn't care about VM for any other purpose.

And yes, they're opcodes because an instruction is a whole thing with
operands, that's what context.Next() returns.
2019-12-03 18:22:14 +03:00
Evgenii Stratonikov
7080b78a6b vm: fix a bug in collection serialize
When encountering already seen stack item we should fail
only if it is a collection. Duplicate Integers or ByteArrays are ok
because they can't lead to recursion.
2019-11-15 12:48:00 +03:00
Evgenii Stratonikov
816d78b5ee vm: redefine SHL/SHR limits based on integer size 2019-11-07 12:50:11 +03:00
Evgenii Stratonikov
439cd72294 vm: restrict BigInteger item size 2019-11-07 12:34:27 +03:00
Evgenii Stratonikov
9ebb793009 vm: revert SUBSTR offset behavior to NEO 2.x 2019-11-06 12:15:55 +03:00
Evgenii Stratonikov
4c688355bc vm: revert bool -> []byte conversion to NEO 2.x 2019-11-06 12:15:48 +03:00
067d9655bf vm: restrict total stack item count 2019-11-06 11:03:43 +03:00
412582dc78 vm: add more serialization tests 2019-11-05 17:04:14 +03:00
59f9c2bddc vm: implement Array and Struct item serialization 2019-11-05 16:58:09 +03:00
e1d019e087 vm: implement Map item serialization 2019-11-05 16:57:48 +03:00
cd690803cf vm: implement BigInteger item serialization 2019-11-05 15:15:43 +03:00
25f77257ce vm: implement Boolean and ByteArray item serialization 2019-11-05 15:15:39 +03:00
c7f0b7bd68 vm: restrict max invocation stack size 2019-10-29 15:09:17 +03:00
Roman Khimov
f0cffe0d3f vm: implement stack isolation opcodes, fix #192
No tests yet.
2019-10-25 18:25:12 +03:00
Roman Khimov
3cbb699eb7
Merge pull request #426 from nspcc-dev/logger_247
Change fmt.Println to log, close #247.
2019-10-22 14:41:30 +03:00
Vsevolod Brekelov
e2bfff8666 vm: removed mute mode and pushed logging to upper lvl
VM should be responsible for code execution and in case anyone interested in additional logging or errors they could handle them like we do it iin cli.
2019-10-22 13:44:14 +03:00
Evgenii Stratonikov
b2609786e9 vm: copy slice in NEWARRAY/NEWSTRUCT
When performing NEWARRAY on a Struct or NEWSTRUCT on a Array,
underlying slice needs to be copied, because when it's capacity
doesn't matches it's length, underlying storage will be used
for appends even if it is already pointed at by another slice.
2019-10-22 13:34:35 +03:00
Evgenii Stratonikov
487570153b vm: restrict max item size in PUSHDATA4 2019-10-17 17:10:00 +03:00
Evgenii Stratonikov
cae431b844 vm: restrict max item size in CAT 2019-10-17 17:09:42 +03:00
Evgenii Stratonikov
6d7016c3b9 vm: restrict max size in SETITEM 2019-10-17 12:17:06 +03:00
Evgenii Stratonikov
6f1f9e56bb vm: restrict max size in PACK 2019-10-17 12:17:06 +03:00
Evgenii Stratonikov
2d56c66bde vm: restrict max size in APPEND 2019-10-17 12:17:01 +03:00
Evgenii Stratonikov
8abcaeee6f vm: restrict max size in NEWARRAY/NEWSTRUCT 2019-10-17 11:48:48 +03:00
Roman Khimov
53a3b18652 vm: completely separate instruction read and execution phases
Make Context.Next() return both opcode and instruction parameter if any. This
simplifies some code and needed to deal with #295.
2019-10-04 16:13:39 +03:00
Roman Khimov
26e3b6abbe vm: extend interops to contain price
The same way C# node does.
2019-10-04 16:13:39 +03:00
Roman Khimov
ceca9cdb67 core/vm: implement contract storage and script retrieval
Fixes script invocations via the APPCALL instruction. Adjust contract state
field types accordingly.
2019-10-04 16:13:39 +03:00
Evgenii Stratonikov
13d7770c68 vm: support Map in ARRAYSIZE
Also make logic the same as in reference implementation
and add tests.
2019-09-25 17:53:36 +03:00
Evgenii Stratonikov
c66f493017 vm: compare Map by reference in EQUAL 2019-09-25 17:53:36 +03:00
Evgenii Stratonikov
c0be2b2a99 vm: support Map in REMOVE 2019-09-25 17:53:36 +03:00
Evgenii Stratonikov
8b6bddca3c vm: support Map in PICKITEM and SETITEM 2019-09-25 17:53:36 +03:00
Evgenii Stratonikov
d7bb50c609 vm: implement VALUES opcode 2019-09-25 17:53:36 +03:00
Evgenii Stratonikov
2da64267b0 vm: implement KEYS opcode 2019-09-25 17:53:34 +03:00
Evgenii Stratonikov
0fb4bb05cf vm: implement HASKEY opcode 2019-09-25 12:08:41 +03:00
Roman Khimov
ca9c9be71f vm: add CHECKSIG/VERIFY/CHECKMULTISIG implementations
Fix #269.
2019-09-24 13:01:54 +03:00
Roman Khimov
3bbeb2476e vm: introduce HasFailed() method and use it where appropriate
It's gonna be used by external modules.
2019-09-23 20:19:07 +03:00
Evgenii Stratonikov
3c53beca82 vm: restrict SHL/SHR arguments to -256..256
Also unify SHL/SHR implementation.
2019-09-23 15:13:10 +03:00
Evgenii Stratonikov
4a8be486f0 vm: do not pop items in OVER 2019-09-23 14:54:59 +03:00
Evgenii Stratonikov
7cd69ea8e2 vm: truncate length in SUBSTR
Also fail on first error, without changing the stack.
2019-09-23 14:54:59 +03:00
Evgenii Stratonikov
a88a8e13fc vm: compare Array by reference in EQUAL 2019-09-23 13:25:59 +03:00
Evgenii Stratonikov
99f1d761ca vm: clone Struct on APPEND 2019-09-23 13:25:59 +03:00
Evgenii Stratonikov
d2ccc3b017 vm: make REVERSE consume an item from stack 2019-09-16 15:50:51 +03:00
Evgenii Stratonikov
fd264cb06f vm: make REVERSE work with structs
Also add more tests.
Extend `Array` method of `Element` to work with `StructItem`.
2019-09-16 15:50:51 +03:00
Evgenii Stratonikov
f0426ac2d5 vm: do nothing if SHL/SHR by 0 2019-09-16 15:50:51 +03:00
Evgenii Stratonikov
9eca5ee317 vm: convert SIZE argument to bytearray 2019-09-16 15:50:51 +03:00
Evgenii Stratonikov
9780889239 vm: make NEWARRAY/NEWSTRUCT accept bytearray 2019-09-16 15:50:51 +03:00
Evgenii Stratonikov
66501f9ef9 vm: make REMOVE consume array from stack 2019-09-16 15:50:14 +03:00
Evgenii Stratonikov
71cfd14b92 vm: create an array of false items in NEWARRAY/NEWSTRUCT 2019-09-16 15:24:58 +03:00
Evgenii Stratonikov
bafdb916a0 vm: make PICKITEM accept bytearrays 2019-09-16 15:24:58 +03:00
Evgenii Stratonikov
1881adabb9 vm: fail if NIP has not enough arguments 2019-09-16 15:24:58 +03:00
Evgenii Stratonikov
6e4014547d vm: fail if DROP has no argument 2019-09-16 15:24:58 +03:00