Commit graph

1543 commits

Author SHA1 Message Date
Evgenii Stratonikov
051e3608ff compiler: support nested struct fielid assignment 2020-05-21 08:30:32 +03:00
Evgenii Stratonikov
1e40f9dac0 compiler: support nested struct reading 2020-05-21 08:30:31 +03:00
Anna Shaleva
9f2cb1726b core: add witness check to nep5 transfer method
We have to check, whether transaction's sender is authorised to transfer
nep5 assets.
2020-05-20 23:34:27 +03:00
Anna Shaleva
1afd630169 core: add senders' fees monitor to mempool
In order to simplify maintainance of overall current senders` fees
in the mempool we are to keep them in a separate map.
2020-05-20 23:34:25 +03:00
Anna Shaleva
c3e08afe34 util: fixed typo in method description 2020-05-20 23:26:51 +03:00
Anna Shaleva
7acf5b2841 core: add SystemFee and NetworkFee to transaction
closes #831
2020-05-20 23:26:48 +03:00
Anna Shaleva
fc3acdc80c core: add native contracts' hashes getters 2020-05-20 23:16:04 +03:00
Anna Shaleva
6b2f4efdd4 core: fix bug in nep5TokenNative.addTokens method
Sometimes we want to add negative amount (e.g. when burning tokens).
2020-05-20 23:16:04 +03:00
Anna Shaleva
c7a040ff81 core: fix bug with native contracts methods initialisation
`NewNEO()` and `NewGAS()` methods are trying to initialise
both `onPersist` and `incBalance` methods of NEO and GAS AFTER
nep5TokenNative is set to the VALUE of created nep5 token.
In this situation an attemmpt to call the corresponding native contracts
methods (e.g. transfer native GAS) leads to contract invocation failure,
as far as `nep5TokenNative.incBalance` method is nil.

Fixed this by initializing both `onPersist` and `incBalance` methods
before getting the value of nep5 contract.
2020-05-20 23:16:04 +03:00
Anna Shaleva
4ebac5a069 core: fix bug in nep5 notifications handling
Native contracts deployment creates `Transfer` notifications and adds
them into interop context. However, these notifications were not stored
for two reasons:
1. typo in `Transfer` (so these notifications were not recognised during
processing of the invocation tx in (*Blockchain).storeBlock(...) method)
2. these notifications have `from` adress setted to null, so conversion
to []byte fails. Same thing could happen with `to`.

Related C# issue: https://github.com/neo-project/neo/issues/1646

For now, made both `transfer` and `Transfer` valid.
2020-05-20 23:16:04 +03:00
Anna Shaleva
45b8bdb51c core: fix bug in consensus
We should set MerkleRoot in approving block irrespective to
transactions presented in the block.
2020-05-20 23:16:04 +03:00
Evgenii Stratonikov
22067d400d rpc: update testchain 2020-05-20 17:45:56 +03:00
Evgenii Stratonikov
1a4a0c154b compiler: support var-declaration of byte slices
Related #801.
2020-05-20 17:45:56 +03:00
Evgenii Stratonikov
3a4ed7dfe8 compiler: emit Buffer for byte slices
All byte slices are mutable so buffer is a right stack item.
2020-05-20 17:45:56 +03:00
Evgenii Stratonikov
b4f1142149 compiler: emit byte constants properly 2020-05-20 17:45:56 +03:00
Evgenii Stratonikov
98c508d361 vm: implement MEMCPY opcode
MEMCPY copies byte-slice to a destination buffer.
2020-05-20 17:45:56 +03:00
Evgenii Stratonikov
a5f6e0e53d vm: implement NEWBUFFER opcode 2020-05-20 17:45:56 +03:00
Evgenii Stratonikov
a3a3a77431 vm: make slice opcodes emit Buffer 2020-05-20 17:45:56 +03:00
Evgenii Stratonikov
c3f7832f3b vm: implement Buffer stack item
Buffer is a stack item type introduced in NEO3
which represents mutable byte-array.
2020-05-20 17:45:56 +03:00
Evgenii Stratonikov
ee9adcdc5c vm: check ByteArray size before converting to Integer 2020-05-20 17:45:56 +03:00
Evgenii Stratonikov
8f5f6fba07 vm: copy slice in (*ByteArrayItem).TryBytes() 2020-05-20 17:45:56 +03:00
Evgenii Stratonikov
1b105a9f1d compiler: allow using OP= with struct fields and slice elements
Do it in a generic way, there is no need in restricting to only
variables.
Port of #954.
2020-05-20 14:14:29 +03:00
Evgenii Stratonikov
fdb217ec81 compiler: process _ as a special variable
It is more convenient to drop values inside `emitStoreVar` because this
makes other code has less special cases.
2020-05-20 14:14:29 +03:00
Evgenii Stratonikov
3926456d86 compiler: add test for iterating over map with range 2020-05-20 14:14:29 +03:00
Evgenii Stratonikov
d0735257ce compiler: support range loops with value variables
Closes #958.
2020-05-20 14:14:29 +03:00
Evgenii Stratonikov
b126056f04 compiler: use iterators in range loops
It is simpler than having some counters on stack and will help us to
support maps in future.
2020-05-20 14:14:29 +03:00
Evgenii Stratonikov
34a4c15932 compiler: support byte slice declaration 2020-05-20 11:10:02 +03:00
Evgenii Stratonikov
582469028b compiler: emit default values in a generic way 2020-05-20 11:10:01 +03:00
Evgenii Stratonikov
2cc58c3c9e compiler: allow to declare multiple compound types in a var decl 2020-05-19 16:57:02 +03:00
Evgenii Stratonikov
b4bad11699 compiler: count the number of variables correctly 2020-05-19 16:47:43 +03:00
Evgenii Stratonikov
0629479560 compiler: support non-struct methods
There is no need to restrict ourselves just to structs.
2020-05-19 16:40:26 +03:00
Evgenii Stratonikov
87f6ba34db compiler: process index expresstions in a generic way
All type errors such as string index in slice will be catched during parse phase.
2020-05-19 16:40:26 +03:00
Evgenii Stratonikov
aeaa4a8210 compiler: process bool literals in a generic way 2020-05-19 16:40:26 +03:00
Evgenii Stratonikov
70d0ff869d compiler: refactor typeinfo functions 2020-05-19 16:40:26 +03:00
Evgenii Stratonikov
89b5e92b83 compiler: add tests for function literal
Add test forgotten in #934.
2020-05-12 16:23:09 +03:00
Evgenii Stratonikov
e21015233b compiler: implement shadowing of global variables
Before introducing slots it was hard to change global variables
preserving changes across multiple function calls.
This commit implements such possibility.
Closes #638.
2020-05-12 16:23:09 +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
a6271f6bf2 vm: reorder splice opcodes 2020-05-12 16:15:35 +03:00
Evgenii Stratonikov
2cec088f08 vm: add reference counter to slots 2020-05-12 16:15:14 +03:00
Evgenii Stratonikov
af2abedd86 vm: implement reference counter
It is convenient to have all reference-counting logic
in a separate struct.
2020-05-12 16:15:14 +03:00
Evgenii Stratonikov
81cbf183af vm: implement storage slots 2020-05-12 16:15:14 +03:00
Evgenii Stratonikov
75fb3af48f compiler: add basic support for function literals
Implement basic support for function literals.
Nested function literals and variables from closure are not supported for now.
2020-05-12 12:56:52 +03:00
Evgenii Stratonikov
1d3fb3d6f5 vm: implement PUSHA/CALLA opcodes 2020-05-12 12:56:51 +03:00
Evgenii Stratonikov
7fcd537b09 vm: implement Pointer stack item
Pointer is a generic address type in VM.
It is used for calling lambda-expressions.
2020-05-12 12:55:31 +03:00
Roman Khimov
b83ee77698
Merge pull request #938 from nspcc-dev/fix/appcall
vm: remove APPCALL, TAILCALL
2020-05-08 13:11:02 +03:00
Evgenii Stratonikov
c0147c76ac emit: remove tailCall argument from AppCall
There is no TAILCALL opcode in NEO3.
2020-05-07 14:59:01 +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
ec900c7ff7 core: implement System.Contract.Call interop 2020-05-07 14:39:06 +03:00
Evgenii Stratonikov
301c1b7601 native: save native contract state on deploy 2020-05-07 14:03:14 +03:00
Evgenii Stratonikov
f9f3192b48 vm: move RET and SYSCALL opcodes 2020-05-07 13:23:05 +03:00
Evgenii Stratonikov
7ac15a7557 compiler: support implicit type in function arguments
Go supports declaring multiple arguments of the same type without
duplicating type name. Now we support this too.
2020-05-07 11:33:09 +03:00
Evgenii Stratonikov
b0a89e8a1a compiler: support named returns 2020-05-06 18:22:52 +03:00
Evgenii Stratonikov
156a2eddc5 compiler: support using return in some branches
When `return` is used in one codepath, but not the other,
we do not clean altstack properly. This commit fixes it.
2020-05-06 18:22:52 +03:00
Evgenii Stratonikov
770cff8b91 compiler: allow to use return with no arguments 2020-05-06 18:22:52 +03:00
Evgenii Stratonikov
5ab4b9284b core: remove unused function from tests 2020-05-06 16:00:16 +03:00
Evgenii Stratonikov
977c431bf1 vm: implement ASSERT/ABORT opcodes
Rename THROWIFNOT to ASSERT, add ABORT opcode.
ABORT cannot be caught, but the implementation should be postponed until
exception handling is implemented.
2020-05-06 15:54:19 +03:00
Roman Khimov
963a70d54a
Merge pull request #926 from nspcc-dev/feature/stack
Implement NEO3 VM stack opcodes
2020-05-06 14:51:04 +03:00
Roman Khimov
7287c01bd0 rpc/server: rework submitblock empty test
The original intention here was to check for server reaction in presence of
validation errors (response.ErrValidationFailed) and it was very easy to make
validation fail for block without transactions in Neo 2. But in Neo 3
transactionless blocks are perfectly valid (see
29d321b5e1) which broke this test even though we
didn't see it until websocket addition (which required
8cec6694ae to make this test work initially).

So make a valid block and then spoil its verification script.
2020-05-06 14:20:35 +03:00
Roman Khimov
fd72f0635e rpc/server: prevent test panicing in checkErrGetResult()
If we expect some resp.Error, then check for it explicitly.
2020-05-06 13:11:12 +03:00
Evgenii Stratonikov
dd20320615 vm: remove XSWAP/XTUCK opcodes
Regenerate RPC testchain as these were used in compiler.
2020-05-06 13:05:22 +03:00
Evgenii Stratonikov
d18199ce42 vm: implement REVERSE* opcodes
Use new opcodes in the compiler instead of XSWAP/ROLL.
2020-05-06 13:03:49 +03:00
Evgenii Stratonikov
c8a1188ee1 vm: implement CLEAR opcode 2020-05-06 13:02:57 +03:00
Evgenii Stratonikov
525527f750 vm: reorder stack opcodes
Leave *ALTSTACK opcodes for now as they are needed in compiler while
slot opcodes are not yet here.
2020-05-06 13:02:14 +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
Roman Khimov
b04c8623c5
Merge pull request #925 from nspcc-dev/rpc-over-websocket
RPC over websocket
2020-05-06 12:52:58 +03:00
Roman Khimov
ec6ade4c9b
Merge pull request #920 from nspcc-dev/neo3/transaction/cosigners
core: implement cosigners mechanism
2020-05-04 17:15:07 +03:00
Roman Khimov
3de48d7d90 rpc/client: add minimalistic websocket client 2020-05-04 16:54:35 +03:00
Roman Khimov
a458a17748 rpc/client: separate out http-related functionality 2020-05-04 16:54:35 +03:00
Roman Khimov
6d202ad4c5 rpc/client: drop Version from Options
It makes no sense at all, it's a JSON-RPC version.
2020-05-04 16:54:35 +03:00
Roman Khimov
19397ec4a8 rpc/client: fix some comments 2020-05-04 16:54:35 +03:00
Roman Khimov
20d477cbd8 client: remove Balancer getter/setter, make it an Option
Keep it internal to the client instance, it makes no sense exposing it to the
outside user.
2020-05-04 16:54:35 +03:00
Roman Khimov
315aabde56 client: make http.Client internal to the Client
Exposing it the outside users is strange, so incapsulate it completely.

Fix DialTimeout setting along the way, handle negative timeouts as invalid.
2020-05-04 16:54:35 +03:00
Roman Khimov
ec62edac68 rpc/server: add websockets support via '/ws' URL 2020-05-04 16:54:35 +03:00
Roman Khimov
8cec6694ae rpc/server: fix test block encoding
The end result of the previous code wasn't even a valid JSON.
2020-05-04 16:54:35 +03:00
Roman Khimov
d275652b37 rpc/server: use httptest.Server for testing
Which allows to reuse it for websockets.
2020-05-04 16:54:35 +03:00
Roman Khimov
1b523be4b6 rpc: shuffle handleHttpRequest/handleRequest responsibilities
Make handleRequest reusable in other contexts like websockets.
2020-05-04 13:57:23 +03:00
Roman Khimov
236f3dabdd rpc: change handlers to always return response.Error for errors
As it's expected by WriteErrorResponse() actually.
2020-05-04 13:57:15 +03:00
Roman Khimov
57de98e1a3 rpc/server: refactor handler methods a little
request.In is a natural request representation, one can always get
request.Params from it.
2020-05-04 13:57:08 +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
73167999cc core: add cosigners field to transaction
closes #864
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
Anna Shaleva
d1ec01c45e util: implement Serializable interface over Uint160 2020-05-04 11:49:14 +03:00
Anna Shaleva
08f5708edb core: remove Script attribute type 2020-05-04 11:49:14 +03:00
Anna Shaleva
2ec1d76320 compiler: add ability to generate .abi.json file
A part of integration with NEO Blockchain Toolkit (see #902). To be
able to deploy smart-contract compiled with neo-go compiler via NEO
Express, we have to generate additional .abi.json file. This file
contains the following information:
 - hash of the compiled contract
 - smart-contract metadata (title, description, version, author,
email, has-storage, has-dynamic-invoke, is-payable)
 - smart-contract entry point
 - functions
 - events

However, this .abi.json file is slightly different from the one,
described in manifest.go, so we have to add auxilaury stractures for
json marshalling. The .abi.json format used by NEO-Express is described
[here](https://github.com/neo-project/neo-devpack-dotnet/blob/master/src/Neo.Compiler.MSIL/FuncExport.cs#L66).
2020-05-04 08:37:39 +03:00
Anna Shaleva
ab7f2cb4fb compiler: fix bug with missing methods parameters
Method `methodInfoFromScope(...)` always returned an empty parameters
set, so we were missing this information in both .abi.json and
.debug.json files. Fixed now.
2020-05-04 08:37:39 +03:00
Anna Shaleva
861aca1547 rpc, smartcontract: move contract metadata to smartcontract package 2020-05-04 08:37:39 +03:00
Evgenii Stratonikov
c8328981ec vm: refactor tests
Most of the tests follow the same logic:
push items on stack -> execute program -> check single result.
This commit reuses this function in most of the tests.
2020-04-30 19:29:52 +03:00
Evgenii Stratonikov
9081211f12 vm: implement NOTEQUAL opcode 2020-04-30 18:00:15 +03:00
Evgenii Stratonikov
70f0c656b0 vm: check Integer size on creation 2020-04-30 18:00:15 +03:00
Evgenii Stratonikov
a64a0f2681 vm: reorder arithmetic opcodes 2020-04-30 18:00:15 +03:00
Evgenii Stratonikov
519b31a704 vm: remove crypto-related opcodes
All cryptography has moved to interops in NEO3.
There is no SHA256 interop RN, but it is to appear later.
Closes #777.
2020-04-29 19:16:38 +03:00
Roman Khimov
c1aa96d614
Merge pull request #911 from nspcc-dev/feature/convert
vm: implement CONVERT opcode
2020-04-28 18:08:36 +03:00
Evgenii Stratonikov
4b064e18aa emit: converto to Boolean in Bool() 2020-04-28 17:36:58 +03:00
Evgenii Stratonikov
2fd63387c0 compiler: support CONVERT interops
When result is needed to have certain type, we should have ability
to convert it, with the help of CONVERT opcode.
2020-04-28 16:44:06 +03:00
Evgenii Stratonikov
bfcb1a409f compiler: extend possible returned values
All integer values (int32, uint64...) should be able to be returned.
2020-04-28 16:44:06 +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
Anna Shaleva
fa467ce628 core: add txes duplication check on block.DecodeBinary 2020-04-27 18:00:01 +03:00
Anna Shaleva
dbda721599 consensus.Block: removed unnecessary setters
As far as we have consensus context in NewBlockFromContext, we don't
need them anymore.
2020-04-27 17:59:56 +03:00
Anna Shaleva
6db4ca874d consensus: replace NewBlock() with NewBlockFromContext(ctx *Context)
We have to set ConsensusData.PrimaryIndex field of Block, so this value
can be retrieved from consensus context.
2020-04-27 17:58:25 +03:00