paradigmxyz / reth

Modular, contributor-friendly and blazing-fast implementation of the Ethereum protocol, in Rust
https://reth.rs/
Apache License 2.0
3.8k stars 1.06k forks source link

Improper handling of engine_newPayloadV2 #4628

Closed 0xTylerHolmes closed 12 months ago

0xTylerHolmes commented 1 year ago

Describe the bug

Pre-shanghai rpc calls for engine_newPayloadV2 do not treat the params as ExecutionPayloadV1 which is the expected behavior. Instead they parse the param as ExecutionPayloadV2 which is an issue if we do not provide a withdrawals field.

Steps to reproduce

Steps to reproduce:

  1. Start Reth post-merge but pre Shanghai.
  2. Submit an engine_newPayloadV2 request without withdrawals.

Run with following chain config:

  ...
  "coinbase": "0x0000000000000000000000000000000000000000",
  "difficulty": "0x01",
  "extraData": "",
  "gasLimit": "0x400000",
  "nonce": "0x1234",
  "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "timestamp": "1694958569",
  "config": {
    "chainId": 1337,
    "homesteadBlock": 0,
    "eip150Block": 0,
    "eip155Block": 0,
    "eip158Block": 0,
    "byzantiumBlock": 0,
    "constantinopleBlock": 0,
    "petersburgBlock": 0,
    "istanbulBlock": 0,
    "berlinBlock": 0,
    "londonBlock": 0,
    "mergeNetsplitBlock": 0,
    "terminalTotalDifficulty": 0,
    "terminalTotalDifficultyPassed": true,
    "shanghaiTime": 1694958665
  }

// shanghaiTime = 0x65070449

Request Used:

{
  "jsonrpc": "2.0",
  "method": "engine_newPayloadV2",
  "params": [
    {
      "baseFeePerGas": "0x342770c0",
      "blockHash": "0x8bf9cd261b0b50f9ff316c7c644b432fb95bcde8a49888959b44a7f43d409182",
      "blockNumber": "0x1",
      "extraData": "0x99726574682f76302e312e302d616c7068612e382f6c696e7578",
      "feeRecipient": "0x00000000219ab540356cbb839cbe05303d7705fa",
      "gasLimit": "0x400000",
      "gasUsed": "0x0",
      "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
      "parentHash": "0xd3a13b40a829ab54962ff7789870395b2a61889e7d3c2d497380d3a5b1d0e46c",
      "prevRandao": "0xd3a13b40a829ab54962ff7789870395b2a61889e7d3c2d497380d3a5b1d0e46c",
      "receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
      "stateRoot": "0xf9041e19685990d392389013e19a1d0543fccd1cd23dd22ed95476800276e985",
      "timestamp": "0x6507040d",
      "transactions": []
    }
  ],
  "id": 1
}

Note: timestamp < shanghaiTime

Response:

{
  "jsonrpc": "2.0",
  "error": {
    "code": -32602,
    "message": "Invalid params",
    "data": "missing field `withdrawals` at line 1 column 1199"
  },
  "id": 1
}

To easily reproduce start a lighthouse-reth instance with a bellatrix genesis. Lighthouse will not be able to follow the chain due to the repeated rpc errors.

Node logs

2023-09-17T13:50:21.256561Z DEBUG connection{remote_addr=127.0.0.1:44248 conn_id=52}: jsonrpsee_server::server: Accepting new connection 1/500
2023-09-17T13:50:21.256708Z TRACE hyper::proto::h1::conn: Conn::read_head
2023-09-17T13:50:21.256815Z TRACE hyper::proto::h1::conn: flushed({role=server}): State { reading: Init, writing: Init, keep_alive: Busy }
2023-09-17T13:50:21.256906Z TRACE hyper::proto::h1::conn: Conn::read_head
2023-09-17T13:50:21.256953Z TRACE hyper::proto::h1::io: received 1531 bytes
2023-09-17T13:50:21.257022Z TRACE parse_headers: hyper::proto::h1::role: Request.parse bytes=1531
2023-09-17T13:50:21.257082Z TRACE parse_headers: hyper::proto::h1::role: Request.parse Complete(265)
2023-09-17T13:50:21.257177Z DEBUG hyper::proto::h1::io: parsed 5 headers
2023-09-17T13:50:21.257221Z DEBUG hyper::proto::h1::conn: incoming body is content-length (1266 bytes)
2023-09-17T13:50:21.257547Z TRACE jsonrpsee_server::server: Request { method: POST, uri: /, version: HTTP/1.1, headers: {"content-type": "application/json", "authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2OTQ5NTg2MjEsImlkIjpudWxsLCJjbHYiOm51bGx9.qSITHnh-TCSsICuPC_9pboAxqK2S7kDFs_2jLLjgHis", "accept": "*/*", "host": "localhost:8551", "content-length": "1266"}, body: Body(Streaming) }
2023-09-17T13:50:21.257609Z TRACE hyper::proto::h1::decode: decode; state=Length(1266)
2023-09-17T13:50:21.257656Z DEBUG hyper::proto::h1::conn: incoming body completed
2023-09-17T13:50:21.257760Z TRACE jsonrpsee_core::http_helpers: HTTP response body: {"jsonrpc":"2.0","method":"engine_newPayloadV2","params":[{"baseFeePerGas":"0x342770c0","blockHash":"0x8bf9cd261b0b50f9ff316c7c644b432fb95bcde8a49888959b44a7f43d409182","blockNumber":"0x1","extraData":"0x99726574682f76302e312e302d616c7068612e382f6c696e7578","feeRecipient":"0x00000000219ab540356cbb839cbe05303d7705fa","gasLimit":"0x400000","gasUsed":"0x0","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","parentHash":"0xd3a13b40a829ab54962ff7789870395b2a61889e7d3c2d497380d3a5b1d0e46c","prevRandao":"0xd3a13b40a829ab54962ff7789870395b2a61889e7d3c2d497380d3a5b1d0e46c","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","stateRoot":"0xf9041e19685990d392389013e19a1d0543fccd1cd23dd22ed95476800276e985","timestamp":"0x6507040d","transactions":[]}],"id":1}
2023-09-17T13:50:21.258809Z TRACE method_call{method="engine_newPayloadV2"}: jsonrpsee_core::tracing: recv="{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"engine_newPayloadV2\",\"params\":[{\"baseFeePerGas\":\"0x342770c0\",\"blockHash\":\"0x8bf9cd261b0b50f9ff316c7c644b432fb95bcde8a49888959b44a7f43d409182\",\"blockNumber\":\"0x1\",\"extraData\":\"0x99726574682f76302e312e302d616c7068612e382f6c696e7578\",\"feeRecipient\":\"0x00000000219ab540356cbb839cbe05303d7705fa\",\"gasLimit\":\"0x400000\",\"gasUsed\":\"0x0\",\"logsBloom\":\"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\"parentHash\":\"0xd3a13b40a829ab54962ff7789870395b2a61889e7d3c2d497380d3a5b1d0e46c\",\"prevRandao\":\"0xd3a13b40a829ab54962ff7789870395b2a61889e7d3c2d497380d3a5b1d0e46c\",\"receiptsRoot\":\"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421\",\"stateRoot\":\"0xf9041e19685990d392389013e19a1d0543fccd1cd23dd22ed95476800276e985\",\"timestamp\":\"0x6507040d\",\"transactions\":[]}]}"
2023-09-17T13:50:21.259402Z TRACE method_call{method="engine_newPayloadV2"}: jsonrpsee_types::params: [next_inner] Params JSON: "[{\"baseFeePerGas\":\"0x342770c0\",\"blockHash\":\"0x8bf9cd261b0b50f9ff316c7c644b432fb95bcde8a49888959b44a7f43d409182\",\"blockNumber\":\"0x1\",\"extraData\":\"0x99726574682f76302e312e302d616c7068612e382f6c696e7578\",\"feeRecipient\":\"0x00000000219ab540356cbb839cbe05303d7705fa\",\"gasLimit\":\"0x400000\",\"gasUsed\":\"0x0\",\"logsBloom\":\"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\"parentHash\":\"0xd3a13b40a829ab54962ff7789870395b2a61889e7d3c2d497380d3a5b1d0e46c\",\"prevRandao\":\"0xd3a13b40a829ab54962ff7789870395b2a61889e7d3c2d497380d3a5b1d0e46c\",\"receiptsRoot\":\"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421\",\"stateRoot\":\"0xf9041e19685990d392389013e19a1d0543fccd1cd23dd22ed95476800276e985\",\"timestamp\":\"0x6507040d\",\"transactions\":[]}]"
2023-09-17T13:50:21.259896Z TRACE method_call{method="engine_newPayloadV2"}: jsonrpsee_types::params: [next_inner] Deserialization to "reth_rpc_types::eth::engine::payload::ExecutionPayloadV2" failed. Error: Error("missing field `withdrawals`", line: 1, column: 1199), input JSON: "{\"baseFeePerGas\":\"0x342770c0\",\"blockHash\":\"0x8bf9cd261b0b50f9ff316c7c644b432fb95bcde8a49888959b44a7f43d409182\",\"blockNumber\":\"0x1\",\"extraData\":\"0x99726574682f76302e312e302d616c7068612e382f6c696e7578\",\"feeRecipient\":\"0x00000000219ab540356cbb839cbe05303d7705fa\",\"gasLimit\":\"0x400000\",\"gasUsed\":\"0x0\",\"logsBloom\":\"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\"parentHash\":\"0xd3a13b40a829ab54962ff7789870395b2a61889e7d3c2d497380d3a5b1d0e46c\",\"prevRandao\":\"0xd3a13b40a829ab54962ff7789870395b2a61889e7d3c2d497380d3a5b1d0e46c\",\"receiptsRoot\":\"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421\",\"stateRoot\":\"0xf9041e19685990d392389013e19a1d0543fccd1cd23dd22ed95476800276e985\",\"timestamp\":\"0x6507040d\",\"transactions\":[]}]"
2023-09-17T13:50:21.259976Z DEBUG method_call{method="engine_newPayloadV2"}: reth_rpc_api::engine: Error parsing "payload" as "ExecutionPayloadV2": ErrorObject { code: InvalidParams, message: "Invalid params", data: Some(RawValue("missing field `withdrawals` at line 1 column 1199")) }
2023-09-17T13:50:21.260046Z TRACE method_call{method="engine_newPayloadV2"}: jsonrpsee_core::tracing: send="{\"jsonrpc\":\"2.0\",\"error\":{\"code\":-32602,\"message\":\"Invalid params\",\"data\":\"missing field `withdrawals` at line 1 column 1199\"},\"id\":1}"
2023-09-17T13:50:21.260258Z TRACE encode_headers: hyper::proto::h1::role: Server::encode status=200, body=Some(Known(134)), req_method=Some(POST)
2023-09-17T13:50:21.260456Z TRACE hyper::proto::h1::io: buffer.queue self.len=124 buf.len=134
Sep 17 13:50:21.260 2023 RESPONSE (status 200 OK)

Platform(s)

Linux (ARM)

What version/commit are you on?

0.1.0-alpha.8/62e7d982

What database version are you on?

1

If you've built Reth from source, provide the full command you used

cargo build --release

Code of Conduct

mattsse commented 1 year ago

this is indeed a bug

https://github.com/ethereum/execution-apis/blob/main/src/engine/shanghai.md#request

@Rjected