Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hex data being truncated in anvil_dumpState #8179

Closed
2 tasks done
Tracked by #8269
NiloCK opened this issue Jun 17, 2024 · 6 comments · Fixed by #8216
Closed
2 tasks done
Tracked by #8269

Hex data being truncated in anvil_dumpState #8179

NiloCK opened this issue Jun 17, 2024 · 6 comments · Fixed by #8216
Assignees
Labels
C-anvil Command: anvil good first issue Good for newcomers T-bug Type: bug
Milestone

Comments

@NiloCK
Copy link
Contributor

NiloCK commented Jun 17, 2024

Component

Anvil

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (c2e5297 2024-06-14T00:18:12.274395967Z)

What command(s) is the bug in?

anvil_dumpState

Operating System

Linux

Describe the bug

When running a state dump, the produced output isn't as read-compatible as it could be.

For the attached dump.json, the following geth code fails as described:

var dump state.Dump
err = json.Unmarshal(unzipped, &dump)

if err != nil {
	panic(err)
}
// panic: json: cannot unmarshal hex string of odd length into Go struct field
//        DumpAccount.accounts.storage of type common.Hash

Inspecting the json shows the following. (comments inserted)

...

"0x068e44eb31e111028c41598e4535be7468674d0a": { // line 32, a contract address

...

"0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc": "0x68e44eb31e111028c41598e4535be7468674d0a", // line 172, a reference to that contract
"0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103": "0x9e2803ad9ecc0a848c8a045329524d295f6ee44f",
"0xd30e835d3f35624761057ff5b27d558f97bd5be034621e62240e5c0b784abe68": "0x9965507d1a55bcc2695c58ba16fb37d819b0a4dc"

It seems that the leading zero of the address was truncated, leading to the deserialize failure.

dump.json

@NiloCK NiloCK added the T-bug Type: bug label Jun 17, 2024
@mattsse
Copy link
Member

mattsse commented Jun 17, 2024

right, we should convert these to B256 because these should mirror how storage is usually formatted

pub storage: BTreeMap<U256, U256>,

cc @samlaf

@mattsse mattsse added the good first issue Good for newcomers label Jun 17, 2024
@mattsse
Copy link
Member

mattsse commented Jun 18, 2024

@yash-atreya this should be straight forward, if you find the time

@AxelAramburu
Copy link
Contributor

Hi, it's possible to take this task even if it's already assigned ?

@mattsse
Copy link
Member

mattsse commented Jun 19, 2024

sure,
I believe @yash-atreya hasn't started yet?

assigning @AxelAramburu

@mattsse mattsse assigned AxelAramburu and unassigned yash-atreya Jun 19, 2024
@samlaf
Copy link
Contributor

samlaf commented Jun 20, 2024

Curious in general, when would you use U256 (256 bits) vs B256 (32 bytes)?

@mattsse
Copy link
Member

mattsse commented Jun 20, 2024

the evm internally prefers u256 but technically all those are hashes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-anvil Command: anvil good first issue Good for newcomers T-bug Type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants