Unable to decode serialized TxOut

Open
#262 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
52/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
rust
Domain
blockchain

Research direction

Start in src/transaction.rs at the TxOut and TxOutWitness definitions and the serialization behavior around the cited lines, then reproduce the issue with the provided transaction and round-trip snippet. Done means a serialized and deserialized TxOut retains its rangeproof so unblind succeeds; add or update regression coverage if the repository provides a suitable location.

Written by the indexing model from the issue text.

Description

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());
Dominant language
Rust
Stars
57
Forks
40
Avg merge
11h 58m
Merged PRs (30d)
1

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ElementsProject/rust-elements

All issues in ElementsProject/rust-elements

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.