Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ Not yet released.

### Proof additions

- In Lean, `sendEth_blob` and `run_no_blob` (`Execution/Proofs/Network/Session.lean`) state that an eth session never sends a Transactions message that holds a blob transaction.
`mayBroadcastWire_of_encodeTransaction` (`Execution/Proofs/Network/Pool.lean`) states that the check on the wire agrees with the check on a decoded transaction.

- In Lean, `answerJson_of_unstructured_params` (`Execution/Proofs/Rpc/Methods.lean`) states that a JSON-RPC object whose parameters are neither an array nor an object gets the error `-32600`.
The response carries the identifier of the object if it can be read, else `null`.

Expand Down Expand Up @@ -2006,6 +2009,12 @@ Not yet released.

### Changes that break callers

- An eth session refuses to send a Transactions message that holds a blob transaction.
The Networking section of EIP-4844 says that nodes must not automatically broadcast one.
`execution.network.session` reports such a send as `refused`, where it reported `sent`.
In Lean, `sendEth` (`Execution/Network/Session.lean`) reads the type of each transaction with `mayBroadcastWire` (`Execution/Network/Transactions.lean`).
`mayBroadcastWhole` (`Execution/Network/Pool.lean`) and `mayBroadcastWire` both read the type through `mayBroadcastType`.

- `engine.get_inclusion_list` leaves out a candidate of type `0x03`, a blob transaction, or `0x06`, a frame transaction of EIP-8141.
EIP-7805 at `edba685` skips both in step 2 of its check, and says the method should omit them; `bogota.md` asks the same for blob transactions.
A skipped candidate takes no bytes, so a later one can still join the list.
Expand Down
11 changes: 2 additions & 9 deletions EthLib/Execution/Network/Pool.lean
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public import EthLib.Execution.Network.Transactions
public import EthLib.Execution.Transactions.Inclusion

/-!

Check warning on line 6 in EthLib/Execution/Network/Pool.lean

View workflow job for this annotation

GitHub Actions / writing

Writing D1

This module or section doc has 9 lines, more than 6. Keep a title, what the module provides and its source. Move each detail to a comment above its line in the body. '# `Execution.Network.Pool`'
# `Execution.Network.Pool`

The rules by which a node keeps a transaction that a peer sends, in its pool of transactions.
Expand All @@ -29,7 +29,7 @@
open EthLib.Execution.State (TransactionState)
open EthLib.Execution.Transactions

/-- Check that a node may keep a transaction from a peer, at `fork` on the chain `chainId`.

Check warning on line 32 in EthLib/Execution/Network/Pool.lean

View workflow job for this annotation

GitHub Actions / writing

Writing D1

This declaration doc has 12 lines, more than 4. Keep what it states or returns. Move each detail to a comment above its line in the body. 'Check that a node may keep a transaction from a peer, at `fork` on the chain `ch'

It returns the sender.

Expand Down Expand Up @@ -99,15 +99,8 @@
-- Any other invalid transaction: the node keeps the peer.
| _ => .discard

/-- Whether a node may send a transaction whole to its peers in a Transactions message.

[EIP-4844][eip-4844] says that a node never sends a blob transaction whole on its own.

It only announces it by its hash, and sends it when a peer asks.

[eip-4844]: https://eips.ethereum.org/EIPS/eip-4844#networking -/
/-- Whether a node may send a transaction whole to its peers in a Transactions message. -/
def mayBroadcastWhole (tx : Transaction) : Bool :=
-- EIP-4844: a blob transaction goes only by announcement and request.
tx.type != BLOB_TX_TYPE
mayBroadcastType tx.type

end EthLib.Execution.Network
17 changes: 13 additions & 4 deletions EthLib/Execution/Network/Session.lean
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@
public import EthLib.Base.List
public import EthLib.Execution.Network.Message

/-!

Check warning on line 6 in EthLib/Execution/Network/Session.lean

View workflow job for this annotation

GitHub Actions / writing

Writing D1

This module or section doc has 9 lines, more than 6. Keep a title, what the module provides and its source. Move each detail to a comment above its line in the body. '# `Execution.Network.Session`'
# `Execution.Network.Session`

The rules of an eth session, from [`caps/eth.md`][eth], and when snap may run beside it.

[eth]: https://github.com/ethereum/devp2p/blob/277ceb399c15df86efb17d51eb58200c26879784/caps/eth.md

The ban on the broadcast of a blob transaction comes from [EIP-4844][eip-4844].

[eip-4844]: https://eips.ethereum.org/EIPS/eip-4844#networking

The source leaves some reactions open, and the session decides none of them:

- a second Status from the peer gets its own error;
- a response that answers no pending request gets its own error;
- a snap message on a connection without eth is only flagged, by the check of shared capabilities;
- a peer that sends a transaction twice, or back to this node, is accepted.
- a peer that sends a transaction twice, or back to this node, is accepted;
- a peer that sends a blob transaction in Transactions, against that ban, is accepted.
-/

@[expose] public section
Expand Down Expand Up @@ -87,7 +92,7 @@
| badRange (earliest latest : Nat)
deriving DecidableEq, Repr

/-- The stable code of an error, one per constructor, for the C exports.

Check warning on line 95 in EthLib/Execution/Network/Session.lean

View workflow job for this annotation

GitHub Actions / writing

Writing D1

This declaration doc has 5 lines, more than 4. Keep what it states or returns. Move each detail to a comment above its line in the body. 'The stable code of an error, one per constructor, for the C exports.'

A refused Status carries the code of its own error, from 101.

Expand Down Expand Up @@ -189,15 +194,19 @@
| .status _, _ => some { session with statusSent := true }
-- Before both Status messages, nothing else may be sent.
| _, false => none
-- Transactions (0x02): at least one new transaction, no resend in the session, nor a relay back.
-- Transactions (0x02): at least one new transaction, no resend, no relay back and no blob.
--
-- A hash twice in one message counts as a resend; the hashes then count as sent.
| .transactions _, true =>
| .transactions txs, true =>
let hashes := m.transactionHashes
-- The hashes sent and received so far, in a search tree, so each test costs a logarithm.
let known := Std.TreeSet.ofList (session.sentTxs ++ session.receivedTxs)
-- The message is checked for a repeat in one pass.
if hashes ≠ [] ∧ (firstRepeated hashes).isNone ∧ hashes.all (!known.contains ·) then
if hashes ≠ [] ∧ (firstRepeated hashes).isNone ∧ hashes.all (!known.contains ·) ∧
-- EIP-4844: a node must not automatically broadcast a blob transaction.
--
-- It only announces one, and sends it whole when a peer requests it.
txs.all mayBroadcastWire then
some { session with sentTxs := session.sentTxs ++ hashes }
else none
-- PooledTransactions answers a request, so a resend is not refused; its hashes count as sent.
Expand Down
20 changes: 20 additions & 0 deletions EthLib/Execution/Network/Transactions.lean
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,26 @@ def wireHash (tx : Encoded) : Hash32 :=
else canonical
| [] => canonical

/-- Whether a node may send a transaction of this type whole, in a Transactions message.

[EIP-4844][eip-4844] says that nodes must not automatically broadcast a blob transaction.

They only announce it, and a peer requests it with GetPooledTransactions.

[eip-4844]: https://eips.ethereum.org/EIPS/eip-4844#networking -/
def mayBroadcastType (type : UInt8) : Bool :=
type != BLOB_TX_TYPE

/-- Whether a node may send a transaction whole in a Transactions message, from its wire form. -/
def mayBroadcastWire (tx : Encoded) : Bool :=
match tx.item with
-- EIP-2976: a typed transaction is the byte array `TransactionType || TransactionPayload`.
--
-- Only the type byte is read, so a malformed payload after the type 3 is also held back.
| .bytes b => (b.data[0]?.map mayBroadcastType).getD true
-- EIP-2976: a legacy transaction is an RLP list, with no type byte.
| .list _ => true

/-- Why the transactions of a PooledTransactions do not answer a GetPooledTransactions. -/
inductive PoolError where
/-- The hashes of the transactions are not a sublist of the requested hashes.
Expand Down
17 changes: 16 additions & 1 deletion EthLib/Execution/Proofs/Network/Pool.lean
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,21 @@ theorem transactions_no_blob (txs : List Transaction) :
∀ tx ∈ txs.filter mayBroadcastWhole, ∀ blob, tx ≠ .blob blob := by
intro tx member blob same
subst same
simp [mayBroadcastWhole, Transaction.type, BLOB_TX_TYPE] at member
simp [mayBroadcastWhole, mayBroadcastType, Transaction.type, BLOB_TX_TYPE] at member

/-- The wire form of a transaction may go whole exactly when the transaction may. -/
theorem mayBroadcastWire_of_encodeTransaction {t : Transaction} {bytes raw : ByteArray}
(h : encodeTransaction t = .ok bytes) :
mayBroadcastWire ⟨.bytes bytes, raw⟩ = mayBroadcastWhole t := by
obtain ⟨h0, -, -⟩ := encodeTransaction_head h
have hget : bytes.data[0]? = some bytes[0] := Array.getElem?_eq_getElem (by simpa using h0)
have hiff := type_eq_three_iff_of_encodeTransaction h
rw [hget, Option.some.injEq] at hiff
simp only [mayBroadcastWire, mayBroadcastWhole, mayBroadcastType, hget, Option.map_some,
Option.getD_some]
-- Both sides compare a type with 3, and the two types are 3 together.
rw [Bool.eq_iff_iff]
simp only [bne_iff_ne, ne_eq, BLOB_TX_TYPE]
exact not_congr hiff.symm

end EthLib.Execution.Network
34 changes: 33 additions & 1 deletion EthLib/Execution/Proofs/Network/Session.lean
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private theorem sendEth_transactions (session next : EthSession) (txs : List Enc
· -- The send goes through only when the hashes are fresh.
split at h
· rename_i fresh
obtain ⟨hne, hscan, hall⟩ := fresh
obtain ⟨hne, hscan, hall, -⟩ := fresh
refine ⟨hne, ?_, fun x hx => ?_⟩
· simpa [Message.transactionHashes] using hscan
-- A hash outside the search tree is in neither list.
Expand All @@ -196,6 +196,19 @@ private theorem sendEth_transactions (session next : EthSession) (txs : List Enc
exact hx'
· cases h

/-- This node never sends a Transactions message that holds a transaction it may not send whole. -/
theorem sendEth_blob (session : EthSession) {txs : List Encoded} {tx : Encoded}
(hmem : tx ∈ txs) (hblob : mayBroadcastWire tx = false) :
sendEth session (.transactions txs) = none := by
cases hb : session.statusSent && session.remoteStatus.isSome <;>
simp only [sendEth, hb]
-- The send needs every transaction to be one that may go whole, and `tx` is not.
· split
· rename_i fresh
obtain ⟨-, -, -, hall⟩ := fresh
simpa [hblob] using List.all_eq_true.mp hall tx hmem
· rfl

/-- Before the peer's Status, this node may send nothing but Status. -/
theorem sendEth_beforeStatus (session : EthSession) (m : Message)
(h : session.remoteStatus = none) (hm : ∀ st, m ≠ .status st) :
Expand Down Expand Up @@ -319,6 +332,25 @@ theorem run_no_resend (s : Schedule) (number timestamp : Nat) (session next : Et
simp only [List.mem_append, not_or] at c1 c2
exact ⟨c1.1, c1.2, c2.1, c2.2⟩

/-- Each transaction of each Transactions message of a run is one that may go whole. -/
theorem run_no_blob (s : Schedule) (number timestamp : Nat) (session next : EthSession)
(events before after : List EthEvent) (txs : List Encoded)
(h : session.run s number timestamp events = some next)
(hev : events = before ++ .sent (.transactions txs) :: after) :
∀ tx ∈ txs, mayBroadcastWire tx = true := by
subst hev
rw [run_append] at h
obtain ⟨s1, -, h2⟩ := Option.bind_eq_some_iff.mp h
rw [run_cons] at h2
obtain ⟨s2, h3, -⟩ := Option.bind_eq_some_iff.mp h2
have h3 : sendEth s1 (.transactions txs) = some s2 := h3
intro tx hmem
-- A transaction that may not go whole would make the send fail.
cases hw : mayBroadcastWire tx
· rw [sendEth_blob s1 hmem hw] at h3
cases h3
· rfl

/-- The eth requirement of snap holds exactly when some shared capability is named eth. -/
theorem snapAllowed_iff (offsets : List (Capability × Nat)) :
snapAllowed offsets = true ↔ ∃ c n, (c, n) ∈ offsets ∧ c.name = ETH_NAME := by
Expand Down
8 changes: 6 additions & 2 deletions SOUNDNESS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3533,23 +3533,27 @@
They follow [Basic Operation](https://github.com/ethereum/devp2p/blob/277ceb399c15df86efb17d51eb58200c26879784/caps/eth.md#basic-operation), [Protocol Messages](https://github.com/ethereum/devp2p/blob/277ceb399c15df86efb17d51eb58200c26879784/caps/eth.md#protocol-messages) and [Transactions (0x02)](https://github.com/ethereum/devp2p/blob/277ceb399c15df86efb17d51eb58200c26879784/caps/eth.md#transactions-0x02) in `caps/eth.md`.
Before the peer's Status, only a Status that passes `checkStatus` is accepted, and until both Status messages have passed, this node sends nothing but Status.
The session keeps the requests that this node sent and that no response has answered yet, and a response must answer one of them.
It keeps the hashes of the transactions sent, in Transactions or PooledTransactions, and received, and refuses a Transactions message that would send a transaction twice, or back to the peer that sent it.

Check warning on line 3536 in SOUNDNESS.md

View workflow job for this annotation

GitHub Actions / writing

Writing S1

This sentence has about 33 words. Consider a split if it improves clarity. 'It keeps the hashes of the transactions sent, in Transactions or PooledTransacti'
It also refuses an empty Transactions message, which "Transactions (0x02)" forbids.
It refuses a Transactions message that holds a blob transaction, since the [Networking section of EIP-4844](https://eips.ethereum.org/EIPS/eip-4844#networking) says that nodes must not automatically broadcast one, and only announce it.

Check warning on line 3538 in SOUNDNESS.md

View workflow job for this annotation

GitHub Actions / writing

Writing S1

This sentence has about 28 words. Consider a split if it improves clarity. 'It refuses a Transactions message that holds a blob transaction, since the [Netw'
On the proof-of-stake networks that the session assumes, NewBlockHashes and NewBlock are discarded.
`snapAllowed` says whether the shared capabilities meet the requirement of snap, since [Relation to eth](https://github.com/ethereum/devp2p/blob/277ceb399c15df86efb17d51eb58200c26879784/caps/snap.md#relation-to-eth) makes snap "a dependent satellite of eth".

`receiveEth_beforeStatus`, `receiveEth_status_iff`, `receiveEth_response`, `receiveEth_unsolicited`, `receiveEth_discard`, `receiveEth_secondStatus`, `receiveEth_sentTxs` and `receiveEth_receivedTxs` (`Execution/Proofs/Network/Session.lean`) state the receiving steps.
`sendEth_beforeStatus`, `sendEth_beforeOwnStatus` and `sendEth_pending` state the sending steps.
`sendEth_beforeStatus`, `sendEth_beforeOwnStatus`, `sendEth_pending` and `sendEth_blob` state the sending steps.
`run_sentTxs` and `run_no_resend` state that along any run of a session, a Transactions message sends no transaction that went out before, and none that the peer sent before it.

Check warning on line 3544 in SOUNDNESS.md

View workflow job for this annotation

GitHub Actions / writing

Writing S1

This sentence has about 29 words. Consider a split if it improves clarity. 'run_sentTxs` and `run_no_resend` state that along any run of a session, a Transa'
`run_no_blob` states that along any run, a Transactions message holds no blob transaction.
`mayBroadcastWire_of_encodeTransaction` (`Execution/Proofs/Network/Pool.lean`) states that the check on the wire agrees with `mayBroadcastWhole` on a decoded transaction.
`snapAllowed_iff` states that the requirement holds exactly when a capability named eth is shared.
The session pairs a response with its request; the content of the response is judged apart, by `checkHeaders`, `receiptsMatch` and the other checks.

The source leaves five points open, and the session decides none of them.
The source leaves six points open, and the session decides none of them.
A second Status from the peer gives the error `secondStatus`, and the source fixes no reaction to it; this node may send a Status at any time.

Check warning on line 3551 in SOUNDNESS.md

View workflow job for this annotation

GitHub Actions / writing

Writing S1

This sentence has about 27 words. Consider a split if it improves clarity. 'A second Status from the peer gives the error `secondStatus`, and the source fix'
A response that answers no pending request gives `unsolicited`; the source fixes a reaction only for the elements of Cells, a disconnect.
A snap message on a connection without eth has no reaction in the source, and `snapAllowed` only names the case.
A peer that keeps sending NewBlock or NewBlockHashes "should be disconnected", with no count, so each such message is only discarded.
A peer that sends a transaction twice, or back to this node, breaks the rule of "Transactions (0x02)", but the source fixes no reaction, so the session accepts the message.

Check warning on line 3555 in SOUNDNESS.md

View workflow job for this annotation

GitHub Actions / writing

Writing S1

This sentence has about 29 words. Consider a split if it improves clarity. 'A peer that sends a transaction twice, or back to this node, breaks the rule of '
A peer that sends a blob transaction in Transactions breaks the rule of EIP-4844, but neither EIP-4844 nor `caps/eth.md` fixes a reaction, so the session accepts the message.

Check warning on line 3556 in SOUNDNESS.md

View workflow job for this annotation

GitHub Actions / writing

Writing S1

This sentence has about 28 words. Consider a split if it improves clarity. 'A peer that sends a blob transaction in Transactions breaks the rule of EIP-4844'

The session also leaves out "A node should never send a transaction back to a peer that it can determine already knows of it" ([Transaction Exchange](https://github.com/ethereum/devp2p/blob/277ceb399c15df86efb17d51eb58200c26879784/caps/eth.md#transaction-exchange)), which also covers announcements.
A PooledTransactions answer is never refused for a resend in an active session, and the session counts its transactions as sent, since "must not resend the same transaction" names no message.
Expand Down
17 changes: 17 additions & 0 deletions bindings/python/tests/eth/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,23 @@ def test_empty_or_duplicate_transactions_refused() -> None:
) == [("sent", 0), ("accept", 0), ("refused", 0), ("refused", 0)]


def test_blob_transactions_refused() -> None:
# EIP-4844, Networking: nodes must not automatically broadcast blob transactions.
#
# So a Transactions message that holds one is refused.
# A typed transaction crosses as the bytes of its type and its payload.
# The session reads only the type byte.
blob = b"\x03\xc0"
dynamic_fee = b"\x02\xc0"
assert _run(
STATUS_OUT,
STATUS_IN,
(SENT, TRANSACTIONS, rlp.encode([blob])),
(SENT, TRANSACTIONS, rlp.encode([list(TX0), blob])),
(SENT, TRANSACTIONS, rlp.encode([dynamic_fee])),
) == [("sent", 0), ("accept", 0), ("refused", 0), ("refused", 0), ("sent", 0)]


def test_pooled_transactions_never_refused() -> None:
pooled = rlp.encode([_p(5), [list(TX3)]])
# Sending the answer to a request never refuses, even for a transaction the peer sent.
Expand Down
Loading