Commit graph

50 commits

Author SHA1 Message Date
Roman Khimov
fe0ec91636 vm: optimize reversing items on the stack
Before:
BenchmarkOpcodes/REVERSE3/null-8                   10000               335 ns/op
BenchmarkOpcodes/REVERSE3/integer-8                10000               355 ns/op
BenchmarkOpcodes/REVERSE3/big_bytes-8              10000               344 ns/op
BenchmarkOpcodes/REVERSE4/null-8                   10000               353 ns/op
BenchmarkOpcodes/REVERSE4/integer-8                10000               336 ns/op
BenchmarkOpcodes/REVERSE4/big_bytes-8              10000               324 ns/op
BenchmarkOpcodes/REVERSEN/5/null-8                 10000               350 ns/op
BenchmarkOpcodes/REVERSEN/5/integer-8              10000               358 ns/op
BenchmarkOpcodes/REVERSEN/5/big_bytes-8            10000               351 ns/op
BenchmarkOpcodes/REVERSEN/1024/null-8              10000            982413 ns/op
BenchmarkOpcodes/REVERSEN/1024/integer-8                   10000            994926 ns/op
BenchmarkOpcodes/REVERSEN/1024/big_bytes-8                 10000            992951 ns/op

After:
BenchmarkOpcodes/REVERSE3/null-8                   10000               241 ns/op
BenchmarkOpcodes/REVERSE3/integer-8                10000               255 ns/op
BenchmarkOpcodes/REVERSE3/big_bytes-8              10000               249 ns/op
BenchmarkOpcodes/REVERSE4/null-8                   10000               249 ns/op
BenchmarkOpcodes/REVERSE4/integer-8                10000               267 ns/op
BenchmarkOpcodes/REVERSE4/big_bytes-8              10000               292 ns/op
BenchmarkOpcodes/REVERSEN/5/null-8                 10000               337 ns/op
BenchmarkOpcodes/REVERSEN/5/integer-8              10000               327 ns/op
BenchmarkOpcodes/REVERSEN/5/big_bytes-8            10000               293 ns/op
BenchmarkOpcodes/REVERSEN/1024/null-8              10000              5414 ns/op
BenchmarkOpcodes/REVERSEN/1024/integer-8                   10000              5487 ns/op
BenchmarkOpcodes/REVERSEN/1024/big_bytes-8                 10000              5609 ns/op
2020-10-15 16:19:59 +03:00
Evgenii Stratonikov
0b76f875c7 core: allow Null in System.Contract.Update
Null means absense of script or manifest, empty
byte-slice is an error.

Related #1459.
2020-10-06 10:34:45 +03:00
Roman Khimov
a7670303e8 stackitem: change Bool() to TryBool(), prepare for its failures 2020-08-21 20:55:20 +03:00
Roman Khimov
fa5ff8dd95
Merge pull request #1242 from nspcc-dev/fix/json
Implement lossless stackitem to json conversion
2020-08-04 12:59:47 +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
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
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
783f5ecb01 vm: move StackItem to a separate package
closes #912
2020-06-08 13:27:08 +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
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
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
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
Evgenii Stratonikov
c23af595c9 core: implement Neo.Crypto.ECDsaCheckMultisig interop 2020-04-13 13:47:39 +03:00
Roman Khimov
2d0ad30fcf vm: rework Map with internal slice representation
Which makes iterating over map stable which is important for serialization and
and even fixes occasional test failures. We use the same ordering here as
NEO 3.0 uses, but it should also be fine for NEO 2.0 because it has no
defined order.
2020-04-01 19:33:53 +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
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
Evgenii Stratonikov
c821e1c4c8 vm: move IntToBytes and BytesToInt to emit package 2020-02-06 18:45:37 +03:00
Evgenii Stratonikov
f15ceff592 vm: make IntToBytes, BytesToInt public
VM serialization format should be able to be reused.
2020-01-28 16:39:19 +03:00
Evgenii Stratonikov
f0083b94c5 vm: use new big.Int (de-)serialization routines
Also fix a test with CAT.
2020-01-17 17:37:50 +03:00
Evgenii Stratonikov
3ff7fd5262 vm: implement Neo.Enumerator.* interops 2019-12-24 10:21:46 +03:00
Roman Khimov
33958be45f
Merge pull request #559 from nspcc-dev/feature/stack_limits
vm: don't refcount simple items

Improves 1.4M to 1.5M 100K mainnet block import test by ~4%.
2019-12-23 12:44:01 +03:00
Evgenii Stratonikov
f957af35d4 vm: do not store items of scalar types in map
As they do not contain any other items,
they can be only accounted via total size.
2019-12-18 11:12:19 +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
587cfc7c66 vm: optimize ROLL/ROT, refactor common code
Add `Roll` method to Stack that doesn't pop and push values and use it for
ROLL and ROT.

1.4M->1.5M 100K block import test before:
real    3m44,292s
user    5m43,494s
sys     0m34,741s

After:
real    3m40,449s
user    5m42,701s
sys     0m35,500s
2019-12-16 19:53:21 +03:00
Roman Khimov
2627628387 vm: optimize SWAP instruction, refactor common code
Add `Swap` method to the Stack and use it for both SWAP and XSWAP. Avoid
element popping and pushing (and associated accounting costs).

1.4M->1.5M 100K block import test before:
real    3m51,885s
user    5m54,744s
sys     0m38,444s

After:
real    3m44,292s
user    5m43,494s
sys     0m34,741s
2019-12-16 19:02:40 +03:00
Roman Khimov
05f3329ec0 vm: add IterBack to the Stack to iterate bottom-to-top
And use it to build user-facing stack representation because that's the order
that C# VM uses.
2019-11-27 13:00:11 +03:00
Roman Khimov
5ce269c035 core: change notify implementation to save notifications
Fixes #453 and makes it possible to refer to these notifications later.
2019-11-15 18:04:59 +03:00
Evgenii Stratonikov
4c688355bc vm: revert bool -> []byte conversion to NEO 2.x 2019-11-06 12:15:48 +03:00
067d9655bf vm: restrict total stack item count 2019-11-06 11:03:43 +03:00
cd690803cf vm: implement BigInteger item serialization 2019-11-05 15:15:43 +03:00
Roman Khimov
94776b8a1f vm: add MarshalJSON to the Stack
To easily dump it in a known format.
2019-10-29 18:26:59 +03:00
Vsevolod Brekelov
8ee421db14 fix spelling and godoc comments 2019-10-22 17:56:03 +03:00
Roman Khimov
1bf232ad50 vm: introduce TryBool() for Element and use it in VerifyWitnesses
Script can return non-bool results that can still be converted to bool
according to the usual VM rules. Unfortunately Bool() panics if this
conversion fails which is OK for things done in vm.execute(), but certainly
not for VerifyWitnesses(), thus there is a need for TryBool() that will just
return an error in this case.
2019-10-04 16:13:39 +03:00
Roman Khimov
d62a367900 vm: add Value() method to Element
It gives access to the internal value's Value() which is essential for interop
functions that need to get something from InteropItems. And it also simplifies
some already existing code along the way.
2019-10-04 16:13:39 +03:00
Roman Khimov
cfa0c13322 vm: add InteropItem type for interop data
This is an opaque data item that is to be used by the interop functions.
2019-10-04 16:13:39 +03:00
Roman Khimov
ca9c9be71f vm: add CHECKSIG/VERIFY/CHECKMULTISIG implementations
Fix #269.
2019-09-24 13:01:54 +03:00
Evgenii Stratonikov
fd264cb06f vm: make REVERSE work with structs
Also add more tests.
Extend `Array` method of `Element` to work with `StructItem`.
2019-09-16 15:50:51 +03:00
Evgenii Stratonikov
f2393e5efc vm: implement * -> Boolean conversion 2019-09-10 17:29:10 +03:00
Evgenii Stratonikov
7e14c5a274 vm: implement * -> ByteArray conversion 2019-09-10 17:29:07 +03:00
Evgenii Stratonikov
52b0d661e0 vm: implement BigInt -> Boolean conversion 2019-09-10 14:19:36 +03:00
Roman Khimov
5bd50c7bcd vm: add some tests for PACK instruction 2019-09-06 13:15:30 +03:00
Roman Khimov
974f5db6bc vm: add a TUCK implementation with tests
Also fix stack's InsertAt for the edge case of inserting into a position that
currently is empty (the first good TUCK test illustrates this).
2019-09-05 17:35:30 +03:00
Roman Khimov
85831e3e92 vm: fix XTUCK implementation, add tests
The code that we have actually implements XTUCK and not TUCK. And it's a bit
broken, so fix it and add some tests. The most interesting one (that required
to touch stack code) is the one when we have 1 element on the stack and are
trying to tell XTUCK to push 2 elements deep.
2019-09-05 17:34:25 +03:00
Evgeniy Kulikov
67cbcac643 Fix typos (#133)
* Fix typos

* revert chains/unit_testnet

* revert chains

* fix review comments (thx @AlexVanin)
2019-02-13 18:01:10 +00:00
Evgeniy Kulikov
630919bf7d Fix typos and warnings for GoReport / GolangCiLinter (#132)
- typos
- gofmt -s
- govet warnings
- golangci-lint run
2019-02-09 16:53:58 +01:00
Anthony De Meulemeester
941bd7e728
VM and compiler update (#63)
* renamed test folders and fixed bug where wrong jump labels would be exectuted for rewrite.

* Added support for Osize (len(string)) and factored out the array tests

* Added current instruction number to VM prompt if program is loaded.

* added support for unary expressions.

* updated README of and sorted the help commands

* updated readme of the compiler

* bumped version -> 0.39.0
2018-04-04 21:41:19 +02:00
Anthony De Meulemeester
69c3e645b6
VM improvements, tests + bugfixes (#61)
* changed vm commands to match more of the standard

* fixed Uint16 jmp bug in VM

* moved test to vm + fixed numnotequal bug

* fixed broken tests

* moved compiler tests to vm tests

* added basic for support + inc and dec stmts

* bumped version
2018-04-02 17:04:42 +02:00
Anthony De Meulemeester
931388b687
Cross platform virtual machine implementation (#60)
* Virtual machine for the NEO blockhain.

* fixed big.Int numeric operation pointer issue.

* added appcall

* Added README for vm package.

* removed main.go

* started VM cli (prompt) integration

* added support for printing the stack.

* moved cli to vm package

* fixed vet errors

* updated readme

* added more test for VM and fixed some edge cases.

* bumped version -> 0.37.0
2018-03-30 18:15:06 +02:00