176 Commits

Author SHA1 Message Date
Sam Kleinman
3d448e1ef8 crypto: cleanup tmhash package (#8434) 2022-04-28 22:21:43 -04:00
Sam Kleinman
e36052c80e crypto: remove unused code (#8412) 2022-04-25 12:35:59 -04:00
M. J. Fromberger
14f41ac5e3 Fix more broken Markdown links. (#8271) 2022-04-07 00:15:20 -07:00
Marko
56ee72424f remove libsecp256k1 build tag (#7823)
We no longer use cgo for anything in this package.
Consolidate the non-cgo code with the rest of the library.
2022-02-15 11:06:18 -08:00
Sergio Mena
d3548eb706 Completed the existing FinalizeBlock PR and rebased to master (#7798)
* Rebased and git-squashed the commits in PR #6546

migrate abci to finalizeBlock

work on abci, proxy and mempool

abciresponse, blok events, indexer, some tests

fix some tests

fix errors

fix errors in abci

fix tests amd errors

* Fixes after rebasing PR#6546

* Restored height to RequestFinalizeBlock & other

* Fixed more UTs

* Fixed kvstore

* More UT fixes

* last TC fixed

* make format

* Update internal/consensus/mempool_test.go

Co-authored-by: William Banfield <4561443+williambanfield@users.noreply.github.com>

* Addressed @williambanfield's comments

* Fixed UTs

* Addressed last comments from @williambanfield

* make format

Co-authored-by: marbar3778 <marbar3778@yahoo.com>
Co-authored-by: William Banfield <4561443+williambanfield@users.noreply.github.com>
2022-02-14 23:41:28 +01:00
M. J. Fromberger
ca6163a3ec Silence a staticcheck warning. (#7811)
There was a nolint directive on this deprecated import, which golangci-lint
complains about being unnecessary. However, removing it angers staticcheck,
which enforces deprecation warnings.

Use the right syntax to make both equally unhappy.
2022-02-11 21:48:40 +00:00
M. J. Fromberger
fcfe157f6b Remove unused xsalsa20symmetric package. (#7691)
This package has no uses within Tendermint core.
PR https://github.com/cosmos/cosmos-sdk/pull/11027 replaces the use in
the Cosmos SDK.

A follow-up to #7689 and #7690.
2022-01-26 06:23:20 -08:00
M. J. Fromberger
51ffb95775 Remove unused chacha20poly1305 package. (#7690)
Fixes #7689.
2022-01-26 05:44:24 -08:00
M. J. Fromberger
7878ca6a8a Delete the custom libs/json (tmjson) package. (#7673)
There are no further uses of this package anywhere in Tendermint.
All the uses in the Cosmos SDK are for types that now work correctly with the
standard encoding/json package.
2022-01-24 08:15:34 -08:00
M. J. Fromberger
f9c6cc9306 rpc: use encoding/json rather than tmjson (#7670)
The main change here is to use encoding/json to encode and decode RPC 
parameters, rather than the custom tmjson package. This includes:

- Update the HTTP POST handler parameter handling.
- Add field tags to 64-bit integer types to get string encoding (to match amino/tmjson).
- Add marshalers to struct types that mention interfaces.
- Inject wrappers to decode interface arguments in RPC handlers.
2022-01-21 15:10:28 -08:00
M. J. Fromberger
dbe2146d0a rpc: simplify the encoding of interface-typed arguments in JSON (#7600)
Add package jsontypes that implements a subset of the custom libs/json 
package. Specifically it handles encoding and decoding of interface types
wrapped in "tagged" JSON objects. It omits the deep reflection on arbitrary
types, preserving only the handling of type tags wrapper encoding.

- Register interface types (Evidence, PubKey, PrivKey) for tagged encoding.
- Update the existing implementations to satisfy the type.
- Register those types with the jsontypes registry.
- Add string tags to 64-bit integer fields where needed.
- Add marshalers to structs that export interface-typed fields.
2022-01-14 18:14:09 -08:00
Sam Kleinman
569629486b tests: remove panics from test fixtures (#7522) 2022-01-06 17:34:32 -05:00
Sam Kleinman
f2cc496f09 testing: pass testing.T to assert and require always, assertion cleanup (#7508) 2022-01-05 09:25:08 -05:00
Callum Waters
59404003ee p2p: rename pexV2 to pex (#7088) 2021-10-08 16:53:54 +02:00
M. J. Fromberger
cf7537ea5f cleanup: Reduce and normalize import path aliasing. (#6975)
The code in the Tendermint repository makes heavy use of import aliasing.
This is made necessary by our extensive reuse of common base package names, and
by repetition of similar names across different subdirectories.

Unfortunately we have not been very consistent about which packages we alias in
various circumstances, and the aliases we use vary. In the spirit of the advice
in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports,
his change makes an effort to clean up and normalize import aliasing.

This change makes no API or behavioral changes. It is a pure cleanup intended
o help make the code more readable to developers (including myself) trying to
understand what is being imported where.

Only unexported names have been modified, and the changes were generated and
applied mechanically with gofmt -r and comby, respecting the lexical and
syntactic rules of Go.  Even so, I did not fix every inconsistency. Where the
changes would be too disruptive, I left it alone.

The principles I followed in this cleanup are:

- Remove aliases that restate the package name.
- Remove aliases where the base package name is unambiguous.
- Move overly-terse abbreviations from the import to the usage site.
- Fix lexical issues (remove underscores, remove capitalization).
- Fix import groupings to more closely match the style guide.
- Group blank (side-effecting) imports and ensure they are commented.
- Add aliases to multiple imports with the same base package name.
2021-09-23 07:52:07 -07:00
Sam Kleinman
87b876a73b crypto/armor: remove unused package (#6963) 2021-09-20 12:30:26 -04:00
Callum Waters
bda948e814 statesync: implement p2p state provider (#6807) 2021-09-02 13:19:18 +02:00
Sam Kleinman
bf77c0c544 rpc: support new p2p infrastructure (#6820) 2021-08-13 15:39:07 -04:00
M. J. Fromberger
6dd8984fef Fix and clarify breaks from select cases. (#6781)
Update those break statements inside case clauses that are intended to reach an
enclosing for loop, so that they correctly exit the loop.

The candidate files for this change were located using:

    % staticcheck -checks SA4011 ./... | cut -d: -f-2

This change is intended to preserve the intended semantics of the code, but
since the code as-written did not have its intended effect, some behaviour may
change. Specifically: Some loops may have run longer than they were supposed
to, prior to this change.

In one case I was not able to clearly determine the intended outcome. That case
has been commented but otherwise left as-written.

Fixes #6780.
2021-07-29 22:28:32 -04:00
Yawning Angel
c5cc3c8d3f crypto: Use a different library for ed25519/sr25519 (#6526)
At Oasis we have spend some time writing a new Ed25519/X25519/sr25519 implementation called curve25519-voi.  This PR switches the import from ed25519consensus/go-schnorrkel, which should lead to performance gains on most systems.

Summary of changes:
 * curve25519-voi is now used for Ed25519 operations, following the existing ZIP-215 semantics.
 * curve25519-voi's public key cache is enabled (hardcoded size of 4096 entries, should be tuned, see the code comment) to accelerate repeated Ed25519 verification with the same public key(s).
 * (BREAKING) curve25519-voi is now used for sr25519 operations.  This is a breaking change as the current sr25519 support does something decidedly non-standard when going from a MiniSecretKey to a SecretKey and or PublicKey (The expansion routine is called twice).  While I believe the new behavior (that expands once and only once) to be more "correct", this changes the semantics as implemented.
 * curve25519-voi is now used for merlin since the included STROBE implementation produces much less garbage on the heap.

Side issues fixed:
 * The version of go-schnorrkel that is currently imported by tendermint has a badly broken batch verification implementation.  Upstream has fixed the issue after I reported it, so the version should be bumped in the interim.

Open design questions/issues:
 * As noted, the public key cache size should be tuned.  It is currently backed by a trivial thread-safe LRU cache, which is not scan-resistant, but replacing it with something better is a matter of implementing an interface.
 * As far as I can tell, the only reason why serial verification on batch failure is necessary is to provide more detailed error messages (that are only used in some unit tests).  If you trust the batch verification to be consistent with serial verification then the fallback can be eliminated entirely (the BatchVerifier provided by the new library supports an option that omits the fallback if this is chosen as the way forward).
 * curve25519-voi's sr25519 support could use more optimization and more eyes on the code.  The algorithm unfortunately is woefully under-specified, and the implementation was done primarily because I got really sad when I actually looked at go-schnorrkel, and we do not use the algorithm at this time.
2021-06-26 16:53:30 +00:00
Sam Kleinman
a855f96946 p2p: renames for reactors and routing layer internal moves (#6547) 2021-06-08 08:17:09 -04:00
Marko
4e06dfef8c crypto/merkle: optimize merkle tree hashing (#6513)
## Description 

Upstream https://github.com/lazyledger/lazyledger-core/pull/351 to optimize merkle tree hashing 

### Benchmarking:

```
benchmark                                 old ns/op     new ns/op     delta
BenchmarkHashAlternatives/recursive-8     22914         21949         -4.21%
BenchmarkHashAlternatives/iterative-8     21634         21939         +1.41%

benchmark                                 old allocs     new allocs     delta
BenchmarkHashAlternatives/recursive-8     398            200            -49.75%
BenchmarkHashAlternatives/iterative-8     399            301            -24.56%

benchmark                                 old bytes     new bytes     delta
BenchmarkHashAlternatives/recursive-8     19088         6496          -65.97%
BenchmarkHashAlternatives/iterative-8     21776         13984         -35.78%
```

cc @odeke-em @cuonglm
2021-06-01 06:24:53 +00:00
Marko
719e028e00 libs: internalize some packages (#6366)
## Description

Internalize some libs. This reduces the amount ot public API tendermint is supporting. The moved libraries are mainly ones that are used within Tendermint-core.
2021-05-25 16:25:31 +00:00
Cuong Manh Le
a9fc0c32b2 crypto/merkle: pre-allocate data slice in innherHash (#6443)
So we can reduce pressure on runtime for checking that slice has enough
capacity before appending.
2021-05-12 11:02:15 +02:00
Marko
990504cd07 crypto: add sr25519 as a validator key (#6376)
## Description

Add sr25519 as a validator key option. We support the crypto in tendermint and added batch verification recently.
2021-04-22 10:37:38 +00:00
Callum Waters
6f6083dae3 linter: fix nolintlint warnings (#6257) 2021-03-19 10:59:14 +01:00
Marko
6ffdf181f2 crypto: ed25519 & sr25519 batch verification (#6120)
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
2021-03-15 10:58:49 +00:00
Callum Waters
162f67cf26 correct spelling to US english (#6077) 2021-02-11 18:59:18 +01:00
Erik Grinaker
4988877f19 crypto: fix infinite recursion in Secp256k1 string formatting (#5707)
This caused stack overflow panics in E2E tests, e.g.:

```
2020-11-24T02:37:17.6085640Z validator04    | runtime: goroutine stack exceeds 1000000000-byte limit
2020-11-24T02:37:17.6087818Z validator04    | runtime: sp=0xc0234b23c0 stack=[0xc0234b2000, 0xc0434b2000]
2020-11-24T02:37:17.6088920Z validator04    | fatal error: stack overflow
2020-11-24T02:37:17.6089776Z validator04    | 
2020-11-24T02:37:17.6090569Z validator04    | runtime stack:
2020-11-24T02:37:17.6091677Z validator04    | runtime.throw(0x12dc476, 0xe)
2020-11-24T02:37:17.6093123Z validator04    | 	/usr/local/go/src/runtime/panic.go:1116 +0x72
2020-11-24T02:37:17.6094320Z validator04    | runtime.newstack()
2020-11-24T02:37:17.6095374Z validator04    | 	/usr/local/go/src/runtime/stack.go:1067 +0x78d
2020-11-24T02:37:17.6096381Z validator04    | runtime.morestack()
2020-11-24T02:37:17.6097657Z validator04    | 	/usr/local/go/src/runtime/asm_amd64.s:449 +0x8f
2020-11-24T02:37:17.6098505Z validator04    | 
2020-11-24T02:37:17.6099328Z validator04    | goroutine 88 [running]:
2020-11-24T02:37:17.6100470Z validator04    | runtime.heapBitsSetType(0xc009565380, 0x20, 0x18, 0x1137e00)
2020-11-24T02:37:17.6101961Z validator04    | 	/usr/local/go/src/runtime/mbitmap.go:911 +0xaa5 fp=0xc0234b23d0 sp=0xc0234b23c8 pc=0x432625
2020-11-24T02:37:17.6103906Z validator04    | runtime.mallocgc(0x20, 0x1137e00, 0x117b601, 0x11e9240)
2020-11-24T02:37:17.6105179Z validator04    | 	/usr/local/go/src/runtime/malloc.go:1090 +0x5a5 fp=0xc0234b2470 sp=0xc0234b23d0 pc=0x428b25
2020-11-24T02:37:17.6106540Z validator04    | runtime.convTslice(0xc002743710, 0x21, 0x21, 0xc0234b24e8)
2020-11-24T02:37:17.6107861Z validator04    | 	/usr/local/go/src/runtime/iface.go:385 +0x59 fp=0xc0234b24a0 sp=0xc0234b2470 pc=0x426379
2020-11-24T02:37:17.6109315Z validator04    | github.com/tendermint/tendermint/crypto/secp256k1.PubKey.String(...)
2020-11-24T02:37:17.6151692Z validator04    | 	/src/tendermint/crypto/secp256k1/secp256k1.go:161
2020-11-24T02:37:17.6153872Z validator04    | github.com/tendermint/tendermint/crypto/secp256k1.(*PubKey).String(0xc009565360, 0x11e9240, 0xc009565360)
2020-11-24T02:37:17.6157421Z validator04    | 	<autogenerated>:1 +0x65 fp=0xc0234b24f8 sp=0xc0234b24a0 pc=0x656965
2020-11-24T02:37:17.6159134Z validator04    | fmt.(*pp).handleMethods(0xc00956c680, 0x58, 0xc0234b2801)
2020-11-24T02:37:17.6161462Z validator04    | 	/usr/local/go/src/fmt/print.go:630 +0x30a fp=0xc0234b2768 sp=0xc0234b24f8 pc=0x518b8a
[...]
2020-11-24T02:37:17.6649685Z validator04    | 	/usr/local/go/src/fmt/print.go:630 +0x30a fp=0xc0234b7f48 sp=0xc0234b7cd8 pc=0x518b8a
2020-11-24T02:37:17.6651177Z validator04    | created by github.com/tendermint/tendermint/node.startStateSync
2020-11-24T02:37:17.6652521Z validator04    | 	/src/tendermint/node/node.go:587 +0x150

```
2020-11-24 11:37:49 +00:00
Marko
fbf2309962 ci: remove add-path (#5674) 2020-11-17 11:49:57 +01:00
Marko
e0950515ff test/e2e: fix secp failures (#5649) 2020-11-16 12:31:32 +01:00
Marko
e7d7ad85d5 crypto: adopt zip215 ed25519 verification (#5632) 2020-11-10 11:39:52 +01:00
Marko
c6f8f0aefc crypto: add in secp256k1 support (#5500)
Secp256k1 was removed in the protobuf migration, this pr adds it back in order to provide this functionality for users (band)

Closes: #5495
2020-10-15 10:10:06 +02:00
Anton Kaliaev
7121f68f25 light/rpc: fix ABCIQuery (#5375)
Closes #5106
2020-10-12 16:36:37 +04:00
Marko
d7d0ffea13 fix RPC blockresults reutrn (#5459)
## Description

In blocks_results we use the proto definition of abciResponses: 2672b91ab0/rpc/core/blocks.go (L152-L155), this leads to the use of the proto definition of the pubkey which is an interface in go (oneof). The interface must be registered with the JSON encoder to have it work correctly.

A clearer divide between proto types and native types is needed.

Closes: #XXX
2020-10-05 13:55:27 +00:00
Marko
5069a8822c crypto: reword readme (#5349)
## Description

Reword the readme of the crypto package. 

Closes: #XXX
2020-09-10 12:52:32 +00:00
Marko
b8d08b9ef4 lint: add errchecks (#5316)
## Description

Work towards enabling errcheck

ref #5059
2020-09-04 11:58:03 +00:00
Marko
e8eef85619 crypto: remove proto privatekey (#5301)
## Description

This type was used for json but was never removed once we migrated to tmjson. 


Closes: #XXX
2020-08-28 09:51:26 +00:00
Marko
1b961d021f crypto: remove secp256k1 (#5280)
## Description

Remove secp256k1 as discussed in the tendermint dev call. The implementation has been moved to the [Cosmos-SDK](443e0c1f89/crypto/keys/secp256k1)

Closes: #XXX
2020-08-25 07:00:44 +00:00
Marko
42e4e8b58e lint: add markdown linter (#5254) 2020-08-17 16:40:50 +02:00
Marko
9e98c74e3c crypto: API modifications (#5236)
## Description

This PR aims to make the crypto.PubKey interface more intuitive. 

Changes: 

- `VerfiyBytes` -> `VerifySignature`

Before `Bytes()` was amino encoded, now since it is the byte representation should we get rid of it entirely?

EDIT: decided to keep `Bytes()` as it is useful if you are using the interface instead of the concrete key

Closes: #XXX
2020-08-13 12:29:16 +00:00
Erik Grinaker
f66b7a8e32 merkle: return hashes for empty merkle trees (#5193)
Fixes #5192.

@liamsi Can you verify that the test vectors match the Rust implementation? I updated `ProofsFromByteSlices()` as well, anything else that should be updated?
2020-08-11 10:31:05 +00:00
Marko
1c9a2640e9 crypto: consistent api across keys (#5214)
## Description

This Pr changes `GenPrivKeySecp256k1` to `GenPrivKeyFromSecret` to be consistent with the other keys. Also the previous name was not descriptive on what it did.

Closes: #XXX
2020-08-07 17:05:31 +00:00
Marko
2d167aefcf ci: freeze golangci action version (#5196)
## Description

This PR updates golang-ci to latest and stops looking at master for the action. 

Closes: #XXX
2020-08-03 07:57:06 +00:00
Erik Grinaker
66ed8ec39d proto: reorganize Protobuf schemas (#5102)
Reorganizes the Protobuf schemas. It is mostly bikeshedding, so if something is contentious or causes a lot of extra work then I'm fine with reverting. Some Protobuf and Go import paths will change.

* Move `abci/types/types.proto` to `abci/types.proto`.

* Move `crypto/keys/types.proto` and `crypto/merkle/types.proto` to `crypto/keys.proto` and `crypto/proof.proto`.

* Drop the use of `msgs` in filenames, as "message" is a very overloaded term (all Protobuf types are messages, and we also have `message Message`). Use `types.proto` as a catch-all, and otherwise name files by conceptual grouping instead of message kind.
2020-07-08 15:47:01 +00:00
Marko
7e2cc1db5e linter: (1/2) enable errcheck (#5064)
## Description

partially cleanup in preparation for errcheck

i ignored a bunch of defer errors in tests but with the update to go 1.14 we can use `t.Cleanup(func() { if err := <>; err != nil {..}}` to cover those errors, I will do this in pr number two of enabling errcheck.

ref #5059
2020-07-01 15:13:11 +00:00
Marko
dedf0d2350 proto: folder structure adhere to buf (#5025) 2020-06-22 10:00:51 +02:00
Marko
b8b50733f0 encoding: remove codecs (#4996)
## Description

This pr removes amino from tendermint. 

Closes: #4278
2020-06-15 11:17:12 +00:00
Marko
74cae49c3b proto: leftover amino (#4986) 2020-06-15 11:14:36 +02:00
Marko
f6243d8b9e privval: migrate to protobuf (#4985) 2020-06-11 11:54:02 +02:00