MCPcopy Create free account
hub / github.com/ElementsProject/elements / VerifyIssuanceAmount

Function VerifyIssuanceAmount

src/confidential_validation.cpp:93–133  ·  view source on GitHub ↗

Helper function for VerifyAmount(), not exported

Source from the content-addressed store, hash-verified

91
92// Helper function for VerifyAmount(), not exported
93static bool VerifyIssuanceAmount(secp256k1_pedersen_commitment& value_commit, secp256k1_generator& asset_gen,
94 const CAsset& asset, const CConfidentialValue& value, const std::vector<unsigned char>& rangeproof,
95 std::vector<CCheck*>* checks, const bool store_result)
96{
97 // This is used to add in the explicit values
98 unsigned char explicit_blinds[32];
99 memset(explicit_blinds, 0, sizeof(explicit_blinds));
100 int ret;
101
102 ret = secp256k1_generator_generate(secp256k1_ctx_verify_amounts, &asset_gen, asset.begin());
103 assert(ret == 1);
104
105 // Build value commitment
106 if (value.IsExplicit()) {
107 if ((asset == Params().GetConsensus().pegged_asset && !MoneyRange(value.GetAmount())) || value.GetAmount() <= 0) {
108 return false;
109 }
110 if (!rangeproof.empty()) {
111 return false;
112 }
113
114 ret = secp256k1_pedersen_commit(secp256k1_ctx_verify_amounts, &value_commit, explicit_blinds, value.GetAmount(), &asset_gen);
115 // The explicit_blinds are all 0, and the amount is not 0. So secp256k1_pedersen_commit does not fail.
116 assert(ret == 1);
117 } else if (value.IsCommitment()) {
118 // Verify range proof
119 std::vector<unsigned char> vchAssetCommitment(CConfidentialAsset::nExplicitSize);
120 secp256k1_generator_serialize(secp256k1_ctx_verify_amounts, vchAssetCommitment.data(), &asset_gen);
121 if (QueueCheck(checks, new CRangeCheck(&value, rangeproof, vchAssetCommitment, CScript(), store_result)) != SCRIPT_ERR_OK) {
122 return false;
123 }
124
125 if (secp256k1_pedersen_commitment_parse(secp256k1_ctx_verify_amounts, &value_commit, value.vchCommitment.data()) != 1) {
126 return false;
127 }
128 } else {
129 return false;
130 }
131
132 return true;
133}
134
135bool VerifyAmounts(const std::vector<CTxOut>& inputs, const CTransaction& tx, std::vector<CCheck*>* checks, const bool store_result) {
136 assert(!tx.IsCoinBase());

Callers 1

VerifyAmountsFunction · 0.85

Calls 14

QueueCheckFunction · 0.85
IsExplicitMethod · 0.80
GetAmountMethod · 0.80
IsCommitmentMethod · 0.80
ParamsClass · 0.70
MoneyRangeFunction · 0.70
CScriptClass · 0.70
beginMethod · 0.45

Tested by

no test coverage detected