Commit graph

646 commits

Author SHA1 Message Date
Evgenii Stratonikov
1611ede58c crypto/keys: implement NewPublicKeyFromBytes()
It is convenient to have a single function instead of
allocating new `PublicKey` and using `DecodeBytes()` on it.
2020-04-13 13:13:15 +03:00
Roman Khimov
5a22651e36
Merge pull request #784 from nspcc-dev/neo3/null
vm: support NULL stack item
2020-04-10 10:38:17 +03:00
Anna Shaleva
9f0bc2aaf5 vm: add tests to CALL* instructions
closes #452
2020-04-09 11:20:39 +03:00
Anna Shaleva
495c1b0565 vm: add tests for missing bit and numeric operations
Added tests for:
  - bit operatoins: AND, OR, XOR
  - numeric operations: BOOLOR, MIN, MAX, WITHIN, NEGATE
2020-04-07 18:10:31 +03:00
Evgenii Stratonikov
96806262bf vm: handle negative arguments in SHL/SHR
Do it as in reference implementation: a >> -b == a << b.
2020-04-06 10:46:35 +03:00
Evgenii Stratonikov
0023c4f1f6 vm: use truncated division in MOD
Mimic C#'s `%` behavior.
Related 4b44190 (#773).
2020-04-06 09:30:48 +03:00
Evgenii Stratonikov
f7f48d0048 vm: implement ISNULL opcode 2020-04-02 14:15:17 +03:00
Evgenii Stratonikov
3db030bbb6 vm: implement PUSHNULL opcode 2020-04-02 14:15:17 +03:00
Evgenii Stratonikov
e50b529631 vm: implement Null item 2020-04-02 14:15:17 +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
Roman Khimov
3dbe549a61 smartcontract: store MapType Parameter as a slice of KV pairs
Fixes #809.

Basically, there are three alternative approaches to fixing it:
 * allowing both []byte and string for ByteArrayType value
   minimal invasion into existing code, but ugly as hell and will probably
   backfire at some point
 * storing string values in ByteArrayType
   incurs quite a number of type conversions (and associated data copying),
   though note that these values are not changed usually, so dynamic
   properties of []byte are almost irrelevant here
 * storing only []byte values in ByteArrayType
   makes it impossible to use them as map keys which can be solved in several
   ways:
   - via an interface (Marshalable)
     which is good, but makes testing and comparing values in general harder,
     because of keys mismatch
   - using serialized Parameter as a key (in a string)
     which will need some additional marshaling/unmarshaling
   - converting MapType from map to a slice of key-value pairs
     not a bad idea as we don't use this map as a map really, the type
     itself is all about input/output for real VM types and this approach is
     also a bit closer to JSON representation of the Map
2020-04-01 19:21:00 +03:00
Anna Shaleva
a8fa9c9244 vm: add tests to stack_item.go
closes #199
2020-03-31 17:18:13 +03:00
Roman Khimov
0d482ceb7f
Merge pull request #808 from nspcc-dev/fix-map-serialization
vm: make map serialization more compatible with C#
2020-03-29 13:40:52 +03:00
Roman Khimov
665bf78d11 vm: make map serialization more compatible with C#
C# pushes value and key to the stack of non-serialized items, so key gets
serialized first followed by value. Fixes #806.

Notice though that neither IDictionary in C#, nor map in Go have elements
ordered, so we can easily get a difference in KV pairs order and it would be
impossible to fix.
2020-03-28 17:25:42 +03:00
Evgenii Stratonikov
db2dccf7cb emit: implement AppCallWithOperationAndArgs
It is nice to have a typical task of calling contract method
with specific arguments incapsulated inside some function.
2020-03-27 11:05:36 +03:00
Evgenii Stratonikov
4522eed1bb vm: fix offset for CALLI opcode
It is different from other JMP* and +2 should be added to the parameter.
2020-03-26 13:09:55 +03:00
Evgenii Stratonikov
dc8fb13021 vm: make NewBigInteger accept int64
It is more correct upconvert to int64 if needed,
so precision is never lost.
2020-03-24 11:10:56 +03:00
Roman Khimov
5148b98f43
Merge pull request #773 from nspcc-dev/fix/bigint
vm: use truncated division for Integers
2020-03-23 18:01:21 +03:00
Evgenii Stratonikov
954e8cdcf1 vm: allow to push integer-like items to stack
Perform automatic conversion of non-standard integer types to
int64 if possible.

Closes #776.
2020-03-18 12:58:31 +03:00
Evgenii Stratonikov
4b44190485 vm: use truncated division for Integers
When divisor is negative, the result is truncated towards
zero.
2020-03-17 15:45:56 +03:00
Roman Khimov
1b5dd53e07
Merge pull request #746 from nspcc-dev/fix/equal
vm: implement EQUAL opcode properly

Fixes #745, #749.
2020-03-12 11:46:51 +03:00
Evgenii Stratonikov
dfc59129c7 vm: implement EQUAL opcode properly
When comparing elements of different types, conversions
should be performed. This commit implement custom equality
predicate for each stack item type.
2020-03-11 17:19:10 +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
8318adac56 vm: add support for dynamic invocations in APPCALL
Fixes #740.
2020-03-10 17:17:36 +03:00
Evgenii Stratonikov
8819d4f970 vm: implement ParseMultisigContract()
When creating witness for a multisig contract, it is
needed to extract the order of public keys from it.
2020-03-05 09:43:14 +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
Roman Khimov
9b4fd99fbc vm: break circular references when recursing into ToContractParameters
Reference types can have circular pointers to each other, thus we need to
control recursion.
2020-03-03 15:38:03 +03:00
Evgenii Stratonikov
6541bd4d42 vm: use Boolean in (*BoolItem).String() 2020-03-02 18:01:49 +03:00
Roman Khimov
252a9f2f31
Merge pull request #690 from nspcc-dev/feature/getapplicationlog
rpc: implement getapplicationlog RPC
2020-03-02 17:41:32 +03:00
Anna Shaleva
ff4384d7ff rpc: implement getapplicationlog RPC
Closes #500
2020-03-02 17:25:27 +03:00
Evgenii Stratonikov
a3dacd3b74 tests: replace t.Fatal with require where possible
This makes tests less verbose and unifies the style
they are written in.
2020-03-02 17:22:27 +03:00
Evgenii Stratonikov
5e229d84d4 compiler: use uint16 for label numbers
As noted in #687 this will make compiler a bit more predictable.
2020-02-21 17:45:45 +03:00
Evgenii Stratonikov
3e84f2bdf8 compiler: rewrite jump targets properly
Old implementation could view 0x62 byte in
a script as a JMP instruction irregardless of whether it is
a real opcode or a part of a parameter of another instruction.
In this commit instructions are decoded together with parameters
during jump label rewriting.
2020-02-12 10:58:53 +03:00
Roman Khimov
268cad5c06
Merge pull request #548 from nspcc-dev/feature/multisig
vm: implement parallel algorithm for CHECKMULTISIG
2020-02-08 16:10:34 +03:00
Roman Khimov
9b9adb28c1
Merge pull request #642 from nspcc-dev/feature/emit
vm, compiler: move Emit* functions to a separate package

Closes #449, #534.
2020-02-08 15:56:48 +03:00
Roman Khimov
b805b1a71b vm: make SerializeItem/DeserializeItem public APIs
They're useful as wrappers around EncodeBinaryStackItem/DecodeBinaryStackItem.
2020-02-07 15:34:59 +03:00
Roman Khimov
7e7ce7f19f vm: rephrase serialization errors
Seeing some
    blockQueue: failed adding block into the blockchain        {"error": "failed to store notifications: not supported", "blockHeight": 713984, "nextIndex": 713985}
in logs is not very helpful.
2020-02-07 11:53:53 +03:00
Evgenii Stratonikov
a8dc704197 emit: add tests for Int 2020-02-06 18:45:37 +03:00
Evgenii Stratonikov
6fd3f0fa48 emit: add tests for Bytes 2020-02-06 18:45:37 +03:00
Evgenii Stratonikov
5e992d8cdd emit: add tests for Syscall, Jmp 2020-02-06 18:45:37 +03:00
Evgenii Stratonikov
8243a8b3a7 emit: use io.BinWriter instead of bytes.Buffer 2020-02-06 18:45:37 +03:00
Evgenii Stratonikov
698c647f07 emit: refactor tests
Add structure and call Bytes() method on buffer once.
2020-02-06 18:45:37 +03:00
Evgenii Stratonikov
1400ecfdde emit: fix Int to serialize integers in correct format
Related #605, #623.
2020-02-06 18:45:37 +03:00
Evgenii Stratonikov
c821e1c4c8 vm: move IntToBytes and BytesToInt to emit package 2020-02-06 18:45:37 +03:00
Evgenii Stratonikov
4d8a3a359b vm: move Emit* functions to a separate package
Also strip 'Emit' prefix because 'emit' is now
in the package name.
2020-02-06 18:45:37 +03:00
Evgenii Stratonikov
2a86149c82 vm: leave single CHECKMULTISIG implementation
Remove sequential implementation and benchmarks.
They will be still present in commit history.
2020-02-05 17:17:22 +03:00
Roman Khimov
02a5e036fc vm: deduplicate checkMultisigPar
Make its logic more clear.
2020-02-05 17:12:23 +03:00
Evgenii Stratonikov
d93d060010 vm: parallelize CHECKMULTISIG 2020-02-05 17:12:18 +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
7a6d6f43ce vm: get rid of recursive (*VM).execute calls
Recursive execute() calls can affect gas calculation.
This commit makes execute() be called only for real opcodes
and moves duplicate logic for CALL/JMP into a separate function.
2020-01-22 14:31:57 +03:00
Evgenii Stratonikov
d72d978a19 vm: abstract out GetInterop() function 2020-01-22 14:04:40 +03:00
Evgenii Stratonikov
c22d09adad vm: set GAS limit
Make it possible to set maximum amount of GAS which can be spent
during execution.
2020-01-22 14:04:40 +03:00
Evgenii Stratonikov
0662a7e3c2 vm: calculate GAS spent during execution
If getPrice callback is provided, accumulate spent GAS.
2020-01-22 14:04:40 +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
f26bdae2c5 vm: implement proper big.Int to []byte conversions
Big.Int Bytes()/SetBytes() methods are not symmetric.
Moreover we need to mimic C# node behavior:
- if a positive number has MSB set, 0x00 byte should be appended
  to distinguish positive number from negatives
- negative numbers should serialize as two's-complement
2020-01-17 17:37:50 +03:00
Roman Khimov
46b82b4fb5 keys: don't return error from PrivateKey.Sign
As it can't ever happen.
2020-01-17 17:00:30 +03:00
Evgenii Stratonikov
7b5c47e7f5 vm: add NewMapIterator() 2019-12-26 14:34:15 +03:00
Evgenii Stratonikov
5bc32b523a vm: implement Neo.Iterator.* interops 2019-12-24 10:21:47 +03:00
Evgenii Stratonikov
3ff7fd5262 vm: implement Neo.Enumerator.* interops 2019-12-24 10:21:46 +03:00
Roman Khimov
cc16dac0b4 vm: optimize script loading a bit
Preseed the scriptHash value when we already know it. Eliminates this time
waste from the pprof graph, but doesn't really change anything in the 1.4M ->
1.5M 100K mainnet blocks import test.
2019-12-23 18:02:39 +03:00
Roman Khimov
094c8474b7 compiler: move tests from vm/tests
These don't belong to VM as they compile some Go code and run it in a VM. One
may call them integration tests, but I prefer to attribute them to
compiler. Moving these tests into pkg/compiler also allows to properly count
the compiler coverage they add:

-ok     github.com/CityOfZion/neo-go/pkg/compiler       (cached)        coverage: 69.7% of statements
+ok     github.com/CityOfZion/neo-go/pkg/compiler       (cached)        coverage: 84.2% of statements

This change also fixes `contant` typo and removes fake packages exposed to the
public by moving foo/bar/foobar into the testdata directory.
2019-12-23 17:05:34 +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
Roman Khimov
79323cc10b
Merge pull request #567 from nspcc-dev/feature/codegen_add_mod
compiler: Add Mod token, closes #563
2019-12-19 15:32:18 +03:00
Vsevolod Brekelov
1458116567 vm: add tests 2019-12-19 15:23:14 +03:00
Roman Khimov
26ea4799c3
Merge pull request #565 from nspcc-dev/hashed-interop-callback
vm/core: add ID support for SYSCALL, redo interop registration
2019-12-19 15:02:53 +03:00
Roman Khimov
5f3a220b48
Merge pull request #566 from nspcc-dev/feature/varindex
compiler: implement assignment to a variable index
2019-12-19 13:40:32 +03:00
Roman Khimov
a7457d08a1 vm/core: add ID support for SYSCALL, redo interop registration
This solves two problems:
 * adds support for shortened SYSCALL form that uses IDs (similar to #434, but
   for NEO 2.0, supporting both forms), which is important for compatibility
   with C# node and mainnet chain that uses it from some height
 * reworks interop plugging to use callbacks rather than appending to the map,
   these map mangling functions are clearly visible in the VM profiling
   statistics and we want spawning a VM to be fast, so it makes sense
   optimizing it. This change moves most of the work to the init() phase
   making VM setup cheaper.

Caveats:
 * InteropNameToID accepts `[]byte` because that's the thing we have in
   SYSCALL processing and that's the most often usecase for it, it leads to
   some conversions in other places but that's acceptable because those are
   either tests or init()
 * three getInterop functions are: `getDefaultVMInterop`, `getSystemInterop`
   and `getNeoInterop`

Our 100K (1.4M->1.5M) block import time improves by ~4% with this change.
2019-12-19 13:35:42 +03:00
Evgenii Stratonikov
891a878af1 compiler: implement assignment to a variable index
Fixes #564.
2019-12-19 13:14:17 +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
10766fe813 vm: add tests for hashing instructions
These were cross-checked with the C# implementation.
2019-12-17 20:31:16 +03:00
Roman Khimov
21efcb012b vm: fix non-dupped items in PICKITEM
TestPICKITEMDupMap and TestPICKITEMDupArray were failing.
2019-12-17 20:26:30 +03:00
Roman Khimov
a6d60e387a vm: fix OVER and PICK to duplicate stack items
TestPICKDup and TestOVERDup failed without this.
2019-12-17 20:26:30 +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
c596a6b273 vm: fix INVERT behaviour for converted values
Tests added were failing before this change.
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
c9257c3de4 vm: optimize Next() in Context
Creating a new BinReader for every instruction is a bit too much and it adds
about 1% overhead on block import (and actually is quite visible in the VM
profiling statistics). So use a bit more ugly but efficient method.
2019-12-13 19:57:17 +03:00
Roman Khimov
0abd55c2c2 vm: add cached ScriptHash() to Context
Avoid recalculating it over and over again in interop.
2019-12-13 17:05:03 +03:00
Roman Khimov
0afaff2f79 vm: microoptimize RegisterInteropFuncs()
Avoid useless copying.
2019-12-13 17:02:28 +03:00
Roman Khimov
8b3080b972 io: rename Read/WriteBytes to Read/WriteB
go vet is not happy about them:
  pkg/io/binaryReader.go:92:21: method ReadByte() byte should have signature ReadByte() (byte, error)
  pkg/io/binaryWriter.go:75:21: method WriteByte(u8 byte) should have signature WriteByte(byte) error
2019-12-12 20:19:50 +03:00
Roman Khimov
54d888ba70 io: add type-specific read/write methods
This seriously improves the serialization/deserialization performance for
several reasons:
 * no time spent in `binary` reflection
 * no memory allocations being made on every read/write
 * uses fast ReadBytes everywhere it's appropriate

It also makes Fixed8 Serializable just for convenience.
2019-12-12 20:19:50 +03:00
Roman Khimov
d0f9a28196 vm/core: improve block import speed with PublicKey caching
This change (closely related to the neo-project/neo#1321 proposal) speeds up
1.4M mainnet blocks import by 30%. Basically, we're eliminating key decoding
for block's multisignature that has the same keys most of the time.

Things I don't like about this patch:
 * yet another parameter for verifyHashAgainstScript()
 * vm keys are not copied in/out

But it's rather simple and solves the problem for this particular case, so I
think it's worth it.
2019-12-10 19:13:29 +03:00
Evgenii Stratonikov
838050f8b5 io: rename ReadBytes() to ReadVarBytes() 2019-12-09 15:00:15 +03:00
Roman Khimov
e4d821f32d
Merge pull request #546 from nspcc-dev/write-optimizations
Write optimizations
2019-12-06 19:40:38 +03:00
Roman Khimov
844491d365 *: use more efficient WriteBytes where appropriate
Before this patch on block import we could easily be spending more than 6
seconds out of 30 in Uint256 encoding for UnspentBalance, now it's completely
off the radar.
2019-12-06 18:22:21 +03:00
Evgenii Stratonikov
7179e4ba9f util: add LE suffix to Uint256 methods 2019-12-06 12:16:55 +03:00
Evgenii Stratonikov
57efad912c util: add LE suffix to Uint160 methods 2019-12-06 12:16:55 +03:00
Roman Khimov
becd4f2333 vm: force neo-vm tests presence
We succeeded this test without running anything real which is certainly not
good and I think we should always run this tests.
2019-12-04 20:30:27 +03:00
Roman Khimov
852e6a335b compiler: move it up from vm
It really deserves it, I think. Especially given that it doesn't have any
direct usage of `vm` package now.
2019-12-03 18:23:46 +03:00
Roman Khimov
8d4dd2d2e1 vm: move opcodes into their own package
This allows easier reuse of opcodes and in some cases allows to eliminate
dependencies on the whole vm package, like in compiler that only needs opcodes
and doesn't care about VM for any other purpose.

And yes, they're opcodes because an instruction is a whole thing with
operands, that's what context.Next() returns.
2019-12-03 18:22:14 +03:00
Vsevolod Brekelov
b08387efdb vm: use BinWriter instead of Buffered version
In the future we could reuse emit interface without buf better
2019-12-03 13:50:23 +03:00
Vsevolod Brekelov
f5e2401984 vm: removed logging to fix #457 2019-12-03 13:49:49 +03:00
Vsevolod Brekelov
03ff2976ed io: refactoring for using WriteVarBytes instead of WriteLE
goal is to be consistent with C# implementation.
For writing []byte WriteBytes used and for byte - WriteVarByte.
2019-12-03 13:49:33 +03:00
Vsevolod Brekelov
d02673c112 vm: add bufBinWriter to emit functions in order to catch errors 2019-12-02 13:04:33 +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
f3ed91a1f7 vm: properly convert arrays to stackItems
They should be arrays of stackItems, not arrays of values.
2019-11-27 13:00:11 +03:00
Roman Khimov
64e20508e0 vm: use hex for ByteArray JSON marshallization
It's way more convenient for different purposes.
2019-11-15 18:04:59 +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
7080b78a6b vm: fix a bug in collection serialize
When encountering already seen stack item we should fail
only if it is a collection. Duplicate Integers or ByteArrays are ok
because they can't lead to recursion.
2019-11-15 12:48:00 +03:00
Evgenii Stratonikov
816d78b5ee vm: redefine SHL/SHR limits based on integer size 2019-11-07 12:50:11 +03:00
Evgenii Stratonikov
439cd72294 vm: restrict BigInteger item size 2019-11-07 12:34:27 +03:00
Evgenii Stratonikov
6c002297cd vm: implement json tests from neoVM
Add neo-vm submodule @master2.x .
Closes #196.
2019-11-06 16:22:56 +03:00
Evgenii Stratonikov
7d40d2f71e vm: make StepOut/StepOver match original VM behavior 2019-11-06 12:25:04 +03:00
Evgenii Stratonikov
9ebb793009 vm: revert SUBSTR offset behavior to NEO 2.x 2019-11-06 12:15:55 +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
ed758458d5 vm: implement serialization interops in core package 2019-11-05 17:10:52 +03:00
412582dc78 vm: add more serialization tests 2019-11-05 17:04:14 +03:00
59f9c2bddc vm: implement Array and Struct item serialization 2019-11-05 16:58:09 +03:00
e1d019e087 vm: implement Map item serialization 2019-11-05 16:57:48 +03:00
cd690803cf vm: implement BigInteger item serialization 2019-11-05 15:15:43 +03:00
25f77257ce vm: implement Boolean and ByteArray item serialization 2019-11-05 15:15:39 +03:00
Roman Khimov
2f6e678a19
Merge pull request #463 from nspcc-dev/smartcontract-fixes
Smartcontract RPC fixes
2019-10-29 20:54:46 +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
Roman Khimov
47f66dfbf3 vm: add State() method to get a state description 2019-10-29 18:26:04 +03:00
c7f0b7bd68 vm: restrict max invocation stack size 2019-10-29 15:09:17 +03:00
Roman Khimov
579aa31ddd compiler: drop useless options parameter to Compile()
It's not used in any way there.
2019-10-29 13:02:54 +03:00
Roman Khimov
e319c6c638 cli: move avm inspect from vm to contract command
Make inspect work with avms by default and with go files if told so. In the
end this makes our CLI interface more consistent and usable. Drop useless
CompileAndInspect() compiler method along the way.
2019-10-29 12:56:44 +03:00
Roman Khimov
ae7687422c vm: clear state in Load()
Make VM usable after the first run.
2019-10-29 12:53:09 +03:00
Roman Khimov
f0cffe0d3f vm: implement stack isolation opcodes, fix #192
No tests yet.
2019-10-25 18:25:12 +03:00
Roman Khimov
1250bf9579
Merge pull request #443 from nspcc-dev/spellcheck
spellcheck and comments fix
2019-10-22 18:01:40 +03:00
Vsevolod Brekelov
8ee421db14 fix spelling and godoc comments 2019-10-22 17:56:03 +03:00
Roman Khimov
a9a2a3c711 vm: fix tests failing, follow-up to #426
Deal with input and transitional VM states properly.
2019-10-22 15:20:44 +03:00
Roman Khimov
3cbb699eb7
Merge pull request #426 from nspcc-dev/logger_247
Change fmt.Println to log, close #247.
2019-10-22 14:41:30 +03:00
Roman Khimov
558a25cbd2
Merge pull request #438 from nspcc-dev/fix/437
vm: copy slice in NEWARRAY/NEWSTRUCT

Fixes #437.
2019-10-22 14:36:32 +03:00
Vsevolod Brekelov
e2bfff8666 vm: removed mute mode and pushed logging to upper lvl
VM should be responsible for code execution and in case anyone interested in additional logging or errors they could handle them like we do it iin cli.
2019-10-22 13:44:14 +03:00
Evgenii Stratonikov
b2609786e9 vm: copy slice in NEWARRAY/NEWSTRUCT
When performing NEWARRAY on a Struct or NEWSTRUCT on a Array,
underlying slice needs to be copied, because when it's capacity
doesn't matches it's length, underlying storage will be used
for appends even if it is already pointed at by another slice.
2019-10-22 13:34:35 +03:00
Vsevolod Brekelov
f2805541cb vm: fix style and comments 2019-10-21 14:22:17 +03:00
Vsevolod Brekelov
fe39c565b9 codestyle: redundant type conversion 2019-10-18 18:39:31 +03:00
Vsevolod Brekelov
1afdb895a1 codestyle: declare empty slice
https://github.com/golang/go/wiki/CodeReviewComments#declaring-empty-slices
2019-10-18 18:38:33 +03:00
Vsevolod Brekelov
3560ada669 codestyle: use camel case 2019-10-18 18:36:54 +03:00
Vsevolod Brekelov
59e3bd2fa9 codestyle: fix error string should not be capitalized 2019-10-18 18:34:58 +03:00
Vsevolod Brekelov
0daef50b9d cli: fix for error wrapping 2019-10-17 18:23:49 +03:00
Vsevolod Brekelov
5b81110d16 cli: print logo via shell 2019-10-17 18:23:49 +03:00
Evgenii Stratonikov
487570153b vm: restrict max item size in PUSHDATA4 2019-10-17 17:10:00 +03:00
Evgenii Stratonikov
cae431b844 vm: restrict max item size in CAT 2019-10-17 17:09:42 +03:00
Evgenii Stratonikov
6d7016c3b9 vm: restrict max size in SETITEM 2019-10-17 12:17:06 +03:00
Evgenii Stratonikov
6f1f9e56bb vm: restrict max size in PACK 2019-10-17 12:17:06 +03:00
Evgenii Stratonikov
2d56c66bde vm: restrict max size in APPEND 2019-10-17 12:17:01 +03:00
Evgenii Stratonikov
8abcaeee6f vm: restrict max size in NEWARRAY/NEWSTRUCT 2019-10-17 11:48:48 +03:00
Roman Khimov
4822c736bb
Merge pull request #418 from nspcc-dev/various-verification-fixes2
Transaction verification fixes, interops and block verification. Fixes #12.
2019-10-15 19:11:00 +03:00
Roman Khimov
d007cc00cc vm: add script check functions
These are required for future interops.
2019-10-15 12:56:25 +03:00
Roman Khimov
acb7ef7fbd vm: support uint8 and uint64 in makeStackItem()
Convenience to avoid casts, uint64 is also a bit special in that it can't be
converted to int64 without data loss.
2019-10-15 12:56:25 +03:00
Roman Khimov
782ca64d92 vm: accept uint16 in makeStackItem() 2019-10-15 12:56:25 +03:00
Vsevolod Brekelov
5109b2e3e7 vm: fix cli comment 2019-10-14 18:38:05 +03:00
Vsevolod Brekelov
591d5eafbe vm: add stepInto,stepOver,stepOut
Original C# vm debugger behavior
2019-10-14 18:37:11 +03:00
Roman Khimov
dca332f333 vm: use new Context.Next() to properly dump programs
Fix #295, deduplicate code and add `inspect` parameter to the vm command to
dump AVMs (`contract inspect` works with Go code).
2019-10-04 16:13:39 +03:00
Roman Khimov
53a3b18652 vm: completely separate instruction read and execution phases
Make Context.Next() return both opcode and instruction parameter if any. This
simplifies some code and needed to deal with #295.
2019-10-04 16:13:39 +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
8441b31b4b vm: accept uint32 in makeStackItem()
Interop services routinely push such things (block index, blockchain height)
onto the stack.
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
0c963875af vm: check for fault flag first in Run()
Switch cases are evaluated sequentially and the fault case is top-priority to
handle.
2019-10-04 16:13:39 +03:00
Roman Khimov
705c7f106f vm: don't panic if there is no result in PopResult()
This function is intended to be ran outside of the execute's panic recovery
mechanism, so it shouldn't panic if there is no result.
2019-10-04 16:13:39 +03:00
Roman Khimov
a357d99624 vm: introduce MaxArraySize constant
This is both for #373 and for interop functions that have to check some
inputs.
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
da2156f955 vm: add batched RegisterInteropFuncs 2019-10-04 16:13:39 +03:00
Roman Khimov
26e3b6abbe vm: extend interops to contain price
The same way C# node does.
2019-10-04 16:13:39 +03:00
Roman Khimov
ceca9cdb67 core/vm: implement contract storage and script retrieval
Fixes script invocations via the APPCALL instruction. Adjust contract state
field types accordingly.
2019-10-04 16:13:39 +03:00
Roman Khimov
c3591d8897 vm: fix CHECKMULTISIG to comply with NEO VM implementation
Testing with testnet quickly revealed that our code has an issue when the key
count doesn't equal signature count, fix it and add some comments.
2019-10-01 13:41:26 +03:00
Evgenii Stratonikov
c7c4291774 vm: simplify APPEND implementation a bit 2019-09-25 17:53:36 +03:00
Evgenii Stratonikov
13d7770c68 vm: support Map in ARRAYSIZE
Also make logic the same as in reference implementation
and add tests.
2019-09-25 17:53:36 +03:00
Evgenii Stratonikov
c66f493017 vm: compare Map by reference in EQUAL 2019-09-25 17:53:36 +03:00
Evgenii Stratonikov
c0be2b2a99 vm: support Map in REMOVE 2019-09-25 17:53:36 +03:00
Evgenii Stratonikov
8b6bddca3c vm: support Map in PICKITEM and SETITEM 2019-09-25 17:53:36 +03:00
Evgenii Stratonikov
d7bb50c609 vm: implement VALUES opcode 2019-09-25 17:53:36 +03:00
Evgenii Stratonikov
2da64267b0 vm: implement KEYS opcode 2019-09-25 17:53:34 +03:00
Evgenii Stratonikov
0fb4bb05cf vm: implement HASKEY opcode 2019-09-25 12:08:41 +03:00
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
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
Evgeniy Kulikov
f000b76879 [FIX] Formatting and code-style (#118)
* [FIX] Formatting and code-style

- gofmt
- import resort
- prealloc slices
- simplify code

* fix vet
2019-01-25 12:20:35 +01:00
Evgeniy Kulikov
6ccb518ab0 Optimizations + some improvements (#105)
* Optimizations + some improvements

- optimized pkg/core/storage.HeaderHashes
- optimized pkg/rpc.performRequest (used json.Encoder)
- fixes for pkg/util.ReadVarUint and pkg/util.WriteVarUint
- optimized and fix fixed8 (Fixed8DecodeString / MarshalJSON) + tests
- optimized and fix uint160 (Bytes / Uint160DecodeString / Equal / MarshalJSON) + tests
- optimized and fix uint256 (Bytes / Equal / MarshalJSON) + tests
- preallocate for pkg/vm.buildStackOutput
- add go.mod / go.sum

* update version
2018-11-26 16:56:45 +01:00
Anthony De Meulemeester
d77354db66
Add missing compiler interop API functions (#93)
* added runtime serialize and deserialize functions

* removed getCurrentBlock from runtime functions

* Added block and header stdlib interop functions

* added transaction interop api

* added asset interop api

* bumped version

* Added missing storage.Find storage API function

* Fixed wrong example in the compiler README

* updated the compiler README to be more accurate on compiler features
2018-08-19 20:47:10 +02:00
Anthony De Meulemeester
311313f2ff
implemented smart contract utility function FromAddress (#88)
* implemented smart contract utility function FromAddress

* bumped version
2018-07-02 15:02:00 +02:00
Anthony De Meulemeester
35551282b0
Porting the NEX ICO template to neo-go as first class smart contract example (#78)
* Initial draft of the ICO template ported from NEX.

* filled in token configuration

* added kyc storage prefix

* fixed byte array conversion + added tests

* fixed broken test + made 1 file for the token sale example.

* implemented the NEP5 handlers

* bumped version
2018-05-06 08:03:26 +02:00
Anthony De Meulemeester
648563c3e2
Compiler (#73)
Compiler and VM update
2018-04-22 20:11:37 +02:00
Anthony De Meulemeester
4bd5b2812e
Optimisations and API changes for smart contracts (#67)
* support VM to pass method and arguments to a script.

* added support for type assertions in smartcontracts.

* added native vm support for print.

* moved VM API packages to vm -> API

* reverted the native Print opcode in favor of runtime.Log

* added support for registering custom interop hooks in the VM.

* Updated README

* Updated compiler with @OPTIMIZE tags

* Moved more tests to VM package.

* optimized and refactored compiler and vm API

* updated README with new smartcontract apis

* bumped version
2018-04-10 11:45:31 +02:00
Anthony De Meulemeester
5b5a7106c1
Fix append for bytearrays (#64) 2018-04-05 10:35:33 +02: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
Pedro Miguel Domingos da Costa
c51a6d3e57 Fix compile output name (#58)
* Fix output file name

* Bump version
2018-03-29 08:24:45 +02:00
Anthony De Meulemeester
34bd9d31ac
Compiler arrays (#49)
* implemented operation and param flags in the cli invoke cmd.

* reverted prev changes and added debug flag for compiling.

* change transactionType variable to Type, for package convention

* index support for arrays.

* implemented builtin (len) for the compiler.

* bumped version -> 0.35.0

* updated compiler README and changed invoke to testinvoke.
2018-03-25 18:21:00 +02:00
Anthony De Meulemeester
1a1a19da7d
Smartcontract (#39)
* deleted transfer_output added asset type and transaction result to core

* removed writing 0x00 when buffer length is 0

* Refactored emit into VM package + moved tx to own package.

* implemented transaction along with claimTransaction.

* refactored naming of transaction + added decode address for uint160 types

* removed unnecessary folder and files.

* transaction/smartcontract logic

* bumped version 0.24.0
2018-03-04 14:56:49 +01:00
Anthony De Meulemeester
b6b8542caf
Compiler (#37)
* refactored structs so the scope is not needed anymore + fix passing struct in func arguments.

* implemented byte arrays and added runtime tests

* Added sc examples in compiler README + added quick nested if test.

* Updated README

* Changed import paths to interop layer
2018-03-02 16:49:10 +01:00
Anthony De Meulemeester
f3f6662fc9
Base wallet implementation (#35)
* Initial draft of the neo-go wallet

* Cleanup + more test for util package

* integrated wallet into neo-cli partially

* base wallet implementation + smartcontract code.
2018-03-02 16:24:09 +01:00
Anthony De Meulemeester
942650dd8b
Fixed typo in README (#33)
* Fix typo in readme file

* bumped version
2018-02-28 20:45:54 +01:00
Anthony De Meulemeester
2345858238
Compiler update (basic sc ready) (#31)
* refactored structs, the scope is not needed anymore + fix passing struct in func arguments.

* implemented byte arrays and added runtime tests

* Added sc examples in compiler README + added quick nested if test.

* Updated README
2018-02-27 10:04:24 +01:00
Anthony De Meulemeester
de3395fb51
Refactor of imports + lots of sweet stuff (#30)
* implemented global variables.

* refactored imports + lots and lots of other sweet stuff + fix #28.

* Implemented the VM interop runtime API (GetTrigger, CheckWitness, ...)
2018-02-25 13:26:56 +01:00
Anthony De Meulemeester
63bc244163
Updated readme in compiler folder + bumped version to match latest tag. (#29)
* Updated readme in compiler folder + bumped version to match latest tag.
2018-02-24 10:19:15 +01:00
Pawan Rawal
e93dfe8062 Better error messages (#24)
* Print proper error messages while using contract subcommands and also exit with status code 1.

* Make -in a flag, also remove dot from avm extension.

* Work on feedback by Anthony.

* Update README and VERSION
2018-02-24 10:10:45 +01:00
Anthony De Meulemeester
23cfebf621
Compiler (#23)
* implemented add, mul, div, sub assign for identifiers.

* Implemented struct field initialization.

* Implemented imports

* Implemented storage VM API (interop layer) + additional bug fixes when encountered.

* Bumped version 0.12.0

* fixed double point extension on compiled output file.

* Fixed bug where callExpr in returns where added to voidCall

* fixed binExpr compare equal

* Check the env for the gopath first

* removed travis.yml

* custom types + implemented general declarations.

* commented out the storage test to make the build pass
2018-02-24 10:06:48 +01:00
Anthony De Meulemeester
8fe079ec8e
Update compiler (#22)
* refactor to use ast.Walk for recursive converting
* added lots of test cases
* added a new way to handle jump labels
* function calls with multiple arguments
* binary expression (LOR LAND)
* struct types + method receives
* cleaner opcode dumps, side by side diff for debugging test cases
2018-02-19 10:24:28 +01:00
Anthony De Meulemeester
b257a06f3e
Compiler update (#21)
* added seperate folders for cmd packages.

* Fix netmodes in test + reverse bigint bytes

* glide get deps

* add, sub, mul, div

* booleans

* strings

* binary expressions

* if statements

* function calls

* composite literals (slice, array)

* Added lots of test cases and update readme.
2018-02-15 16:35:49 +01:00
Anthony De Meulemeester
f7d57e4e49
VM draft + cli setup (#20)
* updated readme

* added basic cmd.

* added seperate folders for cmd packages.

* Fix netmodes in test + reverse bigint bytes

* glide get deps
2018-02-09 17:08:50 +01:00
anthdm
536a499236 initial commit. 2018-01-26 19:04:13 +01:00