Commit graph

37 commits

Author SHA1 Message Date
Anna Shaleva
6b21ad9922 *: replace interface{} with any keyword
Everywhere including examples, external interop APIs, bindings generators
code and in other valuable places. A couple of `interface{}` usages are
intentionally left in the CHANGELOG.md, documentation and tests.
2023-04-04 13:22:42 +03:00
Roman Khimov
dfd4f6978f bigint: don't reallocate big.Int in ToBytes(), fix #2864
In some cases n.Add() can reuse the []Word buffer and n.Sub() reallocate it
away. If that happens, we're out of luck with 0.99.0+ versions (since
3945e81857). I'm not sure why it does that, bit
width doesn't change in most of the cases and even if it does, we still have
enough of it in cap() to hold the old Abs() value (when we have a negative
value we in fact decreate its Abs() first and increase it back
afterwards). Still, that's what we have.

So when we have processTokenTransfer() doing Neg/Neg in-place its value is not
affected, but the original []Word bits that are reused by amount value are
(they're shared initially, Amount: *amount).

name                   old time/op    new time/op    delta
ToPreallocatedBytes-8    65.8ns ± 2%    45.6ns ± 2%  -30.73%  (p=0.008 n=5+5)

name                   old alloc/op   new alloc/op   delta
ToPreallocatedBytes-8     0.00B          0.00B          ~     (all equal)

name                   old allocs/op  new allocs/op  delta
ToPreallocatedBytes-8      0.00           0.00          ~     (all equal)
2023-01-10 22:51:45 +03:00
Evgeniy Stratonikov
affe1ecb4f encoding: add bigint fuzz test
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2022-12-28 11:50:13 +03:00
Roman Khimov
3402b870c8 fixedn: add a test for empty string
Ensure it fails.
2022-08-19 21:52:43 +03:00
Anna Shaleva
916f2293b8 *: apply go 1.19 formatter heuristics
And make manual corrections where needed. See the "Common mistakes
and pitfalls" section of https://tip.golang.org/doc/comment.
2022-08-09 15:37:52 +03:00
Roman Khimov
edb6ca8926
Merge pull request #2531 from nspcc-dev/perf
Minor performance improvements
2022-06-03 10:40:56 +03:00
Roman Khimov
9a06995460 bigint: don't allocate in ToPreallocatedBytes
Turns out, it's almost always allocating because we're mostly dealing with
small integers while the buffer size is calculated in 8-byte chunks here, so
preallocated buffer is always insufficient.

name                   old time/op    new time/op    delta
ToPreallocatedBytes-8    28.5ns ± 7%    19.7ns ± 5%   -30.72%  (p=0.000 n=10+10)

name                   old alloc/op   new alloc/op   delta
ToPreallocatedBytes-8     16.0B ± 0%      0.0B       -100.00%  (p=0.000 n=10+10)

name                   old allocs/op  new allocs/op  delta
ToPreallocatedBytes-8      1.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)

Fix StorageItem reuse at the same time. We don't copy when getting values from
the storage, but we don when we're putting them, so buffer reuse could corrupt
old values.
2022-06-02 15:38:39 +03:00
Roman Khimov
10110d4e70 bigint: correct MaxBytesLen
It can't be 33, positive signed int256 all fit into 32 bytes (no need for
leading zero), negative ones fit into 32 bytes as well.
2022-05-31 16:51:19 +03:00
Roman Khimov
3945e81857 bigint: don't allocate in ToPreallocatedBytes() for negative numbers
In-place modifications are somewhat dangerous, but yet another allocation is
quite costly.
2022-05-31 12:45:34 +03:00
Evgeniy Stratonikov
ec21c14ca9 gomod: upgrade yaml package from v2 to v3
Close #2085.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2022-05-30 15:26:17 +03:00
Elizaveta Chichindaeva
28908aa3cf [#2442] English Check
Signed-off-by: Elizaveta Chichindaeva <elizaveta@nspcc.ru>
2022-05-04 19:48:27 +03:00
Roman Khimov
418ba1dbc3 *: use internal variables for simple big.NewInt() values
Avoid additional allocations.
2021-12-01 21:36:25 +03:00
Roman Khimov
100e97d772 util: move ArrayReverse into package of its own
Leave just uint160 and uint256 types in util.
2021-07-19 22:57:55 +03:00
Evgeniy Stratonikov
9c5b4e5916 encoding/bigint: allow to convert unsigned integers
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-07-15 15:58:49 +03:00
Roman Khimov
9d2712573f *: enable godot linter and fix all its warnings
It's important for NeoGo to have clean documentation. No functional changes.
2021-05-12 23:17:03 +03:00
Roman Khimov
c4e084b0d8 *: fix whitespace errors
leading/trailing newlines
2021-05-12 22:51:41 +03:00
Roman Khimov
cfc067dd24 *: remove dead code
Found by deadcode via golangci-lint.
2021-05-12 18:13:14 +03:00
Roman Khimov
b56e028733 *: add more package-specific documentation
For the most important packages at least.
2021-03-19 16:18:45 +03:00
Evgeniy Stratonikov
5a3fa47b95 encoding: panic on nil slice
After `state.StorageItem` became a slice of bytes
we no longer panic on accessing `si.Value`. This helps
to ensure that nothing was broken. Providing `nil` to `FromBytes`
is probably an error anyway.
2021-03-09 12:11:26 +03:00
Roman Khimov
ca258d6fbd fixedn: always correctly unmarshal Fixed8 values
Quoted or not, they should be unmarshalled without going through float64.
2021-01-22 19:14:33 +03:00
Evgenii Stratonikov
56b23b718d fixedn: allow to parse big decimals 2020-12-09 11:19:25 +03:00
Evgenii Stratonikov
e4c3339c91 util: move Fixed8 to encoding/fixedn package 2020-12-09 11:18:18 +03:00
Roman Khimov
ff11a5f990 state: use more efficient encoding for amount
It's variable-length anyway, so wasting 8 bytes for what typically is 1 byte
makes no sense.
2020-09-21 21:51:33 +03:00
Roman Khimov
5ef08f60ae remove github.com/pkg/errors from dependencies
It's not needed any more with Go 1.13 as we have wrapping/unwrapping in base
packages. All errors.Wrap calls are replaced with fmt.Errorf, some strings are
improved along the way.
2020-08-07 12:21:52 +03:00
Evgenii Stratonikov
7b4ca57e33 *: change address to the new format
NEO3 uses new prefix for address (53 = 0x35), thus string representations as
well as encrypted WIFs should be changed.
2020-06-17 15:58:21 +03:00
Evgenii Stratonikov
b3b1137030 cli: allow to convert wallet from NEO2 to NEO3 format
This command may be helpful to have during transition.
2020-06-17 15:49:34 +03:00
Anna Shaleva
7ca2807875 vm/encoding: move bigint from vm to encoding package 2020-06-08 13:27:13 +03:00
Roman Khimov
e41d434a49 *: move all packages from CityOfZion to nspcc-dev 2020-03-03 17:21:42 +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
Roman Khimov
b246653f62 address: rename functions as per #579 comments
Make them more clear to understand.
2019-12-25 17:34:18 +03:00
Roman Khimov
53e6fbbbf9 base58: add a test for a025b9c42d
As noted by @fyrchik in #579 comments.
2019-12-25 17:33:48 +03:00
Roman Khimov
b7702f3a2e address: improve testing, make it 100% covered 2019-12-25 15:55:39 +03:00
Roman Khimov
c5ceb9128a address: check for prefix when decoding 2019-12-25 15:50:52 +03:00
Roman Khimov
89b6cbf795 address: make Prefix overridable
As it should be, it's specified in the configuration file (and it should be
treated as byte in the config)
2019-12-25 15:42:18 +03:00
Roman Khimov
e685e9bf9a address: move into its own package
Doesn't really belong to the crypto.
2019-12-25 15:22:02 +03:00
Roman Khimov
a025b9c42d base58: remove bogus code from CheckDecode
No other implementation does that and it looks weird, I see nothing meaninful
here.
2019-12-25 15:07:11 +03:00
Roman Khimov
369ac01a27 base58: move into its own package
It doesn't belong to crypto in any way other than it uses hash function
internally.
2019-12-25 15:05:54 +03:00