Commit graph

4588 commits

Author SHA1 Message Date
Roman Khimov
0de949b575 stackitem: remove Item/StackItem from function names
They're useless in a package named 'stackitem', make this package a bit more
user-friendly.
2021-07-06 19:56:23 +03:00
Roman Khimov
b9ff07f32c stackitem: add limit to serialized items
Standard binary serialization/deserialization is mostly used in VM to put/get
elements into/from storage, so they never should exceed MaxSize (otherwise one
won't be able to deserialize these items).

This patch leaves EncodeBinaryStackItem unprotected, but that's a streaming
interface, so it's up to the user of it to ensure its appropriate use (and our
uses are mostly for native contract's data, so they're fine).
2021-07-06 19:34:02 +03:00
Roman Khimov
8472064bbc stackitem: refactor serialization code, add explicit context 2021-07-06 19:32:52 +03:00
Roman Khimov
1b7b7e4bec stackitem: don't overwrite error when serializing Item
We must get out as quickly as possible.
2021-07-06 17:51:46 +03:00
Roman Khimov
e34fa2e915 stackitem: limit JSONization nesting level
We can have very deep reference types and attempt to JSONize them can easily
lead to OOM (even though there are no recursive references inside). Therefore
we have to limit them. While regular ToJSON() is buffer size limited to
MaxSize, ToJSONWithTypes is not and limiting it to MaxSize output will require
substantial rewriting effort while not really providing fair result, MaxSize
is more about stack item size while its JSON representation can be much bigger
because of various overheads.

Initial thought was to limit it by element count based on
MaxIteratorResultItems, but the problem here is that we don't always have this
limit in contexts using ToJSONWithTypes (like notification event
marshaling). Thus we need some generic limit which would be fine for all
users.

We at the same time have maxJSONDepth used when deserializing from JSON, so
it can be used for marshaling as well, it's not often that we have deeper
structures in real results.

Inspired by neo-project/neo#2521.
2021-07-06 17:33:16 +03:00
Roman Khimov
6879cbcdcc stackitem: properly detect recursive references during serialization
If we're done with element it no longer can lead to recursion error, so fix
cases like `[arr, arr]` where we have two copies of `arr` trigger this error
for no good reason (there is no recursion there).
2021-07-06 17:10:31 +03:00
Roman Khimov
ae8f4ebd5e
Merge pull request #2034 from nspcc-dev/fix-state
Fix MPT branch node strip after deletion
2021-07-06 14:05:18 +03:00
Roman Khimov
b345e37b8e
Merge pull request #2041 from nspcc-dev/callflags-json
callflag: add C#-compliant JSONization, fix #2040
2021-07-06 14:03:55 +03:00
Roman Khimov
ac126a300b callflag: add C#-compliant JSONization, fix #2040 2021-07-06 11:17:12 +03:00
Evgeniy Stratonikov
9691eee10c mpt: strip branch if 1 child is left
If the child left is a hash node, we should retrieve it from store.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-07-05 11:04:20 +03:00
Evgeniy Stratonikov
d2e8254848 native: fix typo in comments
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-07-05 11:04:19 +03:00
Evgeniy Stratonikov
a7722f0fa5 native: save balance value in storage for failed transfers
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-07-05 11:03:42 +03:00
Roman Khimov
e5d26a5df1
Merge pull request #2033 from nspcc-dev/sysgas
cli/sc: add sysgas option to add some gas
2021-07-02 12:50:21 +03:00
Roman Khimov
41e0218555 cli/wallet: add sysgas to transfer functions
It might also be useful there.
2021-07-02 12:34:18 +03:00
Roman Khimov
2a57e48897 cli/sc: add sysgas option to add some gas
Sometimes on-chain invocations need a bit more GAS than expected after test
invocations, so let the user compensate for that. 2.x has similar option since
483fefbb62.
2021-07-02 11:57:47 +03:00
Roman Khimov
e3323faf69
Merge pull request #2032 from nspcc-dev/optimize-restore
native: cache GAS per vote values
2021-07-01 15:17:37 +03:00
Evgeniy Stratonikov
0591366f85 native: cache GAS per vote values
`storage.Seek()` is rather expensive and we need only last updated value
of gas per block in `PostPersist()`.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-07-01 10:34:04 +03:00
Roman Khimov
c203995a9b
Merge pull request #2028 from nspcc-dev/core/fix-add-headers
core: allow to add several headers with StateRootInHeader on
2021-06-30 17:11:54 +03:00
Anna Shaleva
9673a04009 core: allow to add several headers with StateRootInHeader on
Problem: with StateRootInHeader setting on only one header of height N+1
can be added to the chain of height N, because we need local stateroot
to verify headers (which is calculated for the last stored block N).
Thus, adding chunk of headers starting from the current chain's heigh
is impossible and (*Blockchain).AddHeaders doesn't have much sense.

Solution: verify header.PrevStateRoot only for header N+1. Rest of the
headers should be added without PrevStateRoot verification.
2021-06-30 11:56:05 +03:00
Roman Khimov
cf12d00b24
Merge pull request #2030 from nspcc-dev/fix-manifest
Fix bugs in manifest permissions
2021-06-30 11:12:02 +03:00
Evgeniy Stratonikov
c9e6350915 manifest: fix group permission handling
We need to have at least one matching group in the manifest.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-06-30 11:02:45 +03:00
Evgeniy Stratonikov
4283e1003f manifest: fix wildcard permission handling
Wildcard contract can coexist with restricted set of methods.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-06-30 11:00:06 +03:00
Roman Khimov
3646270af0
Merge pull request #2026 from nspcc-dev/fix-state
Fix manifest `Extra` field marshaling
2021-06-29 15:11:25 +03:00
Evgeniy Stratonikov
9c06ba6b07 smartcontract: marshal manifest Extra field as object, fix #2021
This is needed to strip whitespace which can be present.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-06-29 11:39:56 +03:00
Evgeniy Stratonikov
8d67a03aec stackitem: fix Buffer deserialization
Fix incorrect application log for transaction in N3 testnet
8eb4076f1f1c07e693eda7e810779488a2d2b50aba9b727fd237cbc3adbec9e9

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-06-29 11:39:55 +03:00
Roman Khimov
eecb952e15
Merge pull request #2025 from nspcc-dev/compiler-check-calls
Check manifest permissions at compile-time
2021-06-28 20:25:10 +03:00
Evgeniy Stratonikov
f0100407ee compiler/test: compile whole directory in examples
For `nft-nd-nns` example only `namestate.go` file was compiled which is
certainly not what we want.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-06-28 11:50:40 +03:00
Evgeniy Stratonikov
aa76383fa7 compiler: extend permission check to runtime hashes
If a method is known at compile time we can still check
if it is present in the list of methods of at least one contract.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-06-28 11:49:30 +03:00
Evgeniy Stratonikov
4249674ddc compiler: check for contract permissions
On many occassions we can determine at compile-time if contract config lacks
some properties it needs. This includes all native contract invocations
through stdlib, as both hashes and methods are known at compile-time
there.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-06-28 11:49:29 +03:00
Roman Khimov
16a8edaa17
Merge pull request #2023 from alexvanin/fix/example-permissions
Fix permissions in example manifests
2021-06-25 10:43:14 +03:00
Alex Vanin
90400d951a examples: add missing permission methods in manifests 2021-06-24 16:00:45 +03:00
Alex Vanin
5fa000cbae examples: rename onNEP11Transfer to onNEP11Payment in manifests
There is no such thing as `onNEP11Transfer` in NEP-11.
2021-06-23 20:48:04 +03:00
Roman Khimov
fecc7a3dd6 keys: simplify code a bit
No functional changes.
2021-06-17 21:55:00 +03:00
Roman Khimov
eace588e48 CHANGELOG: release 0.95.3 2021-06-17 15:57:30 +03:00
Roman Khimov
2f462f68cc
Merge pull request #2018 from nspcc-dev/cli/drop-warn
cli: remove `Can't find matching token in the wallet` warning
2021-06-17 12:03:51 +03:00
Anna Shaleva
67fe2a82bc cli: remove Can't find matching token in the wallet warning 2021-06-17 11:29:16 +03:00
Roman Khimov
880843b17b
Merge pull request #2017 from nspcc-dev/fix-diff-151376
core: fix the way candidates are sorted
2021-06-16 19:25:04 +03:00
Anna Shaleva
d49294b046 core: fix the way candidates are sorted
(*NEO).GetCandidates along with getCandidatesCall use candidates sorted
by serialized ECPoint bytes.

(*NEO).computeCommitteeMembers use candidates sorted by votes, and then
by deserialized ECPoint, i.e. using default ECPoint comparator.
2021-06-16 17:35:04 +03:00
Roman Khimov
d5e11e0a75
Merge pull request #2001 from nspcc-dev/tests/fix-failing-workflows
crypto: use non-default scrypt parameters for encrypting/decrypting
2021-06-11 17:27:03 +03:00
Roman Khimov
8efb8cfbf0
Merge pull request #2012 from nspcc-dev/improve-badges
readme: improve badges
2021-06-11 16:19:43 +03:00
Anna Shaleva
79d2a742a7 readme: unify style of all badges 2021-06-11 15:44:21 +03:00
Anna Shaleva
203f0360f8 readme: add CodeQL badge 2021-06-11 15:44:11 +03:00
Anna Shaleva
f6f464c218 readme: add GithubWorkflow Tests badge 2021-06-11 15:44:01 +03:00
Anna Shaleva
91f4513357 cli: fix + marshalling in TestNEP11_OwnerOf_BalanceOf_Transfer
Problem:
```
executor_test.go:151:
    	Error Trace:	executor_test.go:151
    	            				executor_test.go:147
    	            				nep11_test.go:232
      	Error:      	Expect "{"name":"HASHY 3HNCEX8D9J0p\u002BLxmr3uPhOhSW90="}" to match "{"name":"HASHY 3HNCEX8D9J0p+Lxmr3uPhOhSW90="}"
       	Test:       	TestNEP11_OwnerOf_BalanceOf_Transfer
```

Solution:
Same as preesnted in #2006.
2021-06-11 15:22:32 +03:00
Anna Shaleva
472a44a464 *: regenerate test wallets with resources-friendly scrypt parameters 2021-06-11 15:22:32 +03:00
Anna Shaleva
50296975e2 crypto: allow to provide non-default scrypt parameters 2021-06-11 15:22:28 +03:00
Roman Khimov
61dfca346c
Merge pull request #2003 from carpawell/update-neofs-api-go
Update neofs-api-go
2021-06-11 14:19:12 +03:00
Roman Khimov
61c204f875
Merge pull request #2011 from nspcc-dev/hashy-fix
examples: use base64 encoding to create HASHY token ID
2021-06-11 14:13:24 +03:00
Anna Shaleva
6ca9c87b9c Revert "cli: band-aid failing TestNEP11_OwnerOf_BalanceOf_Transfer"
This reverts commit f01d94ae53.

Extra GAS is not needed here after HASHY fix.
2021-06-11 13:58:57 +03:00
Anna Shaleva
39e096da64 examples: use base64 to encode HASHY token ID
Base58 does not preserve one-to-one byte correspondence with the
original data, so different combinations of the same number of bytes
might have different encoded string length. We use GAS transfer to mint
HASHY token, where the token hash is Base58Encode(Ripemd160(data + txHash)).

The problem is that `invokescript` RPC call is used to define transfer tx
sysfee, thus, txHash during testinvoke differs from the actual one, that's
why resulting token ID may have different length during testinvoke and
real invoke. As far as we use token ID as a key to store contract
values, the storage price may also differ. The result is failing
TestNEP11_OwnerOf_BalanceOf_Transfer test due to `gas limit exceeded`
error:

```
    logger.go:130: 2021-06-10T21:09:08.984+0300	WARN	contract invocation failed	{"tx": "45a0220b19725eaa0a4d01fa7a6cdaac8498592e8f3b43bdde27aae7d9ecf635", "block": 5, "error": "error encountered at instruction 36 (SYSCALL): error during call from native: error encountered at instruction 22 (SYSCALL): failed to invoke syscall 1736177434: gas limit exceeded"}
    executor_test.go:219:
        	Error Trace:	executor_test.go:219
        	            				nep11_test.go:132
        	            				nep11_test.go:235
        	Error:      	Not equal:
        	            	expected: 0x2
        	            	actual  : 0x4
        	Test:       	TestNEP11_OwnerOf_BalanceOf_Transfer
```

Fixed by using base64 instead of base58 (base64 preserves the resulting
encoded string length for the same input length).
2021-06-11 13:57:59 +03:00