Commit graph

2103 commits

Author SHA1 Message Date
Evgenii Stratonikov
e5d538ed21 core: use raw stack items in application logs
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-31 16:07:16 +03:00
Evgenii Stratonikov
9cba25616d rpc: use raw stack items in invoke* RPC
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-31 16:07:16 +03:00
Evgenii Stratonikov
7b4acd5a7f vm: allow to convert stack to a slice
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-31 16:07:16 +03:00
Evgenii Stratonikov
805f746f15 rpc: change NotificationEvent format
Name is now a separate field.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-31 16:07:16 +03:00
Evgenii Stratonikov
9d6ce4bdcc stackitem: implement unmarshaling from JSON with types
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-31 16:07:16 +03:00
Evgenii Stratonikov
ee5ff40b17 stackitem: allow to convert type from string
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-31 16:07:16 +03:00
Evgenii Stratonikov
c16bb466a0 stackitem: implement marshaling to JSON with types
There are 2 kinds of JSON marshaling:
1. Lossy raw marshaling, when type information is lost and
    map keys are expected to be valid utf-8 strings.
2. Almost lossless marshaling, which can handle any non-recursive item.
    Interop value preserves only type.

This commit implements the second.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-31 16:07:16 +03:00
Evgenii Stratonikov
b53f0257f5 stackitem: change ByteArray type to ByteString
Adjust only string representation.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-31 16:07:16 +03:00
Evgenii Stratonikov
a781d299e0 compiler: use fully-qualified names for tracking functions
Function name now consists of 3 parts:
1) full package path
2) method receiver type (if any)
3) function name itself .

Fix #1150.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-31 12:07:06 +03:00
Evgenii Stratonikov
528c184f00 compiler: allow to use exported constants
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-31 12:06:42 +03:00
Evgenii Stratonikov
6df019913d compiler: allow to use exported variables
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-31 12:06:42 +03:00
Evgenii Stratonikov
b8d7e93459 compiler: make ForEachFile accept a package
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-31 12:06:42 +03:00
Evgenii Stratonikov
ac040a6f22 compiler: remove unused resolveEntryPoint
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-31 12:06:42 +03:00
Evgenii Stratonikov
7009417325 compiler: allow to declare global variables in multiple files
Traverse and count globals across all used files.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-31 12:06:42 +03:00
fyrchik
babd84ec10
Merge pull request #1243 from nspcc-dev/protocol/uncompressed_payload_size
network: add uncompressed payload size
2020-07-31 10:03:55 +03:00
fyrchik
e4fc655115
Merge pull request #1239 from nspcc-dev/store_nep5_with_id
core: store contract IDs instead of hashes for NEP5Balances and Transfers
2020-07-30 12:56:19 +03:00
Anna Shaleva
2574b65b74 network: add uncompressed payload size
Closes #1212
2020-07-30 12:47:42 +03:00
Roman Khimov
e21c65c59f core: add state height to prometheus metrics
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-30 12:42:15 +03:00
Evgenii Stratonikov
5ee3ecf381 core: update verified state root height
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-30 12:42:15 +03:00
Evgenii Stratonikov
ab802cdd5f state: implement JSON marshaling for MPT* items
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-30 12:42:15 +03:00
Roman Khimov
236438d799 core: do MPT compaction every once in a while
We need to compact our in-memory MPT from time to time, otherwise it quickly
fills up all available memory. This raises two obvious quesions --- when to do
that and to what level do that.

As for 'when', I think it's quite easy to use our regular persistence interval
as an anchor (and it also frees up some memory), but we can't do that in the
persistence routine itself because of synchronization issues (adding some
synchronization primitives would add some cost that I'd also like to avoid),
so do it indirectly by comparing persisted and current height in `storeBlock`.

Choosing proper level is another problem, but if we're to roughly estimate one
full branch node to use 1K of memory (usually it's way less than that) then we
can easily store 1K of these nodes and that gives us a depth of 10 for our
trie.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-30 12:42:15 +03:00
Roman Khimov
58b7e16e0e core: fix PrevHash calculation for MPTRoot
This was differing from C# notion of PrevHash. It's not a previous root, but
rather a hash of the previous serialized MPTRoot structure (that is to be
signed by CNs).

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-30 12:42:15 +03:00
Roman Khimov
caea6d6ca8 mpt: fix extension node cache invalidation
It should always be invalidated if something changes in the `next` (below the
extension node).

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-30 12:42:15 +03:00
Evgenii Stratonikov
0e29382035 core: update MPT during block processing
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-30 12:42:15 +03:00
Roman Khimov
2b53877dff mpt: don't flush nodes already present in the DB
It's just a waste of time.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-30 12:42:15 +03:00
Roman Khimov
475bf2445a mpt: restructure nodes a bit, implement serialization and hash cache
It drastically reduces the number of allocations and hash calculations.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-30 12:42:15 +03:00
Evgenii Stratonikov
6ca22027d5 mpt: implement (*Trie).Collapse()
Because trie size is rather big, it can't be stored in memory.
Thus some form of caching should also be implemented. To avoid
marshaling/unmarshaling of items which are close to root and are used
very frequenly we can save them across the persists.
This commit implements pruning items at the specified depth,
replacing them by hash nodes.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-30 12:42:15 +03:00
Evgenii Stratonikov
f0b85f8af7 mpt: implement JSON marshaling/unmarshaling
Because there is no distinct type field in JSONized nodes, distinction
is made via payload itself, thus all unmarshaling is done via
NodeObject.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-30 12:42:15 +03:00
Evgenii Stratonikov
9b328240dd mpt: implement MPT proof Get and Verify
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-30 12:42:15 +03:00
Evgenii Stratonikov
dc6741bce7 mpt: implement MPT trie
MPT is a trie with a branching factor = 16, i.e. it consists of sequences in
16-element alphabet.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-30 12:42:15 +03:00
Evgenii Stratonikov
5500195d58 stackitem: ensure map keys are a valid UTF-8 2020-07-30 12:37:32 +03:00
Evgenii Stratonikov
3c99393bef core: simplify System.Contract.Call* parameter handling 2020-07-30 12:37:32 +03:00
Evgenii Stratonikov
f40aba4cd0 vm: convert items to UTF-8 strings
Add `stackitem.ToString` for seamless string conversion.
2020-07-30 12:37:31 +03:00
Anna Shaleva
167bd7d9df rpc: store decimals by contract ID instead of hash
And we should also cache contract scripthash to fill Asset field.
2020-07-29 15:15:48 +03:00
Anna Shaleva
0dd1730632 core: store NEP5Transfer asset by ID instead of hash
To avoid problems with retrieving decimals for migrated contracts.
2020-07-29 15:15:48 +03:00
Anna Shaleva
b9bdab8ec8 core: store nep5balances using contract id
Closes #1194
2020-07-29 15:15:48 +03:00
Anna Shaleva
1f5794b316 rpc: make getDecimals return a standard error
`getDecimals` is an internal method, wo there's no need to return
response.Error.
2020-07-29 15:14:24 +03:00
Anna Shaleva
dbd460d883 core: retrieve contract hash by ID
We'll need this ability further to retrieve contracts hashes for Nep5Balances.
2020-07-29 15:14:24 +03:00
Evgenii Stratonikov
9a992865b1 interop: add Secp2k to the list of crypto interops
Allow to use them during verification.
2020-07-29 13:43:33 +03:00
Evgenii Stratonikov
23a1430395 core: allow to restrict creating callbacks from syscalls
Specify DisallowCallback flag if syscall is not allowed to be used in a
callback.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-29 13:41:08 +03:00
Evgenii Stratonikov
99b0397a61 core: implement System.Callback.CreateFromSyscall interop
Allow to create callbacks from syscalls.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-29 13:41:08 +03:00
Evgenii Stratonikov
c54b45e76d core: implement System.Callback.CreateFromMethod interop
Support creating callbacks from contract methods.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-29 13:41:08 +03:00
Evgenii Stratonikov
f96c217aba core/tests: refactor getting contract state
Get 2 contracts in pair which is useful everytime we need to test
syscall with one contract calling the other.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-29 13:41:08 +03:00
Evgenii Stratonikov
e654d22991 core/tests: introduce loadScript helper
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-29 13:41:08 +03:00
Evgenii Stratonikov
382a7f5b3e core: implement System.Callback.* interops
Support creating callbacks from pointers.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-29 13:41:08 +03:00
Evgenii Stratonikov
c09ea04df3 core: add prices for TRY* opcodes
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-29 13:41:08 +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
Anna Shaleva
4bf88ba6b0 core: decouple native contracts from interop service
Closes #1191.
2020-07-29 10:33:18 +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
0c424a0ed2 rpc: update getrawtransaction RPC call
Closes #1183.

Added VMState to transaction output raw.
2020-07-29 10:14:08 +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
Anna Shaleva
990db9f205 rpc: update getrawmempool RPC-call result
Closes #1182
2020-07-29 10:14:01 +03:00
fyrchik
0d558ef95e
Merge pull request #1230 from nspcc-dev/feature/multitransfer
Generate multitransfer NEP5 transactions on client
2020-07-29 09:50:49 +03:00
fyrchik
5cf4481331
Merge pull request #1228 from nspcc-dev/fix/contractcall
Adjust `System.Contract.Call.*` interops
2020-07-28 13:18:24 +03:00
Evgenii Stratonikov
5fe8095cee vmcli: implement parse command
Implement parse command for converting arbitrary values to other
formats. It supports Integer, String, Hex, Base64 and
Address representations.
2020-07-27 13:05:37 +03:00
Evgenii Stratonikov
b3e166aeff vmcli: remove unused method 2020-07-27 13:04:52 +03:00
Evgenii Stratonikov
84c148575d rpc: remove Main func from test contract 2020-07-27 13:00:35 +03:00
Evgenii Stratonikov
685d44dbc1 *: support _initialize method in contracts
Invoke `_initialize` method on every call if present.
In NEO3 there is no entrypoint and methods are invoked by offset,
thus `Main` function is no longer required.
We still have special `Main` method in tests to simplify them.
2020-07-27 13:00:35 +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
28e0661f82 interop: update AppCall comment
Do not require contract hash to be known at compile time.
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
e87eba51f9 compiler: emit bytecode for unused exported functions
Exported functions should always be present in byte-code.
This will be needed later when arbitrary method calls are allowed.
2020-07-27 13:00:35 +03:00
Evgenii Stratonikov
54d7882acf core: compiler contract on-the-fly in helper test
Generate proper manifest file too.
2020-07-27 13:00:34 +03:00
Evgenii Stratonikov
04bf357fa5 compiler: make DebugInfo.convertToManifest public
Allow to generate manifest when using compiler as a library.
2020-07-27 11:08:01 +03:00
Evgenii Stratonikov
7d8fead1fd native: change onPersist return type to Void 2020-07-27 11:08:01 +03:00
Evgenii Stratonikov
a892e3ffa8 manifest: add Offset in method descriptor 2020-07-27 11:08:01 +03:00
Evgenii Stratonikov
e52c39ae7e manifest: remove EntryPoint from manifest 2020-07-27 11:08:01 +03:00
Roman Khimov
d2c823daa6
Merge pull request #1233 from nspcc-dev/fix/gasverify
core: restrict maximum gas allow for verification
2020-07-26 22:40:13 +03:00
Roman Khimov
5983e6bd55
Merge pull request #1232 from nspcc-dev/fix/verifytest
crypto: fix failing Secp256r1 test
2020-07-26 09:09:55 +03:00
Evgenii Stratonikov
121c9664b4 core: restrict maximum gas allow for verification
Disallow costly verification methods. We put this limit in policy
contract as it may be a subject to change in future.
In fact this value also overrides gas limit for header verification.
Close #1202.
2020-07-25 14:33:38 +03:00
Evgenii Stratonikov
8931c9a794 core/interop: increase coverate for crypto interops 2020-07-25 12:16:56 +03:00
Evgenii Stratonikov
83e53fab24 core/test: ensure public key is invalid in test
When providing public key as a subslice, it still can be
decoded as a valid key, thus interop will not return an error
but rather push `false` on stack. This test is about providing
invalid key, so ensure this via setting invalid prefix.
2020-07-25 12:01:16 +03:00
Evgenii Stratonikov
76fdbea331 keys: fix failing Secp256k1 test
Pad R and S when computing signature.
Fix #1223.
2020-07-25 12:01:12 +03:00
Evgenii Stratonikov
e013477bc9 rpc,cli: support multitransfer transactions
Allow to transfer single asset to multiple recepients
in a single transaction. It is currently a separate command in CLI
and can be merged in future.
2020-07-24 17:01:30 +03:00
Evgenii Stratonikov
299491080a vm: simplify interop id in json tests 2020-07-24 10:44:02 +03:00
Evgenii Stratonikov
68ad620af0 vm: update json tests to master 2020-07-24 10:44:02 +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
a45c160f10
Merge pull request #1225 from nspcc-dev/fix/equal
vm: make EQUAL type strict
2020-07-23 23:42:22 +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
Roman Khimov
d8a1c3de46
Merge pull request #1221 from nspcc-dev/neo3/interop/post-preview2_adjustment3
interop: post-preview2 adjustment, part 3
2020-07-23 20:35:53 +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
9252ef65bb vm: make EQUAL type strict
Do not perform type conversions when comparing elements.
2020-07-23 13:01:43 +03:00
Roman Khimov
18dcc16553
Merge pull request #1222 from nspcc-dev/fix/rvcount
Remove return value count
2020-07-23 10:34:34 +03:00
Evgenii Stratonikov
58a594e3d4 vm: remove rvcount
It isn't used anymore.
2020-07-23 10:29:05 +03:00
Roman Khimov
06f70e6a0b
Merge pull request #1218 from nspcc-dev/neo3/interop/post-preview2_adjustment2
interop: post-preview2 adjustment, part 2
2020-07-23 09:35:34 +03:00
Anna Shaleva
ef8de3b2dc core: adjust System.Runtime.GetNotifications interop
Part of #1055.

Forgot to add this pretty interop to the list of system interops.
2020-07-23 07:54:51 +03:00
Anna Shaleva
120eff92f7 core: adjust System.Runtime.Notify interop
Part of #1198.

Notification name should be UTF8-encoded.
2020-07-23 07:55:12 +03:00
Anna Shaleva
2c41b7b254 core: adjust System.Runtime.Log interop
Part of #1055 and #1198.

It should check the message length and encoding.
2020-07-23 07:54:51 +03:00
Anna Shaleva
76acef18ad core: adjust System.Runtime.Platform interop
Part of #1055.

Added `Platform` method to compiler.
2020-07-23 07:51:24 +03:00
Anna Shaleva
88e003d219 core: adjust System.Runtime.GetTime interop
Part of #1055.

It should have AllowStates flag.
2020-07-23 07:51:24 +03:00
Anna Shaleva
990ef5525c core: adjust System.Runtime.GasLeft interop
Part of #1055.

In test mode it should return -1.
2020-07-23 07:51:24 +03:00
Anna Shaleva
8fed383523 core: adjust System.Runtime.CheckWitness interop
Part of #1055.

It should have `AllowStates` flag.

Also removed unreachable code: we can't have such situation when
script container is not a transaction in the scope of `CheckWitness`
method because:
1. Blocks have their own implementation of CheckWitness for
internal usage (it's (bc *Blockchain) verifyHeaderWitnesses method).
2. For the outside calls of System.Runtime.CheckWitness interop (e.g.
calls from smart-contract) script container is always a transaction.
2020-07-23 07:51:24 +03:00
Anna Shaleva
c9ef7425ac core: adjust System.Iterator.Create interop
Closes #1201.

It should be able to iterate over primitive byte-array-like types also.
2020-07-23 07:51:55 +03:00
Anna Shaleva
459ac34839 core: adjust System.Enumerator.Create interop
Part of #1201.

It should be able to create enumerator from primitive byte-array-like
stack items too.
2020-07-23 07:51:24 +03:00
Roman Khimov
c4cde44543
Merge pull request #1216 from nspcc-dev/neo3/rpc/sendrawtransaction
rpc: adjust `sendrawtransaction` and `submitblock` RPC calls
2020-07-22 22:13:21 +03:00