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

Fixing issuance cases and half blinded cases in PSET #1145

Merged
merged 1 commit into from
Aug 18, 2022

Conversation

allenpiscitello
Copy link
Contributor

A few minor cases fixed in PSET-related code. Caused either a crash or invalid transactions created in some cases.

@@ -123,13 +123,26 @@ CMutableTransaction PartiallySignedTransaction::GetUnsignedTx(bool force_unblind
txin.nSequence = input.sequence.value_or(max_sequence);
txin.assetIssuance.assetBlindingNonce = input.m_issuance_blinding_nonce;
txin.assetIssuance.assetEntropy = input.m_issuance_asset_entropy;
if (input.m_issuance_value != std::nullopt && input.m_issuance_inflation_keys_amount != std::nullopt && force_unblinded) {
// If there is a commitment we should set the value to the commitment unless we are forcing unblinded.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This code handled blinded vs. unblinded issuances badly. It always tried to blind the issuances, even if they were unblinded issuance assets.

Since there are no fields in the PSET spec to define if an issuance should be blinded or not, we will use the presence of the issuance blinding commitment to tell us what to do.

Copy link

@tiero tiero Aug 18, 2022

Choose a reason for hiding this comment

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

Not sure is related, but it seems very similar?

#1103

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This looks similar that it may solve the problem. The use case I was trying to solve was an unblinded re-issuance.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just tested #1119 which provides a testcase for #1103 and it is not fixed by this

@@ -2048,11 +2048,15 @@ TransactionError CWallet::SignPSBT(PartiallySignedTransaction& psbtx, bool& comp
txin.assetIssuance.nAmount = input.m_issuance_value_commitment;
} else if (input.m_issuance_value) {
txin.assetIssuance.nAmount.SetToAmount(*input.m_issuance_value);
} else {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These variables were never cleared, so they retained the value of the previous loop iteration, which resulted in problems when there were multiple inputs beyond the first issuance, as well as problems when reissuing assets (where there are no inflation keys created).

@@ -531,12 +544,9 @@ bool PSBTOutput::Merge(const PSBTOutput& output)
CTxOut PSBTOutput::GetTxOut() const
{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This would fail on situations where an asset was blinded but a value was not. I simplified the code to ensure that a value or commitment was checked in the assert (note: this will still crash if you don't provide either, maybe we should't assert?). Then it will use whatever combination of what is given.

Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

utACK 8e1153a

(I cannot run tests because of #1142)

@psgreco
Copy link
Contributor

psgreco commented Aug 18, 2022

Tests pass after the assert fix, @apoelstra can you re-ack, even after I merge this?

@psgreco psgreco merged commit debf46b into ElementsProject:master Aug 18, 2022
@apoelstra
Copy link
Member

re-utACK 5954b10

apoelstra added a commit that referenced this pull request Aug 18, 2022
…or rc4

85c25b1 Bump version to -rc4 (Pablo Greco)
bb684f2 Update manpages (Pablo Greco)
38e9490 Elements-qt: Fix arrows to increase/decrease Amount (Andrea Bonel)
5954b10 Fixing issuance cases and half blinded cases in PSET (Allen Piscitello)
707cf20 Fix tapscript comment (roconnor-blockstream)
7fb99ff Fix Icon position in dmg (Pablo Greco)

Pull request description:

  Backport #1140 #1141 #1145 and #1146  from master.
  Fix manpages
  Bump to -rc4

ACKs for top commit:
  delta1:
    utACK 85c25b1

Tree-SHA512: 78a30bec870530275d103b6cab630ebf96b2df39fd03fc426bb16b6743ce9311f7e7128e43bf7a6452d261377e6ac017d61b77cd9ad4e4c20040629ae20e13b4
@@ -476,6 +476,9 @@ BlindingStatus BlindPSBT(PartiallySignedTransaction& psbt, std::map<uint32_t, st
}
}
}
else {
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer to have this as the if, with the existing code in the else. As it is its difficult to see what if this else relates to when reviewing. i.e.

                if (!blind_issuance) {
                    input_asset_blinders.emplace_back();
                } else {

Copy link
Contributor

Choose a reason for hiding this comment

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

Also all of your else statements (here and elsewhere) are on new lines which is inconsistent with the rest of the code. Please use

} else {

Instead of

}
else {

Here and in the other changes.

Copy link

Choose a reason for hiding this comment

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

for code formatting/style wouldn't be better to rely on a GitHub action that enforces shared rules automatically?

Copy link
Contributor

Choose a reason for hiding this comment

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

That would make the code harder to rebase over upstream core changes, unfortunately.

gwillen added a commit to gwillen/elements that referenced this pull request Mar 2, 2023
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