#38766 [BC-Insight] Nil Pointer Dereference Panics in encodePayload() of Blob Tx’s Encoding

Submitted on Jan 13th 2025 at 03:44:37 UTC by @CertiK for Attackathon | Ethereum Protocol

  • Report ID: #38766

  • Report Type: Blockchain/DLT

  • Report severity: Insight

  • Target: https://github.com/ledgerwatch/erigon

  • Impacts:

    • (Specifications) A bug in specifications with no direct impact on client implementations

Description

Brief/Intro

EIP-4844 (https://github.com/ethereum/EIPs/blob/master/EIPS/eip-4844.md ) introduces a new transaction type, blob tx, which does not allow the To address to be nil (i.e., it cannot be used to create contract).

In Erigon (https://github.com/erigontech/erigon/ ), the blob tx allows the To address to be nil. In case that the blob tx includes a nil To address, the tx encoding causes a nil pointer dereference panics due to a flaw in function encodePayload().

Vulnerability Details

Affected Codebase: https://github.com/erigontech/erigon/tree/v2.61.0

The blob tx is defined via embedding the DynamicFeeTransaction, which allows the To address to be nil.

https://github.com/erigontech/erigon/blob/v2.61.0/core/types/blob_tx.go#L20C1-L24C2

https://github.com/erigontech/erigon/blob/v2.61.0/core/types/dynamic_fee_tx.go#L35

https://github.com/erigontech/erigon/blob/v2.61.0/core/types/legacy_tx.go#L34

However, this violates the EIP-4844 (https://github.com/ethereum/EIPs/blob/master/EIPS/eip-4844.md )

The field to deviates slightly from the semantics with the exception that it MUST NOT be nil and therefore must always represent a 20-byte address. This means that blob transactions cannot have the form of a create transaction.

In case that the To address is set to be nil in a blob tx, the encoding with two functions EncodeRLP() and MarshalBinary() calls the encodePayload() to perform the encoding of blob tx:

https://github.com/erigontech/erigon/blob/v2.61.0/core/types/blob_tx.go#L243

https://github.com/erigontech/erigon/blob/v2.61.0/core/types/blob_tx.go#L167

At line 197, the stx.To.Bytes() directly invokes the Bytes() method without checking if the To is nil or not. This overlook would lead to the nil pointer dereference panics.

The latest commit makes slight changes to the affected code, but it still cause nil pointer deference panics when writing nil To address. (Demonstrated in the Proof of Concept)

https://github.com/erigontech/erigon/blob/main/core/types/blob_tx.go#L218

Impact Details

Since the encoding of tx is used frequently in the codebase, through users, p2p or consensus layer, any invocation of the blob tx encoding with nil To address would crash the Erigon node.

References

  • https://github.com/erigontech/erigon/tree/v2.61.0

  • https://github.com/ethereum/EIPs/blob/master/EIPS/eip-4844.md

Proof of Concept

Proof of Concept

For simplicity, using the existing tests in file https://github.com/erigontech/erigon/blob/v2.61.0/core/types/transaction_test.go#L600 we create the following unit test to demonstrate the nil pointer dereference panics with MarshalBinary() of the blob tx.

  1. Set the To address as nil:

  1. Run the following unit test in the same file:

  1. The test result shows an nil pointer dereference panics occur due to the method invocation To.Bytes():

  1. Nil Pointer dereference also occurs in the latest commit (https://github.com/erigontech/erigon/blob/main/core/types/blob_tx.go#L218 ) when writing nil To address:

Was this helpful?