Commit Graph

51 Commits

Author SHA1 Message Date
jangko 622e6489d8
EIP-4399 changes: random -> prevRandao 2022-02-27 11:40:15 +07:00
Kim De Mey 05ef9a8e00
More --styleCheck fixes for discoveryv5 and eth/common (#473) 2022-02-03 15:51:08 +01:00
jangko cf95b688e6
EIP-4399 preparation
From EIP-4399 spec:

Renaming

The mixHash field SHOULD further be renamed to random.

...
2022-02-01 13:41:50 +07:00
Kim De Mey 2c236f6495
Style fixes according to --styleCheck:usages (#452)
Currently only setting `--styleCheck:hint` as there are some
dependency fixes required and the compiler seems to trip over the
findnode MessageKind, findnode Message field and the findNode
proc. Also over protocol.Protocol usage.
2021-12-20 13:14:50 +01:00
Jamie Lokier 04ff8e460f Fix RLP serialisation of `seq[Transaction]` used in `eth` protocol
1. Generalises the special cases for serialising RLP `seq[Transaction]`.
   Previously it only used the special case inside `BlockBody` and `EthBlock`.
   Now it uses it for all `seq[Transaction]` regardless of what objects they
   are parts of, or no object at all.  `openArray[Transaction]` is also
   included, as this was found to be necessary to match in some places.

2. Bug fix parsing `Transaction`: Always read the first byte to get the
   transaction type instead of parsing an RLP `int`.  This way invalid or
   adversarial input gives a correct error (i.e. invalid type code).

   When it was read with `rlp.read(int)`, those inputs gave many crazy
   messages (e.g. "too large to fit in memory").  In the specification it's a
   byte.  (Technically the input is not RLP and we shouldn't be using the RLP
   parser anyway to parse standalone transaction objects).

3. Bug fix parsing `Transaction`: If a typed transaction is detected in
   `seq[Transaction]`, the previous code removed the RLP (blob) wrapper, then
   passed the contents to `read(Transaction)`.  That meant a blob-wrapped
   legacy transaction would be accepted.  This is incorrect.  The new code
   passes the contents to the typed transaction decoder, which correctly
   rejects a wrapped legacy transaction as having invalid type.

Change 1 has a large, practical effect on `eth/65` syncing with peers.

Serialisation of `eth` message types `Transactions` and `PooledTransactions`
have been broken since the introduction of typed transactions (EIP-2718), as
used in Berlin/London forks.  (The special case for `seq[Transaction]` inside
`BlockBody` only fixed message type `BlockBodies`.)

Due to this, whenever a peer sent us a `Transactions` message, we had an RLP
decoding error processing it, and disconnected the peer thinking it was the
peer's error.

These messages are sent often by good peers, so whenever we connected to a
really good peer, we'd end up disconnecting from it within a few tens of
seconds due to this.

This didn't get noticed before updating to `eth/65`, because with old protocols
we tend to only connect to old peers, which may be out of date themselves and
have no typed transactions.  Also, we didn't really investigate occasional
disconnects before, we assumed they're just part of P2P life.

The root cause is the RLP serialisation of individual `Transaction` is meant to
be subtly different from arrays/sequences of `Transaction` objects in network
messages.  RFC-2976 covers this but it's quite subtle:

- Individual transactions are encoded and stored as either `RLP([fields..])`
  for legacy transactions, or `Type || RLP([fields..])`.  Both of these
  encodings are byte sequences.  The part after `Type` doesn't have to be
  RLP in theory, but all types so far use RLP.  EIP-2718 covers this.

- In arrays (sequences), transactions are encoded as either `RLP([fields..])`
  for legacy transactions, or `RLP(Type || RLP([fields..]))` for all typed
  transactions to date.  Spot the extra `RLP(..)` blob encoding, to make it
  valid RLP inside a larger RLP.  EIP-2976 covers this, "Typed Transactions
  over Gossip", although it's not very clear about the blob encoding.

In practice the extra `RLP(..)` applies to all arrays/sequences of transactions
that are to be RLP-encoded as a list.  In principle, it should be all
aggregates (object fields etc.), but it's enough for us to enable it for all
arrays/sequences, as this is what's used in the protocol and EIP-2976.

Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-07-29 15:37:11 +03:00
jangko a10d301085
implement EIP-1559 Transaction and BlockHeader 2021-06-27 20:12:47 +07:00
jangko ea8530f6a0
EIP-2718: fixes BlockBody rlp encoding 2021-05-17 10:07:05 +07:00
jangko d0eb2de328
eip2718: protect against malformed rlp in tx sequence decoder 2021-05-16 19:15:48 +07:00
jangko ef49a6f50a
fixes EIP2718/EIP2930 misinterpretation
the new Tx format (txType || txPayload) needs envelope
encoding at EthBlock level, not at the Tx level itself.
2021-05-16 12:10:09 +07:00
jangko 343d4f25e1
fix eip2718 bug
- fixes bug in rlp decoder of Receipt
- fixes bug in rlp decoder of Transaction
- refactor rlpEncode for AccessListTx in eth/common/transaction.nim
2021-05-15 14:34:43 +07:00
jangko b6b6f3dec7
implement txHashNoSignature for EIP2817's AccessListTx 2021-05-15 08:18:19 +07:00
jangko 61d5327f55
implement eip2718: transaction type envelope
also add more test cases for both tx and receipt
rlp encoding decoding
2021-05-15 08:18:08 +07:00
Kim De Mey d05cb5d3bd
Fix raw Exceptions in hexary caused by forward declarations (#349)
* Fix raw Exceptions in hexary caused by forward declarations

* Fix raw Exceptions in trie/db caused by forward declarations

* And now we can remove those db Proc CatchableError raises
2021-05-11 17:32:47 +02:00
kdeme bcb58216d1
Add CatchableErrors where needed because of db backends used
In nim-eth this will not fail, as they are base, not implemented
methods. In for example Nimbus-eth1 it will.
2021-05-07 16:28:48 +02:00
kdeme 90b4724492
Adjust for chronosStrictException usage in rest of eth/p2p 2021-05-06 17:20:54 +02:00
Kim De Mey 762415319c
Add build_dcli target and add it to CI (#344)
* Add build_dcli target and add it to CI

* Fix local imports for dcli

* And use local imports for all other files too

* Use local imports in tests and rlpx protocols
2021-04-06 13:33:24 +02:00
Kim De Mey d024ea8e85
Change invalid distance warning to debug (#316)
And also:

* move connected_peers metric so it does get added where it
shouldn't.

* imports cleanup
2020-12-14 12:21:03 +01:00
Zahary Karadjov 5dff021cbc
Add a helper type used in web3 and elsewhere to denote blocks 2020-11-12 20:56:31 +02:00
jangko b5cabdfde4
add getForkId interface to AbstractChainDB 2020-07-02 11:09:48 +07:00
Zahary Karadjov 964a380191 Stricter error handling 2020-06-22 17:32:32 +03:00
Ștefan Talpalaru 66e2dc7ba3
ignoreSignalsInThread() 2020-06-21 01:32:13 +02:00
Viktor Kirilov 28e684ce80 removed redundant definitions which are also present in nim-json-serialization/json_serialization/std/net 2020-04-23 18:30:14 +03:00
Jacek Sieka fd6caa0fdc
Rlp experimental (#227)
* rlp: remove experimental features

* avoid range library

* trie: avoid reference-unsafe bitrange type
2020-04-20 20:14:39 +02:00
Jacek Sieka 1646d78d83
cleanups (#226) 2020-04-18 10:17:59 +02:00
Jacek Sieka a899e09f68
fix endian conversion issues 2020-03-05 12:13:48 +01:00
Jacek Sieka 4c6878343c tighten a few imports 2019-12-09 14:37:21 +02:00
kdeme 17f90920e0 Add unittest for rlpx thunk payload tests 2019-10-23 09:35:33 +09:00
kdeme 757ac1ab86
Remove standalone define and add specific afl/libFuzzer define 2019-10-11 15:25:11 +02:00
kdeme 9b69910570
Fix AssertionError that should be RlpTypeMismatch 2019-10-10 13:07:20 +02:00
Jacek Sieka 0f020d5df8
compat with latest chronos 2019-09-10 17:28:38 -04:00
Yuriy Glukhov 4552e0333d
Export EIP155_CHAIN_ID_OFFSET 2019-08-13 10:42:50 +02:00
Yuriy Glukhov 3e1ce94961 Moved Transaction encodings from nimbus 2019-08-06 10:33:55 +03:00
Ștefan Talpalaru e195868a64
metrics: port to new API 2019-07-17 00:21:37 +02:00
Ștefan Talpalaru 0a5ffaa8b3
small syntax change for collector declaration 2019-07-16 13:10:34 +02:00
Ștefan Talpalaru 620573f63c use new nim-metrics API 2019-07-16 14:06:46 +03:00
Ștefan Talpalaru 93637fa060
Merge branch 'master' of github.com:status-im/nim-eth 2019-07-10 15:35:19 +02:00
Ștefan Talpalaru 6bd5c35986
forgot about metric naming convention 2019-07-10 15:34:50 +02:00
kdeme fb7743e9db Prepare for allowing BlockNumber as int64 2019-07-10 14:27:11 +02:00
Ștefan Talpalaru d445412297
use nim-metrics 2019-07-10 03:01:30 +02:00
kdeme 3088cb462e Support skip and reverse in the GetBlockHeaders request + reactivate getBlockBodies 2019-07-08 18:03:55 +03:00
Jacek Sieka 75c7c62651
std_shims -> stew 2019-07-07 11:56:01 +02:00
Ștefan Talpalaru 799b1a7bb0
initial statistics collection setup 2019-06-26 14:49:38 +02:00
kdeme 21c3c3946d Fix another Assertion + change error pragma to fatal 2019-06-14 16:15:09 +03:00
Zahary Karadjov f0bf0570d1 Support compiling with json logging; Drop package_visible_types 2019-03-25 02:10:09 +02:00
Ștefan Talpalaru 9146e8e2f0
assert() -> doAssert() 2019-03-13 23:15:26 +01:00
Ștefan Talpalaru 1481c824fa
AbstractChainDB.getStateDb() renamed to getTrieDB() 2019-03-13 21:35:22 +01:00
Ștefan Talpalaru 4ac8812707 avoid segfault in Nimbus with -d:release (#19) 2019-03-12 19:37:36 -06:00
Ștefan Talpalaru 4329cc1cb6 AbstractChainDb -> AbstractChainDB (#18) 2019-03-12 19:37:04 -06:00
Yuriy Glukhov fe9fa7689b Fixed imports 2019-02-05 18:54:58 +02:00
Yuriy Glukhov 32998f0dc1 Moved rlp and trie to eth 2019-02-05 14:01:10 +02:00