@@ -386,99 +386,54 @@ BlindingStatus BlindPSBT(PartiallySignedTransaction& psbt, std::map<uint32_t, st
386
386
}
387
387
388
388
// Handle issuances
389
- if (input.m_issuance_value ) {
390
- if (!input.m_issuance_value_commitment .IsCommitment () && input.m_issuance_rangeproof .size () == 0 && input.m_issuance_inflation_keys_rangeproof .size () == 0 ) {
391
- CAsset issuance_asset;
392
- CAsset reissuance_asset;
393
-
394
- uint256 entropy;
395
- if (!input.m_issuance_blinding_nonce .IsNull ()) {
396
- // Reissuance, use assetEntropy as the asset entropy
397
- entropy = input.m_issuance_asset_entropy ;
398
- } else {
399
- // New issuance, make new entropy
400
- GenerateAssetEntropy (entropy, input.GetOutPoint (), input.m_issuance_asset_entropy );
401
- }
389
+ if (input.m_issuance_value != std::nullopt || input.m_issuance_value_commitment .IsCommitment () || input.m_issuance_inflation_keys_amount != std::nullopt || input.m_issuance_inflation_keys_commitment .IsCommitment ()) {
390
+ CAsset issuance_asset;
391
+ CAsset reissuance_asset;
392
+
393
+ uint256 entropy;
394
+ if (!input.m_issuance_blinding_nonce .IsNull ()) {
395
+ // Reissuance, use assetEntropy as the asset entropy
396
+ entropy = input.m_issuance_asset_entropy ;
397
+ } else {
398
+ // New issuance, make new entropy
399
+ GenerateAssetEntropy (entropy, input.GetOutPoint (), input.m_issuance_asset_entropy );
400
+ }
402
401
402
+ if (input.m_issuance_value != std::nullopt || input.m_issuance_value_commitment .IsCommitment ()) {
403
403
// Asset isn't blinded yet. Add it to the list of input assets
404
404
CalculateAsset (issuance_asset, entropy);
405
405
fixed_input_tags.emplace_back ();
406
406
memcpy (fixed_input_tags.back ().data , issuance_asset.begin (), 32 );
407
407
ephemeral_input_tags.emplace_back ();
408
- if (secp256k1_generator_generate (secp256k1_blind_context, &ephemeral_input_tags.back (), issuance_asset.begin ()) != 1 ) {
409
- return BlindingStatus::INVALID_ASSET;
408
+ if (input.m_issuance_value_commitment .IsNull ()) {
409
+ if (secp256k1_generator_generate (secp256k1_blind_context, &ephemeral_input_tags.back (), issuance_asset.begin ()) != 1 ) {
410
+ return BlindingStatus::INVALID_ASSET;
411
+ }
410
412
}
411
- unsigned int iss_to_blind = 1 ; // Always do the first issuance blinding iteration for the issuance value
413
+ else {
414
+ memcpy (ephemeral_input_tags.back ().data , input.m_issuance_value_commitment .vchCommitment .data (), 33 );
415
+ }
416
+ input_asset_blinders.emplace_back ();
417
+ }
412
418
413
- bool blind_issuance = our_issuances_to_blind. count (i) > 0 ;
419
+ bool blind_issuance = input. m_issuance_value_commitment . IsCommitment () ;
414
420
415
- if (input.m_issuance_blinding_nonce .IsNull () && input.m_issuance_inflation_keys_amount ) {
416
- // New issuance, do reissuance token things
417
- CalculateReissuanceToken (reissuance_asset, entropy, blind_issuance);
418
- // Add the reissuance_asset to the list of input assets
419
- fixed_input_tags.emplace_back ();
420
- memcpy (fixed_input_tags.back ().data , reissuance_asset.begin (), 32 );
421
- ephemeral_input_tags.emplace_back ();
421
+ if (input.m_issuance_blinding_nonce .IsNull () && (input.m_issuance_inflation_keys_amount != std::nullopt || input.m_issuance_inflation_keys_commitment .IsCommitment ())) {
422
+ // New issuance, do reissuance token things
423
+ CalculateReissuanceToken (reissuance_asset, entropy, blind_issuance);
424
+ // Add the reissuance_asset to the list of input assets
425
+ fixed_input_tags.emplace_back ();
426
+ memcpy (fixed_input_tags.back ().data , reissuance_asset.begin (), 32 );
427
+ ephemeral_input_tags.emplace_back ();
428
+ if (input.m_issuance_inflation_keys_commitment .IsNull ()) {
422
429
if (secp256k1_generator_generate (secp256k1_blind_context, &ephemeral_input_tags.back (), reissuance_asset.begin ()) != 1 ) {
423
430
return BlindingStatus::INVALID_ASSET;
424
431
}
425
- iss_to_blind++; // If we have a reissuance, do the second blinding iteration for the inflation keys
426
- }
427
-
428
- if (blind_issuance) {
429
- for (unsigned int blind_i = 0 ; blind_i < iss_to_blind; ++blind_i) {
430
- // To blind an issuance, both the issuance value and the number of inflation keys need to be blinded
431
- // Since this process is basically the same for both, do it in a loop and switch based on the index
432
- bool blind_value = blind_i == 0 ; // True for blinding the value, false for blinding the inflation keys
433
- CAmount value = blind_value ? *input.m_issuance_value : *input.m_issuance_inflation_keys_amount ;
434
- CAsset asset = blind_value ? issuance_asset : reissuance_asset;
435
- CKey blinding_privkey = blind_value ? our_issuances_to_blind.at (i).first : our_issuances_to_blind.at (i).second ;
436
-
437
- uint256 value_blinder;
438
- GetStrongRandBytes (value_blinder.begin (), value_blinder.size ());
439
-
440
- // Create unblinded generator. Throw away everything except asset_gen
441
- uint256 asset_blinder;
442
- CConfidentialAsset conf_asset;
443
- secp256k1_generator asset_gen;
444
- CreateAssetCommitment (conf_asset, asset_gen, asset, asset_blinder);
445
- input_asset_blinders.push_back (asset_blinder);
446
-
447
- // Compute the scalar for this blinding and add to the input scalar
448
- if (!ComputeAndAddToScalarOffset (input_scalar, value, asset_blinder, value_blinder)) return BlindingStatus::SCALAR_UNABLE;
449
-
450
- // Create value commitment
451
- secp256k1_pedersen_commitment value_commit;
452
- CConfidentialValue conf_value;
453
- CreateValueCommitment (conf_value, value_commit, value_blinder, asset_gen, value);
454
-
455
- // Nonce is the blinding key
456
- uint256 nonce = uint256 (std::vector<unsigned char >(blinding_privkey.begin (), blinding_privkey.end ()));
457
-
458
- // Generate rangeproof
459
- std::vector<unsigned char > rangeproof;
460
- bool rangeresult = CreateValueRangeProof (rangeproof, value_blinder, nonce, value, CScript (), value_commit, asset_gen, asset, asset_blinder);
461
- assert (rangeresult);
462
-
463
- // Create explicit value rangeproofs
464
- std::vector<unsigned char > blind_value_proof;
465
- rangeresult = CreateBlindValueProof (blind_value_proof, value_blinder, value, value_commit, asset_gen);
466
- assert (rangeresult);
467
-
468
- if (blind_value) {
469
- input.m_issuance_value_commitment = conf_value;
470
- input.m_issuance_rangeproof = rangeproof;
471
- input.m_blind_issuance_value_proof = blind_value_proof;
472
- } else {
473
- input.m_issuance_inflation_keys_commitment = conf_value;
474
- input.m_issuance_inflation_keys_rangeproof = rangeproof;
475
- input.m_blind_issuance_inflation_keys_proof = blind_value_proof;
476
- }
477
- }
478
432
}
479
- else {
480
- input_asset_blinders. emplace_back ( );
433
+ else if (input. m_issuance_inflation_keys_commitment . IsCommitment ()) {
434
+ memcpy (ephemeral_input_tags. back (). data , input. m_issuance_inflation_keys_commitment . vchCommitment . data (), 33 );
481
435
}
436
+ input_asset_blinders.emplace_back ();
482
437
}
483
438
}
484
439
}
0 commit comments