-
Notifications
You must be signed in to change notification settings - Fork 388
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure is related, but it seems very similar? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
// If we are forcing unblinded but there is no value, we just use the commitment. | ||
if (input.m_issuance_value != std::nullopt && (input.m_issuance_value_commitment.IsNull() || force_unblinded)) { | ||
txin.assetIssuance.nAmount.SetToAmount(*input.m_issuance_value); | ||
txin.assetIssuance.nInflationKeys.SetToAmount(*input.m_issuance_inflation_keys_amount); | ||
} else { | ||
} | ||
else if(!input.m_issuance_value_commitment.IsNull()) { | ||
txin.assetIssuance.nAmount = input.m_issuance_value_commitment; | ||
} | ||
else { | ||
txin.assetIssuance.nAmount.SetNull(); | ||
} | ||
if (input.m_issuance_inflation_keys_amount != std::nullopt && (input.m_issuance_inflation_keys_commitment.IsNull() || force_unblinded)) { | ||
txin.assetIssuance.nInflationKeys.SetToAmount(*input.m_issuance_value); | ||
} | ||
else if(!input.m_issuance_inflation_keys_commitment.IsNull()) { | ||
txin.assetIssuance.nInflationKeys = input.m_issuance_inflation_keys_commitment; | ||
} | ||
else { | ||
txin.assetIssuance.nInflationKeys.SetNull(); | ||
} | ||
mtx.vin.push_back(txin); | ||
} | ||
for (const PSBTOutput& output : outputs) { | ||
|
@@ -531,12 +544,9 @@ bool PSBTOutput::Merge(const PSBTOutput& output) | |
CTxOut PSBTOutput::GetTxOut() const | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
assert(script != std::nullopt); | ||
if (!m_value_commitment.IsNull() && !m_asset_commitment.IsNull()) { | ||
return CTxOut(m_asset_commitment, m_value_commitment, *script); | ||
} | ||
assert(amount != std::nullopt); | ||
assert(!m_asset.IsNull()); | ||
return CTxOut(CConfidentialAsset(CAsset(m_asset)), CConfidentialValue(*amount), *script); | ||
assert(amount != std::nullopt || !m_value_commitment.IsNull()); | ||
assert(!m_asset.IsNull() || !m_asset_commitment.IsNull()); | ||
return CTxOut(!m_asset_commitment.IsNull() ? m_asset_commitment : CAsset(m_asset), !m_value_commitment.IsNull() ? m_value_commitment : CConfidentialValue(*amount), *script); | ||
} | ||
|
||
bool PSBTOutput::IsBlinded() const | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). |
||
txin.assetIssuance.nAmount.SetNull(); | ||
} | ||
if (!input.m_issuance_inflation_keys_commitment.IsNull()) { | ||
txin.assetIssuance.nInflationKeys = input.m_issuance_inflation_keys_commitment; | ||
} else if (input.m_issuance_inflation_keys_amount) { | ||
txin.assetIssuance.nInflationKeys.SetToAmount(*input.m_issuance_inflation_keys_amount); | ||
} else { | ||
txin.assetIssuance.nInflationKeys.SetNull(); | ||
} | ||
if (!input.m_issuance_rangeproof.empty()) { | ||
txinwit.vchIssuanceAmountRangeproof = input.m_issuance_rangeproof; | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 useInstead of
Here and in the other changes.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.