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

Fix #2035 again #2039

Merged
merged 3 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/src/trie/proof_decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1069,8 +1069,14 @@ impl<T: AsRef<[u8]>> DecodedTrieProof<T> {
// after the last entry of the trie.
return Ok(None);
};
let Ok(parent_entry_decoded) =
trie_node::decode(&proof[self.entries[parent_entry].range_in_proof.clone()])
else {
// Proof has been checked to be entirely decodable.
unreachable!()
};

let Some(child_num) = iter_entry_decoded
let Some(child_num) = parent_entry_decoded
.children
.iter()
.skip(usize::from(parent_to_child_nibble) + 1)
Expand Down
Binary file added lib/src/trie/proof_decode/issue_2035_bis_proof
Binary file not shown.
40 changes: 40 additions & 0 deletions lib/src/trie/proof_decode/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2391,3 +2391,43 @@ fn issue_2035() {
.collect::<Vec<_>>()
);
}

#[test]
fn issue_2035_bis() {
// Repro for the second issue in <https://github.com/smol-dot/smoldot/issues/2035>.
let proof = include_bytes!("./issue_2035_bis_proof");
let state_root_hash: [u8; 32] = [
241, 25, 249, 180, 210, 108, 169, 82, 223, 38, 152, 201, 41, 218, 107, 136, 119, 165, 62,
159, 100, 159, 44, 63, 211, 220, 195, 145, 119, 29, 251, 98,
];
let key: [u8; 44] = [
0x63, 0xf7, 0x8c, 0x98, 0x72, 0x3d, 0xdc, 0x90, 0x73, 0x52, 0x3e, 0xf3, 0xbe, 0xef, 0xda,
0x0c, 0xa9, 0x5d, 0xac, 0x46, 0xc0, 0x7a, 0x40, 0xd9, 0x15, 0x06, 0xe7, 0x63, 0x7e, 0xc4,
0xba, 0x57, 0x07, 0x1c, 0xef, 0xf5, 0xb0, 0xf6, 0x4d, 0x36, 0x2e, 0x08, 0x00, 0x00,
];

let decoded = super::decode_and_verify_proof(super::Config { proof }).unwrap();

let next_key = decoded.next_key(
&state_root_hash,
trie::bytes_to_nibbles(key.iter().copied()),
false,
iter::empty(),
false,
);

assert_eq!(
next_key.unwrap().unwrap().collect::<Vec<_>>(),
trie::bytes_to_nibbles(
[
0x63, 0xf7, 0x8c, 0x98, 0x72, 0x3d, 0xdc, 0x90, 0x73, 0x52, 0x3e, 0xf3, 0xbe, 0xef,
0xda, 0x0c, 0xa9, 0x5d, 0xac, 0x46, 0xc0, 0x7a, 0x40, 0xd9, 0x15, 0x06, 0xe7, 0x63,
0x7e, 0xc4, 0xba, 0x57, 0x0f, 0x47, 0x4e, 0xe8, 0x5a, 0x3c, 0xd6, 0x22, 0xf8, 0x07,
0x00, 0x00
]
.iter()
.copied()
)
.collect::<Vec<_>>()
);
}
4 changes: 4 additions & 0 deletions wasm-node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Fixed

- Fix another bug concerning incomplete Merkle proofs, similar to the one fixed in v2.0.32. ([#2039](https://github.com/smol-dot/smoldot/pull/2039))

## 2.0.32 - 2024-11-08

### Fixed
Expand Down
Loading