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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/blindpsbt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.

input_asset_blinders.emplace_back();
psgreco marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
Expand Down
28 changes: 19 additions & 9 deletions src/psbt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

// 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) {
Expand Down Expand Up @@ -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.

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
Expand Down
4 changes: 4 additions & 0 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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).

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;
Expand Down