Commit graph

496 commits

Author SHA1 Message Date
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
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
a34ba92d46 compiler: allow to split main package across multiple files 2020-08-11 11:12:55 +03:00
Evgenii Stratonikov
057e1c6e3c compiler: provide filename to Compile() 2020-08-11 11:10:45 +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
Evgenii Stratonikov
b65369e111 emit: remove unused functions 2020-08-10 11:14:48 +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
c3c88a57cd
Merge pull request #1281 from nspcc-dev/drop-go-1.12-and-fix-some-things
Drop go 1.12 and fix some things
2020-08-07 13:34:54 +03:00
Roman Khimov
0e2784cd2c always wrap errors when creating new ones with fmt.Errorf()
It doesn't really change anything in most of the cases, but it's a useful
habit anyway.

Fix #350.
2020-08-07 12:21:52 +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
a3f419f8df emit: allow to emit Null 2020-08-06 20:39:13 +03:00
Roman Khimov
f5fbef165a
Merge pull request #1259 from nspcc-dev/fix/notifications
Disallow changing notifications
2020-08-05 19:50:45 +03:00
Evgenii Stratonikov
b8cc33d0b2 stackitem: implement DeepCopy 2020-08-05 11:19:41 +03:00
Evgenii Stratonikov
7e3813a88f cli: use TAB as delimiter in vm parse
Make it simpler to use result in pipes:

neo-go vm parse 123 | rg "Integer to Hex" | cut -f1- | sed -r 's/\t//g'
2020-08-05 09:40:50 +03:00
Evgenii Stratonikov
227c6a2caa cli: allow to use vm parse directly 2020-08-05 09:40:50 +03:00
Roman Khimov
fa5ff8dd95
Merge pull request #1242 from nspcc-dev/fix/json
Implement lossless stackitem to json conversion
2020-08-04 12:59:47 +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