Skip to content

Commit

Permalink
Fix #2035 again (#2039)
Browse files Browse the repository at this point in the history
* Add repro case

* Fix #2035 again

* CHANGELOG
  • Loading branch information
tomaka authored Nov 18, 2024
1 parent 4a8e391 commit c6aecf7
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
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

0 comments on commit c6aecf7

Please sign in to comment.