Skip to content

Conversation

karalabe
Copy link
Member

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.

@karalabe karalabe added this to the 1.10.13 milestone Nov 23, 2021
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.

LGTM

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")
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Member Author

Choose a reason for hiding this comment

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

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.

@karalabe karalabe merged commit 7322b25 into ethereum:master Nov 23, 2021
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
gzliudan added a commit to XinFinOrg/XDPoSChain that referenced this pull request Aug 8, 2025
)

Co-authored-by: Péter Szilágyi <peterke@gmail.com>
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