ElementsProject / ElementsProject/rust-elements

Unable to decode serialized TxOut

Aberta
#262 2 comentários 1 reação 0 responsáveis Ver no GitHub
Linguagem predominante
Rust
Estrelas
57
Forks
40
Merge médio
11h 58min
PRs com merge (30d)
1

Descrição

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](https://github.com/user-attachments/assets/cbcc9fe2-2f86-43b6-afd2-c66b6a0966aa)

Here is a quick code snippet to test it:
```rust
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());
```

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.