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
2245fedbb1
core: deduplicate state commit methods, use interim MemCachedStore
...
commit methods duplicated putSmthIntoStore functions, but have MemCachedStore
now that can easily substitute for a Batch, especially given that interop
needs something like that for its storage purposes anyway.
2019-10-16 17:33:45 +03:00
Roman Khimov
fc0031e5aa
core: move write caching layer into MemCacheStore
...
Simplify Blockchain and associated functions, deduplicate code, fix Get() and
Seek() implementations.
2019-10-16 17:33:45 +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
8926cbe368
core: fix potential data race in logging code
...
Spotted in CircleCI build with Go 1.12:
WARNING: DATA RACE
Write at 0x00c00011095c by goroutine 88:
sync/atomic.SwapInt32()
/usr/local/go/src/runtime/race_amd64.s:249 +0xb
github.com/CityOfZion/neo-go/pkg/core.(*Blockchain).persist()
/go/src/github.com/CityOfZion/neo-go/pkg/core/blockchain.go:483 +0x172
github.com/CityOfZion/neo-go/pkg/core.(*Blockchain).Run.func2()
/go/src/github.com/CityOfZion/neo-go/pkg/core/blockchain.go:191 +0x50
Previous read at 0x00c00011095c by goroutine 64:
github.com/CityOfZion/neo-go/pkg/core.(*Blockchain).persist()
/go/src/github.com/CityOfZion/neo-go/pkg/core/blockchain.go:492 +0x4be
github.com/CityOfZion/neo-go/pkg/core.(*Blockchain).Run.func2()
/go/src/github.com/CityOfZion/neo-go/pkg/core/blockchain.go:191 +0x50
Goroutine 88 (running) created at:
github.com/CityOfZion/neo-go/pkg/core.(*Blockchain).Run()
/go/src/github.com/CityOfZion/neo-go/pkg/core/blockchain.go:190 +0x264
Goroutine 64 (finished) created at:
github.com/CityOfZion/neo-go/pkg/core.(*Blockchain).Run()
/go/src/github.com/CityOfZion/neo-go/pkg/core/blockchain.go:190 +0x264
2019-10-15 18:58:22 +03:00
Roman Khimov
a6610ba082
core: verify blocks, fix #12
...
This adds the following verifications:
* merkleroot check
* index check
* timestamp check
* witnesses verification
VerifyWitnesses is also renamed to verifyTxWitnesses here to not confuse it
with verifyBlockWitnesse and to hide it from external access (no users at the
moment).
2019-10-15 18:58:17 +03:00
Roman Khimov
03c20f1876
core: make ContractState receiver names consistent
...
Linter isn't happy with our recent changes:
pkg/core/contract_state.go:109:1: receiver name cs should be consistent with previous receiver name a for ContractState
pkg/core/contract_state.go:114:1: receiver name cs should be consistent with previous receiver name a for ContractState
pkg/core/contract_state.go:119:1: receiver name cs should be consistent with previous receiver name a for ContractState
But actually `a` here most probably is a copy-paste from AssetState methods,
so fit the old code to match the new one.
2019-10-15 12:56:25 +03:00
Roman Khimov
aec6a5f029
core/config: make block and transaction verification configurable
...
Enable transaction verification for privnets and tests, testnet can't
successfuly verify block number 316711 with it enabled and mainnet stops at
105829.
2019-10-15 12:56:25 +03:00
Roman Khimov
56dcff2894
core: invoke contracts for Invocation TXes
...
They can have some side-effects that future invocations rely on.
2019-10-15 12:56:25 +03:00
Roman Khimov
74590551c4
core: add some interops
...
This also changes Verify to VerifyTx and VerifyWitnesses, because there is a
need to pass a block for some interop functions.
2019-10-15 12:56:25 +03:00
Roman Khimov
667f346c04
core: improve error message in AddBlock test
2019-10-15 12:56:25 +03:00
Roman Khimov
8266a5ce19
core: export GetContractState/GetScriptHashesForVerifying via Blockchainer
...
These are gonna be used by interops and are also useful in general.
2019-10-15 12:56:25 +03:00
Roman Khimov
19fd7f844e
core: add GetUnspentCoinState() for future interops
2019-10-15 12:56:25 +03:00
Roman Khimov
bfddf9b3f6
core: implement StorageItem for future interops
2019-10-15 12:56:25 +03:00
Roman Khimov
2156d5db73
core: add put/delete functions for ContractState
...
These are gonna be used by interops.
2019-10-15 12:56:25 +03:00
Roman Khimov
58d9b79fe3
core: avoid duplicates in GetScriptHashesForVerifyingClaim()
...
As they can break VerifyWitnesses().
2019-10-15 12:56:25 +03:00
Roman Khimov
35824728eb
core: add putAssetStateIntoStore()
...
Will be used by interops.
2019-10-15 12:56:25 +03:00
Roman Khimov
96934cfeab
core: return error from verifyOutputs()
...
Make debugging easier.
2019-10-15 12:56:25 +03:00
Roman Khimov
ab4ff79e02
core: fix typo in GetTransactionResults()
2019-10-15 12:56:25 +03:00
Roman Khimov
cffe8d0ee2
core: return error from verifyResults()
...
Make it easier to find out what the real problem is.
2019-10-15 12:56:25 +03:00
Roman Khimov
16bc5296cb
block: return error from Verify
...
Don't hide real problem behind the bool value. Makes it easier to identify
problems when looking at log messages.
2019-10-15 12:56:25 +03:00
Roman Khimov
258f397b9a
core: append transactions to the block in GetBlock()
...
We want to get a full block, so it has to have transactions
inside. Unfortunately our tests were used to this wrong behavior and utilized
completely bogus transactions without data that couldn't be persisted, so fix
that also.
2019-10-15 12:56:25 +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
7ab58ff8cb
keys: make public key's IsInfinity() public
...
It's gonna be used in interops for key validity check.
2019-10-15 12:56:25 +03:00
Roman Khimov
c5a4cfaebe
smartcontract: add CreateSignatureRedeemScript()
...
It's very similar to the CreateMultiSigRedeemScript() and it will be used in
interop functions.
2019-10-15 12:56:25 +03:00
Roman Khimov
238c590ddb
core: fix contract state's Properties to use PropertyState
...
PublishTX only had one of these flags, but newer contracts (created via the
interop function) can have more and these flags are aggregated into one field
that uses PropertyState enumeration (it's used to publish contract, so
supposedly it's also a nice choice for contract state storage).
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
6b70c5f2bd
keys: rename New*FromRawBytes to New*FromASN1
...
RawBytes is too confusing and may be read as being compatible with
NEO-serialized format.
2019-10-15 12:56:25 +03:00
Roman Khimov
782ca64d92
vm: accept uint16 in makeStackItem()
2019-10-15 12:56:25 +03:00
Roman Khimov
78861485b6
storage: simplify MemoryBatch
...
It's used a lot and it looks a lot like MemoryStore, it just needs not to
return errors from Put and Delete, so make it use MemoryStore internally with
adjusted interface.
2019-10-15 12:56:25 +03:00
Roman Khimov
13bf2618ef
storage: improve PutBatch for MemoryStore
...
Make it look more like a real transaction, put/delete things with a single
lock. Make a copy of value in Put also, just for safety purposes, no one knows
how this value slice can be used after the Put.
2019-10-15 12:56:25 +03:00
Roman Khimov
3ada92944a
storage: drop Len from the Batch interface
...
It's almost meaningless now and we can easily live without it.
2019-10-15 12:56:25 +03:00
Roman Khimov
e111892653
storage: redo DB testing
...
Make generic tests for all Store implementations, deduplicate tests. Implement
Delete() tests, test Seek() better, add LevelDB tests (finally!).
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
48b6a427cf
storage: add Delete method for Batch and Store
...
It's gonna be used by Storage and Contract interops, both can delete their
data.
2019-10-07 19:40:11 +03:00
Roman Khimov
add9368e9d
storage: use strings as keys for memory batch
...
Using pointers is just plain wrong here, because the batch can be updated with
newer values for the same keys.
Fixes Seek() to use HasPrefix also because this is the intended behavior.
2019-10-07 17:05:53 +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