trie: reject deletions when verifying range proofs#23960
Merged
karalabe merged 1 commit intoethereum:masterfrom Nov 23, 2021
karalabe:verify-range-deletion
Merged
trie: reject deletions when verifying range proofs#23960karalabe merged 1 commit intoethereum:masterfrom karalabe:verify-range-deletion
karalabe merged 1 commit intoethereum:masterfrom
karalabe:verify-range-deletion
Conversation
holiman
approved these changes
Nov 23, 2021
Comment on lines
+475
to
+485
| // Ensure the received batch is monotonic increasing and contains no deletions | ||
| for i := 0; i < len(keys)-1; i++ { | ||
| if bytes.Compare(keys[i], keys[i+1]) >= 0 { | ||
| return false, errors.New("range is not monotonically increasing") | ||
| } | ||
| } | ||
| for _, value := range values { | ||
| if len(value) == 0 { | ||
| return false, errors.New("range contains deletion") | ||
| } | ||
| } |
Contributor
There was a problem hiding this comment.
len(keys) == len(values), so you could use the same loop, with a slight modification
Suggested change
| // Ensure the received batch is monotonic increasing and contains no deletions | |
| for i := 0; i < len(keys)-1; i++ { | |
| if bytes.Compare(keys[i], keys[i+1]) >= 0 { | |
| return false, errors.New("range is not monotonically increasing") | |
| } | |
| } | |
| for _, value := range values { | |
| if len(value) == 0 { | |
| return false, errors.New("range contains deletion") | |
| } | |
| } | |
| // Ensure the received batch is monotonic increasing and contains no deletions | |
| for i := 0; i < len(keys); i++ { | |
| if i > 0 && bytes.Compare(keys[i-1], keys[i]) >= 0 { | |
| return false, errors.New("range is not monotonically increasing") | |
| } | |
| if len(values[i]) == 0 { | |
| return false, errors.New("range contains deletion") | |
| } | |
| } |
Feel free to ignore
Member
Author
There was a problem hiding this comment.
It did occur to me, but the off by one and extra clause check seemed wonky. The code is cleaner this way, we're not saving anything by optimizing out an extra addition per array item. Unless you guys feel very strongly, I'd leave it as is.
19 tasks
gzliudan
pushed a commit
to gzliudan/XDPoSChain
that referenced
this pull request
Jun 9, 2025
gzliudan
pushed a commit
to gzliudan/XDPoSChain
that referenced
this pull request
Aug 4, 2025
gzliudan
pushed a commit
to gzliudan/XDPoSChain
that referenced
this pull request
Aug 4, 2025
gzliudan
pushed a commit
to gzliudan/XDPoSChain
that referenced
this pull request
Aug 8, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reject trie range proofs if they contain deletions, otherwise these would be noop entries that just bloat the response and may potentially cause trouble down the line since a semi-invalid proof passes verification.