diff --git a/contrib/assets_tutorial/pset_swap_tutorial.py b/contrib/assets_tutorial/pset_swap_tutorial.py index ff03ff63df..3f40270bbd 100755 --- a/contrib/assets_tutorial/pset_swap_tutorial.py +++ b/contrib/assets_tutorial/pset_swap_tutorial.py @@ -242,7 +242,8 @@ assert all([x["next"] == "updater" for x in analysis["inputs"]]) # in turn, or by both updating their copies and then one party calls # `combinepsbt` to combine the results. # -# We will do the latter for symmetry reasons. +# We will do the latter since `combinepsbt` will automatically check that +# neither party changed the transaction out from under the other. # print ("3. Both parties fill in their UTXO data.") @@ -257,17 +258,23 @@ assert all([x["has_utxo"] for x in analysis["inputs"]]) assert not any([x["is_final"] for x in analysis["inputs"]]) assert all([x["next"] == "signer" for x in analysis["inputs"]]) -## 3. Blind the PSET +## 4. Blind the PSET # # Both parties now blind the PSET. Importantly, the final person to blind must # have a combined PSET that has everyone else's blinding data included, so that # they can make the blinding factors add up. # -# In the 2-party case this is particularly simple because there is no need to -# combine anything. +# The most straightforward way to implement this is to have each party blind +# the PSET, then pass to the next party, who blinds in-turn. If there are more +# than 2 parties, then you can have all parties but one blind independently, +# `combinepsbt` the results, and give this to the final party to blind. +# +# In the two-party case these are equivalent. # -# Just for fun, try to have both parties blind independently and combine +# Just for fun, try to have both parties blind independently and combine. This +# will fail because `combinepsbt` needs there to be at least one remaining +# unblinded output. alice_blinded = alice.walletprocesspsbt(filled_pset) carol_blinded = carol.walletprocesspsbt(filled_pset) try: @@ -278,13 +285,20 @@ else: raise Exception("combinepsbt should return 'Cannot combine PSETs as the values and blinders would become imbalanced'") # Ok, back to the tutorial -print ("3. One party blinds the PSET and passes to the other party, who also blinds") +print ("4. One party blinds the PSET and passes to the other party, who also blinds") # We set sign=False here, because otherwise carol's `walletprocesspsbt` # will sign the transaction (since after she does her blinding, the # transaction will be completely blinded and therefore signable). # But for this tutorial we want that to happen only in the next step. alice_blinded = alice.walletprocesspsbt(filled_pset) +# Alice gives `alice_blinded` to Carol, who uses `combinepsbt` to verify +# that Alice blinded honestly (not changing any of the output amounts/assets) +carol.combinepsbt([filled_pset, alice_blinded["psbt"]]) +# If this passes (does not throw any exception) she can blind. carol_blinded = carol.walletprocesspsbt(psbt=alice_blinded["psbt"], sign=False) +# Similarly, Carol passes the result to Alice, who checks it +carol.combinepsbt([alice_blinded["psbt"], carol_blinded["psbt"]]) +# Now both parties have a copy of the fully-blinded transaction. blinded = carol_blinded # We won't print these out because they're very big now @@ -300,7 +314,7 @@ assert all([x["has_utxo"] for x in analysis["inputs"]]) assert not any([x["is_final"] for x in analysis["inputs"]]) assert all([x["next"] == "signer" for x in analysis["inputs"]]) -## 4. Sign the PSET +## 5. Sign the PSET # # When signing, there are a couple options for workflows. Each party can sign # in turn, like we did when blinding, or they can each sign independently and @@ -308,7 +322,7 @@ assert all([x["next"] == "signer" for x in analysis["inputs"]]) # demonstration purposes. # -print ("4. Both parties sign the PSET") +print ("5. Both parties sign the PSET") alice_signed = alice.walletprocesspsbt(blinded["psbt"]) carol_signed = carol.walletprocesspsbt(blinded["psbt"]) @@ -324,7 +338,7 @@ assert all([x["has_utxo"] for x in analysis["inputs"]]) assert all([x["is_final"] for x in analysis["inputs"]]) assert all([x["next"] == "extractor" for x in analysis["inputs"]]) -print ("5. Finalize and Extract") +print ("6. Finalize and Extract") x = alice.finalizepsbt(complete, True) assert x["complete"] # The complete transaction is in x["hex"] but again we won't print it because diff --git a/src/blindpsbt.cpp b/src/blindpsbt.cpp index 201f035865..295d57691b 100644 --- a/src/blindpsbt.cpp +++ b/src/blindpsbt.cpp @@ -66,7 +66,7 @@ bool CreateAssetSurjectionProof(std::vector& output_proof, const return true; } -static bool VerifyBlindAssetProof(const uint256& asset, const std::vector& proof, const CConfidentialAsset& conf_asset) +bool VerifyBlindAssetProof(const uint256& asset, const std::vector& proof, const CConfidentialAsset& conf_asset) { secp256k1_surjectionproof surj_proof; if (secp256k1_surjectionproof_parse(secp256k1_blind_context, &surj_proof, proof.data(), proof.size()) == 0) { @@ -173,7 +173,7 @@ static bool CreateBlindAssetProof(std::vector& assetproof, const return true; } -static bool VerifyBlindValueProof(CAmount value, const CConfidentialValue& conf_value, const std::vector& proof, const CConfidentialAsset& conf_asset) +bool VerifyBlindValueProof(CAmount value, const CConfidentialValue& conf_value, const std::vector& proof, const CConfidentialAsset& conf_asset) { secp256k1_pedersen_commitment value_commit; if (secp256k1_pedersen_commitment_parse(secp256k1_blind_context, &value_commit, conf_value.vchCommitment.data()) == 0) { diff --git a/src/blindpsbt.h b/src/blindpsbt.h index 51cc09dff5..17fda2b7d9 100644 --- a/src/blindpsbt.h +++ b/src/blindpsbt.h @@ -47,6 +47,10 @@ bool CreateValueRangeProof(std::vector& rangeproof, const uint256 void CreateAssetCommitment(CConfidentialAsset& conf_asset, secp256k1_generator& asset_gen, const CAsset& asset, const uint256& asset_blinder); void CreateValueCommitment(CConfidentialValue& conf_value, secp256k1_pedersen_commitment& value_commit, const uint256& value_blinder, const secp256k1_generator& asset_gen, const CAmount amount); BlindingStatus BlindPSBT(PartiallySignedTransaction& psbt, std::map> our_input_data, std::map> our_issuances_to_blind); + + +bool VerifyBlindValueProof(CAmount value, const CConfidentialValue& conf_value, const std::vector& proof, const CConfidentialAsset& conf_asset); +bool VerifyBlindAssetProof(const uint256& asset, const std::vector& proof, const CConfidentialAsset& conf_asset); BlindProofResult VerifyBlindProofs(const PSBTOutput& o); #endif //BITCOIN_BLINDPSBT_H diff --git a/src/psbt.cpp b/src/psbt.cpp index 776b107191..1cb308f461 100644 --- a/src/psbt.cpp +++ b/src/psbt.cpp @@ -2,6 +2,7 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#include #include #include @@ -135,13 +136,29 @@ CMutableTransaction PartiallySignedTransaction::GetUnsignedTx(bool force_unblind CTxOut txout; CTxOutWitness txoutwit; txout.scriptPubKey = *output.script; - if (output.m_value_commitment.IsNull() || (output.amount != nullopt && force_unblinded)) { + + bool exp_value = output.m_value_commitment.IsNull() || force_unblinded; + exp_value = exp_value && output.amount != nullopt; + if (!output.m_value_commitment.IsNull() && output.amount != nullopt) { + exp_value = exp_value && !output.m_blind_value_proof.empty(); + exp_value = exp_value && !output.m_asset_commitment.IsNull(); + exp_value = exp_value && VerifyBlindValueProof(*output.amount, output.m_value_commitment, output.m_blind_value_proof, output.m_asset_commitment); + } + if (exp_value) { txout.nValue.SetToAmount(*output.amount); } else { txout.nValue = output.m_value_commitment; txoutwit.vchRangeproof = output.m_value_rangeproof; } - if (output.m_asset_commitment.IsNull() || (!output.m_asset.IsNull() && force_unblinded)) { + + bool exp_asset = output.m_asset_commitment.IsNull() || force_unblinded; + exp_asset = exp_asset && !output.m_asset.IsNull(); + if (!output.m_asset_commitment.IsNull() && !output.m_asset.IsNull()) { + exp_asset = exp_asset && !output.m_blind_asset_proof.empty(); + exp_asset = exp_asset && !output.m_asset.IsNull(); + exp_asset = exp_asset && VerifyBlindAssetProof(output.m_asset, output.m_blind_asset_proof, output.m_asset_commitment); + } + if (exp_asset) { txout.nAsset.SetToAsset(CAsset(output.m_asset)); } else { txout.nAsset = output.m_asset_commitment; diff --git a/test/functional/rpc_psbt.py b/test/functional/rpc_psbt.py index ec25408a41..7925a98977 100755 --- a/test/functional/rpc_psbt.py +++ b/test/functional/rpc_psbt.py @@ -717,6 +717,7 @@ class PSBTTest(BitcoinTestFramework): self.sync_all() def pset_confidential_proofs(self): + UNBLINDED = "cHNldP8BAgQCAAAAAQMEAAAAAAEEAQEBBQECAfsEAgAAAAABAP1UAQIAAAAAASopobdl5W15RSedscp/8bxEXKuKIMOZw+JTqgD8qJEKBAAAAAD9////Awrye7Xu4kI5VnpTDeGaq8sYdXP3qdzYaHrLDRzaC8y51ggl1U8hJxSo+8GcTzHv926wsqTTkOrdBnJo8qcLwLQauQKktt71EJU7HTH5HsgG4kJV/tC32F992/WgieIPRkUkmxYAFPrs/iioimRS5hoJKl/hua83d7rwC1uuuLvfuQh38wHS+0Vg2ecXzypsUabYofOFaGSrICByCKvjgT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17JIRUnAFfPgy3xKOozYazJR+oL4TLf4A8aCHngxgu34ccqa3qJty8TUMNT9QalWj4jdxj+SAonOtYwbrL+MOb8IdwXj0vwQG1gLuJKsGHDOYOTsOaJWKJAUJNQN8iqKVf+mKpL1mU7gk3J0DmSYupeSP/G1HaEq3nvCSeqq8zv9xqvVLgOjxWWO0b2ULO9I4G0G+KNLCkVjUppUWOmPRRkj1clDZ4RsyuoLSrKA0GLV/5QvJkVxw1IaldpmetkAf8BHBzZXQFQwEAAQKfB2gnitWcaAtPQd7kZosSEOcaoIpwfSeVOLVPne0FgwjwieidAZPrUgCOgtxHE6rMwuAQLcpeDvJbzHp3pWYH/ARwc2V0BiEDDGY09r3hWD27+dkFYL/whhOCenzlXlMw4QVZNMBwXakH/ARwc2V0ByECK0ZVsb9tk1xXaJ+OKa6HTgU7BGXE2s0+9rrpTr9GIcUH/ARwc2V0CAQAAAAAAAEEAAEDCADh9QUAAAAAB/wEcHNldAIgIw9PXUt8b6hFgG7k9ncTRZ4baejmD87i5JQMeg1d4bIH/ARwc2V0CAQAAAAAAA==" ## Check warnings for PSETs + stats = [output.get("status") for output in self.nodes[0].decodepsbt(UNBLINDED)["outputs"]] + assert_equal(stats, ["needs blinding", None]) + stats = [output for output in self.nodes[0].analyzepsbt(UNBLINDED)["outputs"]] + assert_equal(stats, [ + {"blind": True, "status": "unblinded" }, + {"blind": False, "status": "done" }, + ]) + for output in self.nodes[0].decodepsbt(BLINDED)["outputs"]: assert "status" not in output for output in self.nodes[0].analyzepsbt(BLINDED)["outputs"]: @@ -782,20 +791,22 @@ class PSBTTest(BitcoinTestFramework): {"blind": False, "status": "done" }, ]) - # Check that we can combine these in any combination, as they all have explicit data - assert_equal (self.nodes[0].combinepsbt([BLINDED, BLINDED]), BLINDED) - for pset1 in [ BLINDED, NO_VALUE_PROOF, BAD_VALUE_PROOF, NO_ASSET_PROOF, BAD_ASSET_PROOF ]: - for pset2 in [ BLINDED, NO_VALUE_PROOF, BAD_VALUE_PROOF, NO_ASSET_PROOF, BAD_ASSET_PROOF ]: - combo = self.nodes[0].combinepsbt([pset1, pset2]) - if combo != pset1: - assert_equal (combo, BLINDED) - - # On the other hand, none of these can be combined with the "only confidential, no - # explicit values" version - assert_equal (self.nodes[0].combinepsbt([ONLY_BLIND, ONLY_BLIND]), ONLY_BLIND) - for pset in [ BLINDED, NO_VALUE_PROOF, BAD_VALUE_PROOF, NO_ASSET_PROOF, BAD_ASSET_PROOF ]: - assert_raises_rpc_error(-8, "PSBTs not compatible (different transactions)", self.nodes[0].combinepsbt, [pset, ONLY_BLIND]) - assert_raises_rpc_error(-8, "PSBTs not compatible (different transactions)", self.nodes[0].combinepsbt, [ONLY_BLIND, pset]) + # The fully-blinded (with proofs) PSET will combine with the blinded one, + # and will copy the blinded data + assert_equal (self.nodes[0].combinepsbt([UNBLINDED, BLINDED]), BLINDED) + assert_equal (self.nodes[0].combinepsbt([BLINDED, UNBLINDED]), BLINDED) + # When combining, "bad proofs" are the same as blinded data. So these transactions + # will be interpreted as partially blinded (exp asset blind value, or vice-versa), + # and will combine accordingly. These details are not so important, but what *IS* + # important is that you cannot combine any of the bad-proof PSETs with the + # unblinded one. + self.nodes[0].combinepsbt([NO_VALUE_PROOF, BAD_VALUE_PROOF]) + self.nodes[0].combinepsbt([NO_ASSET_PROOF, BAD_ASSET_PROOF]) + assert_raises_rpc_error(-8, "PSBTs not compatible (different transactions)", self.nodes[0].combinepsbt, [BAD_VALUE_PROOF, BAD_ASSET_PROOF]) + for bad_pset in [ NO_VALUE_PROOF, BAD_VALUE_PROOF, NO_ASSET_PROOF, BAD_ASSET_PROOF ]: + assert_raises_rpc_error(-8, "PSBTs not compatible (different transactions)", self.nodes[0].combinepsbt, [UNBLINDED, bad_pset]) + assert_raises_rpc_error(-8, "PSBTs not compatible (different transactions)", self.nodes[0].combinepsbt, [ONLY_BLIND, bad_pset]) + assert_raises_rpc_error(-8, "PSBTs not compatible (different transactions)", self.nodes[0].combinepsbt, [BLINDED, bad_pset]) def run_test(self): self.nodes[0].generate(200)