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

core/state: storage journal entry should revert dirtyness too #29641

Merged
merged 1 commit into from
Apr 24, 2024

Conversation

karalabe
Copy link
Member

@karalabe karalabe commented Apr 24, 2024

Currently our state journal tracks each storage update to a contract, having the ability to revert those changes to the previously set value.

For the very first modification however, it behaves a bit wonky. Reverting the update doesn't actually remove the dirty-ness of the slot, rather leaves it as "change this slot to it's original value". This can cause issues down the line with for example write witnesses needing to gather an unneeded proof.

This PR modifies the storageChange journal entry to not only track the previous value of a slot, but also whether there was any previous value at all set in the current execution context. In essence, the PR changes the semantic of storageChange so it does not simply track storage changes, rather it tracks dirty storage changes, an important distinction for being able to cleanly revert the journal item.

I do not expect any performance impact whatsoever, even if we load a few slots fewer. The PR is more about correctness to handle a corner-case that would bubble up in later code.

@karalabe karalabe added this to the 1.14.1 milestone Apr 24, 2024
@holiman
Copy link
Contributor

holiman commented Apr 24, 2024

Interesting. I think this "error" should ideally have been detected by the post-state checker in TestSnapshotRandom, which I'm adding some improvements to in #29627 . IMO we should add detection

@holiman
Copy link
Contributor

holiman commented Apr 24, 2024

IMO we should add detection

Nevermind this. The error here is unrelated to what I was talking about

Copy link
Contributor

@holiman holiman left a comment

Choose a reason for hiding this comment

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

Correct as far as I can tell

@holiman
Copy link
Contributor

holiman commented Apr 24, 2024

The error here is unrelated to what I was talking about

No wait, it is related. Rolling back a journal-entry which dirtied a slot would results in dirties different than not applying the journal in the first place. Why doesn't this change detect it already?

https://github.com/ethereum/go-ethereum/pull/29627/files#diff-79d0959fe3c60993c127325cbb40c585d2f43a1e6fd04c95f63640425f7847e7R587

Ah, instead of iterating and checking key by key, we should compare the whole dirtyStorage map.
This is what happens, and it's not detected:

a. dirty[`0x11`] = `original`

b.dirty[`0x11`] does not eixt
b.trie[`0x11`] = `original`

@karalabe
Copy link
Member Author

Indeed, that's what happens

@holiman
Copy link
Contributor

holiman commented Apr 24, 2024

This commit should detect it: 9b3104d

So this PR should fix the error I thus introduce into that PR

@holiman holiman merged commit 4f4f9d8 into ethereum:master Apr 24, 2024
3 checks passed
jorgemmsilva pushed a commit to iotaledger/go-ethereum that referenced this pull request Jun 17, 2024
…um#29641)

Currently our state journal tracks each storage update to a contract, having the ability to revert those changes to the previously set value.

For the very first modification however, it behaves a bit wonky. Reverting the update doesn't actually remove the dirty-ness of the slot, rather leaves it as "change this slot to it's original value". This can cause issues down the line with for example write witnesses needing to gather an unneeded proof.

This PR modifies the storageChange journal entry to not only track the previous value of a slot, but also whether there was any previous value at all set in the current execution context. In essence, the PR changes the semantic of storageChange so it does not simply track storage changes, rather it tracks dirty storage changes, an important distinction for being able to cleanly revert the journal item.
stwiname pushed a commit to subquery/data-node-go-ethereum that referenced this pull request Sep 9, 2024
…um#29641)

Currently our state journal tracks each storage update to a contract, having the ability to revert those changes to the previously set value.

For the very first modification however, it behaves a bit wonky. Reverting the update doesn't actually remove the dirty-ness of the slot, rather leaves it as "change this slot to it's original value". This can cause issues down the line with for example write witnesses needing to gather an unneeded proof.

This PR modifies the storageChange journal entry to not only track the previous value of a slot, but also whether there was any previous value at all set in the current execution context. In essence, the PR changes the semantic of storageChange so it does not simply track storage changes, rather it tracks dirty storage changes, an important distinction for being able to cleanly revert the journal item.
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