Skip to content

Conversation

@and-cb
Copy link
Collaborator

@and-cb and-cb commented Dec 3, 2025

The biggest change in this PR is that alloy-trie has been upgraded to the latest major version. This upgrade changed the Nibbles structure so that it can store at most 32 bytes only. Some of the triedb code was using Nibbles to store more than that (which by itself was a source of bugs even with the previous version of alloy-trie). This PR addresses the problem by introducing a new RawPath struct that is essentially an unbounded version of Nibbles.

A better approach would be to avoid passing Nibbles/RawPath around, and rather create a Path enum that can be either AccountPath or StoragePath. That way it will be much easier to reason about the size of paths and about the safety of converting such paths to Nibbles. However that is a much larger refactor; for this PR I prefer to focus on getting things to work with minimum effort.

@cb-heimdall
Copy link
Collaborator

cb-heimdall commented Dec 3, 2025

✅ Heimdall Review Status

Requirement Status More Info
Reviews 2/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 1
Sum 2

@and-cb and-cb requested a review from BrianBland December 3, 2025 02:23
@and-cb and-cb force-pushed the andrea/reth-v1.9.3 branch from a869364 to 8a5b330 Compare December 3, 2025 02:32
@henridevieux henridevieux requested a review from refcell December 3, 2025 17:20
BrianBland
BrianBland previously approved these changes Dec 3, 2025
Copy link
Collaborator

@BrianBland BrianBland left a comment

Choose a reason for hiding this comment

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

:shipit:

Comment on lines +83 to +97
pub fn slice(&self, range: impl RangeBounds<usize>) -> Self {
let start = range.start_bound().map(|b| *b);
let end = range.end_bound().map(|b| *b);
Self::from_nibbles(&self.nibbles()[(start, end)])
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not urgent, but we may also want a copy-less slice method, which returns a view of the underlying nibbles instead of an owned slice.

if let Some(hash) = pointer.rlp().as_hash() {
// No overlay, just add the pointer by hash
root_builder.add_branch(path, hash, true);
root_builder.add_branch(path.try_into().unwrap(), hash, true);
Copy link

Choose a reason for hiding this comment

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

Should this properly handle the error or do we not expect the unwrap to be hit?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good question. Answering it requires some context: the current code implicitly assumes that all Nibbles that are passed around to third-party functions (e.g. to reth) have the correct size (32 bytes / 64 nibbles). Failure to do so results in panics in third-party code, and we have seen multiple examples of that in the past.

The code that I wrote still relies in the implicit assumption that path has the right size. The only difference between this new code and the old one is where we get the panic: now we get it right away (from .try_into().unwrap()), while previously we would get it later on in third-party code.

If path does not have the right size, then it's a bug. As with most bugs, we prefer to panic, rather than bubbling up an error to the user.

This is by the way the exact reason why I wrote this in the PR description:

A better approach would be to avoid passing Nibbles/RawPath around, and rather create a Path enum that can be either AccountPath or StoragePath. That way it will be much easier to reason about the size of paths and about the safety of converting such paths to Nibbles.

When I say that "it will be much easier to reason about the size of paths" I refer exactly to code like this one: right now there is a possibility that this code might panic because path was not constructed properly, but if we refactor the code to use an enum, then we can simply request the necessary bits instead of truncating path or making implicit assumptions about its length.

Copy link

@refcell refcell left a comment

Choose a reason for hiding this comment

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

A few comments on use of unwrap but otherwise changes look good to me

@and-cb and-cb force-pushed the andrea/reth-v1.9.3 branch from 8a5b330 to 5ffe0e3 Compare December 3, 2025 23:27
@and-cb and-cb force-pushed the andrea/reth-v1.9.3 branch from 5ffe0e3 to 71caf87 Compare December 3, 2025 23:28
@cb-heimdall cb-heimdall dismissed BrianBland’s stale review December 3, 2025 23:28

Approved review 3536331830 from BrianBland is now dismissed due to new commit. Re-request for approval.

@and-cb and-cb requested review from BrianBland and refcell December 3, 2025 23:40
@cb-heimdall
Copy link
Collaborator

Review Error for BrianBland @ 2025-12-04 00:44:26 UTC
User failed mfa authentication, see go/mfa-help

Copy link

@refcell refcell left a comment

Choose a reason for hiding this comment

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

Nice!

@and-cb and-cb merged commit 20b03c3 into main Dec 4, 2025
19 checks passed
@and-cb and-cb deleted the andrea/reth-v1.9.3 branch December 4, 2025 22:25
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.

5 participants