Skip to content

fix(geth_state_diffs): use pre value as to_value when post is absent#251

Open
AuburyEssentian wants to merge 1 commit intoparadigmxyz:mainfrom
AuburyEssentian:fix/geth-state-diffs-to-value
Open

fix(geth_state_diffs): use pre value as to_value when post is absent#251
AuburyEssentian wants to merge 1 commit intoparadigmxyz:mainfrom
AuburyEssentian:fix/geth-state-diffs-to-value

Conversation

@AuburyEssentian
Copy link
Copy Markdown

Problem

Closes #245.

The geth prestate tracer only writes a post entry when a value actually changes. When post is None and pre is Some, the value was accessed but not modified — to_value should equal from_value (pre).

The current code returns a zero default in this case (U256::ZERO for balance, 0u64 for nonce, Bytes::new() for code), so any touched-but-unchanged account produces a diff record claiming the value dropped to zero. This is reproducible with block 16983180 as described in the issue.

Root cause

Two code sites share the same pattern:

parse_pre_post() (used by add_balances and add_nonces):

// before
(Some(pre), None) => (pre, new),  // new = U256::ZERO or 0u64

add_codes() (inline match):

// before
(Some(pre), None) => (pre, &blank),  // blank = Bytes::new()

Fix

Return (pre, pre) in both (Some(pre), None) arms so an unchanged value is correctly reflected as from == to.

Storage diffs use a separate BTreeMap-based approach and are unaffected (as noted in the issue).

The geth prestate tracer only records post-state when a value actually
changes. When post is None but pre is Some, the value was accessed but
not modified — so to_value should equal from_value (pre), not zero.

The current code passes U256::ZERO / 0u64 / Bytes::new() as the default
for the (Some(pre), None) arm, producing incorrect to_value output for
balances, nonces, and code when the geth trace omits post.

Fix both affected sites:

- parse_pre_post(): used by add_balances and add_nonces
- add_codes(): has its own inline match with the same pattern

Storage diffs use a separate BTreeMap-based approach and are unaffected.

Fixes paradigmxyz#245.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

geth_state_diffs dataset calculates wrong to_value of balance, nonce, and code

1 participant