ElementsProject / rust-elements

Rust support for Elements transaction/block deserialization

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

serde: BlindingFactors are serialized inconsistently

LeoComandini opened this issue · comments

serde implementation is derived from Tweak which does not reverse the hex
string, unlike from_str and Elements Core. So the following falis:

    #[cfg(feature = "serde")]
    #[test]
    fn serde() {
        use std::str::FromStr;

        let abf_from_serde: AssetBlindingFactor = serde_json::from_str("\"a5b3d111cdaa5fc111e2723df4caf315864f25fb4610cc737f10d5a55cd4096f\"").unwrap();
        let abf_from_str = AssetBlindingFactor::from_str("a5b3d111cdaa5fc111e2723df4caf315864f25fb4610cc737f10d5a55cd4096f").unwrap();
        assert_eq!(abf_from_serde, abf_from_str);

        let vbf_from_serde: ValueBlindingFactor = serde_json::from_str("\"e36a4de359469f547571d117bc5509fb74fba73c84b0cdd6f4edfa7ff7fa457d\"").unwrap();
        let vbf_from_str = ValueBlindingFactor::from_str("e36a4de359469f547571d117bc5509fb74fba73c84b0cdd6f4edfa7ff7fa457d").unwrap();
        assert_eq!(vbf_from_serde, vbf_from_str);
    }

Whew, Elements Core outputs blinding factors in reverse?

Whew, Elements Core outputs blinding factors in reverse?

It seems so, BlindingFactors are uint256 which are hex-serialized in reverse