Skip to content

Commit

Permalink
Merge #846: [RFC] Remove GetNumIssuance from BlindTransaction assert
Browse files Browse the repository at this point in the history
34ef250 Move GetNumIssuances to issuance.cpp (Steven Roose)
f992585 Remove the GetNumIssuances in the assertion (Steven Roose)

Pull request description:

  This is in response to @dgpv 's #842.

  I'm not 100% confident this is correct, but it seems so. It also passed all tests on my machine.

Tree-SHA512: 65206ac5e464a222b379043ca7943e9764382d25db6afc3ade89a1c637404c9f902d9ac21e1671722f1a29592a135b69c2c9164932958929d6a6588a12a14ac2
  • Loading branch information
stevenroose committed Apr 1, 2020
2 parents b47d087 + 34ef250 commit 51f62dc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
20 changes: 2 additions & 18 deletions src/blind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,28 +206,12 @@ void CreateValueCommitment(CConfidentialValue& conf_value, secp256k1_pedersen_co
assert(conf_value.IsValid());
}

size_t GetNumIssuances(const CTransaction& tx)
{
unsigned int num_issuances = 0;
for (unsigned int i = 0; i < tx.vin.size(); i++) {
if (!tx.vin[i].assetIssuance.IsNull()) {
if (!tx.vin[i].assetIssuance.nAmount.IsNull()) {
num_issuances++;
}
if (!tx.vin[i].assetIssuance.nInflationKeys.IsNull()) {
num_issuances++;
}
}
}
return num_issuances;
}

int BlindTransaction(std::vector<uint256 >& input_value_blinding_factors, const std::vector<uint256 >& input_asset_blinding_factors, const std::vector<CAsset >& input_assets, const std::vector<CAmount >& input_amounts, std::vector<uint256 >& out_val_blind_factors, std::vector<uint256 >& out_asset_blind_factors, const std::vector<CPubKey>& output_pubkeys, const std::vector<CKey>& issuance_blinding_privkey, const std::vector<CKey>& token_blinding_privkey, CMutableTransaction& tx, std::vector<std::vector<unsigned char> >* auxiliary_generators)
{
// Sanity check input data and output_pubkey size, clear other output data
assert(tx.vout.size() >= output_pubkeys.size());
assert(tx.vin.size()+GetNumIssuances(CTransaction(tx)) >= issuance_blinding_privkey.size());
assert(tx.vin.size()+GetNumIssuances(CTransaction(tx)) >= token_blinding_privkey.size());
assert(tx.vin.size() >= issuance_blinding_privkey.size());
assert(tx.vin.size() >= token_blinding_privkey.size());
out_val_blind_factors.clear();
out_val_blind_factors.resize(tx.vout.size());
out_asset_blind_factors.clear();
Expand Down
2 changes: 0 additions & 2 deletions src/blind.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,4 @@ int BlindTransaction(std::vector<uint256 >& input_value_blinding_factors, const
*/
void RawFillBlinds(CMutableTransaction& tx, std::vector<uint256>& output_value_blinds, std::vector<uint256>& output_asset_blinds, std::vector<CPubKey>& output_pubkeys);

size_t GetNumIssuances(const CTransaction& tx);

#endif //BITCOIN_BLIND_H
16 changes: 16 additions & 0 deletions src/issuance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@
#include <primitives/transaction.h>
#include <amount.h>

size_t GetNumIssuances(const CTransaction& tx)
{
unsigned int num_issuances = 0;
for (unsigned int i = 0; i < tx.vin.size(); i++) {
if (!tx.vin[i].assetIssuance.IsNull()) {
if (!tx.vin[i].assetIssuance.nAmount.IsNull()) {
num_issuances++;
}
if (!tx.vin[i].assetIssuance.nInflationKeys.IsNull()) {
num_issuances++;
}
}
}
return num_issuances;
}

void GenerateAssetEntropy(uint256& entropy, const COutPoint& prevout, const uint256& contracthash)
{
// E : entropy
Expand Down
5 changes: 5 additions & 0 deletions src/issuance.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
#include <hash.h>
#include <consensus/merkle.h>

/**
* Get the number of issuances in the given transaction.
*/
size_t GetNumIssuances(const CTransaction& tx);

/**
* Calculate the asset entropy from an COutPoint and a tx-author specified
* Ricardian contract. See Definition 18 of the confidential assets paper.
Expand Down

0 comments on commit 51f62dc

Please sign in to comment.