paradigmxyz / op-rs

Apache License 2.0
36 stars 4 forks source link

fix(net): ENR Decoding #58

Closed refcell closed 2 weeks ago

refcell commented 2 weeks ago

Description

The net crate defines a custom ENR type for the OP Stack called OpStackEnr that implements serialization and deserialization.

Currently, the encoding and decoding is failing. See the reproducible test below which uses the op-node reference implementation on the OP Stack Enr Data (chain id: 10, version: 0).

This should encode the data as 820A00 but instead produces C20A80.

#[cfg(test)]
mod tests {
    use super::*;
    use alloy::primitives::{Bytes, bytes};
    use alloy_rlp::Decodable;

    #[test]
    fn test_encode_decode_enr() {
        let enr = OpStackEnr::new(10, 0);
        let bytes = alloy_rlp::encode(enr).to_vec();
        assert_eq!(Bytes::from(bytes.clone()), bytes!("820A00"));
        let decoded = OpStackEnr::decode(&mut bytes.as_slice()).unwrap();
        assert_eq!(decoded, enr);
    }
}