Roman Khimov
bf9ecc2bd3
vm: improve REVERSEITEMS for 1M Buffer
...
Before:
BenchmarkOpcodes/REVERSEITEMS/buffer/1M-8 1680 758747 ns/op
After:
BenchmarkOpcodes/REVERSEITEMS/buffer/1M-8 2649 442720 ns/op
2020-11-06 23:31:26 +03:00
Roman Khimov
2522271161
vm: use Application trigger by default
...
Don't mess with System, it's too powerful to be the default.
2020-10-29 19:17:07 +03:00
Roman Khimov
27a01c7759
vm: optimize stack traversal on exception handling
...
Before:
BenchmarkOpcodes/THROW/0/1-8 10000 506 ns/op
BenchmarkOpcodes/THROW/0/16-8 10000 524 ns/op
BenchmarkOpcodes/THROW/255/0-8 10000 49363 ns/op
BenchmarkOpcodes/THROW/1023/0-8 10000 1628480 ns/op
After:
BenchmarkOpcodes/THROW/0/1-8 10000 575 ns/op
BenchmarkOpcodes/THROW/0/16-8 10000 516 ns/op
BenchmarkOpcodes/THROW/255/0-8 10000 8290 ns/op
BenchmarkOpcodes/THROW/1023/0-8 10000 34605 ns/op
2020-10-15 16:20:34 +03:00
Roman Khimov
3d8434a50c
vm: fix invocation stack checks
...
It should be done on every new context push.
2020-10-15 16:20:34 +03:00
Anna Shaleva
fe1f0a7245
core: introduce CheckReturnState constants
...
At the moment we should have 3 possible options to check return state
during vm context unloading:
* no check
* ensure the stack is empty
* ensure the stack is not empty
It is necessary to distinguish them because new _deploy method shouldn't
left anything on stack. Example: if we use _deploy method before some
ordinary contract method which returns one value. Without these changes
the contract invocation will fail due to 2 elements on stack left after
invocation (the first `null` element is from _deploy, the second element
is return-value from the ordinary contract method).
2020-10-13 19:14:44 +03:00
Anna Shaleva
cbf89fbb19
vm: add Call method which increments invocation counter
2020-10-08 16:25:45 +03:00
Anna Shaleva
6ce00fde82
vm, core: move invocation counter from InteropContext to VM
2020-10-08 11:33:26 +03:00
Anna Shaleva
66ca654b07
vm: refactor ISNULL opcode handling
2020-09-29 18:46:20 +03:00
Anna Shaleva
543fd58e93
vm: restrict map key size
2020-09-29 18:46:15 +03:00
Roman Khimov
26339c75dc
vm/core: drop old key caching system
...
Obsoleted by f5f58a7e91
.
2020-09-10 14:43:24 +03:00
Evgenii Stratonikov
04f5fdefa0
vm: properly unload context on exception
...
Do not copy exception context on CALL*.
2020-08-27 10:28:50 +03:00
Evgenii Stratonikov
ab4cd8a990
vm: fix typo in MEMCPY handling
2020-08-25 08:53:29 +03:00
Roman Khimov
681ae4d5d6
vm: fix TRY offsets check
...
TRY can have an offset != 0 and still it can't have both parameters set to
zero.
2020-08-24 16:20:57 +03:00
Roman Khimov
32112249d5
vm: limit maximum nesting of exception contexts
...
Follow neo-project/neo#365 . neo-vm submodule is updated just to show the
relevant latest commit, nothing really changed there.
2020-08-24 15:37:39 +03:00
Roman Khimov
324f4c265b
stackitem: don't copy existing slices for TryBytes
...
Most often we only need to read them and it doesn't require copying. Make an
explicit copy (and copy only things we need!) where needed.
After the recent neo-vm tests update our vm package testing time jumped to
~12s, with this change it's now more like ~8s.
2020-08-22 23:36:38 +03:00
Roman Khimov
74097ae8b0
stackitem: add NewPointerWithHash() to save on hash calculations
...
Inspired by neo-project/neo-vm#352 . We can't directly compare slices, so we're
better optimize things we already have. At the same time this code would
behave a bit different if A is to call B and then B is call A and then some
pointer from the first A invocation is to be compared with a pointer from the
second A invocation. Not sure it really matters.
2020-08-22 22:19:44 +03:00
Evgenii Stratonikov
a080d24cf5
vm: fix debugger and add tests
...
1. `Run()` must be able to continue execution after a breakpoint.
2. VM must stop right before the breakpoint, not after.
3. Initial vm state is NONE, not HALT.
2020-08-18 11:26:27 +03:00
Evgenii Stratonikov
b2e53fedac
vm: pretty-print SYSCALL opcode
2020-08-14 14:22:46 +03:00
Evgenii Stratonikov
9cc6e22365
vm: pretty-print ST*/LD* opcodes
2020-08-13 10:38:13 +03:00
Evgenii Stratonikov
7d08d38cd2
vm: pretty-print PUSHINT* opcodes
2020-08-13 10:38:13 +03:00
Evgenii Stratonikov
92ddc474d8
vm: pretty-print CONVERT and ISTYPE opcodes
2020-08-13 10:38:13 +03:00
Evgenii Stratonikov
bf01599430
vm: check return value on context unload
...
When calling external contracts we expect exactly 1 value to be on
stack. For methods returning nothing, `Null` value is pushed, otherwise
it is an error.`
2020-08-10 11:52:33 +03:00
Roman Khimov
f5131491b7
Merge pull request #1271 from nspcc-dev/core/call_from_native
...
core: contractCall from native contracts
2020-08-07 21:24:50 +03:00
Anna Shaleva
c87e2262c3
core: remove ScriptHashGetter from interop context
...
We have VM inside the context, so don't need ScriptHashGetter anymore.
2020-08-07 20:31:20 +03:00
Roman Khimov
5ef08f60ae
remove github.com/pkg/errors from dependencies
...
It's not needed any more with Go 1.13 as we have wrapping/unwrapping in base
packages. All errors.Wrap calls are replaced with fmt.Errorf, some strings are
improved along the way.
2020-08-07 12:21:52 +03:00
Evgenii Stratonikov
54590062e6
vm: use raw stack items when printing stack
...
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-31 16:07:16 +03:00
Evgenii Stratonikov
51ae12e4fd
*: move syscall handling out of VM
...
Remove interop-related structures from the `vm` package.
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-29 13:41:08 +03:00
fyrchik
b187dfe3ce
Merge pull request #1236 from nspcc-dev/rpc/getrawmempool
...
rpc: update `getrawmempool` and `getrawtransaction` RPC-calls
2020-07-29 10:18:51 +03:00
Anna Shaleva
70ef733ce7
core, vm: store VMState as byte instead of string
...
Part of #1183
2020-07-29 10:14:08 +03:00
Evgenii Stratonikov
466af55dea
vm: isolate stack in LoadScript
...
When calling contract it must be provided with a new stack containing
only it's arguments. The result is then copied back on RET.
Fix #1220 .
2020-07-27 13:00:35 +03:00
Evgenii Stratonikov
13b9eda08d
vm: allow to call VM methods from outside
...
Abstract out (*VM).Call method and use in in CALL* opcodes.
2020-07-27 13:00:35 +03:00
Evgenii Stratonikov
6ecd1ae437
vm: allow to initialize static slot in method
2020-07-27 13:00:35 +03:00
Evgenii Stratonikov
d2ddf7b7cb
*: support invoking methods by offset
...
Allow to invoke methods by offset:
1. Every invoked contract must have manifest.
2. Check arguments count on invocation.
3. Change AppCall to a regular syscall.
4. Add test suite for `System.Contract.Call`.
2020-07-27 13:00:35 +03:00
Evgenii Stratonikov
797324cb04
vm: support exceptions
...
Implement 3 new instructions: TRY,ENDTRY,ENDFINALLY.
1. TRY marks the start of the block where exceptions are catched.
It has 2 arguments which are relative offsets of exception handler
and the end of the whole try/catch construction.
2. ENDTRY denotes either end of try or catch block.
3. ENDFINALLY denotes end of finally block which is executed
irregardless of whether an exception has occured.
2020-07-24 10:41:41 +03:00
Evgenii Stratonikov
c0d7b9d234
vm: clear references on context unload
...
Remove argument and local references from the reference counter when
returning from function.
2020-07-24 10:41:40 +03:00
Evgenii Stratonikov
aec9111961
vm: replace jumpIf with jump
...
`jumpIf` is used only once with non-constant condition.
2020-07-24 10:36:51 +03:00
Roman Khimov
2800179ce0
Merge pull request #1226 from nspcc-dev/fix/pusha
...
vm: make offset in PUSHA relative
2020-07-23 23:40:21 +03:00
Anna Shaleva
8fde41001e
core, vm: remove allowed triggers from syscalls
...
Closes #1205 .
2020-07-23 20:44:39 +03:00
Evgenii Stratonikov
b8843a2dfa
vm: make offset in PUSHA relative
...
Follow neo-project/neo-vm#317 .
2020-07-23 13:07:30 +03:00
Evgenii Stratonikov
58a594e3d4
vm: remove rvcount
...
It isn't used anymore.
2020-07-23 10:29:05 +03:00
Evgenii Stratonikov
261ff3c655
vm: remove alt.stack
...
It is no longer present in NEO3.
2020-07-22 13:20:31 +03:00
Anna Shaleva
a3e306ff78
core: implement Secp256k1 Verify and CheckMultisig interops
...
Closes #918 .
2020-07-14 16:21:34 +03:00
Roman Khimov
db027ad9c5
vm: zero GAS means no GAS, use fee data to properly limit execution
...
We were accepting transactions with zero system fee, but we shouldn't do
that. Also, transaction's verification execution has to be limited by network
fee.
2020-07-14 08:37:29 +03:00
Roman Khimov
15c6cc932d
vm: drop checkedhash, it's an unused NeoVM 2 remnant
2020-07-09 15:05:14 +03:00
Roman Khimov
1bb26dcdc1
vm: fix INITSSLOT, it's context-wide, not VM-wide
...
It's tied to the current contract, not to VM.
2020-07-09 15:00:49 +03:00
Roman Khimov
08c516014f
Merge pull request #1132 from nspcc-dev/neo3/rpc/fixed8_marshalling
...
*: switch from Fixed8 to int64
2020-06-29 21:44:40 +03:00
Anna Shaleva
73b630db9b
*: switch from fixed8 to int64
...
Follow C# implementation, we have to marshall JSON Fixed8 fields without
taking into account decimals.
2020-06-29 21:39:27 +03:00
Roman Khimov
372dd71708
Merge pull request #1108 from nspcc-dev/neo3/compiler/nef
...
compiler: support *.nef and *.manifest.json generation
2020-06-29 20:55:47 +03:00
Anna Shaleva
b387deaa05
vm: switch from .avm to .nef
2020-06-29 09:15:29 +03:00
Evgenii Stratonikov
bdaffe75cb
vm: extend PrintOps() with INITSSLOT & INITSLOT
2020-06-26 19:35:03 +03:00
Evgenii Stratonikov
82417499d7
vm: beautify PrintOps() output for JMP* instructions
2020-06-26 19:34:58 +03:00
Evgenii Stratonikov
709f656bcf
vm: remove unused parameter from getJumpOffset
2020-06-26 19:17:17 +03:00
Roman Khimov
a77357227a
vm: fix caller's script hash returned from VM
...
Regular CALLs don't update it, only Contract.Call does. Fixes the following
mismatch on preview2 testnet:
file BlockStorage_100000/dump-block-49000.json: block 48644, changes number mismatch: 6 vs 4
2020-06-24 10:22:21 +03:00
Evgenii Stratonikov
a7d4fff897
vm: make (*VM).GasLimit public
...
VM is inherently single-threaded and replacing setter/getter methods
with public field simplifies code a bit.
2020-06-16 15:13:20 +03:00
Evgenii Stratonikov
f2f01a08c9
vm: move MaxArraySize and MaxItemSize to stackitem package
2020-06-16 11:32:16 +03:00
Evgenii Stratonikov
4dfce07d11
vm: provide trigger upon VM creation
2020-06-11 13:16:07 +03:00
Evgenii Stratonikov
bda94c74c3
vm: check calling flags on syscall invocation
2020-06-11 13:16:07 +03:00
Evgenii Stratonikov
55ab7535be
core: optimize contractCallEx
...
Provide script hash upon script load.
2020-06-11 13:06:10 +03:00
Evgenii Stratonikov
5514b3f52f
smartcontract,vm: remove DynamicInvoke feature
...
It doesn't exist in NEO3.
2020-06-11 10:45:25 +03:00
Evgenii Stratonikov
7256efd1ed
vm: implement (*VM).AddGas
...
Calculating interop prices can be tricky. It is more convenitent to burn
gas inside interops where necessary parameters are popped.
2020-06-11 10:45:25 +03:00
Anna Shaleva
7ca2807875
vm/encoding: move bigint from vm to encoding package
2020-06-08 13:27:13 +03:00
Anna Shaleva
783f5ecb01
vm: move StackItem to a separate package
...
closes #912
2020-06-08 13:27:08 +03:00
Evgenii Stratonikov
9dca2288ba
vm: make LEFT fail if count is too big
2020-05-22 14:16:32 +03:00
Evgenii Stratonikov
86c4f1abc5
vm: do not use State as a mask
...
In NEO2 state could be used as a mask, but now it contains only a single
value.
2020-05-22 14:16:32 +03:00
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
781def735d
vm: use Null item as a default value for Array/Struct elements
2020-05-22 14:16:32 +03:00
Evgenii Stratonikov
f4fa712440
vm: make PUSH0 emit Integer
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
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
977c431bf1
vm: implement ASSERT/ABORT opcodes
...
Rename THROWIFNOT to ASSERT, add ABORT opcode.
ABORT cannot be caught, but the implementation should be postponed until
exception handling is implemented.
2020-05-06 15:54:19 +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
525527f750
vm: reorder stack opcodes
...
Leave *ALTSTACK opcodes for now as they are needed in compiler while
slot opcodes are not yet here.
2020-05-06 13:02:14 +03:00
Evgenii Stratonikov
115919aaf7
vm: process OLDPUSH1 at the context level
...
The only usecase for this opcode is single-byte verification scripts.
2020-05-06 13:00:00 +03:00
Anna Shaleva
5ece9922c1
vm: hide GetContextScriptHash() method
...
After adding ScriptHashGetter interface to vm, there's no need in
GetContextScriptHash() to be exported.
2020-05-04 11:53:31 +03:00
Anna Shaleva
73167999cc
core: add cosigners field to transaction
...
closes #864
2020-05-04 11:53:31 +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
a64a0f2681
vm: reorder arithmetic opcodes
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
cde4ccf01c
vm: remove CHECKSIG/VERIFY/CHECKMULTISIG opcodes
2020-04-20 11:55:24 +03:00
Evgenii Stratonikov
4740d937aa
vm: dont use SetCheckedHash outside of vm
package
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
2fd26287c5
vm: update SUBSTR to NEO3 version
...
This reverts commit 9ebb793009
.
2020-04-17 11:46:31 +03:00
Evgenii Stratonikov
948729137f
vm: remove HASH160/HASH256 opcodes
2020-04-13 13:47:39 +03:00
Evgenii Stratonikov
c23af595c9
core: implement Neo.Crypto.ECDsaCheckMultisig interop
2020-04-13 13:47:39 +03:00
Evgenii Stratonikov
1611ede58c
crypto/keys: implement NewPublicKeyFromBytes()
...
It is convenient to have a single function instead of
allocating new `PublicKey` and using `DecodeBytes()` on it.
2020-04-13 13:13:15 +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
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
Evgenii Stratonikov
4522eed1bb
vm: fix offset for CALLI opcode
...
It is different from other JMP* and +2 should be added to the parameter.
2020-03-26 13:09:55 +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
Roman Khimov
56e37ad6ba
vm: drop duplicating stackItem structure, build JSON from Parameters
...
smartcontract.Parameter has everything needed now.
2020-03-03 15:38:03 +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
Roman Khimov
02a5e036fc
vm: deduplicate checkMultisigPar
...
Make its logic more clear.
2020-02-05 17:12:23 +03:00
Evgenii Stratonikov
d93d060010
vm: parallelize CHECKMULTISIG
2020-02-05 17:12:18 +03:00
Evgenii Stratonikov
7a6d6f43ce
vm: get rid of recursive (*VM).execute calls
...
Recursive execute() calls can affect gas calculation.
This commit makes execute() be called only for real opcodes
and moves duplicate logic for CALL/JMP into a separate function.
2020-01-22 14:31:57 +03:00
Evgenii Stratonikov
d72d978a19
vm: abstract out GetInterop() function
2020-01-22 14:04:40 +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
Roman Khimov
cc16dac0b4
vm: optimize script loading a bit
...
Preseed the scriptHash value when we already know it. Eliminates this time
waste from the pprof graph, but doesn't really change anything in the 1.4M ->
1.5M 100K mainnet blocks import test.
2019-12-23 18:02:39 +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
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
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
0afaff2f79
vm: microoptimize RegisterInteropFuncs()
...
Avoid useless copying.
2019-12-13 17:02:28 +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
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
7d40d2f71e
vm: make StepOut/StepOver match original VM behavior
2019-11-06 12:25:04 +03:00
Evgenii Stratonikov
9ebb793009
vm: revert SUBSTR offset behavior to NEO 2.x
2019-11-06 12:15:55 +03:00
067d9655bf
vm: restrict total stack item count
2019-11-06 11:03:43 +03:00
ed758458d5
vm: implement serialization interops in core package
2019-11-05 17:10:52 +03:00
25f77257ce
vm: implement Boolean and ByteArray item serialization
2019-11-05 15:15:39 +03:00
Roman Khimov
2f6e678a19
Merge pull request #463 from nspcc-dev/smartcontract-fixes
...
Smartcontract RPC fixes
2019-10-29 20:54:46 +03:00
Roman Khimov
47f66dfbf3
vm: add State() method to get a state description
2019-10-29 18:26:04 +03:00
c7f0b7bd68
vm: restrict max invocation stack size
2019-10-29 15:09:17 +03:00
Roman Khimov
ae7687422c
vm: clear state in Load()
...
Make VM usable after the first run.
2019-10-29 12:53:09 +03:00
Roman Khimov
f0cffe0d3f
vm: implement stack isolation opcodes, fix #192
...
No tests yet.
2019-10-25 18:25:12 +03:00