Skip to content

Improve types on AssetIssuance struct#289

Open
apoelstra wants to merge 4 commits into
ElementsProject:masterfrom
apoelstra:2026-07/issance-typing
Open

Improve types on AssetIssuance struct#289
apoelstra wants to merge 4 commits into
ElementsProject:masterfrom
apoelstra:2026-07/issance-typing

Conversation

@apoelstra

Copy link
Copy Markdown
Member

Use strong types for asset entropy and blinding nonce.

…nonce

Previously we had been using the secp265k1_zkp::Tweak type to represent
a blinding nonce in an issuance. This had a number of issues:

* `Tweak` is a low-level crypto type which is ambiguous about whether or
   not it's secret or public, and doesn't have any meaning beyond "value
   you can add to a secp point"
* In particular the special `ZERO_TWEAK` constant was interpreted to
  mean "new issuance" and this was implicit throughout the codebase.
* As a foreign type, we could not directly implement any encoding or
  decoding traits on this; we had to convert it to/from a byte array.
* As a "general" type, it doesn't distinguish between various uses of
  tweak, which can lead to dangerous type confusion.
* `Tweak` cannot represent values that are out of range of the secp256k1
  group, while technically Elements permits such transactions to exist
  (e.g. `decoderawtransaction` will accept them), even though it will
  fail VerifyAmounts. (I carefully checked all the codepaths: if the
  amounts in an issuance are null, so much be the nonce (or else you get
  a "superfluous issuance" error; if they're non-null and the blinding
  nonce is zero (which is in-range), it's a new issuance; if it's not
  zero then it's put into secp256k1_generator_generate_blinded which
  checks for overflow as its very first check.)
The only place this is actually "consensus encoded" is arguably in the
pegin witness stack, but that's reason enough to have these.
@apoelstra

Copy link
Copy Markdown
Member Author

I think after this we should cut a 0.27 release of rust-elements. I have a bunch of breakage related to encoding coming down the pike and it'd be good to have a release right before and after that to try to contain the damage for people updating their stuff.

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.

1 participant