Commit graph

514 commits

Author SHA1 Message Date
Evgenii Stratonikov
e4ee7cd407 vm: improve coverage for default interops 2020-12-02 15:54:03 +03:00
Evgenii Stratonikov
33f13ab1c0 vmcli: add tests 2020-12-02 10:49:37 +03:00
Evgenii Stratonikov
f8728e4f44 vmcli: unify error messages 2020-12-02 10:49:37 +03:00
Evgenii Stratonikov
bea5125d42 vmcli: return after error in break 2020-12-02 10:49:37 +03:00
Evgenii Stratonikov
d7ffa89811 vmcli: set breakpoint before the instruction
Breakpoint should occur before actual instruction execution.
2020-12-02 10:49:37 +03:00
Evgenii Stratonikov
2f39701d76 vm: provide writer in PrintOps()
Make it more flexible and testable. Fallback to using
stdout if no writer is provided.
2020-12-02 10:49:37 +03:00
Roman Khimov
d93aa745bb contract: avoid going to the DB for entry scripts
This optimizes out DB access for non-deployed contracts under the assumption
that deployed ones are always loaded via `LoadScriptWithHash` (and if they're
not --- it's a bug anyway with the new hashing model) which actually is a very
popular case (every entry script does that).
2020-11-27 21:47:08 +03:00
Anna Shaleva
0f68528095 core: add callback to VM context 2020-11-25 18:37:29 +03:00
Evgenii Stratonikov
7d91a3a89e pkg: move internal/ package to the root directory
This way we can use it in scripts and cli.
2020-11-24 16:39:56 +03:00
Evgenii Stratonikov
42ae226f9e native: use proper stack for result
When native method calls other contract result should be put
on the stack of current context. With oracles this problem wasn't
noticed because of void return type.
2020-11-24 12:17:28 +03:00
Evgenii Stratonikov
4de233b339 emit: allow to emit nested arrays 2020-11-24 11:23:44 +03:00
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
6849499f56
Merge pull request #1493 from nspcc-dev/vm-opcode-bench
vm: add opcode benchmark
2020-10-16 11:02:04 +03:00
Roman Khimov
0709e20fbb vm: add opcode benchmark
For future optimizations and price adjustments.
2020-10-15 16:27:36 +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
Roman Khimov
fe0ec91636 vm: optimize reversing items on the stack
Before:
BenchmarkOpcodes/REVERSE3/null-8                   10000               335 ns/op
BenchmarkOpcodes/REVERSE3/integer-8                10000               355 ns/op
BenchmarkOpcodes/REVERSE3/big_bytes-8              10000               344 ns/op
BenchmarkOpcodes/REVERSE4/null-8                   10000               353 ns/op
BenchmarkOpcodes/REVERSE4/integer-8                10000               336 ns/op
BenchmarkOpcodes/REVERSE4/big_bytes-8              10000               324 ns/op
BenchmarkOpcodes/REVERSEN/5/null-8                 10000               350 ns/op
BenchmarkOpcodes/REVERSEN/5/integer-8              10000               358 ns/op
BenchmarkOpcodes/REVERSEN/5/big_bytes-8            10000               351 ns/op
BenchmarkOpcodes/REVERSEN/1024/null-8              10000            982413 ns/op
BenchmarkOpcodes/REVERSEN/1024/integer-8                   10000            994926 ns/op
BenchmarkOpcodes/REVERSEN/1024/big_bytes-8                 10000            992951 ns/op

After:
BenchmarkOpcodes/REVERSE3/null-8                   10000               241 ns/op
BenchmarkOpcodes/REVERSE3/integer-8                10000               255 ns/op
BenchmarkOpcodes/REVERSE3/big_bytes-8              10000               249 ns/op
BenchmarkOpcodes/REVERSE4/null-8                   10000               249 ns/op
BenchmarkOpcodes/REVERSE4/integer-8                10000               267 ns/op
BenchmarkOpcodes/REVERSE4/big_bytes-8              10000               292 ns/op
BenchmarkOpcodes/REVERSEN/5/null-8                 10000               337 ns/op
BenchmarkOpcodes/REVERSEN/5/integer-8              10000               327 ns/op
BenchmarkOpcodes/REVERSEN/5/big_bytes-8            10000               293 ns/op
BenchmarkOpcodes/REVERSEN/1024/null-8              10000              5414 ns/op
BenchmarkOpcodes/REVERSEN/1024/integer-8                   10000              5487 ns/op
BenchmarkOpcodes/REVERSEN/1024/big_bytes-8                 10000              5609 ns/op
2020-10-15 16:19:59 +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
Roman Khimov
124ce9d247
Merge pull request #1455 from nspcc-dev/get_invocation_counter
core: remove error from runtime.GetInvocationCounter
2020-10-08 16:34:40 +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
Roman Khimov
0120a8f239 stackitem: limit buffer/bytearray reads upon deserialization
This is not the way it's done in C#, but that's the most sensible approach to
me.
2020-10-07 23:08:20 +03:00
Roman Khimov
64e9775707 vm/stackitem: limit reads for bigint values
They can't exceed 33 bytes.
2020-10-07 23:07:10 +03:00
Evgenii Stratonikov
96bca91e4b vm: handle very big int creation properly
Determine size as in reference implementation instead of
`big.Int.BitLen()`

Close #1437.
2020-10-07 11:50:42 +03:00
Roman Khimov
d6a1a22afa
Merge pull request #1452 from nspcc-dev/contract/deploy
Support `_deploy` method
2020-10-06 19:54:14 +03:00
Evgenii Stratonikov
b2a3a0851e emit: accept multiple opcodes in Opcode() 2020-10-06 18:03:25 +03:00
Evgenii Stratonikov
0b76f875c7 core: allow Null in System.Contract.Update
Null means absense of script or manifest, empty
byte-slice is an error.

Related #1459.
2020-10-06 10:34:45 +03:00
Anna Shaleva
6761c297b5 vm: add test to check reference counter after PACK-UNPACK
Related issue: https://github.com/neo-project/neo-vm/pull/370
2020-09-29 18:46:20 +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
Anna Shaleva
1f9b92c295 vm: restrict comparable ByteArray length
MaxByteArrayComparableSize should equals to 65535.
2020-09-29 10:42:01 +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
fa1d1a8b00 compiler: support defer statement
Compile `defer` statement to a TRY/ENDFINALLY opcode pair.
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
77ea3d361b vm: update neo-vm tests, simplify parsing
We no longer have "*N" notation, see neo-project/neo-vm#326.
2020-08-22 23:35:29 +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
Roman Khimov
93f51f922a stackitem: return error in TryBytes() for big byte strings
Follow neo-project/neo-vm#349.
2020-08-21 21:05:47 +03:00
Roman Khimov
a7670303e8 stackitem: change Bool() to TryBool(), prepare for its failures 2020-08-21 20:55:20 +03:00
Evgenii Stratonikov
681e81420a vm: make (*Context).IP() return instruction pointer
It is misleading to return +1 in code, and user representation
can always be altered.
2020-08-21 08:44:32 +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
8659fd79e5 vm: add tests for ByteString enumerator/iterator 2020-08-18 11:24:48 +03:00
Evgenii Stratonikov
b2e53fedac vm: pretty-print SYSCALL opcode 2020-08-14 14:22:46 +03:00
Evgenii Stratonikov
7854dcfd8f core: replace interop names with named constants 2020-08-14 14:21:54 +03:00
Evgenii Stratonikov
f3650e20b0 vm: move InteropNameToID to a separate package 2020-08-14 13:54:11 +03:00
Evgenii Stratonikov
9cc6e22365 vm: pretty-print ST*/LD* opcodes 2020-08-13 10:38:13 +03:00