Commit graph

253 commits

Author SHA1 Message Date
Anna Shaleva
793f27084b vm: specify syscall ID when panicing on syscall invocation
It's convinient to know the failing syscall without dumping
smartcontract instructions.
2021-03-31 19:00:59 +03:00
Evgeniy Stratonikov
d255c4a517 vm: implement SQRT opcode 2021-03-01 16:58:53 +03:00
Evgeniy Stratonikov
6496782736 vm: implement POW opcode 2021-03-01 16:58:53 +03:00
Roman Khimov
158f0d9d9c native/vm: add script check for deployed contracts
Refs. #1699.
2021-02-09 22:31:26 +03:00
Anna Shaleva
6a4e312eac core: move GetPrice from core to interop
We have additional logic for getting BaseExecFee policy value. This
logic should be moved to interop context instead of being in Policer,
because Policer is just an interface over Policy contract.

After moving this logic to interop context, we need to use it to define
BaseExecFee instead of (Policer).BaseExecFee. Thus, moving
(*Blockchain).GetPrice to (*Context).GetPrice is necessary.
2021-02-05 11:36:32 +03:00
Evgeniy Stratonikov
49de8161ef core: implement LoadToken handler 2021-01-22 09:04:37 +03:00
Evgenii Stratonikov
bb706aa55b vm: implement CALLT opcode 2021-01-21 19:30:04 +03:00
Evgeniy Stratonikov
324107b31e vm: implement POPITEM opcode 2021-01-19 09:46:01 +03:00
Evgenii Stratonikov
1c0c331e25 core: update System.Contract.Call syscall
1. Remove `System.Contract.CallEx`.
2. Extend number of parameters.
3. Add return value count to `VM.Context`.
2021-01-14 18:23:36 +03:00
Evgenii Stratonikov
dbe81f9b80 smartcontract: move flags to a separate package 2021-01-14 17:52:09 +03:00
Evgenii Stratonikov
e63191d31f core: hangle CallingScriptHash correctly
When using native contracts, script hash of second-to-top context
on invocation stack does not always correspond to a real calling
contract.
2020-12-10 16:52:36 +03:00
Evgenii Stratonikov
e903e40085 core: call from native contracts synchronously
Follow neo-project/neo#2130.
2020-12-10 16:43:46 +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
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