Evgenii Stratonikov
063c29636b
vm: fail if NEWSTRUCT/NEWARRAY argument is not an integer
...
NEO3 VM does not support creating new Array from a Struct.
For this purpose CONVERT opcode is used.
2020-05-22 14:16:32 +03:00
Evgenii Stratonikov
1a0290edc6
vm: copy slice when converting between Array<->Struct
...
Related #437 . Becase in NEO3 NEWSTRUCT/NEWARRAY accept only an integer
change tests too.
2020-05-22 14:16:32 +03:00
Evgenii Stratonikov
781def735d
vm: use Null item as a default value for Array/Struct elements
2020-05-22 14:16:32 +03:00
Evgenii Stratonikov
3917b4b4e4
vm: update stack size in SETITEM properly
2020-05-21 18:00:51 +03:00
Evgenii Stratonikov
98c508d361
vm: implement MEMCPY opcode
...
MEMCPY copies byte-slice to a destination buffer.
2020-05-20 17:45:56 +03:00
Evgenii Stratonikov
a5f6e0e53d
vm: implement NEWBUFFER opcode
2020-05-20 17:45:56 +03:00
Evgenii Stratonikov
a3a3a77431
vm: make slice opcodes emit Buffer
2020-05-20 17:45:56 +03:00
Evgenii Stratonikov
c3f7832f3b
vm: implement Buffer stack item
...
Buffer is a stack item type introduced in NEO3
which represents mutable byte-array.
2020-05-20 17:45:56 +03:00
Evgenii Stratonikov
0cb6dc47e4
vm: implement slot-related opcodes
...
1. Slot is a new mechanism for storing variables during execution
which is more convenient than alt.stack. This commit implements
support for slot opcodes in both vm and compiler.
2. Remove old alt.stack opcodes.
3. Do not process globals at the start of every function, but instead
load them single time at main.
2020-05-12 16:23:08 +03:00
Evgenii Stratonikov
af2abedd86
vm: implement reference counter
...
It is convenient to have all reference-counting logic
in a separate struct.
2020-05-12 16:15:14 +03:00
Evgenii Stratonikov
1d3fb3d6f5
vm: implement PUSHA/CALLA opcodes
2020-05-12 12:56:51 +03:00
Evgenii Stratonikov
7fcd537b09
vm: implement Pointer stack item
...
Pointer is a generic address type in VM.
It is used for calling lambda-expressions.
2020-05-12 12:55:31 +03:00
Evgenii Stratonikov
73c82584a3
vm,compiler: replace APPCALL with System.Contract.Call
...
Contract calls are performed via syscall System.Contract.Call
in NEO3. This implements this in compiler and removes APPCALL from the
VM.
2020-05-07 14:52:03 +03:00
Evgenii Stratonikov
dd20320615
vm: remove XSWAP/XTUCK opcodes
...
Regenerate RPC testchain as these were used in compiler.
2020-05-06 13:05:22 +03:00
Evgenii Stratonikov
d18199ce42
vm: implement REVERSE* opcodes
...
Use new opcodes in the compiler instead of XSWAP/ROLL.
2020-05-06 13:03:49 +03:00
Evgenii Stratonikov
c8a1188ee1
vm: implement CLEAR opcode
2020-05-06 13:02:57 +03:00
Evgenii Stratonikov
c8328981ec
vm: refactor tests
...
Most of the tests follow the same logic:
push items on stack -> execute program -> check single result.
This commit reuses this function in most of the tests.
2020-04-30 19:29:52 +03:00
Evgenii Stratonikov
9081211f12
vm: implement NOTEQUAL opcode
2020-04-30 18:00:15 +03:00
Evgenii Stratonikov
70f0c656b0
vm: check Integer size on creation
2020-04-30 18:00:15 +03:00
Evgenii Stratonikov
519b31a704
vm: remove crypto-related opcodes
...
All cryptography has moved to interops in NEO3.
There is no SHA256 interop RN, but it is to appear later.
Closes #777 .
2020-04-29 19:16:38 +03:00
Evgenii Stratonikov
7e98a2ffa0
vm: implements CONVERT opcode
2020-04-28 16:38:52 +03:00
Evgenii Stratonikov
7c3d7c0261
vm: implement NEWARRAYT opcode
2020-04-27 09:06:48 +03:00
Evgenii Stratonikov
d3b9aef8e2
vm: implement ISTYPE opcode
...
Also make StackItemType public and reorder it according to NEO3.
2020-04-27 09:01:26 +03:00
Evgenii Stratonikov
48a41bd737
vm: implement CLEARITEMS opcode
2020-04-27 09:01:26 +03:00
Evgenii Stratonikov
9fd04aefa5
vm: implement NEWARRAY0 and NEWSTRUCT0 opcodes
2020-04-24 13:49:10 +03:00
Evgenii Stratonikov
03761421f8
vm: reorder Array/Map opcodes
...
Also SIZE can be used for both Arrays/Maps and ByteArrays.
2020-04-24 13:48:44 +03:00
Evgenii Stratonikov
d6624a92ca
vm: implement new JMP* and CALL* opcodes
...
In compiler JMP*_L opcodes are always used, as this requires less effort.
2020-04-24 10:16:41 +03:00
Evgenii Stratonikov
fba185cd99
vm: remove stack isolation opcodes
...
They are not present in NEO3 and will be creating additional difficulties
during future flow-control opcodes implementation.
2020-04-24 10:15:14 +03:00
Evgenii Stratonikov
008e6eb233
vm: implement new PUSH opcodes
2020-04-23 10:52:28 +03:00
Evgenii Stratonikov
1a54be279e
vm: simplify SimpleCall test
...
It was taken from the compiler output, but there is
no need in using a lot of complex instructions.
2020-04-23 10:36:44 +03:00
Evgenii Stratonikov
cde4ccf01c
vm: remove CHECKSIG/VERIFY/CHECKMULTISIG opcodes
2020-04-20 11:55:24 +03:00
Roman Khimov
91f8626c42
vm: disallow negative shifts for SHL/SHR
...
Follow neo-project/neo-vm#257 change for Neo 3.
2020-04-19 19:15:00 +03:00
Evgenii Stratonikov
ceff8736f2
vm: use ID-based syscalls
...
In NEO3 SYSCALL opcode has 4-byte ID parameter.
This commit removes support for string-based syscalls and
changes SYSCALL's parameter to be fixed 4-byte value.
2020-04-17 11:46:31 +03:00
Evgenii Stratonikov
bfbbef952a
vm: move InteropNameToID to emit package
2020-04-17 11:46:31 +03:00
Evgenii Stratonikov
93d2a3e031
vm: serialize zero Integer to an empty ByteArray
2020-04-17 11:46:31 +03:00
Evgenii Stratonikov
5dba30a49d
vm: update bool -> []byte conversion to NEO 3
...
This reverts commit 4c688355bc
.
2020-04-17 11:46:31 +03:00
Evgenii Stratonikov
2fd26287c5
vm: update SUBSTR to NEO3 version
...
This reverts commit 9ebb793009
.
2020-04-17 11:46:31 +03:00
Evgenii Stratonikov
3831aec53f
vm: make NewBigInteger accept *big.Int
...
It creates big.Int internally anyway, so this is the most flexible way.
2020-04-16 15:54:58 +03:00
Evgenii Stratonikov
948729137f
vm: remove HASH160/HASH256 opcodes
2020-04-13 13:47:39 +03:00
Roman Khimov
5a22651e36
Merge pull request #784 from nspcc-dev/neo3/null
...
vm: support NULL stack item
2020-04-10 10:38:17 +03:00
Anna Shaleva
9f0bc2aaf5
vm: add tests to CALL* instructions
...
closes #452
2020-04-09 11:20:39 +03:00
Anna Shaleva
495c1b0565
vm: add tests for missing bit and numeric operations
...
Added tests for:
- bit operatoins: AND, OR, XOR
- numeric operations: BOOLOR, MIN, MAX, WITHIN, NEGATE
2020-04-07 18:10:31 +03:00
Evgenii Stratonikov
96806262bf
vm: handle negative arguments in SHL/SHR
...
Do it as in reference implementation: a >> -b == a << b.
2020-04-06 10:46:35 +03:00
Evgenii Stratonikov
0023c4f1f6
vm: use truncated division in MOD
...
Mimic C#'s `%` behavior.
Related 4b44190
(#773 ).
2020-04-06 09:30:48 +03:00
Evgenii Stratonikov
f7f48d0048
vm: implement ISNULL opcode
2020-04-02 14:15:17 +03:00
Evgenii Stratonikov
3db030bbb6
vm: implement PUSHNULL opcode
2020-04-02 14:15:17 +03:00
Roman Khimov
2d0ad30fcf
vm: rework Map with internal slice representation
...
Which makes iterating over map stable which is important for serialization and
and even fixes occasional test failures. We use the same ordering here as
NEO 3.0 uses, but it should also be fine for NEO 2.0 because it has no
defined order.
2020-04-01 19:33:53 +03:00
Roman Khimov
665bf78d11
vm: make map serialization more compatible with C#
...
C# pushes value and key to the stack of non-serialized items, so key gets
serialized first followed by value. Fixes #806 .
Notice though that neither IDictionary in C#, nor map in Go have elements
ordered, so we can easily get a difference in KV pairs order and it would be
impossible to fix.
2020-03-28 17:25:42 +03:00
Evgenii Stratonikov
4b44190485
vm: use truncated division for Integers
...
When divisor is negative, the result is truncated towards
zero.
2020-03-17 15:45:56 +03:00
Roman Khimov
1b5dd53e07
Merge pull request #746 from nspcc-dev/fix/equal
...
vm: implement EQUAL opcode properly
Fixes #745 , #749 .
2020-03-12 11:46:51 +03:00
Evgenii Stratonikov
dfc59129c7
vm: implement EQUAL opcode properly
...
When comparing elements of different types, conversions
should be performed. This commit implement custom equality
predicate for each stack item type.
2020-03-11 17:19:10 +03:00
Roman Khimov
8318adac56
vm: add support for dynamic invocations in APPCALL
...
Fixes #740 .
2020-03-10 17:17:36 +03:00
Roman Khimov
e41d434a49
*: move all packages from CityOfZion to nspcc-dev
2020-03-03 17:21:42 +03:00
Evgenii Stratonikov
a3dacd3b74
tests: replace t.Fatal with require where possible
...
This makes tests less verbose and unifies the style
they are written in.
2020-03-02 17:22:27 +03:00
Roman Khimov
268cad5c06
Merge pull request #548 from nspcc-dev/feature/multisig
...
vm: implement parallel algorithm for CHECKMULTISIG
2020-02-08 16:10:34 +03:00
Roman Khimov
9b9adb28c1
Merge pull request #642 from nspcc-dev/feature/emit
...
vm, compiler: move Emit* functions to a separate package
Closes #449 , #534 .
2020-02-08 15:56:48 +03:00
Roman Khimov
b805b1a71b
vm: make SerializeItem/DeserializeItem public APIs
...
They're useful as wrappers around EncodeBinaryStackItem/DecodeBinaryStackItem.
2020-02-07 15:34:59 +03:00
Evgenii Stratonikov
8243a8b3a7
emit: use io.BinWriter instead of bytes.Buffer
2020-02-06 18:45:37 +03:00
Evgenii Stratonikov
4d8a3a359b
vm: move Emit* functions to a separate package
...
Also strip 'Emit' prefix because 'emit' is now
in the package name.
2020-02-06 18:45:37 +03:00
Evgenii Stratonikov
2a86149c82
vm: leave single CHECKMULTISIG implementation
...
Remove sequential implementation and benchmarks.
They will be still present in commit history.
2020-02-05 17:17:22 +03:00
Evgenii Stratonikov
d93d060010
vm: parallelize CHECKMULTISIG
2020-02-05 17:12:18 +03:00
Evgenii Stratonikov
c22d09adad
vm: set GAS limit
...
Make it possible to set maximum amount of GAS which can be spent
during execution.
2020-01-22 14:04:40 +03:00
Evgenii Stratonikov
0662a7e3c2
vm: calculate GAS spent during execution
...
If getPrice callback is provided, accumulate spent GAS.
2020-01-22 14:04:40 +03:00
Evgenii Stratonikov
f0083b94c5
vm: use new big.Int (de-)serialization routines
...
Also fix a test with CAT.
2020-01-17 17:37:50 +03:00
Roman Khimov
46b82b4fb5
keys: don't return error from PrivateKey.Sign
...
As it can't ever happen.
2020-01-17 17:00:30 +03:00
Evgenii Stratonikov
5bc32b523a
vm: implement Neo.Iterator.* interops
2019-12-24 10:21:47 +03:00
Evgenii Stratonikov
3ff7fd5262
vm: implement Neo.Enumerator.* interops
2019-12-24 10:21:46 +03:00
Roman Khimov
a7457d08a1
vm/core: add ID support for SYSCALL, redo interop registration
...
This solves two problems:
* adds support for shortened SYSCALL form that uses IDs (similar to #434 , but
for NEO 2.0, supporting both forms), which is important for compatibility
with C# node and mainnet chain that uses it from some height
* reworks interop plugging to use callbacks rather than appending to the map,
these map mangling functions are clearly visible in the VM profiling
statistics and we want spawning a VM to be fast, so it makes sense
optimizing it. This change moves most of the work to the init() phase
making VM setup cheaper.
Caveats:
* InteropNameToID accepts `[]byte` because that's the thing we have in
SYSCALL processing and that's the most often usecase for it, it leads to
some conversions in other places but that's acceptable because those are
either tests or init()
* three getInterop functions are: `getDefaultVMInterop`, `getSystemInterop`
and `getNeoInterop`
Our 100K (1.4M->1.5M) block import time improves by ~4% with this change.
2019-12-19 13:35:42 +03:00
Roman Khimov
10766fe813
vm: add tests for hashing instructions
...
These were cross-checked with the C# implementation.
2019-12-17 20:31:16 +03:00
Roman Khimov
21efcb012b
vm: fix non-dupped items in PICKITEM
...
TestPICKITEMDupMap and TestPICKITEMDupArray were failing.
2019-12-17 20:26:30 +03:00
Roman Khimov
a6d60e387a
vm: fix OVER and PICK to duplicate stack items
...
TestPICKDup and TestOVERDup failed without this.
2019-12-17 20:26:30 +03:00
Roman Khimov
60dfa05b19
vm: duplicate an item in Dup
...
TestDupByteArray and TestDupInt were failing before this patch.
2019-12-17 20:26:30 +03:00
Roman Khimov
c596a6b273
vm: fix INVERT behaviour for converted values
...
Tests added were failing before this change.
2019-12-17 20:26:30 +03:00
Roman Khimov
587cfc7c66
vm: optimize ROLL/ROT, refactor common code
...
Add `Roll` method to Stack that doesn't pop and push values and use it for
ROLL and ROT.
1.4M->1.5M 100K block import test before:
real 3m44,292s
user 5m43,494s
sys 0m34,741s
After:
real 3m40,449s
user 5m42,701s
sys 0m35,500s
2019-12-16 19:53:21 +03:00
Roman Khimov
2627628387
vm: optimize SWAP instruction, refactor common code
...
Add `Swap` method to the Stack and use it for both SWAP and XSWAP. Avoid
element popping and pushing (and associated accounting costs).
1.4M->1.5M 100K block import test before:
real 3m51,885s
user 5m54,744s
sys 0m38,444s
After:
real 3m44,292s
user 5m43,494s
sys 0m34,741s
2019-12-16 19:02:40 +03:00
Roman Khimov
d0f9a28196
vm/core: improve block import speed with PublicKey caching
...
This change (closely related to the neo-project/neo#1321 proposal) speeds up
1.4M mainnet blocks import by 30%. Basically, we're eliminating key decoding
for block's multisignature that has the same keys most of the time.
Things I don't like about this patch:
* yet another parameter for verifyHashAgainstScript()
* vm keys are not copied in/out
But it's rather simple and solves the problem for this particular case, so I
think it's worth it.
2019-12-10 19:13:29 +03:00
Evgenii Stratonikov
7179e4ba9f
util: add LE suffix to Uint256 methods
2019-12-06 12:16:55 +03:00
Evgenii Stratonikov
57efad912c
util: add LE suffix to Uint160 methods
2019-12-06 12:16:55 +03:00
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