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

Function VerifyAmounts

src/confidential_validation.cpp:135–410  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

133}
134
135bool VerifyAmounts(const std::vector<CTxOut>& inputs, const CTransaction& tx, std::vector<CCheck*>* checks, const bool store_result) {
136 assert(!tx.IsCoinBase());
137 assert(inputs.size() == tx.vin.size());
138
139 std::vector<secp256k1_pedersen_commitment> vData;
140 std::vector<secp256k1_pedersen_commitment *> vpCommitsIn, vpCommitsOut;
141
142 vData.reserve((tx.vin.size() + tx.vout.size() + GetNumIssuances(tx)));
143 secp256k1_pedersen_commitment *p = vData.data();
144 secp256k1_pedersen_commitment commit;
145 secp256k1_generator gen;
146 // This is used to add in the explicit values
147 unsigned char explicit_blinds[32] = {0};
148 int ret;
149
150 uint256 wtxid(tx.GetWitnessHash());
151
152 // This list is used to verify surjection proofs.
153 // Proofs must be constructed with the list being in
154 // order of input and non-null issuance pseudo-inputs, with
155 // input first, asset issuance second, reissuance token third.
156 std::vector<secp256k1_generator> target_generators;
157 target_generators.reserve(tx.vin.size() + GetNumIssuances(tx));
158
159 // Tally up value commitments, check balance
160 for (size_t i = 0; i < tx.vin.size(); ++i) {
161 const CConfidentialValue& val = inputs[i].nValue;
162 const CConfidentialAsset& asset = inputs[i].nAsset;
163
164 if (val.IsNull() || asset.IsNull())
165 return false;
166
167 if (asset.IsExplicit()) {
168 ret = secp256k1_generator_generate(secp256k1_ctx_verify_amounts, &gen, asset.GetAsset().begin());
169 assert(ret != 0);
170 }
171 else if (asset.IsCommitment()) {
172 if (secp256k1_generator_parse(secp256k1_ctx_verify_amounts, &gen, &asset.vchCommitment[0]) != 1)
173 return false;
174 }
175 else {
176 return false;
177 }
178
179 target_generators.push_back(gen);
180
181 if (val.IsExplicit()) {
182 if (!MoneyRange(val.GetAmount()))
183 return false;
184
185 // Fails if val.GetAmount() == 0
186 if (secp256k1_pedersen_commit(secp256k1_ctx_verify_amounts, &commit, explicit_blinds, val.GetAmount(), &gen) != 1)
187 return false;
188 } else if (val.IsCommitment()) {
189 if (secp256k1_pedersen_commitment_parse(secp256k1_ctx_verify_amounts, &commit, &val.vchCommitment[0]) != 1)
190 return false;
191 } else {
192 return false;

Callers 3

SignPSBTMethod · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85
CheckTxInputsMethod · 0.85

Calls 15

GetNumIssuancesFunction · 0.85
GenerateAssetEntropyFunction · 0.85
CalculateAssetFunction · 0.85
CalculateReissuanceTokenFunction · 0.85
VerifyIssuanceAmountFunction · 0.85
QueueCheckFunction · 0.85
IsExplicitMethod · 0.80
GetAssetMethod · 0.80
IsCommitmentMethod · 0.80
GetAmountMethod · 0.80
IsUnspendableMethod · 0.80

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.68