Skip to content

Commit cf50df7

Browse files
committed
fix(rpc-types-trace): add 0x prefix to storage keys and values in StructLog
The opcode tracer spec (ethereum/execution-apis#762) requires storage keys and values to be 0x-prefixed bytes32. The serializer was explicitly stripping the prefix with [2..].
1 parent bc4ffa2 commit cf50df7

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

  • crates/rpc-types-trace/src/geth

crates/rpc-types-trace/src/geth/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ impl From<GethDebugTracingOptions> for GethDebugTracingCallOptions {
781781
}
782782
}
783783

784-
/// Serializes a storage map as a list of key-value pairs _without_ 0x-prefix
784+
/// Serializes a storage map as a list of key-value pairs with 0x-prefix
785785
fn serialize_string_storage_map_opt<S: Serializer>(
786786
storage: &Option<BTreeMap<B256, B256>>,
787787
s: S,
@@ -793,8 +793,7 @@ fn serialize_string_storage_map_opt<S: Serializer>(
793793
for (key, val) in storage {
794794
let key = format!("{key:?}");
795795
let val = format!("{val:?}");
796-
// skip the 0x prefix
797-
m.serialize_entry(&key.as_str()[2..], &val.as_str()[2..])?;
796+
m.serialize_entry(key.as_str(), val.as_str())?;
798797
}
799798
m.end()
800799
}
@@ -872,7 +871,7 @@ mod tests {
872871

873872
#[test]
874873
fn test_serialize_storage_map() {
875-
let s = r#"{"pc":3349,"op":"SLOAD","gas":23959,"gasCost":2100,"depth":1,"stack":[],"memory":[],"storage":{"6693dabf5ec7ab1a0d1c5bc58451f85d5e44d504c9ffeb75799bfdb61aa2997a":"0000000000000000000000000000000000000000000000000000000000000000"}}"#;
874+
let s = r#"{"pc":3349,"op":"SLOAD","gas":23959,"gasCost":2100,"depth":1,"stack":[],"memory":[],"storage":{"0x6693dabf5ec7ab1a0d1c5bc58451f85d5e44d504c9ffeb75799bfdb61aa2997a":"0x0000000000000000000000000000000000000000000000000000000000000000"}}"#;
876875
let log: StructLog = serde_json::from_str(s).unwrap();
877876
let val = serde_json::to_value(&log).unwrap();
878877
let input = serde_json::from_str::<serde_json::Value>(s).unwrap();

0 commit comments

Comments
 (0)