#37199 [BC-Low] Potential Chain Fork Due to Shallow Copy of Byte Slice
Submitted on Nov 28th 2024 at 17:16:42 UTC by @CertiK for Attackathon | Ethereum Protocol
Report ID: #37199
Report Type: Blockchain/DLT
Report severity: Low
Target: https://github.com/ledgerwatch/erigon
Impacts:
Unintended chain split affecting less than 25% of the network (Network partition)
Description
Brief/Intro
A potential chain fork has been discovered in the Ethereum client Erigon ( https://github.com/erigontech/erigon ) due to the shallow copy of the byte slice in precompile contract dataCopy.
Vulnerability Details
The issue outlined in this report pertains to the precompile contract dataCopy, detailed as follows:
Affected Codebase: https://github.com/erigontech/erigon/tree/v2.61.0-beta1
The precompile contract dataCopy is utilized to copy the input (byte slice):
https://github.com/erigontech/erigon/blob/v2.61.0-beta1/core/vm/contracts.go#L303
Which directly returns the input as a shallow copy of the input, which does not align with other Ethereum clients, for example, in Go Ethereum:
https://github.com/ethereum/go-ethereum/blob/v1.14.12/core/vm/contracts.go#L315
It performs a deep copy of the byte slice
https://github.com/ethereum/go-ethereum/blob/v1.14.12/common/bytes.go#L40
Deep copy is also applied in REVM (https://github.com/bluealloy/revm), which is used in the Reth Ethereum client:
https://github.com/bluealloy/revm/blob/main/crates/precompile/src/identity.rs#L19
This discrepancy in implementation could lead to chain fork as observed in go-ethereum clients in the post mortem: https://gist.github.com/karalabe/e1891c8a99fdc16c4e60d9713c35401f
Impact Details
This discrepancy in implementation of shallow copy and deep copy could lead to chain fork.
References
https://gist.github.com/karalabe/e1891c8a99fdc16c4e60d9713c35401f
https://github.com/erigontech/erigon
https://github.com/bluealloy/revm
Proof of Concept
Proof of Concept
This attack scenario has been observed in two opcodes RETURNDATASIZE and RETURNDATACOPY in go-ethereum as described in the post mortem: https://gist.github.com/karalabe/e1891c8a99fdc16c4e60d9713c35401f
Here we provide a unit test to show the difference between the implementation of data copy precompile contract with shallow copy and deep copy:
Test result:
The result shows that the shallow copy modifies the original input while deep copy does not.
Since Erigon uses the shallow copy in the data copy precompile contract, once the input is modified, it would lead to inconsistent data with other Ethereum clients, potentially lead to chain fork/split.
Was this helpful?