Skip to content

trie: add edgecase for rangeproof correctness #31667

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

holiman
Copy link
Contributor

@holiman holiman commented Apr 17, 2025

This PR adds checking for an edgecase which theoretically can happen in the range-prover. Right now, we check that a key does not overwrite a previous one by checking that the key is increasing. However, if keys are of different lengths, it is possible to create a key which is increasing and overwrites the previous key. Example: 0xaabbcc followed by 0xaabbccdd.

This can not happen in go-ethereum, which always uses fixed-size paths for accounts and storage slot paths in the trie, but it might happen if the range prover is used without guaranteed fixed-size keys.

This PR also adds some testcases for the errors that are expected.

@holiman holiman requested a review from rjl493456442 as a code owner April 17, 2025 18:53
@rjl493456442 rjl493456442 self-assigned this Apr 18, 2025
if bytes.Compare(keys[i], keys[i+1]) >= 0 {
return false, errors.New("range is not monotonically increasing")
}
if bytes.HasPrefix(keys[i+1], keys[i]) {
Copy link
Member

Choose a reason for hiding this comment

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

In the case of ethereum, the key length is always 32.

e.g. in func (s *Syncer) OnAccount or func (s *Syncer) OnStorage

so it's not risky.

I have to think about if it makes sense to ensure the length of keys are all same.

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.

2 participants