@@ -34,33 +34,32 @@ const secp256k1_context* ECC_Blinding_Context() {
3434 return secp256k1_blind_context;
3535}
3636
37- int UnblindOutput (const CKey &key, const CTxOut& txout, CAmount& amount_out, std::vector< unsigned char > & blinding_factor_out)
37+ bool UnblindOutput (const CKey &key, const CTxOut& txout, CAmount& amount_out, uint256 & blinding_factor_out)
3838{
39- if (txout.nValue .IsAmount ()) {
40- amount_out = txout.nValue .GetAmount ();
41- blinding_factor_out.resize (0 );
42- return -1 ;
39+ if (!key.IsValid ()) {
40+ return false ;
4341 }
4442 CPubKey ephemeral_key (txout.nValue .vchNonceCommitment );
4543 if (!ephemeral_key.IsValid ()) {
46- return 0 ;
44+ return false ;
4745 }
4846 uint256 nonce = key.ECDH (ephemeral_key);
4947 CSHA256 ().Write (nonce.begin (), 32 ).Finalize (nonce.begin ());
5048 unsigned char msg[4096 ];
5149 int msg_size;
5250 uint64_t min_value, max_value, amount;
53- blinding_factor_out.resize (32 );
54- int res = secp256k1_rangeproof_rewind (secp256k1_blind_context, &blinding_factor_out[0 ], &amount, msg, &msg_size, nonce.begin (), &min_value, &max_value, &txout.nValue .vchCommitment [0 ], &txout.nValue .vchRangeproof [0 ], txout.nValue .vchRangeproof .size ());
51+ int res = secp256k1_rangeproof_rewind (secp256k1_blind_context, blinding_factor_out.begin (), &amount, msg, &msg_size, nonce.begin (), &min_value, &max_value, &txout.nValue .vchCommitment [0 ], &txout.nValue .vchRangeproof [0 ], txout.nValue .vchRangeproof .size ());
5552 if (!res || amount > (uint64_t )MAX_MONEY || !MoneyRange ((CAmount)amount)) {
5653 amount_out = 0 ;
57- blinding_factor_out.resize (0 );
58- } else
54+ blinding_factor_out = uint256 ();
55+ return false ;
56+ } else {
5957 amount_out = (CAmount)amount;
60- return res ? 1 : 0 ;
58+ return true ;
59+ }
6160}
6261
63- void BlindOutputs (const std::vector<std::vector< unsigned char > > & input_blinding_factors, const std::vector<std::vector< unsigned char > >& output_blinding_factors, const std::vector<CPubKey>& output_pubkeys, CMutableTransaction& tx)
62+ void BlindOutputs (const std::vector<uint256 > & input_blinding_factors, const std::vector<uint256 >& output_blinding_factors, const std::vector<CPubKey>& output_pubkeys, CMutableTransaction& tx)
6463{
6564 assert (tx.vout .size () == output_blinding_factors.size ());
6665 assert (tx.vout .size () == output_pubkeys.size ());
@@ -71,20 +70,19 @@ void BlindOutputs(const std::vector<std::vector<unsigned char> >& input_blinding
7170
7271 int nBlindsIn = 0 ;
7372 for (size_t nIn = 0 ; nIn < tx.vin .size (); nIn++) {
74- if (input_blinding_factors[nIn]. size () != 0 ) {
73+ if (input_blinding_factors[nIn] != uint256 () ) {
7574 assert (input_blinding_factors[nIn].size () == 32 );
76- blindptrs.push_back (& input_blinding_factors[nIn][ 0 ] );
75+ blindptrs.push_back (input_blinding_factors[nIn]. begin () );
7776 nBlindsIn++;
7877 }
7978 }
8079
8180 int nBlindsOut = 0 ;
8281 int nToBlind = 0 ;
8382 for (size_t nOut = 0 ; nOut < tx.vout .size (); nOut++) {
84- assert ((output_blinding_factors[nOut].size () != 0 ) == !tx.vout [nOut].nValue .IsAmount ());
85- if (output_blinding_factors[nOut].size () != 0 ) {
86- assert (output_blinding_factors[nOut].size () == 32 );
87- blindptrs.push_back (&output_blinding_factors[nOut][0 ]);
83+ assert ((output_blinding_factors[nOut] != uint256 ()) == !tx.vout [nOut].nValue .IsAmount ());
84+ if (output_blinding_factors[nOut] != uint256 ()) {
85+ blindptrs.push_back (output_blinding_factors[nOut].begin ());
8886 nBlindsOut++;
8987 } else {
9088 if (output_pubkeys[nOut].IsValid ()) {
@@ -98,7 +96,7 @@ void BlindOutputs(const std::vector<std::vector<unsigned char> >& input_blinding
9896 }
9997
10098 int nBlinded = 0 ;
101- unsigned char blind[nToBlind ][32 ];
99+ unsigned char blind[tx. vout . size () ][32 ];
102100
103101 for (size_t nOut = 0 ; nOut < tx.vout .size (); nOut++) {
104102 if (tx.vout [nOut].nValue .IsAmount () && output_pubkeys[nOut].IsValid ()) {
0 commit comments