Skip to content

Commit

Permalink
Merge ElementsProject#661: Don't assert on user-inputed values
Browse files Browse the repository at this point in the history
f9d159b Don't assert on user-inputed values (Steven Roose)

Pull request description:

  This prevents the assertion from crashing the node when an RPC user
  enters invalid blinding factors.

  Fixes ElementsProject#540.

Tree-SHA512: d68787edb9919a3a55b94884180700854941c5f273c2ac07f534bd0a3981f163fa26c8cef931001bc9906d6c74a58cdc0148eb7d53d3edbedf005a0be7c60c5b
  • Loading branch information
instagibbs committed Jun 21, 2019
2 parents c977f2b + f9d159b commit a409d01
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/blind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,10 @@ int BlindTransaction(std::vector<uint256 >& input_value_blinding_factors, const
}
} else {
ret = secp256k1_generator_generate_blinded(secp256k1_blind_context, &target_asset_generators[totalTargets], input_assets[i].begin(), input_asset_blinding_factors[i].begin());
assert(ret == 1);
if (ret != 1) {
// Possibly invalid blinding factor provided by user.
return -1;
}
}
memcpy(&surjection_targets[totalTargets], input_assets[i].begin(), 32);
target_asset_blinders.push_back(input_asset_blinding_factors[i]);
Expand Down Expand Up @@ -519,7 +522,10 @@ int BlindTransaction(std::vector<uint256 >& input_value_blinding_factors, const

// Generate value we intend to insert
ret = secp256k1_pedersen_blind_generator_blind_sum(secp256k1_blind_context, &blinded_amounts[0], &asset_blindptrs[0], &value_blindptrs[0], num_blind_attempts + num_known_input_blinds, num_issuance_blind_attempts + num_known_input_blinds);
assert(ret);
if (!ret) {
// Possibly invalid blinding factor provided by user.
return -1;
}

// Resulting blinding factor can sometimes be 0
// where inputs are the negations of each other
Expand Down
5 changes: 5 additions & 0 deletions test/functional/feature_confidential_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,11 @@ def run_test(self):
except JSONRPCException:
pass

# Make sure RPC throws when an invalid blinding factor is provided.
bad_blinder = 'FF'*32
assert_raises_rpc_error(-8, "Unable to blind transaction: Are you sure each asset type to blind is represented in the inputs?", self.nodes[0].rawblindrawtransaction, rawtx, [unspent[0]["amountblinder"], bad_blinder], [unspent[0]["amount"], unspent[1]["amount"]], [unspent[0]["asset"], unspent[1]["asset"]], [unspent[0]["assetblinder"], unspent[1]["assetblinder"]])
assert_raises_rpc_error(-8, "Unable to blind transaction: Are you sure each asset type to blind is represented in the inputs?", self.nodes[0].rawblindrawtransaction, rawtx, [unspent[0]["amountblinder"], unspent[1]["amountblinder"]], [unspent[0]["amount"], unspent[1]["amount"]], [unspent[0]["asset"], unspent[1]["asset"]], [unspent[0]["assetblinder"], bad_blinder])

blindtx = self.nodes[0].rawblindrawtransaction(rawtx, [unspent[0]["amountblinder"], unspent[1]["amountblinder"]], [unspent[0]["amount"], unspent[1]["amount"]], [unspent[0]["asset"], unspent[1]["asset"]], [unspent[0]["assetblinder"], unspent[1]["assetblinder"]])
signtx = self.nodes[0].signrawtransactionwithwallet(blindtx)
txid = self.nodes[0].sendrawtransaction(signtx["hex"])
Expand Down

0 comments on commit a409d01

Please sign in to comment.