Skip to content

[SharovBot] fix: add 0x prefix to structLogs storage keys/values in debug_traceCall#20647

Closed
erigon-copilot[bot] wants to merge 3 commits into
release/3.4from
agent-fix/structlog-storage-0x-prefix
Closed

[SharovBot] fix: add 0x prefix to structLogs storage keys/values in debug_traceCall#20647
erigon-copilot[bot] wants to merge 3 commits into
release/3.4from
agent-fix/structlog-storage-0x-prefix

Conversation

@erigon-copilot
Copy link
Copy Markdown
Contributor

[SharovBot]

Problem

mainnet-rpc-integ-tests-latest CI has been failing on every commit to release/3.4 branch (10/10 commits) due to a mismatch in debug_traceCall/test_43.json.

The diff shows:

storage: {
-  0x2fa8c5322c1048470ad77c09da3654fc909cba75d0344927ddd1da93527c2044: "0x0000000000000000000000000000000000000000000000000000000000000000"
+  2fa8c5322c1048470ad77c09da3654fc909cba75d0344927ddd1da93527c2044: "0000000000000000000000000000000000000000000000000000000000000000"
}

The reference implementation returns storage keys/values with 0x prefix, but Erigon was returning bare hex.

Root Cause

FormatLogs() in both rpc/ethapi/api.go and execution/tracing/tracers/logger/logger.go formats storage map keys and values using:

storage[fmt.Sprintf("%x", i)] = fmt.Sprintf("%x", storageValue)

%x format verb produces bare hex without the 0x prefix.

Fix

Use common.Hash.Hex() which calls hexutil.Encode() and produces properly 0x-prefixed output:

storage[i.Hex()] = storageValue.Hex()

Impact

Affects debug_traceCall, debug_traceTransaction, debug_traceBlock, debug_traceBlockByNumber, and any other endpoint that uses FormatLogs() for structLog output.

Testing

…ebug_traceCall

FormatLogs() was formatting storage map keys and values using
fmt.Sprintf("%x", ...) which produces bare hex without the 0x prefix.

The reference implementation returns storage keys/values with 0x prefix
(e.g. "0x2fa8c5322c..."), but Erigon was returning "2fa8c5322c...".

Fix: use common.Hash.Hex() which internally calls hexutil.Encode()
and properly produces 0x-prefixed hex strings for both keys and values.

This affects both rpc/ethapi/api.go (FormatLogs used by debug_traceCall,
debug_traceTransaction, etc.) and the duplicate copy in
execution/tracing/tracers/logger/logger.go.

Fixes mainnet-rpc-integ-tests-latest CI failure consistently seen across
all 10 recent release/3.4 commits (debug_traceCall/test_43.json).

Refs: https://github.com/erigontech/erigon/actions/runs/24602505567/job/71943405095

Co-authored-by: Giulio Rebuffo <giulio.rebuffo@gmail.com>
@erigon-copilot
Copy link
Copy Markdown
Contributor Author

[SharovBot]

⚠️ CI regression detected on this PR

The test-hive (rpc, compat, 23) job is failing with 56/204 tests on this PR's branch, while it passes cleanly (failed=0) on the release/3.4 base.

Failing job: https://github.com/erigontech/erigon/actions/runs/24602883581/job/71944385182

This suggests that the 0x prefix change in FormatLogs() is breaking the Hive RPC compat test suite expectations. The hive tests likely expect the old bare-hex format for structLog storage keys/values.

Before merging, the fix needs to either:

  1. Also update the Hive test fixture expectations to match the 0x-prefixed format, OR
  2. Investigate whether the reference implementation used in mainnet-rpc-integ-tests-latest and the Hive compat tests have different expectations (one wants 0x, the other wants bare hex)

The release/3.4 branch itself has mainnet-rpc-integ-tests-latest failing on all 10 recent commits due to debug_traceCall/test_43.json, which this PR correctly targets — but the current implementation introduces a new regression.

…raceCall)

Co-authored-by: Giulio Rebuffo <giulio.rebuffo@gmail.com>
@erigon-copilot
Copy link
Copy Markdown
Contributor Author

[SharovBot]

The initial fix only patched FormatLogs() in logger.go and rpc/ethapi/api.go, but debug_traceCall uses the streaming path via JsonStreamLogger (json_stream.go) which writes storage directly using hex.Encode — bypassing FormatLogs() entirely.

Added a follow-up commit to fix the streaming path:

  • execution/tracing/tracers/logger/json_stream.go: Changed hex.Encode(l.hexEncodeBuf[:], loc[:])loc.Hex() and hex.Encode(l.hexEncodeBuf[:], value[:])common.Hash(value).Hex()

This should resolve the remaining debug_traceCall/test_43.json failure.

@erigon-copilot
Copy link
Copy Markdown
Contributor Author

[SharovBot]

CI analysis update (release/3.4 monitor run — 2026-04-22T20:25:49Z)

The mainnet-rpc-integ-tests failure on this PR is due to stale test fixtures in the erigontech/rpc-tests repository, not a code regression in this PR.

Root cause: The .tar test fixtures (e.g., debug_traceTransaction/test_117.tar, debug_traceBlockByHash/test_09.tar, etc.) contain pre-recorded expected responses that were captured when Erigon returned bare-hex storage keys (without 0x prefix). After this PR's fix, Erigon correctly returns 0x-prefixed keys — matching the Ethereum JSON-RPC spec — but the 57 stale fixture files still expect the old bare-hex format.

Evidence:

  • debug_traceTransaction/test_117-response.json: Erigon now returns "0x000...0002" (correct)
  • debug_traceTransaction/test_117-expResponse.json: fixture expects "000...0002" (stale)

The debug_getModifiedAccountsByNumber failures (test_05–test_18) appear to be a test runner infrastructure issue: sh: 2: 2936122: not found errors appear in the log before those failures, and those same tests pass cleanly on release/3.4 HEAD. This is unrelated to this PR's changes.

Action needed: A PR to erigontech/rpc-tests is required to regenerate the 57 affected test fixtures with the correct 0x-prefixed storage keys.

@lupin012
Copy link
Copy Markdown
Contributor

This PR is substituted by #20478

@yperbasis yperbasis closed this Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants