Evgenii Stratonikov
df18da0ac9
vm: implement NEWMAP opcode
2019-09-24 17:06:17 +03:00
Roman Khimov
ca9c9be71f
vm: add CHECKSIG/VERIFY/CHECKMULTISIG implementations
...
Fix #269 .
2019-09-24 13:01:54 +03:00
Roman Khimov
3bbeb2476e
vm: introduce HasFailed() method and use it where appropriate
...
It's gonna be used by external modules.
2019-09-23 20:19:07 +03:00
Evgenii Stratonikov
3c53beca82
vm: restrict SHL/SHR arguments to -256..256
...
Also unify SHL/SHR implementation.
2019-09-23 15:13:10 +03:00
Evgenii Stratonikov
4a8be486f0
vm: do not pop items in OVER
2019-09-23 14:54:59 +03:00
Evgenii Stratonikov
7cd69ea8e2
vm: truncate length in SUBSTR
...
Also fail on first error, without changing the stack.
2019-09-23 14:54:59 +03:00
Evgenii Stratonikov
a88a8e13fc
vm: compare Array by reference in EQUAL
2019-09-23 13:25:59 +03:00
Evgenii Stratonikov
99f1d761ca
vm: clone Struct on APPEND
2019-09-23 13:25:59 +03:00
Roman Khimov
42df4c2f39
vm: update and move README, refs. #339
2019-09-18 12:10:12 +03:00
Roman Khimov
778d29f543
compiler: update and move README to the docs folder
...
Refs. #339 .
2019-09-17 19:09:02 +03:00
Evgenii Stratonikov
d2ccc3b017
vm: make REVERSE consume an item from stack
2019-09-16 15:50:51 +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
f0426ac2d5
vm: do nothing if SHL/SHR by 0
2019-09-16 15:50:51 +03:00
Evgenii Stratonikov
9eca5ee317
vm: convert SIZE argument to bytearray
2019-09-16 15:50:51 +03:00
Evgenii Stratonikov
9780889239
vm: make NEWARRAY/NEWSTRUCT accept bytearray
2019-09-16 15:50:51 +03:00
Evgenii Stratonikov
09e197eaf3
vm: make PUSH0 create empty bytearray
...
Also make tests expect []byte{} instead of 0.
2019-09-16 15:50:51 +03:00
Evgenii Stratonikov
66501f9ef9
vm: make REMOVE consume array from stack
2019-09-16 15:50:14 +03:00
Evgenii Stratonikov
71cfd14b92
vm: create an array of false
items in NEWARRAY/NEWSTRUCT
2019-09-16 15:24:58 +03:00
Evgenii Stratonikov
bafdb916a0
vm: make PICKITEM accept bytearrays
2019-09-16 15:24:58 +03:00
Evgenii Stratonikov
1881adabb9
vm: fail if NIP has not enough arguments
2019-09-16 15:24:58 +03:00
Evgenii Stratonikov
6e4014547d
vm: fail if DROP has no argument
2019-09-16 15:24:58 +03:00
Evgenii Stratonikov
729b7a0b24
vm: fail if ROT has not enough arguments
2019-09-16 15:24:58 +03:00
Evgenii Stratonikov
cf7fbb80ba
vm: fail if EQUAL has not enough arguments
2019-09-16 15:24:58 +03:00
Evgenii Stratonikov
d257044298
vm: fail if XTUCK argument is 0
2019-09-16 15:24:58 +03:00
Evgenii Stratonikov
56ec097d76
vm: fix codegen for APPEND
2019-09-13 11:24:21 +03:00
Evgenii Stratonikov
68c6c93980
vm: do not allow APPEND to operate on bytearray
2019-09-11 17:17:37 +03:00
Evgenii Stratonikov
723dcc6e25
vm: make APPEND push no value on stack
2019-09-11 17:17:34 +03:00
Roman Khimov
8311bda355
vm: harden LEFT and RIGHT implementations against negative indexes
2019-09-11 14:51:04 +03:00
Roman Khimov
17f3a21e27
vm: harden SUBSTR implementation against bad index/offset values
...
The upper index bound for slices is capacity, not length. Check for negative
values also. Fixes #387 .
2019-09-11 14:37:41 +03:00
Roman Khimov
fc1075bf75
vm: protect PUSHDATA from short reads
...
Same thing done in a2a8981979
for PUSHBYTES,
failing to read the amount of bytes specified should lead to FAULT. Also
makes readUint16() and readUint32() panic as this is the behavior we want in
these cases. Add some tests along the way.
2019-09-11 12:35:37 +03:00
Roman Khimov
392a4c4f39
vm/cli: add some convenience heuristic to ease 'run' use
2019-09-10 23:31:06 +03:00
Roman Khimov
c5911c2f10
vm/cli: add support for bool type as 'run' parameter
2019-09-10 23:31:06 +03:00
Roman Khimov
982bdcd704
vm/cli: make operation mandatory if anything added to run
...
Matches neo-cli behavior.
2019-09-10 23:31:06 +03:00
Roman Khimov
5bd666b786
vm: return NOP as current instruction for just loaded VM
...
Before:
NEO-GO-VM > loadgo h.go
READY: loaded 16 instructions
NEO-GO-VM > ip
instruction pointer at -1 (PUSH0)
After:
NEO-GO-VM > loadgo h.go
READY: loaded 16 instructions
NEO-GO-VM > ip
instruction pointer at -1 (NOP)
I think NOP is a little less scary.
2019-09-10 23:31:06 +03:00
Roman Khimov
e872b6b421
vm/cli: redo the whole thing using abiosoft/ishell
...
Adds history support, better editing and way better help system. Expand on
some helps while at it.
2019-09-10 23:31:06 +03:00
Evgenii Stratonikov
31f4c7486b
vm: add tests for CAT
2019-09-10 17:33:42 +03:00
Evgenii Stratonikov
1289d0f7e9
vm: add tests for NOT
2019-09-10 17:29:10 +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
9b10b4c4d8
vm: add tests for SIGN
2019-09-10 15:08:42 +03:00
Evgenii Stratonikov
52b0d661e0
vm: implement BigInt -> Boolean conversion
2019-09-10 14:19:36 +03:00
Evgenii
0b58ed4a22
vm: do not fault on LEFT with big index
...
Fixes #378 .
2019-09-09 17:29:31 +03:00
Roman Khimov
a039ae6cdb
Merge pull request #374 from nspcc-dev/makefile-and-gofmt
...
Makefile convenience targets and gofmt
2019-09-09 15:05:12 +03:00
Roman Khimov
a2a8981979
vm: fix not failing PUSHBYTES* on short read
...
Add some tests also. Fixes #361 .
2019-09-09 12:09:05 +03:00
Roman Khimov
fabd11699a
*: gofmt -s
...
Appy gofmt for all the source tree.
2019-09-09 12:02:24 +03:00
Roman Khimov
450063de7d
Merge pull request #362 from nspcc-dev/add-missing-opcodes-into-the-list
...
Add missing opcodes into the list
2019-09-09 11:24:39 +03:00
Roman Khimov
7b0c2781d2
vm: expand instruction list with commands from current VM spec
...
Current NEO documentation lists them:
https://docs.neo.org/docs/en-us/tooldev/advanced/neo_vm.html
CALL_* instructions were left out because of conflict with golint (but they're
removed in NEO 3.0 anyway, so wasting time on them makes no sense).
Update autogenerated instruction_string.go accordingly.
2019-09-08 20:46:35 +03:00
Evgenii
bcc8234155
vm: implement Array <-> Struct conversion
...
Reference VM implementation supports convertation from
Struct to Array via NEWARRAY and vice versa.
https://github.com/neo-project/neo-vm/pull/91
2019-09-08 13:40:21 +03:00
Roman Khimov
7e8dc9ad66
vm: uncomment TestForLoopBigIter
...
It works just fine.
2019-09-07 10:10:11 +03:00
Roman Khimov
1c7d203993
compiler: drop TODO comment, #294 was fixed a while ago
2019-09-07 10:09:42 +03:00
Roman Khimov
8169edf04c
vm: expand PUSHBYTES instructions
...
Allows to reliably use String() on any of those. Update autogenerated
instruction_string.go accordingly.
2019-09-06 19:14:47 +03:00
Roman Khimov
aefe572df3
vm: implement UNPACK, REVERSE, REMOVE opcodes
...
Also expand makeStackItem() to accept slices of int for testing
convenience. Fixes #195 .
2019-09-06 19:00:34 +03:00
Roman Khimov
5bd50c7bcd
vm: add some tests for PACK instruction
2019-09-06 13:15:30 +03:00
Roman Khimov
b3ed3d24ee
vm: implement CAT, SUBSTR, LEFT and RIGHT
...
String instruction set.
2019-09-06 12:41:27 +03:00
Roman Khimov
3f40334979
vm: add generic stub for all unimplemented instructions
2019-09-05 17:35:30 +03:00
Roman Khimov
59de72f446
vm: implement INVERT instruction
2019-09-05 17:35:30 +03:00
Roman Khimov
b494e094c0
vm: add XDROP implementation
2019-09-05 17:35: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
eb224aeebe
vm: add some checks for OVER and PICK, add OVER tests
...
These actually behaved correctly because of deferred sigsegv recover, but I
think it would be nice to print something more meaningful for users.
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
Roman Khimov
5f0f9e1638
vm: implement PICK instruction
2019-09-05 15:18:04 +03:00
Roman Khimov
b34a1b6c25
vm: harden tests against VM failures
...
Add a check for failed VM state, some of tests using logic values (like NZ
test) can succeed even with VM in FAULT state otherwise.
2019-09-05 15:09:08 +03:00
Roman Khimov
fcf9c1213b
vm: implement the NZ opcode
2019-09-05 15:05:44 +03:00
Roman Khimov
a9b9c9226d
*: add/fix godoc comments to satisfy golint
...
Fixes things like:
* exported type/method/function X should have comment or be unexported
* comment on exported type/method/function X should be of the form "X ..."
(with optional leading article)
Refs. #213 .
2019-09-03 17:57:51 +03:00
Roman Khimov
42dfca47cf
vm: fix double VM run from CLI
...
Fixes one more instruction being ran when VM FAULTs:
NEO-GO-VM > run
NEO-GO-VM > error encountered at instruction 6 (ROLL)
NEO-GO-VM > runtime error: invalid memory address or nil pointer dereference
FAULT
NEO-GO-VM > error encountered at instruction 7 (SETITEM)
NEO-GO-VM > interface conversion: interface {} is []vm.StackItem, not []uint8
Refs. #96 .
2019-08-31 09:06:56 +03:00
Roman Khimov
428e789ddc
vm: produce better error for ROLL with wrong index
...
Current VM implementation doesn't return errors for many operations, so the
only way to handle it here is to check for NULL. Refs. #96 .
2019-08-31 09:04:59 +03:00
Roman Khimov
ec7e17ffa6
pkg: make use of the new crypto/hash package
...
Simplifies a lot of code and removes some duplication. Unfortunately I had to
move test_util random functions in same commit to avoid cycle
dependencies. One of these random functions was also used in core/transaction
testing, to simplify things I've just dropped it there and used a static
string (which is nice to have for a test anyway).
There is still sha256 left in wallet (but it needs to pass Hash structure into
the signing function).
2019-08-26 13:32:19 +03:00
Roman Khimov
18d971440b
vm: expand binary expr tests with cases from #294
...
Make a full set of numeric/string comparisons with `==` and `!=` being
evaluated to true and false.
2019-08-20 20:43:43 +03:00
Roman Khimov
9b421874ae
vm: enable assign/binary/numeric/struct tests
...
These were not used for some reason.
2019-08-20 20:37:06 +03:00
Roman Khimov
0309cff5a2
vm: implement EQUAL via reflection
...
Fixes failing tests.
2019-08-20 19:46:52 +03:00
Roman Khimov
4ccda04eea
compiler: fix string/numbers equality/inequality gen again
...
Unfortunately d58fbe0c88
didn't really fix the
problem because tinfo.Type (the expression resulting type) actually is a bool
and we need to check its parameters. Also, there is need to fix the NEQ
operation.
2019-08-19 19:18:17 +03:00
Evgenii
d58fbe0c88
compiler: use separate opcodes for string and number equality
2019-08-16 16:56:09 +03:00
Roman Khimov
1e09037902
pkg/vm/compiler: update README
...
s/opdump/inspect/ and new sample output.
2019-08-15 19:53:21 +03:00
Roman Khimov
a1e3655560
interop: move into pkg/interop, replace pkg/vm/api
...
neo-storm has developed more wrappers for syscall APIs, so they can and should
be used as a drop-in replacement for pkg/vm/api. Moving it out of vm, as it's
not exactly related to the VM itself.
2019-08-15 19:41:51 +03:00
Roman Khimov
7cd91610df
compiler: quick and dirty inspection fix for JMP instrs
...
These were interpreted completely wrong, they actually have two next bytes
indicating an offset. This patch is a quick fix, actually more work is needed
here to properly display various instructions.
2019-08-15 18:26:52 +03:00
Roman Khimov
1a4055a962
compiler: fix codegen for OR, fixes failing TestLOR
...
0880e88fa5
breaks it by introducing a new label
that is not counted here.
2019-08-15 18:25:22 +03:00
Roman Khimov
810f096811
compiler: change codegen to emit NUMEQUAL instead of EQUAL
...
This is wrong, see issue #294 , but it makes our VM tests work (as VM is
missing EQUAL implementation), so until #294 is properly resolved we're better
have this kind of wrong code generation.
2019-08-15 18:22:56 +03:00
Evgenii
2daebdfce2
compiler: convert unary operators properly
...
Imported from CityOfZion/neo-storm#62 PR.
2019-08-14 20:08:17 +03:00
Evgenii
05c07a8567
compiler: fix argument handling for function arity >= 3
...
Imported from CityOfZion/neo-storm#61 PR.
2019-08-14 20:08:14 +03:00
Evgenii
5ba835d25b
compiler: process packages in deterministic order
...
Imported from CityOfZion/neo-storm#60 PR.
2019-08-14 20:08:05 +03:00
1883a11f44
swap arguments for functions with more than 3 arguments ( CityOfZion/neo-storm#51 )
...
Imported from CityOfZion/neo-storm (402ebb1d6226e2a30d8fdc19663227361cc72ca0).
2019-08-14 19:14:08 +03:00
74602b6143
concatenate strings using CAT opcode ( CityOfZion/neo-storm#54 )
...
Imported from CityOfZion/neo-storm (7d759a23e3af792657c7515645b890eadfa7329f).
2019-08-14 19:14:07 +03:00
Anthony De Meulemeester
36b253872f
WIP
...
Imported from CityOfZion/neo-storm (cbfc89972e977fa808e9f68c9ad5c6c18bef291d).
2019-08-14 19:14:07 +03:00
Anthony De Meulemeester
a765561b3a
implemented bitwise instructions and fixed loading constants of type uint ( CityOfZion/neo-storm#49 )
...
Imported from CityOfZion/neo-storm (b8a9b14dacc4fd6a62c236b2e89545684435a8fb).
2019-08-14 19:14:07 +03:00
Anthony De Meulemeester
459d3654a2
fixed missing syscall transaction.GetHash() ( CityOfZion/neo-storm#43 )
...
Several bug fixes and improvements
Imported from CityOfZion/neo-storm (8e8fe5c215bfaed51452482f4f28cc9956a1f69b).
2019-08-14 19:14:07 +03:00
BlackTrace
69511e053f
update right neo api ( CityOfZion/neo-storm#40 )
...
Imported from CityOfZion/neo-storm (eee635918c80a9444dc1b37e537f9ecaf1a83d33).
2019-08-14 19:14:07 +03:00
Anthony De Meulemeester
0880e88fa5
Fixed bug in else stmts ( CityOfZion/neo-storm#42 )
...
* Fixed bug in else stmts
* Fixed if else bug
* Back to %v for formatting instructions
Imported from CityOfZion/neo-storm (ea8440e1454207753c8d209ce7c2cf724fd4ea16).
2019-08-14 19:14:07 +03:00
Anthony De Meulemeester
b97e5aafec
Fix/bugs ( CityOfZion/neo-storm#38 )
...
* Fixed bug where void functions cleaned up their mess multiple times
* Compiler improvements
* Fixed Neo APIs naming convention
* Added NOP after syscall for matching AVM files with neo-python.
Imported from CityOfZion/neo-storm (f93a28ef87d272a74f821d45ae0c6735a8c610be).
2019-08-14 19:14:07 +03:00
Anthony De Meulemeester
55966c7e07
Draft of iterator and enumerator ( CityOfZion/neo-storm#26 )
...
* Draft of iterator and enumerator
* Added iterator API to the syscall mapping
* Added draft of the enumerator.go file
* Added enumerator interop API.
* Updated the changelog
Imported from CityOfZion/neo-storm (156093318b8612e810965bb1ea26e1babfb46cdd).
2019-08-14 19:14:06 +03:00
Jeroen Peeters
df173c295d
chore: change CompareBytes to EqualBytes ( CityOfZion/neo-storm#22 )
...
* chore: change CompareBytes to EqualBytes
* chore: remove trailing spaces
* chore: rename EqualBytes to Equals
Imported from CityOfZion/neo-storm (da16e967d9631e132488731a42966bccb5ad7f30).
2019-08-14 19:14:06 +03:00
Anthony De Meulemeester
f14833893c
CityOfZion/neo-storm#17 Implemented util.CompareBytes ( CityOfZion/neo-storm#21 )
...
Imported from CityOfZion/neo-storm (c0ee185a7cfd2c222fb7b4c8ca19885844d53855).
2019-08-14 19:14:05 +03:00
Anthony De Meulemeester
b997eeb051
fixed token example and fixed compiler test with multiple dirs ( CityOfZion/neo-storm#20 )
...
Imported from CityOfZion/neo-storm (2d0814a04c34f320dee41674066ccd766a7a8ea1).
2019-08-14 19:14:05 +03:00
Jeroen Peeters
1f8ccdba16
chore: move token example to nep5 as package name ( CityOfZion/neo-storm#19 )
...
* feat: add token example
* feat: code splitted package
* feat: use updated apis
* chore: change token namespace to nep5
* chore: add transfer event and readme updates
Imported from CityOfZion/neo-storm (63ec2d7dc23a60f128a8b383ceda1eaa15d919c1).
2019-08-14 19:14:05 +03:00
Anthony De Meulemeester
9e15ab04ce
Added missing execution interop api ( CityOfZion/neo-storm#14 )
...
Imported from CityOfZion/neo-storm (ab12273da74e0d35df8863f08f1a914723d2bdba).
2019-08-14 19:14:05 +03:00
Anthony De Meulemeester
0b33cf3193
new mapping for interop api ( CityOfZion/neo-storm#10 )
...
* new mapping for interop api
* Fixed interop API mapping + added missing apis
* added engine apis
Imported from CityOfZion/neo-storm (ec5e6c8e2b587704a1e071e83b633d2d3a235300).
2019-08-14 19:14:05 +03:00
Anthony De Meulemeester
2fbb269c0d
added compiler to test all example files. ( CityOfZion/neo-storm#9 )
...
Imported from CityOfZion/neo-storm (e756a91b292f525f2cd7e6d6c05b46df582c8ece).
2019-08-14 19:14:05 +03:00
Anthony De Meulemeester
1927bc54d5
added partial syscall mapping
...
Imported from CityOfZion/neo-storm (26d10c72f6e3d298135ec3995eb2d821640c3b7c).
2019-08-14 18:55:29 +03:00
Roman Khimov
33c512032f
vm: switch from Opcode to Instruction
...
Which matches the changes done in neo-storm and also make this codebase closer
to the `dev` branch (that also uses Instruction).
2019-08-14 15:40:31 +03:00
Evgeniy Kulikov
cdba88b9f2
Code refactoring ( #143 )
...
- simplify code
- prealoc slices
- check errors in tests
- regexp Compile replaced with MustCompile
- uint* cannot be negative
2019-02-19 14:22:33 +01:00
57cb289bcd
make State a set as in reference C# implementation ( #123 )
...
* make State a set as in reference C# implementation
* fix issues
2019-02-19 12:47:25 +01:00