Panic in trie operation logic – Assertion Failure in `nibbleslice.rs:120:9` · Issue #217 · paritytech/trie · GitHub
More Web Proxy on the site http://driver.im/
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Performing specific operations on TrieDBMut with a custom trie layout that uses nibbles (NoExtensionLayout) causes a panic. The issue occurs when attempting to remove non-existent key, triggering an assertion failure in nibble/nibbleslice.rs:120:9.
Code to Reproduce
/// This module contains test to showcase issue with trie#[cfg(test)]mod tests {use memory_db::{HashKey,MemoryDB};use reference_trie::{RefHasher,ReferenceNodeCodecNoExt};use trie_db::{TrieDBMutBuilder,TrieLayout,TrieMut};/// Custom Trie layout that does not use extensions.#[derive(Default)]pubstructNoExtensionLayout;implTrieLayoutforNoExtensionLayout{constUSE_EXTENSION:bool = false;constALLOW_EMPTY:bool = false;constMAX_INLINE_VALUE:Option<u32> = None;typeHash = RefHasher;typeCodec = ReferenceNodeCodecNoExt<RefHasher>;}/// Reproduces panic issue in trie/// The panic occurs due to an assertion failure in `nibble/nibbleslice.rs:120:9`////// #### Related Error Message:/// ```/// assertion failed: self.len() >= i/// ```#[test]fntest_trie_panic() -> Result<(),Box<dyn std::error::Error>>{let pairs = [(hex::decode("ffff")?, hex::decode("0a")?),(hex::decode("feffe9")?, hex::decode("0b")?),(hex::decode("ffffff")?, hex::decode("0c")?),(hex::decode("ff")?, hex::decode("")?),// Removal of non-existent key triggers panic];letmut memdb = MemoryDB::<_,HashKey<_>,_>::default();letmut root = Default::default();letmut trie = TrieDBMutBuilder::<NoExtensionLayout>::new(&mut memdb,&mut root).build();for(key, value)in&pairs {
trie.insert(key, value)?;}Ok(())}}
Cargo.toml
[package]
name = "trie_panic"version = "0.1.0"edition = "2021"
[dependencies]
hex = "0.4.3"memory-db = "0.32.0"reference-trie = "0.29.1"trie-db = "0.27.0"# Using this version to match the older trie-db version used by reference-trie.
Expected Behavior
The trie should handle this scenario gracefully without triggering a panic.
Actual Behavior
The test fails with a panic at /trie-db-0.27.1/src/nibble/nibbleslice.rs:120:9, resulting in the following assertion error:
`assertion failed: self.len() >= i`
Additional Information
This issue has also been tested with the latest trie-db version (0.29.1), and the behavior remains the same
The text was updated successfully, but these errors were encountered:
Description
Performing specific operations on
TrieDBMut
with a custom trie layout that uses nibbles (NoExtensionLayout
) causes a panic. The issue occurs when attempting to remove non-existent key, triggering an assertion failure innibble/nibbleslice.rs:120:9
.Code to Reproduce
Cargo.toml
Expected Behavior
The trie should handle this scenario gracefully without triggering a panic.
Actual Behavior
The test fails with a panic at
/trie-db-0.27.1/src/nibble/nibbleslice.rs:120:9
, resulting in the following assertion error:Additional Information
This issue has also been tested with the latest trie-db version (
0.29.1
), and the behavior remains the sameThe text was updated successfully, but these errors were encountered: