diff --git a/.gitignore b/.gitignore index fa8d85a..b6012ba 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,25 @@ +# Generated by Cargo +# will have compiled files and executables +debug/ +target/ + +# This project does not check in Cargo.lock Cargo.lock -target + +# These are backup files generated by rustfmt +**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information +*.pdb + +# Generated by Intellij-based IDEs. +.idea + +# Generated by MacOS +.DS_Store + +# VSCode +.vscode + +# Rust bug report +rustc-ice-* diff --git a/Cargo.toml b/Cargo.toml index ca9bf1d..bd297db 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,13 +23,13 @@ sha3 = "0.10" k256 = { version = "0.13", features = ["ecdsa"], optional = true } serde = { version = "1.0", features = ["derive"], optional = true } ed25519-dalek = { version = "2.1.1", optional = true, features = ["rand_core"] } -secp256k1 = { version = "0.28", optional = true, default-features = false, features = [ +secp256k1 = { version = "0.29", optional = true, default-features = false, features = [ "global-context", ] } [dev-dependencies] alloy-rlp = { version = "0.3.4", features = ["derive"] } -secp256k1 = { version = "0.28", features = ["rand-std"] } +secp256k1 = { version = "0.29", features = ["rand-std"] } serde_json = "1.0" [features] diff --git a/src/lib.rs b/src/lib.rs index 97aa12a..faeb4ef 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1088,12 +1088,19 @@ impl Decodable for Enr { _ => { let other_header = Header::decode(payload)?; let value = &payload[..other_header.payload_length]; - // Preserve the valid encoding payload.advance(other_header.payload_length); - let mut out = Vec::::new(); - other_header.encode(&mut out); - out.extend_from_slice(value); - out + + // Encode the header for list values, for non-list objects, we remove the + // header for compatibility with commonly used key entries (i.e it's the + // current convention). + if other_header.list { + let mut out = Vec::::new(); + other_header.encode(&mut out); + out.extend_from_slice(value); + out + } else { + alloy_rlp::encode(value) + } } }; content.insert(key.to_vec(), Bytes::from(value)); @@ -2082,4 +2089,16 @@ mod tests { assert_eq!(info.1, "v1.0.0"); assert_eq!(info.2, None); } + /// Tests a common ENR which uses RLP encoded values without the header + #[test] + fn test_common_rlp_convention() { + const COMMON_VALID_ENR: &str = concat!( + "-LW4QCAyOCtqvQjd8AgpqbaCgfjy8oN8cBBRT5jtzarkGJQWZx1eN70EM0QafVCugLa-Bv493DPNzflagqfTOsWSF78Ih2F0d", + "G5ldHOIAGAAAAAAAACEZXRoMpBqlaGpBAAAAP__________gmlkgnY0hHF1aWOCIymJc2VjcDI1NmsxoQPg_HgqXzwRIK39Oy", + "lGdC30YUFwsfXvATnGUvEZ6MtBQIhzeW5jbmV0cwCDdGNwgiMo" + ); + + // Expect this to be able to be decoded + let _decoded: DefaultEnr = COMMON_VALID_ENR.parse().unwrap(); + } }