Commit graph

511 commits

Author SHA1 Message Date
AnnaShaleva
aefb6f9fee *: fix tests failing due to path.Join usage
Solution:
Use `file/filepath` package to construct expected path. This package is OS-aware, see https://github.com/golang/go/issues/30616.
2021-11-29 11:11:09 +03:00
Roman Khimov
7fa58a4dc8
Merge pull request #2255 from nspcc-dev/compiler-noreturn-defers
compiler: correctly handle defer in functions without return values
2021-11-15 10:43:00 +03:00
Roman Khimov
db99368e96 compiler: optimize GAS cost of type conversion
CONVERT call base price is 8192. DUP, ISTYPE and JMPIF all cost 2. So we add
0.07% overhead in the worst case and save 99.93% otherwise.

At the same time, old code was just two bytes and new one is seven, but I
think it's tolerable considering how much GAS it can potentially save.

Fix #2250.
2021-11-12 19:58:21 +03:00
Roman Khimov
a91581fa16 compiler: correctly handle defer in functions without return values
Fix #2253.
2021-11-12 19:36:59 +03:00
Roman Khimov
410aabe7a1 compiler: drop some useless NOPs
They're all obsolete and not needed.
2021-11-12 17:19:59 +03:00
Roman Khimov
0d50730382 compiler: optimize map initialization with PACKMAP 2021-11-12 17:19:59 +03:00
Roman Khimov
a8befeea33 compiler: optimize new empty struct creation with PACKSTRUCT 2021-11-12 17:19:59 +03:00
Roman Khimov
909ea477f4 compiler: create arrays/structs more effectively
Use PACK/PACKSTRUCT.
2021-11-12 17:19:59 +03:00
Evgeniy Stratonikov
7758378d28 compiler: allow to overload methods in manifest
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-10-29 20:15:21 +03:00
Evgeniy Stratonikov
4fe188a60d compiler: check correctness of emitted bytecode
The error here indicates a bug in compiler implementation.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-10-25 13:55:55 +03:00
Evgeniy Stratonikov
a885f84cad compiler: fail if some functions are missing
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-10-25 13:55:55 +03:00
Evgeniy Stratonikov
8a0429036b compiler: set type information during traversal, fix #2231
Set all necessary context before file traversal, not only import
maps. Also, we can skip restoring import maps because all our code is
processed via `For*` iterators which set necessary context.
We can also refactor this a bit to have all context in one place,
this will be done in #2086.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-10-25 13:55:55 +03:00
Evgeniy Stratonikov
b91de50e65 compiler: remove convert.To* from the list of builtins
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-10-23 16:16:03 +03:00
Evgeniy Stratonikov
a92bf281c1 compiler: remove custom logic for util builtins
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-10-23 16:12:47 +03:00
Roman Khimov
36295357d8 interop: add Abort() function to ABORT things
Related to #2227.
2021-10-22 14:50:51 +03:00
Evgeniy Stratonikov
0bc81aecf4 compiler: do not emit code for unused imported functions
Our current algorithm marks function as used if it is called
at least ones, even if the callee function is itself unused.
This commit implements more clever traversal to collect usage
information more precisely.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-10-13 15:56:07 +03:00
Evgeniy Stratonikov
8d562cef99 compiler: allow to use multiple underscores in func arguments
It should still be present in the argument array in VM so just don't
save them in the map.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-10-09 13:23:11 +03:00
Evgeniy Stratonikov
0c01d89827 compiler: check that safe methods exist
If a method is missing from the manifest, it is most likely a typo
or regression after refactoring. There is no "turn-off" flag
for this error because we can do this precisely.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-10-06 15:18:58 +03:00
Roman Khimov
42a9d3d7b8 nef: add Source field
Follow neo-project/neo#2605.
2021-09-24 00:19:37 +03:00
Anna Shaleva
4b35a1cf92 core: remove conflicting transactions wrt MaxTraceableBlocks 2021-08-18 13:31:47 +03:00
Evgeniy Stratonikov
dc9287bf5c compiler: use parameter directly in writeJumps
`Next` doesn't longer copy parameter.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-08-13 11:59:04 +03:00
Roman Khimov
d6bd6b6888 native: drop Refuel method from GAS
It can be used to attack the network (amplifying DOS), so it's broken
beyond repair. This reverts ac601601c1.

See also neo-project/neo#2560 and neo-project/neo#2561.
2021-08-05 10:27:13 +03:00
Roman Khimov
4d1e952be6 go.mod: update go-datastructures to 1.0.53
We're only using queue library and it didn't change in any way, but 1.0.53 has
proper go.mod, so it's still an improvement.

It at the same time pulls some new packages also like x/tools.
2021-07-21 23:28:00 +03:00
Roman Khimov
36d486a664 config: add InitialGASSupply, fix #2073
We now have 52M by default.
2021-07-20 16:59:54 +03:00
Roman Khimov
f4a9139a05
Merge pull request #2071 from nspcc-dev/fix-more-vm-bugs
Fix more VM bugs
2021-07-19 22:00:17 +03:00
Roman Khimov
233307aca5 stackitem: completely drop MaxArraySize
Turns out C# VM doesn't have it since preview2, so our limiting of
MaxArraySize in incompatible with it. Removing this limit shouldn't be a
problem with the reference counter we have, both APPEND and SETITEM add things
to reference counter and we can't exceed MaxStackSize. PACK on the other hand
can't get more than MaxStackSize-1 of input elements.

Unify NEWSTRUCT with NEWARRAY* and use better integer checks at the same time.

Multisig limit is still 1024.
2021-07-19 15:42:42 +03:00
Evgeniy Stratonikov
8077f9232d interop: implement System.Runtime.GetRandom
Our murmur3 implementation is architecture independent and optimized in
assembly.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-07-15 16:00:01 +03:00
Evgeniy Stratonikov
96a42cd011 interop: add System.Runtime.GetNetwork, fix #2038
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-07-08 17:02:37 +03:00
Evgeniy Stratonikov
f0100407ee compiler/test: compile whole directory in examples
For `nft-nd-nns` example only `namestate.go` file was compiled which is
certainly not what we want.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-06-28 11:50:40 +03:00
Evgeniy Stratonikov
aa76383fa7 compiler: extend permission check to runtime hashes
If a method is known at compile time we can still check
if it is present in the list of methods of at least one contract.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-06-28 11:49:30 +03:00
Evgeniy Stratonikov
4249674ddc compiler: check for contract permissions
On many occassions we can determine at compile-time if contract config lacks
some properties it needs. This includes all native contract invocations
through stdlib, as both hashes and methods are known at compile-time
there.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-06-28 11:49:29 +03:00
Roman Khimov
352450d25a
Merge pull request #1988 from nspcc-dev/cli-permission
cli,compiler: allow to specify manifest permissions
2021-06-07 10:27:29 +03:00
Roman Khimov
efb814a97e
Merge pull request #1995 from nspcc-dev/compiler-verify-notify
compiler: disallow `runtime.Notify` in `Verify` function
2021-06-06 11:34:42 +03:00
Evgeniy Stratonikov
1578904da2 compiler: disallow runtime.Notify in Verify function
Only direct invocations are considered. The check can be disabled
with '--no-events' compiler option.
2021-06-06 09:34:24 +03:00
Evgeniy Stratonikov
4467e2cbfd cli,compiler: allow to specify manifest permissions 2021-06-04 11:16:22 +03:00
Evgeniy Stratonikov
1d6d7206e9 compiler: inline expressions with type conversions, fix #1879
Don't count `string(data)` or `[]byte(data)` as function calls.
2021-06-04 11:08:00 +03:00
Evgeniy Stratonikov
6b3afe9131 compiler: inline all expression with no side-effects, fix #1881
This has the drawback of traversing expression each time the argument is
used. However this is not the case in our syscall/native wrappers.
The old behaviour can be restored by explicit local assignment.
2021-06-04 11:07:59 +03:00
Evgeniy Stratonikov
3749f38720 compiler/test: add more tests for inline behaviour 2021-06-04 11:06:09 +03:00
Evgeniy Stratonikov
c538512e60 compiler/test: check Main locals in inline tests 2021-06-04 11:06:09 +03:00
Evgeniy Stratonikov
5e92a254b2 compiler: check event name length in runtime.Notify 2021-06-03 10:32:56 +03:00
Evgeniy Stratonikov
1a5e656d38 compiler: restore event check warnings
It was broken after changes for inlining. Add tests.
2021-06-03 10:32:56 +03:00
Evgeniy Stratonikov
233996eec0 native/neo: add getAccountState method, close #1975 2021-05-27 10:59:38 +03:00
Evgeniy Stratonikov
e314e55a1b compiler: add Base58Check* interop wrappers
Missing piece from #1977.
2021-05-25 18:06:40 +03:00
Evgeniy Stratonikov
60a3e0d778 compiler: count auxiliary locals introduced by inlining
During initialization of globals no function scope is present thus
locals number is not saved anywere. Save it in `codegen` directly.
2021-05-19 11:50:07 +03:00
Evgeniy Stratonikov
87a69b13f1 compiler/test: add test for inlining with local alias
INITSLOT count should be 1 more than for the same test with global.
2021-05-19 11:50:07 +03:00
Evgeniy Stratonikov
b693d54282 compiler: count local variables on the go
Create local variables as they are needed and remove `INITSLOT`
if there were no locals. This helps to eliminate a whole class
of bugs when calculated and real amount mismatched.
2021-05-19 11:50:07 +03:00
Evgeniy Stratonikov
bfa2bafb04 compiler: optimize jumps in tests
Jump target shortening affects manifest, so we better be sure.
2021-05-19 09:54:10 +03:00
Evgeniy Stratonikov
2aaaf30db7 compiler: remove finallyProcessIndex from funcScope 2021-05-19 09:54:10 +03:00
Anna Shaleva
6eee868b4a interop: remove native NNS API wrappers 2021-05-17 22:08:15 +03:00
Roman Khimov
834743ec88
Merge pull request #1958 from nspcc-dev/linter
Linter improvements
2021-05-13 10:52:58 +03:00