Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: describe elements transaction serialization format #1148

Merged
merged 9 commits into from
Sep 1, 2022

Conversation

jamesdorfman
Copy link
Contributor

@jamesdorfman jamesdorfman commented Aug 19, 2022

Note: When reviewing this markdown file, please open it in a markdown viewer. Otherwise, the tables will be illegible. Github will show you the rendered markdown if you open the "Files changed" tab, click the three dots on the top right of the file, and select "View file".

This PR adds a new markdown document which contains a detailed description of the elements transaction serialization format.

The document includes a detailed descriptions of all fields and examples where complex raw transactions are deserialized, step-by-step.

Intended audience:

  • Hardware Wallet developers implementing liquid apps
  • Developers creating Liquid integrations
  • Developers writing their own serialized Liquid transactions from other languages
  • Bitcoin users wanting to see what's new in an Elements transactions
  • People creating and using PSETs (PSETs use serialized transactions)
  • People wanting to know how Liquid and Elements work

@jamesdorfman jamesdorfman changed the title docs: add detailed description of elements transaction serialization format docs: describe elements transaction serialization format Aug 19, 2022
Copy link
Member

@delta1 delta1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, I have just done a first pass with mostly grammatical suggestions, and will make a second pass (when I can) to go over the examples closely.

Comment on lines 3 to 5
This document describes the format used to serialize elements transactions. Once a transaction has been converted into this raw, serialized form, it can be broadcast across the network.

This document requires familiarity with the architecture of bitcoin and elements, as well the various parts that are expected in an elements transaction (inputs, outputs, assets, pegin data, etc.). For more information on those, please refer to the [elements code tutorial](https://elementsproject.org/elements-code-tutorial/overview).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This document describes the format used to serialize elements transactions. Once a transaction has been converted into this raw, serialized form, it can be broadcast across the network.
This document requires familiarity with the architecture of bitcoin and elements, as well the various parts that are expected in an elements transaction (inputs, outputs, assets, pegin data, etc.). For more information on those, please refer to the [elements code tutorial](https://elementsproject.org/elements-code-tutorial/overview).
This document describes the format used to serialize Elements transactions. Once a transaction has been converted into this raw, serialized form, it can be broadcast across the network.
This document requires familiarity with the architecture of Bitcoin and Elements, as well the various parts that are expected in an Elements transaction (inputs, outputs, assets, peg-in data, etc.). For more information on those, please refer to the [Elements code tutorial](https://elementsproject.org/elements-code-tutorial/overview).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I will add all these, except for the "peg-in" one.

It appears that the existing elements docs use "pegin", not "peg-in".

claimpegin "bitcoinTx" "txoutproof" ( "claim_script" )
Claim coins from the main chain by creating a pegin transaction with the necessary metadata after the corresponding Bitcoin transaction.

https://elementsproject.org/en/doc/0.18.1.6/rpc/wallet/claimpegin/

Comment on lines 9 to 11
*Note:* The encoding column in the following tables corresponds to the way that the fields are serialized. In bitcoin, numbers and hashes are serialized in little endian, and this same notion carries over to elements.

*Note:* Values are listed in multiples of 100,000,000 (this corresponds directly to how bitcoin encodes value, where 1 BTC is divisible into 100,000,000 satoshis). For example, a `ConfidentialAmount` representing 7 inflation keys would be encoded as 700,000,000.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
*Note:* The encoding column in the following tables corresponds to the way that the fields are serialized. In bitcoin, numbers and hashes are serialized in little endian, and this same notion carries over to elements.
*Note:* Values are listed in multiples of 100,000,000 (this corresponds directly to how bitcoin encodes value, where 1 BTC is divisible into 100,000,000 satoshis). For example, a `ConfidentialAmount` representing 7 inflation keys would be encoded as 700,000,000.
*Note:* The encoding column in the following tables corresponds to the way that the fields are serialized. In Bitcoin, numbers and hashes are serialized in little-endian, and this same notion carries over to Elements.
*Note:* Values are listed in multiples of 100,000,000 (this corresponds directly to how Bitcoin encodes value, where 1 BTC is divisible into 100,000,000 Satoshis). For example, a `ConfidentialAmount` representing 7 inflation keys would be encoded as 700,000,000.


|Field|Required|Size|Data Type|Encoding|Notes|
|-----|--------|-----|---------|--------|-----|
| Version | Yes | 4 bytes | `UnsignedInteger` | Little endian | Protocol version (should always be 2). |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a signed int32 - link

Might be worth adding some info from https://developer.bitcoin.org/reference/transactions.html#raw-transaction-format

Maybe "Data Type" should be the actual C++ type used?

Suggested change
| Version | Yes | 4 bytes | `UnsignedInteger` | Little endian | Protocol version (should always be 2). |
| Version | Yes | 4 bytes | `uint32_t` | Little-Endian | Transaction version number. Currently version 2. Version 2 means that [BIP 68](https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki#specification) applies. |

|Field|Required|Size|Data Type|Encoding|Notes|
|-----|--------|-----|---------|--------|-----|
| Version | Yes | 4 bytes | `UnsignedInteger` | Little endian | Protocol version (should always be 2). |
| Flags | Yes | 1 byte | | | Whether the transaction contains a witness. Either 0 or 1. |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| Flags | Yes | 1 byte | | | Whether the transaction contains a witness. Either 0 or 1. |
| Flags | Yes | 1 byte | unsigned char | | Whether the transaction contains a witness. Either 0 (no witness) or 1. |

| Num Inputs | Yes | Varies | `VarInt` | | Number of outputs from the transaction. |
| Outputs | Yes | Varies | `Vector<TxOut>` | | |
| Locktime | Yes | 4 bytes | `UnsignedInteger` | Little endian | See [BIP 113](https://github.com/bitcoin/bips/blob/master/bip-0113.mediawiki). |
| Witness | Only if flags is 1 | Varies | `Witness` | | See [BIP 141](https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki). Note that elements witnesses contain more data than bitcoin witnesses. This extra data is described further below. |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| Witness | Only if flags is 1 | Varies | `Witness` | | See [BIP 141](https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki). Note that elements witnesses contain more data than bitcoin witnesses. This extra data is described further below. |
| Witness | Only if flags is 1 | Varies | `Witness` | | See [BIP 141](https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki). Note that Elements witnesses contain more data than Bitcoin witnesses. This extra data is described further below. |

|-----|--------|-----|---------|--------|-----|
| Output Hash (TXID) | Yes | 32 bytes | `UnsignedInteger` | Little endian | Hashes in bitcoin are encoded as integers in little endian. Be mindful – this means that they will look backwards when serialized. |
| Output Index | Yes | 4 bytes | `UnsignedInteger` | Little endian | **Output is a coinbase**: `0xffffffff`<br><br>The two most significant bits are reserved for flags.<br><br>**Output is a pegin:** second most significant bit is 1.<br><br>**Output is an asset issuance:** most significant bit is 1. |
| ScriptSig Length | Yes | Varies | `VarInt` | | Set to `0x00` if the transaction is segwit and the witness contains the signature. |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| ScriptSig Length | Yes | Varies | `VarInt` | | Set to `0x00` if the transaction is segwit and the witness contains the signature. |
| ScriptSig Length | Yes | Varies | `VarInt` | | Set to `0x00` if the transaction is SegWit and the witness contains the signature. |


#### Witness

As noted above, the witness is only present for segwit transactions.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
As noted above, the witness is only present for segwit transactions.
As noted above, the witness is only present for SegWit transactions.

Serialized format:
`[Issuance Amount Range Proof][Inflation Keys Range Proof][Script Witness][Pegin Witness]`

The range proofs must be empty if their asociated amount (issuance / inflation keys) is explicit.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The range proofs must be empty if their asociated amount (issuance / inflation keys) is explicit.
The range proofs must be empty if their associated amounts (issuance / inflation keys) are explicit.


The Range Proof must be empty if the output’s amount is explicit.

The Surjectionproof must be empty if the output’s assetId is explicit.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The Surjectionproof must be empty if the output’s assetId is explicit.
The Surjection Proof must be empty if the output’s assetId is explicit.


This data type is derived from bitcoin and allows an integer to be encoded depending on the represented value, to save space. Variable length integers always precede an vector of a type of data that may vary in length. Longer numbers are encoded in little endian.

Refer to the [bitcoin protocol documentation](https://en.bitcoin.it/wiki/Protocol_documentation#Variable_length_integer) for a full description on how this type is serialized.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Refer to the [bitcoin protocol documentation](https://en.bitcoin.it/wiki/Protocol_documentation#Variable_length_integer) for a full description on how this type is serialized.
Refer to the [Bitcoin protocol documentation](https://en.bitcoin.it/wiki/Protocol_documentation#Variable_length_integer) for a full description on how this type is serialized.

|Field|Required|Size|Data Type|Encoding|Notes|
|-----|--------|-----|---------|--------|-----|
| Asset | Yes | 1 or 33 bytes | `ConfidentialAsset` | | |
| Amount | Yes | 1 or 9 or 33 bytes | `ConfidentialAmount` | | |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Null asset and null amounts are illegal in outputs. They cannot be 1 byte.

Copy link
Contributor Author

@jamesdorfman jamesdorfman Aug 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

|Field|Required|Size|Data Type|Encoding|Notes|
|-----|--------|-----|---------|--------|-----|
| Asset Blinding Nonce | Yes | 32 bytes | `hex` | | Zero for a new asset issuance; otherwise a blinding factor for the input. |
| Asset Entropy | Yes | 32 bytes | `hex` | | Freeform entropy field, no consensus-defined meaning, but is used as additional entropy to the asset tag calculation. |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only freeform for new issuances. For reissuances it is required to be the asset's entropy value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

| Asset Blinding Nonce | Yes | 32 bytes | `hex` | | Zero for a new asset issuance; otherwise a blinding factor for the input. |
| Asset Entropy | Yes | 32 bytes | `hex` | | Freeform entropy field, no consensus-defined meaning, but is used as additional entropy to the asset tag calculation. |
| Amount | Yes | 1 or 9 or 33 bytes | `ConfidentialAmount` | | Amount of the asset to issue. Both explicit and blinded amounts are supported. |
| Num Inflation Keys | Yes | 1 or 9 or 33 bytes | `ConfidentialAmount` | | Number of inflation keys to issue. Both explicit and blinded amounts are supported. |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Inflation Keys cannot be reissued.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a note here explaining this.

|Field|Required|Size|Data Type|Encoding|Notes|
|-----|--------|-----|---------|--------|-----|
| Output Hash (TXID) | Yes | 32 bytes | `UnsignedInteger` | Little endian | Hashes in bitcoin are encoded as integers in little endian. Be mindful – this means that they will look backwards when serialized. |
| Output Index | Yes | 4 bytes | `UnsignedInteger` | Little endian | **Output is a coinbase**: `0xffffffff`<br><br>The two most significant bits are reserved for flags.<br><br>**Output is a pegin:** second most significant bit is 1.<br><br>**Output is an asset issuance:** most significant bit is 1. |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Input is a pegin; Input has an asset issuance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

| Locktime | Yes | 4 bytes | `uint32_t` | Little-endian | See [BIP 113](https://github.com/bitcoin/bips/blob/master/bip-0113.mediawiki). |
| Witness | Only if flags is 1 | Varies | `Witness` | | See [BIP 141](https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki). Note that Elements witnesses contain more data than Bitcoin witnesses. This extra data is described further below. |

Serialized format: `[Version][Flags][Num Inputs][Inputs][Num Outputs][Outputs][Locktime][Witness]`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to have the serialized form listed here? The table is sequential and conveys the form. Duplicating it makes it redundant and the reader may wonder if it differs .


|Field|Required|Size|Data Type|Encoding|Notes|
|-----|--------|-----|---------|--------|-----|
| Output Hash (TXID) | Yes | 32 bytes | `uint256` | Little-endian | Bytes of the output hash are encoded in little-endian. **NB**: this means that they appear backwards when serialized. |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can probably omit the NB. We can assume familiarity with little-endian and big-endian serializations.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I think the situation here is more complex than this documentation presents. The serialization order of the hashes is the correct order of the bytes produced by SHA256. It is the elements client that takes this correct serialization order, reinterprets it as a 256 bit integer in little endian format and then displays that integer in hex, which has the effect of displaying AssetIDs backwards.

I just don't know a concise way of explaining all this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Thank you for the clarification.

I was actually under the (incorrect) impression that the elements client displayed the correct order of bytes produced by SHA256, and the hashes were just serialized in reverse.

Your explanation makes much more sense.

I will make this distinction more clear.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should drop any reference to endianness and just say that the bytes are reversed. You can add a footnote explaining that historically this has something to do with endianness and type conversions but I don't think it would make things any clearer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I've stated that the bytes are reversed, and I've added a footnote explaining the historical reasons for this.

|Field|Required|Size|Data Type|Encoding|Notes|
|-----|--------|-----|---------|--------|-----|
| Version | Yes | 4 bytes | `int32_t` | Little-endian | Transaction version number. Currently version 2 (see [BIP 68](https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki#specification)). | |
| Flags | Yes | 1 byte | `unsigned char` | | Whether the transaction contains a witness. Either 0 (no witness) or 1. |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should state if other values are accepted or ignored. (In this case, they are rejected)

Serialized format: `[Input Witnesses][Output Witnesses]`

#### InputWitness

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be helpful to add a one sentence description of this field, in case someone is arriving here without the previous context.

| 00 ................................. Pegin witness (0x00 → null)
|
| Input #2 witness
| 00 ................................. IssuanceAmountRangeproof (null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the use of camel case here is inconsistent with input 1

|Field|Required|Size|Data Type|Encoding|Notes|
|-----|--------|-----|---------|--------|-----|
| Output Hash (TXID) | Yes | 32 bytes | `uint256` | Little-endian | Bytes of the output hash are encoded in little-endian. **NB**: this means that they appear backwards when serialized. |
| Output Index | Yes | 4 bytes | `uint32_t` | Little-endian | **Input is a coinbase**: `0xffffffff`<br><br>The two most significant bits are reserved for flags.<br><br>**Input is a pegin:** second most significant bit is 1.<br><br>**Input has an asset issuance:** most significant bit is 1. |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if both bits are 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's self-evident that an asset issuance and a pegin are mutually exclusive, from a logical perspective.

I'd prefer not to enumerate every single thing that could be invalid, because that would make the document much longer and more confusing to read.

I could add a link to the actual transaction validation code here, but I'm not sure how helpful that will be.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I am aware you can pegin and issue an asset at the same time. I've never tried it though.


#### ConfidentialAsset

Serialized format: `[header][value]`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be helpful to keep with the table description for these types, for consistency and clarity (even though there are only 2 fields).

@jamesdorfman jamesdorfman force-pushed the tx-serialization-docs branch 4 times, most recently from 48f6101 to dc35239 Compare August 26, 2022 14:30
@jamesdorfman jamesdorfman force-pushed the tx-serialization-docs branch 2 times, most recently from ee113d8 to 0ba641b Compare August 26, 2022 15:19
| Output Hash (TXID) | Yes | 32 bytes | `hex` | [^1] | |
| Output Index | Yes | 4 bytes | `uint32_t` | Little-endian | **Input is a coinbase**: `0xffffffff`<br><br>The two most significant bits are reserved for flags.<br><br>**Input is a pegin:** second most significant bit is 1.<br><br>**Input has an asset issuance:** most significant bit is 1. |
| ScriptSig Length | Yes | Varies | `VarInt` | | Set to `0x00` if the transaction is SegWit and the witness contains the signature. |
| ScriptSig | If ScriptSig Length is non-zero | Varies | `hex` | Big-endian | |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would drop the "Big-endian" for scripts and leave the field blank.

|-----|--------|-----|---------|--------|-----|
| Asset Blinding Nonce | Yes | 32 bytes | `hex` | | Zero for a new asset issuance; otherwise a blinding factor for the input. |
| Asset Entropy | Yes | 32 bytes | `hex` | | **New issuances:** Freeform entropy field, no consensus-defined meaning, but is used as additional entropy to the asset tag calculation.<br><br>**Reissuances:** Required to be the asset's entropy value (from its initial issuance). |
| Amount | Yes | 1 or 9 or 33 bytes | `ConfidentialAmount` | | Amount of the asset to issue. Both explicit and blinded amounts are supported. |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Amount and Num Inflation Keys cannot be explicitly 0. (Instead they should be NULL values).


* The *Encoding* column in the following tables indicates how the fields are serialized.

* Values are defined in multiples of 100,000,000 (this corresponds directly to how Bitcoin encodes value, where 1 BTC is divisible into 100,000,000 Satoshis). For example, a `ConfidentialAmount` representing 7 units of something (`L-BTC`, inflation keys, etc.) would be encoded as 700,000,000.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@apoelstra correct me if I'm wrong, but how the element/green UI handles units is ... more complicated than this suggests. There is something about the asset registry etc. etc.

I think we should simply note that all unit values are in satoshis, or say all values are in the smallest indivisible unit (i.e. satoshis) or something like that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

Even if other assets didn't have "natural units" that differed from 10^8 I don't know what 10^8 would have to do with the encoding, so we should drop any mention of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I mentioned this was because Example 2 below contains an asset issuance with the number of inflation keys encoded as:

0x29b92700 = 700 000 000 

Does this correspond to 7 keys? A single inflation key is indivisible, correct?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's 700 million reissuance keys.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. So when I parse the full issuance transaction with $elements-cli decoderawtransaction <...>, the result contains:

"issuance": {
        "assetBlindingNonce": "0000000000000000000000000000000000000000000000000000000000000000",
        "assetEntropy": "503f1db03b8ed61ace8fbadc2fcb6c200bdf1ada403d74b891e55e1a047b6596",
        "isreissuance": false,
        "token": "6e88fa86a097b9ede564f67c60e8c5d24ed1f10eeb56c3a60223961f2e38737f",
        "asset": "d42c5ba3724b7f7a045968e0c04e69f81070aca8b6e2db88cd84c65dd07b8324",
        "assetamount": 33.00000000,
        "tokenamount": 7.00000000
}

Is the "tokenamount": 7.00000000 indicating that there are really 700,000,000 reissuance tokens?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol. yes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok that makes sense now. Thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened #1152 about this.


|Field|Required|Size|Data Type|Encoding|Notes|
|-----|--------|-----|---------|--------|-----|
| Header | Yes | 1 byte | | | A header byte of `0x00` indicates a “null” value with no subsequent bytes.<br><br>A header byte of `0x01` indicates an “explicit” value with the following 32 bytes denoting a value (big-endian).<br><br>A header byte of `0x02` or `0x03` indicates a compressed elliptic curve point. With the least significant bit of the header byte denoting the least significant bit of the y-coordinate, and the remaining 32 bytes denoting the x-coordinate (big-endian). This point is not required to be on the curve. |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@apoelstra Is there any existing wallet interpretation of an explicit nonce? Care to comment on its endianness?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, and lol. It's hard to imagine an interpretation of "endianness" for nonces.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you would take the explicit value as an secp256k1 scalar value and multiply the generator with it, that would give it an endianness. But I wasn't sure if a wallet is expected to do anything with an explicit nonce.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that would make sense. But no, in practice nobody interprets "explicit nonces" at all.

|
| Input #1
| 3d0bfb6e61989331d67dac3b6adf067a
| fda20f504cabb1a7364853a68a0bb6df ... Outpoint TXID
Copy link
Contributor

@roconnor-blockstream roconnor-blockstream Aug 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest commenting that the previous TXID is dfb6... here and for other examples.

| Output #1
| 01 ................................. Asset header (0x01 → explicit, unblinded value)
| 6d521c38ec1ea15734ae22b7c4606441
| 2829c0d0579f0a713d1c04ede979026f ... Key used to generate asset ID
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest commenting that the assetID is 6f02... here and in the other examples.

| | | 7cb3495046 ..................... Stack item #2
| 06 ................................. Pegin witness stack length
| | 08 ............................... Stack item #1 length
| | | e8092b0000000000 ............... Stack item #1
Copy link
Contributor

@roconnor-blockstream roconnor-blockstream Aug 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@apoelstra Should be be describing the pegin structure here, amount, claim_script, genesis hash, peg-in transaction? I know that the transaction tool does this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think that we should. I'm tempted to say "it's a stack of byte vectors" but in this case every field has a clear meaning and fixed format, and it's simple enough to parse.

Copy link
Contributor

@roconnor-blockstream roconnor-blockstream left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved, though I think we might as well inline the definition of the encoding for VarInts.

@philippem
Copy link
Contributor

ack thank you!!

Copy link
Contributor

@philippem philippem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great job, thank you!

@jamesdorfman jamesdorfman merged commit 872478b into master Sep 1, 2022
@jamesdorfman jamesdorfman deleted the tx-serialization-docs branch September 1, 2022 17:24
apoelstra added a commit that referenced this pull request Sep 6, 2022
…or rc5

37076d7 Bump version to -rc5 (Pablo Greco)
5629cae fs: Make compatible with boost 1.78 (Andrew Chow)
60b913e Elements-qt: Correctly display the amount in the sender's wallet after using Send button (Andrea Bonel)
872478b docs: describe elements transaction serialization format (#1148) (James Dorfman)
dd2d758 fixed minor issues found in review (Allen Piscitello)
2da7d75 removing test that fails due to blinded issuances, which results in incorrect reissuance token ids (Allen Piscitello)
420de43 removing code to blind issuances. PSET should be modified to include an option to blind or unblind issuances, defaulting to unblind. (Allen Piscitello)

Pull request description:

  Backport #1150 #1154 and #1148 from master.
  Backport bitcoin/bitcoin#24104 from Bitcoin Core
  Bump to -rc5

ACKs for top commit:
  jamesdorfman:
    utACK 37076d7.
  delta1:
    utACK 37076d7

Tree-SHA512: 616322f94c17008cc7fd582203c22b33c73b922269ab33fd13b270f491eda9b30d4f18efa3f7887e247bef46b63c4810f4084e409bea98120702c426a83343a8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants