Commit graph

57 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
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
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
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
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
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
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
f2f01a08c9 vm: move MaxArraySize and MaxItemSize to stackitem package 2020-06-16 11:32:16 +03:00
Evgenii Stratonikov
0dd00a49f5 core: specify require call flags in interop description
Related #1026, #1027, #1028, #1031.
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
5514b3f52f smartcontract,vm: remove DynamicInvoke feature
It doesn't exist in NEO3.
2020-06-11 10:45:25 +03:00
Anna Shaleva
783f5ecb01 vm: move StackItem to a separate package
closes #912
2020-06-08 13:27:08 +03:00
Roman Khimov
35b30ccfdf core: drop OLDPUSH1, it's no longer needed
Fixes #927.
2020-06-05 19:20:16 +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
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
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
9ecac14aee vm: fix bug in GetContextScriptHash()
v.Istack.Peek(n) can return nil pointer, so .Value() on this pointer
leads to panic here. Fixed by adding nil check.
2020-05-04 11:49:14 +03:00
Evgenii Stratonikov
7e98a2ffa0 vm: implements CONVERT opcode 2020-04-28 16:38:52 +03:00
Evgenii Stratonikov
be38798785 vm: move Bool method to the StackItem interface 2020-04-28 15:13:41 +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
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
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
b446753c57 core,vm: move get/putContextScriptHash to vm package 2020-04-16 15:54:52 +03:00
Evgenii Stratonikov
be407332b9 vm: add TryInteger() to StackItem interface
Conversion should be done in a StackItem, not in an Element.
2020-04-16 14:05:32 +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
Evgenii Stratonikov
5da82e8cf0 vm: add TryBytes() to StackItem interface
Conversion should be done in a StackItem, not in an Element.
2020-03-11 16:33:46 +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
Roman Khimov
9b4fd99fbc vm: break circular references when recursing into ToContractParameters
Reference types can have circular pointers to each other, thus we need to
control recursion.
2020-03-03 15:38:03 +03:00
Anna Shaleva
ff4384d7ff rpc: implement getapplicationlog RPC
Closes #500
2020-03-02 17:25:27 +03:00
Evgenii Stratonikov
3e84f2bdf8 compiler: rewrite jump targets properly
Old implementation could view 0x62 byte in
a script as a JMP instruction irregardless of whether it is
a real opcode or a part of a parameter of another instruction.
In this commit instructions are decoded together with parameters
during jump label rewriting.
2020-02-12 10:58:53 +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
c9257c3de4 vm: optimize Next() in Context
Creating a new BinReader for every instruction is a bit too much and it adds
about 1% overhead on block import (and actually is quite visible in the VM
profiling statistics). So use a bit more ugly but efficient method.
2019-12-13 19:57:17 +03:00
Roman Khimov
0abd55c2c2 vm: add cached ScriptHash() to Context
Avoid recalculating it over and over again in interop.
2019-12-13 17:05:03 +03:00
Roman Khimov
8b3080b972 io: rename Read/WriteBytes to Read/WriteB
go vet is not happy about them:
  pkg/io/binaryReader.go:92:21: method ReadByte() byte should have signature ReadByte() (byte, error)
  pkg/io/binaryWriter.go:75:21: method WriteByte(u8 byte) should have signature WriteByte(byte) error
2019-12-12 20:19:50 +03:00
Roman Khimov
54d888ba70 io: add type-specific read/write methods
This seriously improves the serialization/deserialization performance for
several reasons:
 * no time spent in `binary` reflection
 * no memory allocations being made on every read/write
 * uses fast ReadBytes everywhere it's appropriate

It also makes Fixed8 Serializable just for convenience.
2019-12-12 20:19:50 +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
Roman Khimov
f0cffe0d3f vm: implement stack isolation opcodes, fix #192
No tests yet.
2019-10-25 18:25:12 +03:00
Vsevolod Brekelov
8ee421db14 fix spelling and godoc comments 2019-10-22 17:56:03 +03:00
Evgenii Stratonikov
487570153b vm: restrict max item size in PUSHDATA4 2019-10-17 17:10:00 +03:00