From a9f589b9ecce8e0bb3f62dc2f03aea064469f147 Mon Sep 17 00:00:00 2001 From: Steven Roose Date: Wed, 12 Jun 2019 22:25:09 +0100 Subject: [PATCH] Add support for blinding pegin transactions Both via blindrawtransaction and rawblindrawtransaction. --- src/blind.cpp | 4 ++-- src/rpc/rawtransaction.cpp | 14 ++++++++++++++ src/wallet/rpcwallet.cpp | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/blind.cpp b/src/blind.cpp index 5f465f1e1d..e723ecbb27 100644 --- a/src/blind.cpp +++ b/src/blind.cpp @@ -530,7 +530,7 @@ int BlindTransaction(std::vector& input_value_blinding_factors, const // abort and not blind and the math adds up. // Count as success(to signal caller that nothing wrong) and return early if (memcmp(diff_zero, &blind[num_blind_attempts-1][0], 32) == 0) { - return ++num_blinded; + return ++num_blinded; } } @@ -539,7 +539,7 @@ int BlindTransaction(std::vector& input_value_blinding_factors, const out_val_blind_factors[nOut] = uint256(std::vector(value_blindptrs[value_blindptrs.size()-1], value_blindptrs[value_blindptrs.size()-1]+32)); out_asset_blind_factors[nOut] = uint256(std::vector(asset_blindptrs[asset_blindptrs.size()-1], asset_blindptrs[asset_blindptrs.size()-1]+32)); - //Blind the asset ID + // Blind the asset ID BlindAsset(conf_asset, asset_gen, asset, asset_blindptrs.back()); // Create value commitment diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 9003385d2c..684217eca4 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -2248,6 +2248,20 @@ UniValue rawblindrawtransaction(const JSONRPCRequest& request) std::vector output_assets; std::vector output_pubkeys; for (size_t nIn = 0; nIn < tx.vin.size(); nIn++) { + // Special handling for pegin inputs: no blinds and explicit amount/asset. + if (tx.vin[nIn].m_is_pegin) { + std::string err; + if (tx.witness.vtxinwit.size() != tx.vin.size() || !IsValidPeginWitness(tx.witness.vtxinwit[nIn].m_pegin_witness, tx.vin[nIn].prevout, err, false)) { + throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Transaction contains invalid peg-in input: %s", err)); + } + CTxOut pegin_output = GetPeginOutputFromWitness(tx.witness.vtxinwit[nIn].m_pegin_witness); + input_blinds.push_back(uint256()); + input_asset_blinds.push_back(uint256()); + input_assets.push_back(pegin_output.nAsset.GetAsset()); + input_amounts.push_back(pegin_output.nValue.GetAmount()); + continue; + } + if (!inputBlinds[nIn].isStr()) throw JSONRPCError(RPC_INVALID_PARAMETER, "input blinds must be an array of hex strings"); if (!inputAssetBlinds[nIn].isStr()) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 16abc05e40..16c9028a09 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5778,6 +5778,20 @@ UniValue blindrawtransaction(const JSONRPCRequest& request) for (size_t nIn = 0; nIn < tx.vin.size(); ++nIn) { COutPoint prevout = tx.vin[nIn].prevout; + // Special handling for pegin inputs: no blinds and explicit amount/asset. + if (tx.vin[nIn].m_is_pegin) { + std::string err; + if (tx.witness.vtxinwit.size() != tx.vin.size() || !IsValidPeginWitness(tx.witness.vtxinwit[nIn].m_pegin_witness, prevout, err, false)) { + throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Transaction contains invalid peg-in input: %s", err)); + } + CTxOut pegin_output = GetPeginOutputFromWitness(tx.witness.vtxinwit[nIn].m_pegin_witness); + input_blinds.push_back(uint256()); + input_asset_blinds.push_back(uint256()); + input_assets.push_back(pegin_output.nAsset.GetAsset()); + input_amounts.push_back(pegin_output.nValue.GetAmount()); + continue; + } + std::map::iterator it = pwallet->mapWallet.find(prevout.hash); if (it == pwallet->mapWallet.end() || pwallet->IsMine(tx.vin[nIn]) == ISMINE_NO) { // For inputs we don't own, input assetcommitments for the surjection must be supplied.