Commit graph

811 commits

Author SHA1 Message Date
Roman Khimov
c899ec3038
Merge pull request #354 from nspcc-dev/some-vm-opcodes-and-fixes
Implements NZ, PICK, TUCK, XDROP, INVERT. Fixes XTUCK.
2019-09-05 19:55:50 +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
bcd81bcfb2
Merge pull request #352 from nspcc-dev/drop-bad-crypto-fix-245
Really simplifies our crypto library and fixes #245.
2019-09-05 13:18:17 +03:00
Roman Khimov
e537dc9ee4 keys: improve publick key checks with a check against P
ANSI X9.62 says that if x or y coordinate are greater than or equal to
curve.Params().P, the conversion should return an error (see ANSI X9.62:2005
Section A.5.8 Step b, which invokes Section A.5.5, which does the check and
rejects when x or y are too big.

See https://github.com/golang/go/issues/20482 for more details.
2019-09-05 12:34:12 +03:00
Roman Khimov
f12194f3b0 keys: deduplicate DecodeBytes/DecodeBinary for PrivateKey
They shared prefix logic for no good reason, don't do that.
2019-09-05 12:34:12 +03:00
Roman Khimov
2c3e92923f keys: simplify error handling for PublicKey() and associated
PublicKey() for PrivateKey now just can't fail and it makes no sense to return
an error from it. There is a lot of associated functionality for which this
also is true, so adjust it accordingly and simplify a lot of code.
2019-09-05 12:34:12 +03:00
Roman Khimov
60bc2e8053 keys: simplify PublicKey() for PrivateKey
Public key is just a point, so use the coordinates obtained previously to
initialize the PublicKey structure without jumping through the hoops of
encoding/decoding.
2019-09-05 12:34:12 +03:00
Roman Khimov
f0fbe9f6c9 crypto: drop home-grown elliptic crypto, use crypto/elliptic
As NEO uses P256 we can use standard crypto/elliptic library for almost
everything, the only exception being decompression of the Y coordinate. For
some reason the standard library only supports uncompressed format in its
Marshal()/Unmarshal() functions. elliptic.P256() is known to have
constant-time implementation, so it fixes #245 (and the decompression using
big.Int operates on public key, so nobody really cares about that part being
constant-time).

New decompress function is inspired by
https://stackoverflow.com/questions/46283760, even though the previous one
really did the same thing just in a little less obvious way.
2019-09-05 12:33:27 +03:00
Roman Khimov
0b884b92b3 crypto: use PrivateKey to generate a key pair
It makes no sense to provide an API for throw-away public keys, so obtain it
via a new real keypair generation where appropriate (and that's only needed
for testing).
2019-09-05 09:38:13 +03:00
Roman Khimov
1ffda460bd
Merge pull request #351 from nspcc-dev/drop-redundant-dev-code-part-7
Drop redundant dev code part 7, the next one in series of #315, #318, #322, #328, #330, #338.
2019-09-04 19:53:56 +03:00
fabwa
1af97a7a87
Update README.md 2019-09-04 18:19:22 +02:00
Roman Khimov
cea983acc6 _pkg.dev: drop peer/peermgr/syncmgr
It was a nice attempt, but there is not a lot that we can reuse for the
master branch. Refs. #307.
2019-09-04 15:30:04 +03:00
Roman Khimov
441f1d3bf5 _pkg.dev: drop chain package
Duplicated by blockchain code in core. Refs. #307.
2019-09-04 12:12:02 +03:00
Roman Khimov
e636537844
Merge pull request #340 from nspcc-dev/fix-golint-213
Make our build green again! Fixes #213.
2019-09-03 19:54:29 +03:00
Roman Khimov
2c2f91564f rpc: comment out getBlock and getRawTransaction
After the 8388f4a55e Golint quickly pointed that
these are unused, so comment 'em out for now.
2019-09-03 18:25:19 +03:00
Roman Khimov
6bfcc615b2 *: fix some misspellings
Found by goreport.
2019-09-03 18:20:05 +03:00
Roman Khimov
22bea5eccf core: remove ineffective assignment from test code
Spotted by goreport:
  Line 89: warning: ineffectual assignment to hash (ineffassign)
2019-09-03 18:17:44 +03:00
Roman Khimov
8388f4a55e rpc: unexport methods returning internal structures
Golint:
pkg/rpc/rpc.go:15:67: exported method GetBlock returns unexported type *rpc.response, which can be annoying to use
pkg/rpc/rpc.go:82:64: exported method GetRawTransaction returns unexported type *rpc.response, which can be annoying to use
pkg/rpc/rpc.go:97:52: exported method SendRawTransaction returns unexported type *rpc.response, which can be annoying to use

Refs. #213.
2019-09-03 18:16:48 +03:00
Roman Khimov
1fd5e5928c rpc: fix bad name spellings noted by golint
pkg/rpc/neoScanBalanceGetter.go:54:56: method parameter assetIdUint should be assetIDUint
pkg/rpc/neoScanBalanceGetter.go:62:3: var assetId should be assetID
pkg/rpc/server_test.go:27:5: var testRpcCases should be testRPCCases
pkg/rpc/txTypes.go:19:3: struct field assetId should be assetID
pkg/rpc/txTypes.go:39:35: interface method parameter assetId should be assetID
pkg/rpc/types.go:115:2: struct field TxId should be TxID

Refs. #213.
2019-09-03 18:16:48 +03:00
Roman Khimov
db9e37b3bb *: fix golint's omit type suggestions
pkg/core/transaction/attribute.go:67:14: should omit type uint8 from declaration of var urllen; it will be inferred from the right-hand side
pkg/crypto/keys/publickey.go:184:8: should omit type []byte from declaration of var b; it will be inferred from the right-hand side
pkg/network/payload/version_test.go:15:12: should omit type bool from declaration of var relay; it will be inferred from the right-hand side

Refs. #213.
2019-09-03 18:16:48 +03:00
Roman Khimov
a74518691c crypto: improve error messages for base58
Golint:
  error strings should not be capitalized or end with punctuation or a newline

Refs. #213.
2019-09-03 18:16:48 +03:00
Roman Khimov
89ed00ddfb core: simplify GetTransationResults() based on golint suggestion
Golint:
  pkg/core/blockchain.go:796:9: if block ends with a return statement, so drop
    this else and outdent its block (move short variable declaration to its own
    line if necessary)

Refs. #213.
2019-09-03 18:16:48 +03:00
Roman Khimov
0c160a81fe transaction: use increments instead of '+1's
Fixes golint warning:
  should replace sz += 1 with sz++

Refs. #213.
2019-09-03 18:01:37 +03:00
Roman Khimov
30eb137200 examples: remove underscores from package names
Fixes golint warnings: "don't use an underscore in package name" and makes our
examples better. Refs. #213.
2019-09-03 18:00:10 +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
Vsevolod
de84e074a2
Merge pull request #337 from nspcc-dev/cli_documentation
Add neo-go cli documentation
2019-09-02 18:38:15 +03:00
Roman Khimov
9de8413d06
Merge pull request #338 from nspcc-dev/drop-redundant-dev-code-part-6
The big delete (#307) series episode six airs today for every subscriber of the neo-go repo (previous episodes: #315, #318, #322, #328, #330).

This one is easy, nothing moved, just the red things.
2019-09-02 18:38:00 +03:00
Vsevolod Brekelov
51b93a9a55 Add neo-go cli documentation
Comments fix
2019-09-02 18:32:11 +03:00
Roman Khimov
46c02de2f3 _pkg.dev: drop server
Nothing useful here for master, it has it all implemented already. Refs. #307.
2019-09-02 17:40:53 +03:00
Roman Khimov
eb95758ddc _pkg.dev: drop connmgr
I don't think it's of any use for us now. Refs. #307.
2019-09-02 17:37:48 +03:00
Roman Khimov
5bdf3682ed _pkg.dev: drop chaincfg package
It's just a wrapper around hardcoded genesis block, we don't need it.
2019-09-02 10:10:31 +03:00
Roman Khimov
f9a5ce89da
Merge pull request #331 from nspcc-dev/vm-fix-things-for-96
This fixes two minor things observed in #96:

    running VM twice, which leads to instruction execution attempt for VM in FAULT state
    panicing with nil dereference (it's better to show some error message)

Before this patchset:

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

After this patchset:

NEO-GO-VM > run
NEO-GO-VM > error encountered at instruction 6 (ROLL)
NEO-GO-VM > bad index
FAULT
2019-08-31 12:34:49 +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
c96be81229
Merge pull request #330 from nspcc-dev/drop-redundant-dev-code-part-5
Drop redundant dev code part 5. The next one in series of #315, #318, #322 and #328. Continuing with #307. Fixes #319 along the way.
2019-08-30 20:08:09 +03:00
Roman Khimov
973d39eceb _pkg.dev: drop wire
Nothing interesting left here, thanks. Refs. #307.
2019-08-30 19:45:39 +03:00
Roman Khimov
6767bb5446 transaction: move state test from dev 2019-08-30 19:35:57 +03:00
Roman Khimov
b8adc36e6a transaction: add missing alloc in state decoder
Fixes panic two lines below:
panic: runtime error: index out of range [recovered]
        panic: runtime error: index out of range
2019-08-30 19:34:26 +03:00
Roman Khimov
203aab6a7e transaction: add binary encoding for publish
And expand the test to check for it. Fixes #319.
2019-08-30 19:19:43 +03:00
Roman Khimov
af212f496e transaction: implement encoding for state 2019-08-30 19:13:19 +03:00
Roman Khimov
868c9d6e8c transaction: add miner tx test from dev 2019-08-30 18:53:26 +03:00
Roman Khimov
88a47aeeb4 transaction: move enrollment test from dev into the master 2019-08-30 18:28:12 +03:00