| 38 | static Blind_ECC_Init ecc_init_on_load; |
| 39 | |
| 40 | bool VerifyConfidentialPair(const CConfidentialValue& conf_value, const CConfidentialAsset& conf_asset, const CAmount& claimed_value, const CAsset& claimed_asset, const uint256& value_blinding_factor, const uint256& asset_blinding_factor) { |
| 41 | if (conf_value.IsNull() || conf_asset.IsNull() || claimed_asset.IsNull()) { |
| 42 | return false; |
| 43 | } |
| 44 | |
| 45 | if (conf_value.IsExplicit()) { |
| 46 | // Match behavior of UnblindConfidentialPair |
| 47 | return false; |
| 48 | } |
| 49 | if (conf_asset.IsExplicit() && conf_asset.GetAsset() != claimed_asset) { |
| 50 | return false; |
| 51 | } |
| 52 | |
| 53 | // Just to be safe |
| 54 | if (!MoneyRange(claimed_value)) { |
| 55 | return false; |
| 56 | } |
| 57 | |
| 58 | // Valid asset commitment? |
| 59 | secp256k1_generator observed_gen; |
| 60 | if (conf_asset.IsCommitment()) { |
| 61 | if (secp256k1_generator_parse(secp256k1_blind_context, &observed_gen, &conf_asset.vchCommitment[0]) != 1) |
| 62 | return false; |
| 63 | } else if (conf_asset.IsExplicit()) { |
| 64 | if (secp256k1_generator_generate(secp256k1_blind_context, &observed_gen, conf_asset.GetAsset().begin()) != 1) |
| 65 | return false; |
| 66 | } |
| 67 | |
| 68 | // Valid value commitment? |
| 69 | secp256k1_pedersen_commitment value_commit; |
| 70 | if (secp256k1_pedersen_commitment_parse(secp256k1_blind_context, &value_commit, conf_value.vchCommitment.data()) != 1) { |
| 71 | return false; |
| 72 | } |
| 73 | |
| 74 | const unsigned char *asset_type = claimed_asset.id.begin(); |
| 75 | const unsigned char *asset_blinder = asset_blinding_factor.begin(); |
| 76 | secp256k1_generator recalculated_gen; |
| 77 | if (secp256k1_generator_generate_blinded(secp256k1_blind_context, &recalculated_gen, asset_type, asset_blinder) != 1) { |
| 78 | return false; |
| 79 | } |
| 80 | |
| 81 | // Serialize both generators then compare |
| 82 | unsigned char observed_generator[33]; |
| 83 | unsigned char derived_generator[33]; |
| 84 | secp256k1_generator_serialize(secp256k1_blind_context, observed_generator, &observed_gen); |
| 85 | secp256k1_generator_serialize(secp256k1_blind_context, derived_generator, &recalculated_gen); |
| 86 | if (memcmp(observed_generator, derived_generator, sizeof(observed_generator))) { |
| 87 | return false; |
| 88 | } |
| 89 | |
| 90 | const unsigned char *value_blinder = value_blinding_factor.begin(); |
| 91 | secp256k1_pedersen_commitment recalculated_commit; |
| 92 | if(secp256k1_pedersen_commit(secp256k1_blind_context, &recalculated_commit, value_blinder, claimed_value, &observed_gen) != 1) { |
| 93 | return false; |
| 94 | } |
| 95 | |
| 96 | // Serialize both value commitments then compare |
| 97 | unsigned char claimed_commitment[33]; |
nothing calls this directly
no test coverage detected