Skip to content
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
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ alloy-trie = { version = "0.9.0", default-features = false }

# mega
mega-evm = { git = "https://github.com/megaeth-labs/mega-evm.git", rev = "915f71e324141140c7f08687fc23db63402e06e0", default-features = false }
salt = { git = "https://github.com/megaeth-labs/salt.git", rev = "v1.0.2", default-features = false }
salt = { git = "https://github.com/megaeth-labs/salt.git", rev = "a04647065f12dbd8461dc40569731656d160d694", default-features = false }

# op
op-alloy-network = { version = "0.18.12", default-features = false }
Expand Down
30 changes: 29 additions & 1 deletion crates/stateless-core/src/light_witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ type FxHashMap<K, V> = HashMap<K, V, FxBuildHasher>;
pub struct LightWitness {
/// All witnessed key-value pairs (same as SaltWitness.kvs)
pub kvs: BTreeMap<SaltKey, Option<SaltValue>>,
/// Bucket subtree levels (same as SaltProof.levels)
/// Bucket subtree levels (same as SaltProof.levels).
///
/// Routed through [`salt::fx_hashmap_serde`] so we don't have to enable
/// `hashbrown/serde` (which transitively pulls in `serde_core 1.0.221+`
/// and breaks downstream `alloy-tx-macros 1.0.23`).
#[serde(with = "salt::fx_hashmap_serde")]
pub levels: FxHashMap<BucketId, u8>,
}

Expand Down Expand Up @@ -198,4 +203,27 @@ mod tests {
assert!(fast.kvs.is_empty());
assert!(fast.levels.is_empty());
}

/// Round-trip a populated `LightWitness` through bincode to confirm the
/// `#[serde(with = "salt::fx_hashmap_serde")]` wiring on the `levels`
/// field actually works end-to-end. The adapter itself is covered by
/// salt's own tests; this test just guards the integration.
#[test]
fn round_trip_through_bincode() {
let mut levels: FxHashMap<BucketId, u8> = HashMap::with_hasher(FxBuildHasher);
for (k, v) in [(0u32, 0u8), (42, 3), (1_000_000, 7), (BucketId::MAX, 255)] {
levels.insert(k, v);
}
let original = LightWitness { kvs: BTreeMap::new(), levels };

let bytes = bincode::serde::encode_to_vec(&original, bincode::config::standard()).unwrap();
let (decoded, _): (LightWitness, _) =
bincode::serde::decode_from_slice(&bytes, bincode::config::standard()).unwrap();

assert_eq!(original.kvs, decoded.kvs);
assert_eq!(original.levels.len(), decoded.levels.len());
for (k, v) in &original.levels {
assert_eq!(decoded.levels.get(k), Some(v));
}
}
}
Loading