Unable to decode serialized TxOut

未关闭
#262 2 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
52/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
rust
领域
blockchain

调研方向

从 src/transaction.rs 中的 TxOut 和 TxOutWitness 定义以及所引用行附近的序列化行为开始,然后使用提供的 transaction 和 round-trip 代码片段重现该问题。当序列化并反序列化后的 TxOut 保留其 rangeproof,从而使 unblind 成功时,即表示完成;如果 repository 提供了合适的位置,请添加或更新回归覆盖。

由索引模型根据 Issue 内容生成。

描述

There is an issue in serialization of TxOut, we're unable to decode it after serialization.
The problem lyes in the simplicityhl::elements::encode::serialize.
For unblinding it misses Rangeproof inside. For some reason it isn't serialized inside.
TxOut contains TxOutSecrets inside https://github.com/ElementsProject/rust-elements/blob/2d94f5dcb5e4a81838681c71ed8a49b337feecd2/src/transaction.rs#L703, but TxOutWitness has its own serialization https://github.com/ElementsProject/rust-elements/blob/2d94f5dcb5e4a81838681c71ed8a49b337feecd2/src/transaction.rs#L653 while TxOut just truncates it https://github.com/ElementsProject/rust-elements/blob/2d94f5dcb5e4a81838681c71ed8a49b337feecd2/src/transaction.rs#L719.

Image

Here is a quick code snippet to test it:

use std::time::Duration;
        use simplicityhl::elements::{ Transaction, TxOut,};
        use simplicityhl::elements::bitcoin::secp256k1;
        use simplicityhl::elements::encode;
        
        pub const PUBLIC_SECRET_BLINDER_KEY: [u8; 32] = [1; 32];
        let secret_key = SecretKey::from_slice(&PUBLIC_SECRET_BLINDER_KEY).unwrap();

        
        let tx_id = "8e12b0c994293d15b7f43abaeb6c119ce3612ff00246b7ae9079dca90a35031f";
        let url = format!("https://blockstream.info/liquidtestnet/api/tx/{}/hex", tx_id);
        let client = reqwest::blocking::Client::builder()
            .timeout(Duration::from_secs(10))
            .build()
            .unwrap();
        let tx_hex = client
            .get(&url)
            .send()
            .unwrap()
            .error_for_status()
            .unwrap()
            .text()
            .unwrap();
        
        let transaction: Transaction = encode::deserialize(&hex::decode(&tx_hex).unwrap()).unwrap();
        let tx_out_from_reqwest = transaction.output[0].clone();
        assert!(tx_out_from_reqwest.unblind(secp256k1::SECP256K1, secret_key).is_ok());
        
        let tx_out_from_request_serialized = encode::serialize(&tx_out_from_reqwest);
        let tx_out_from_request_deserialized: TxOut = encode::deserialize(&tx_out_from_request_serialized).unwrap();
        
        assert!(tx_out_from_request_deserialized.unblind(secp256k1::SECP256K1, secret_key).is_ok());
主要语言
Rust
星标
57
派生
40
平均合并
11 小时 58 分钟
30 天内合并 PR
1

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ElementsProject/rust-elements 的其他 Issue

查看 ElementsProject/rust-elements 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。