Skip to content

fix: account proof storage key with leading 0s#12980

Merged
protolambda merged 7 commits intoethereum-optimism:developfrom
meyer9:meyer9/fix-storage-key-type
Jan 24, 2025
Merged

fix: account proof storage key with leading 0s#12980
protolambda merged 7 commits intoethereum-optimism:developfrom
meyer9:meyer9/fix-storage-key-type

Conversation

@meyer9
Copy link
Copy Markdown
Contributor

@meyer9 meyer9 commented Nov 19, 2024

Description

hexutil.Big errors decoding if there are leading 0s, and common.Hash errors decoding if there aren't exactly 32 bytes of hex.

This switches to hexutil.Bytes so hashes with leading 0s can be serialized.

Tests

Added test for leading 0s.

@meyer9 meyer9 requested a review from a team as a code owner November 19, 2024 18:06
@meyer9 meyer9 requested a review from protolambda November 19, 2024 18:06
@ajsutton
Copy link
Copy Markdown
Contributor

/ci authorize f97e71c

Copy link
Copy Markdown
Contributor

@ajsutton ajsutton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM assuming CI passes.

The encoding of key in geth is "a bit special", encoding as a hash with leading zeros if it is 32 bytes or as a big without leading 0s if not: https://github.com/ethereum-optimism/op-geth/blob/ee3d19b4cba58e6f45f3d4aee4535b572d655882/internal/ethapi/api.go#L774-L778

The execution-apis spec which is unfortunately hard to link to defines it as a string and allows leading 0s (as opposed to value which explicitly forbids them)
image

@ajsutton
Copy link
Copy Markdown
Contributor

@meyer9 CI didn't pass - looks like another place that needs updating for the new type:

5.582 ../op-service/sources/eth_client.go:350:67: getProofResponse.StorageProof[i].Key.ToInt undefined (type hexutil.Bytes has no field or method ToInt)

@meyer9
Copy link
Copy Markdown
Contributor Author

meyer9 commented Nov 20, 2024

ah sorry, not sure how that wasn't caught before. Should be fixed now!

@ajsutton
Copy link
Copy Markdown
Contributor

/ci authorize 3c88c8e

@meyer9
Copy link
Copy Markdown
Contributor Author

meyer9 commented Dec 12, 2024

Sorry for the delay, I just checked out the error and it seems like it still had trouble handling the case where there were an odd number of hex digits even with hexutil.Bytes.

I think we have to introduce a new type here "StorageKey" or serialize it as a string. I added the new type and tests since I think deserializing from string every time we want to use the value would be annoying. Let me know what you think!

@meyer9 meyer9 requested a review from ajsutton December 12, 2024 18:48
@ajsutton
Copy link
Copy Markdown
Contributor

/ci authorize 1186238

Copy link
Copy Markdown
Contributor

@ajsutton ajsutton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - just a stray println to remove.

@protolambda
Copy link
Copy Markdown
Contributor

/ci authorize 5994e1d

Copy link
Copy Markdown
Contributor

@protolambda protolambda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but recommend to use the text marshaler interface instead of JSON-specific interface. The JSON lib will use it, but this way the type can be reused in other contexts, e.g. TOML or YAML.

@meyer9 meyer9 requested a review from protolambda January 1, 2025 03:54
@protolambda
Copy link
Copy Markdown
Contributor

/ci authorize f82102d

@protolambda protolambda enabled auto-merge January 23, 2025 19:30
@meyer9
Copy link
Copy Markdown
Contributor Author

meyer9 commented Jan 24, 2025

rebased!

@meyer9 meyer9 force-pushed the meyer9/fix-storage-key-type branch from f82102d to 4a0925a Compare January 24, 2025 18:04
@protolambda
Copy link
Copy Markdown
Contributor

/ci authorize 4a0925a

@protolambda protolambda added this pull request to the merge queue Jan 24, 2025
Merged via the queue into ethereum-optimism:develop with commit 5d2d03f Jan 24, 2025
samlaf pushed a commit to Layr-Labs/optimism that referenced this pull request Jan 27, 2025
* fix: account proof storage key with leading 0s

* Add test for leading 0s

* Remove extra whitespace

* Fix one more usage of key

* Use new storage key type instead of hexutil

* remove debugging statement

* use TextMarshaler instead of json.Marshaler
Rjected pushed a commit to paradigmxyz/optimism that referenced this pull request Feb 25, 2025
* fix: account proof storage key with leading 0s

* Add test for leading 0s

* Remove extra whitespace

* Fix one more usage of key

* Use new storage key type instead of hexutil

* remove debugging statement

* use TextMarshaler instead of json.Marshaler
QuentinI pushed a commit to EspressoSystems/optimism-espresso-integration that referenced this pull request Mar 7, 2025
* fix: account proof storage key with leading 0s

* Add test for leading 0s

* Remove extra whitespace

* Fix one more usage of key

* Use new storage key type instead of hexutil

* remove debugging statement

* use TextMarshaler instead of json.Marshaler
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.

3 participants