@@ -25,9 +25,8 @@ namespace cbdc::transaction {
25
25
26
26
auto output::operator ==(const output& rhs) const -> bool {
27
27
return m_witness_program_commitment == rhs.m_witness_program_commitment
28
- && m_id == rhs.m_id && m_nonce == rhs.m_nonce
29
- && m_auxiliary == rhs.m_auxiliary && m_range == rhs.m_range
30
- && m_consistency == rhs.m_consistency ;
28
+ && m_id == rhs.m_id && m_auxiliary == rhs.m_auxiliary
29
+ && m_range == rhs.m_range ;
31
30
}
32
31
33
32
auto output::operator !=(const output& rhs) const -> bool {
@@ -37,21 +36,18 @@ namespace cbdc::transaction {
37
36
compact_output::compact_output (const output& put)
38
37
: m_id(put.m_id),
39
38
m_auxiliary (put.m_auxiliary),
40
- m_range(put.m_range),
41
- m_consistency(put.m_consistency) {}
39
+ m_range(put.m_range) {}
42
40
43
41
compact_output::compact_output (const hash_t & id,
44
42
const commitment_t & aux,
45
- const rangeproof_t <>& range,
46
- const signature_t & consist)
43
+ const rangeproof_t <>& range)
47
44
: m_id(id),
48
45
m_auxiliary(aux),
49
- m_range(range),
50
- m_consistency(consist) {}
46
+ m_range(range) {}
51
47
52
48
auto compact_output::operator ==(const compact_output& rhs) const -> bool {
53
49
return m_id == rhs.m_id && m_auxiliary == rhs.m_auxiliary
54
- && m_range == rhs.m_range && m_consistency == rhs. m_consistency ;
50
+ && m_range == rhs.m_range ;
55
51
}
56
52
57
53
auto compact_output::operator !=(const compact_output& rhs) const -> bool {
@@ -151,6 +147,18 @@ namespace cbdc::transaction {
151
147
return buf;
152
148
}
153
149
150
+ auto output_nested_hash (const out_point& point, const output& put)
151
+ -> hash_t {
152
+ auto buf = output_preimage (point, put);
153
+ CSHA256 sha;
154
+ sha.Write (buf.data (), buf.size ());
155
+
156
+ hash_t res{};
157
+ sha.Finalize (res.data ());
158
+
159
+ return res;
160
+ }
161
+
154
162
auto output_randomness (
155
163
std::array<unsigned char ,
156
164
sizeof (compact_tx::m_id) + sizeof(out_point::m_index)
@@ -195,6 +203,21 @@ namespace cbdc::transaction {
195
203
return calculate_uhs_id (ctx, rng, buf, value);
196
204
}
197
205
206
+ auto calculate_uhs_id (const out_point& point,
207
+ const output& put,
208
+ const commitment_t & value) -> hash_t {
209
+ auto buf = output_nested_hash (point, put);
210
+
211
+ CSHA256 sha;
212
+ sha.Write (buf.data (), buf.size ());
213
+ sha.Write (value.data (), value.size ());
214
+
215
+ hash_t id{};
216
+ sha.Finalize (id.data ());
217
+
218
+ return id;
219
+ }
220
+
198
221
auto roll_auxiliaries (secp256k1_context* ctx,
199
222
random_source& rng,
200
223
const std::vector<hash_t >& blinds,
@@ -261,43 +284,10 @@ namespace cbdc::transaction {
261
284
const out_point& point,
262
285
const spend_data& out_spend_data,
263
286
const secp256k1_pedersen_commitment* auxiliary) -> bool {
264
- const auto out_preimage = output_preimage (point, put);
265
- auto [uhs, nonce]
266
- = calculate_uhs_id (ctx, rng, out_preimage, out_spend_data.m_value );
267
-
268
- put.m_id = uhs;
269
- put.m_nonce = nonce;
270
-
271
- // manually derive the secret key
272
- auto esk = output_randomness (out_preimage, nonce);
273
- auto rprime = out_spend_data.m_blind ;
274
- [[maybe_unused]] auto ret
275
- = secp256k1_ec_seckey_negate (ctx, rprime.data ());
276
- // fails when rprime == 0 (which is fine)
277
- ret = secp256k1_ec_seckey_tweak_add (ctx, esk.data (), rprime.data ());
278
- assert (ret == 1 );
279
-
280
- secp256k1_keypair kp{};
281
- ret = secp256k1_keypair_create (ctx, &kp, esk.data ());
282
- assert (ret == 1 );
283
-
284
- auto consistency = signature_t {};
285
- std::array<unsigned char , hash_size> consist_contents{
286
- " consistent proof" };
287
- ret = secp256k1_schnorrsig_sign (ctx,
288
- consistency.data (),
289
- consist_contents.data (),
290
- &kp,
291
- nullptr ,
292
- nullptr );
293
- assert (ret == 1 );
294
-
295
- put.m_consistency = consistency;
296
-
297
287
rangeproof_t <> range{};
298
288
size_t rangelen = range.size ();
299
289
static constexpr auto upper_bound = 64 ; // 2^64 - 1
300
- ret = secp256k1_bulletproofs_rangeproof_uncompressed_prove (
290
+ [[maybe_unused]] auto ret = secp256k1_bulletproofs_rangeproof_uncompressed_prove (
301
291
ctx,
302
292
gens,
303
293
secp256k1_generator_h,
@@ -318,6 +308,9 @@ namespace cbdc::transaction {
318
308
put.m_range = range;
319
309
put.m_auxiliary = serialize_commitment (ctx, *auxiliary);
320
310
311
+ auto uhs = calculate_uhs_id (point, put, put.m_auxiliary );
312
+ put.m_id = uhs;
313
+
321
314
return true ;
322
315
}
323
316
@@ -354,8 +347,7 @@ namespace cbdc::transaction {
354
347
add_proof (secp256k1_context* ctx,
355
348
secp256k1_bulletproofs_generators* gens,
356
349
random_source& rng,
357
- full_tx& tx,
358
- const std::vector<std::pair<privkey_t , pubkey_t >>& spending_keys)
350
+ full_tx& tx)
359
351
-> bool {
360
352
std::vector<hash_t > blinds{};
361
353
for (const auto & inp : tx.m_inputs ) {
@@ -405,14 +397,6 @@ namespace cbdc::transaction {
405
397
// inp.m_spend_data = std::nullopt;
406
398
// }
407
399
408
- std::vector<unsigned char > nonces{};
409
- for (const auto & put : tx.m_outputs ) {
410
- const auto & nonce = put.m_nonce ;
411
- std::copy (nonce.begin (), nonce.end (), std::back_inserter (nonces));
412
- }
413
-
414
- tx.m_tx_proofs = {sign_nonces (ctx, nonces, spending_keys)};
415
-
416
400
return true ;
417
401
}
418
402
0 commit comments