Skip to content

Commit c45f515

Browse files
committed
tx: use SHA256_LEN for nonce and entropy lengths
This is the same size as WALLY_TX_ASSET_TAG_LEN but doesn't give the incorrect impression that these fields hold asset tags.
1 parent 5261a02 commit c45f515

File tree

3 files changed

+38
-38
lines changed

3 files changed

+38
-38
lines changed

include/wally_transaction.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -892,9 +892,9 @@ WALLY_CORE_API int wally_tx_get_elements_weight_discount(
892892
*
893893
* :param input: The input to add to.
894894
* :param nonce: Asset issuance or revelation blinding factor.
895-
* :param nonce_len: Size of ``nonce`` in bytes. Must be `WALLY_TX_ASSET_TAG_LEN`.
895+
* :param nonce_len: Size of ``nonce`` in bytes. Must be `SHA256_LEN`.
896896
* :param entropy: Entropy for the asset tag calculation.
897-
* :param entropy_len: Size of ``entropy`` in bytes. Must be `WALLY_TX_ASSET_TAG_LEN`.
897+
* :param entropy_len: Size of ``entropy`` in bytes. Must be `SHA256_LEN`.
898898
* :param issuance_amount: The (blinded) issuance amount.
899899
* :param issuance_amount_len: Size of ``issuance_amount`` in bytes.
900900
* :param inflation_keys: The (blinded) token reissuance amount.
@@ -939,9 +939,9 @@ WALLY_CORE_API int wally_tx_elements_input_issuance_free(
939939
* :param script_len: Size of ``script`` in bytes.
940940
* :param witness: The witness stack for the input, or NULL if no witness is present.
941941
* :param nonce: Asset issuance or revelation blinding factor.
942-
* :param nonce_len: Size of ``nonce`` in bytes. Must be `WALLY_TX_ASSET_TAG_LEN`.
942+
* :param nonce_len: Size of ``nonce`` in bytes. Must be `SHA256_LEN`.
943943
* :param entropy: Entropy for the asset tag calculation.
944-
* :param entropy_len: Size of ``entropy`` in bytes. Must be `WALLY_TX_ASSET_TAG_LEN`.
944+
* :param entropy_len: Size of ``entropy`` in bytes. Must be `SHA256_LEN`.
945945
* :param issuance_amount: The (blinded) issuance amount.
946946
* :param issuance_amount_len: Size of ``issuance_amount`` in bytes.
947947
* :param inflation_keys: The (blinded) token reissuance amount.
@@ -1101,9 +1101,9 @@ WALLY_CORE_API int wally_tx_elements_output_init_alloc(
11011101
* :param script_len: Size of ``script`` in bytes.
11021102
* :param witness: The witness stack for the input, or NULL if no witness is present.
11031103
* :param nonce: Asset issuance or revelation blinding factor.
1104-
* :param nonce_len: Size of ``nonce`` in bytes. Must be `WALLY_TX_ASSET_TAG_LEN`.
1104+
* :param nonce_len: Size of ``nonce`` in bytes. Must be `SHA256_LEN`.
11051105
* :param entropy: Entropy for the asset tag calculation.
1106-
* :param entropy_len: Size of ``entropy`` in bytes. Must be `WALLY_TX_ASSET_TAG_LEN`.
1106+
* :param entropy_len: Size of ``entropy`` in bytes. Must be `SHA256_LEN`.
11071107
* :param issuance_amount: The (blinded) issuance amount.
11081108
* :param issuance_amount_len: Size of ``issuance_amount`` in bytes.
11091109
* :param inflation_keys: The (blinded) token reissuance amount.
@@ -1153,9 +1153,9 @@ WALLY_CORE_API int wally_tx_add_elements_raw_input(
11531153
* :param script_len: Size of ``script`` in bytes.
11541154
* :param witness: The witness stack for the input, or NULL if no witness is present.
11551155
* :param nonce: Asset issuance or revelation blinding factor.
1156-
* :param nonce_len: Size of ``nonce`` in bytes. Must be `WALLY_TX_ASSET_TAG_LEN`.
1156+
* :param nonce_len: Size of ``nonce`` in bytes. Must be `SHA256_LEN`.
11571157
* :param entropy: Entropy for the asset tag calculation.
1158-
* :param entropy_len: Size of ``entropy`` in bytes. Must be `WALLY_TX_ASSET_TAG_LEN`.
1158+
* :param entropy_len: Size of ``entropy`` in bytes. Must be `SHA256_LEN`.
11591159
* :param issuance_amount: The (blinded) issuance amount.
11601160
* :param issuance_amount_len: Size of ``issuance_amount`` in bytes.
11611161
* :param inflation_keys: The (blinded) token reissuance amount.

src/ctest/test_elements_tx.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ static bool tx_roundtrip(const char *tx_hex, const char *sighash_hex)
8080
ret = wally_tx_elements_input_init_alloc(in->txhash, sizeof(in->txhash),
8181
in->index, in->sequence,
8282
in->script, in->script_len, in->witness,
83-
in->blinding_nonce, WALLY_TX_ASSET_TAG_LEN,
84-
in->entropy, WALLY_TX_ASSET_TAG_LEN,
83+
in->blinding_nonce, SHA256_LEN,
84+
in->entropy, SHA256_LEN,
8585
in->issuance_amount, in->issuance_amount_len,
8686
in->inflation_keys, in->inflation_keys_len,
8787
in->issuance_amount_rangeproof,
@@ -101,8 +101,8 @@ static bool tx_roundtrip(const char *tx_hex, const char *sighash_hex)
101101
new_in->index, new_in->sequence,
102102
new_in->script, new_in->script_len,
103103
new_in->witness,
104-
new_in->blinding_nonce, WALLY_TX_ASSET_TAG_LEN,
105-
new_in->entropy, WALLY_TX_ASSET_TAG_LEN,
104+
new_in->blinding_nonce, SHA256_LEN,
105+
new_in->entropy, SHA256_LEN,
106106
new_in->issuance_amount, new_in->issuance_amount_len,
107107
new_in->inflation_keys, new_in->inflation_keys_len,
108108
new_in->issuance_amount_rangeproof,
@@ -262,8 +262,8 @@ static bool tx_pegin(const char *tx_hex, const char **tx_pegin_wit_hex, size_t n
262262
in->index | WALLY_TX_PEGIN_FLAG, in->sequence,
263263
in->script, in->script_len,
264264
in->witness,
265-
in->blinding_nonce, WALLY_TX_ASSET_TAG_LEN,
266-
in->entropy, WALLY_TX_ASSET_TAG_LEN,
265+
in->blinding_nonce, SHA256_LEN,
266+
in->entropy, SHA256_LEN,
267267
in->issuance_amount, in->issuance_amount_len,
268268
in->inflation_keys, in->inflation_keys_len,
269269
in->issuance_amount_rangeproof,

src/transaction.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,8 @@ static int tx_elements_input_issuance_init(
482482
#endif
483483

484484
if (!input ||
485-
BYTES_INVALID_N(nonce, nonce_len, WALLY_TX_ASSET_TAG_LEN) ||
486-
BYTES_INVALID_N(entropy, entropy_len, WALLY_TX_ASSET_TAG_LEN) ||
485+
BYTES_INVALID_N(nonce, nonce_len, SHA256_LEN) ||
486+
BYTES_INVALID_N(entropy, entropy_len, SHA256_LEN) ||
487487
BYTES_INVALID(issuance_amount, issuance_amount_len) ||
488488
BYTES_INVALID(inflation_keys, inflation_keys_len) ||
489489
BYTES_INVALID(issuance_amount_rangeproof, issuance_amount_rangeproof_len) ||
@@ -1311,8 +1311,8 @@ static int tx_add_elements_raw_input_at(
13111311
return WALLY_EINVAL; /* TODO: Allow creation of p2pkh/p2sh using flags */
13121312

13131313
if (!txhash || txhash_len != WALLY_TXHASH_LEN ||
1314-
BYTES_INVALID_N(nonce, nonce_len, WALLY_TX_ASSET_TAG_LEN) ||
1315-
BYTES_INVALID_N(entropy, entropy_len, WALLY_TX_ASSET_TAG_LEN) ||
1314+
BYTES_INVALID_N(nonce, nonce_len, SHA256_LEN) ||
1315+
BYTES_INVALID_N(entropy, entropy_len, SHA256_LEN) ||
13161316
BYTES_INVALID(issuance_amount, issuance_amount_len) ||
13171317
BYTES_INVALID(inflation_keys, inflation_keys_len) ||
13181318
BYTES_INVALID(issuance_amount_rangeproof, issuance_amount_rangeproof_len) ||
@@ -1336,9 +1336,9 @@ static int tx_add_elements_raw_input_at(
13361336
memcpy(input.txhash, txhash, WALLY_TXHASH_LEN);
13371337
#ifdef BUILD_ELEMENTS
13381338
if (nonce)
1339-
memcpy(input.blinding_nonce, nonce, WALLY_TX_ASSET_TAG_LEN);
1339+
memcpy(input.blinding_nonce, nonce, SHA256_LEN);
13401340
if (entropy)
1341-
memcpy(input.entropy, entropy, WALLY_TX_ASSET_TAG_LEN);
1341+
memcpy(input.entropy, entropy, SHA256_LEN);
13421342
#endif /* BUILD_ELEMENTS */
13431343
ret = wally_tx_add_input_at(tx, index, &input);
13441344
wally_clear(&input, sizeof(input));
@@ -2214,10 +2214,10 @@ static inline int tx_to_bip143_bytes(const struct wally_tx *tx,
22142214
unsigned char *tmp_p = buff_p;
22152215
for (i = 0; i < tx->num_inputs; ++i) {
22162216
if (tx->inputs[i].features & WALLY_TX_IS_ISSUANCE) {
2217-
memcpy(tmp_p, tx->inputs[i].blinding_nonce, WALLY_TX_ASSET_TAG_LEN);
2218-
tmp_p += WALLY_TX_ASSET_TAG_LEN;
2219-
memcpy(tmp_p, tx->inputs[i].entropy, WALLY_TX_ASSET_TAG_LEN);
2220-
tmp_p += WALLY_TX_ASSET_TAG_LEN;
2217+
memcpy(tmp_p, tx->inputs[i].blinding_nonce, SHA256_LEN);
2218+
tmp_p += SHA256_LEN;
2219+
memcpy(tmp_p, tx->inputs[i].entropy, SHA256_LEN);
2220+
tmp_p += SHA256_LEN;
22212221
tmp_p += confidential_value_to_bytes(tx->inputs[i].issuance_amount,
22222222
tx->inputs[i].issuance_amount_len, tmp_p);
22232223
tmp_p += confidential_value_to_bytes(tx->inputs[i].inflation_keys,
@@ -2249,10 +2249,10 @@ static inline int tx_to_bip143_bytes(const struct wally_tx *tx,
22492249

22502250
#ifdef BUILD_ELEMENTS
22512251
if (is_elements && (tx->inputs[opts->index].features & WALLY_TX_IS_ISSUANCE)) {
2252-
memcpy(p, tx->inputs[opts->index].blinding_nonce, WALLY_TX_ASSET_TAG_LEN);
2253-
p += WALLY_TX_ASSET_TAG_LEN;
2254-
memcpy(p, tx->inputs[opts->index].entropy, WALLY_TX_ASSET_TAG_LEN);
2255-
p += WALLY_TX_ASSET_TAG_LEN;
2252+
memcpy(p, tx->inputs[opts->index].blinding_nonce, SHA256_LEN);
2253+
p += SHA256_LEN;
2254+
memcpy(p, tx->inputs[opts->index].entropy, SHA256_LEN);
2255+
p += SHA256_LEN;
22562256
p += confidential_value_to_bytes(tx->inputs[opts->index].issuance_amount,
22572257
tx->inputs[opts->index].issuance_amount_len, p);
22582258
p += confidential_value_to_bytes(tx->inputs[opts->index].inflation_keys,
@@ -2660,10 +2660,10 @@ static int tx_to_bytes(const struct wally_tx *tx,
26602660
if (!is_elements)
26612661
return WALLY_EINVAL;
26622662
#ifdef BUILD_ELEMENTS
2663-
memcpy(p, input->blinding_nonce, WALLY_TX_ASSET_TAG_LEN);
2664-
p += WALLY_TX_ASSET_TAG_LEN;
2665-
memcpy(p, input->entropy, WALLY_TX_ASSET_TAG_LEN);
2666-
p += WALLY_TX_ASSET_TAG_LEN;
2663+
memcpy(p, input->blinding_nonce, SHA256_LEN);
2664+
p += SHA256_LEN;
2665+
memcpy(p, input->entropy, SHA256_LEN);
2666+
p += SHA256_LEN;
26672667
p += confidential_value_to_bytes(input->issuance_amount, input->issuance_amount_len, p);
26682668
p += confidential_value_to_bytes(input->inflation_keys, input->inflation_keys_len, p);
26692669
#endif
@@ -2926,8 +2926,8 @@ static int analyze_tx(const unsigned char *bytes, size_t bytes_len,
29262926
ensure_n(sizeof(uint32_t));
29272927
p += sizeof(uint32_t);
29282928
if (expect_issuance) {
2929-
ensure_n(2 * WALLY_TX_ASSET_TAG_LEN);
2930-
p += 2 * WALLY_TX_ASSET_TAG_LEN;
2929+
ensure_n(2 * SHA256_LEN);
2930+
p += 2 * SHA256_LEN;
29312931
ensure_committed_value(p); /* issuance amount */
29322932
ensure_committed_value(p); /* inflation keys */
29332933
}
@@ -3069,18 +3069,18 @@ static int tx_from_bytes(const unsigned char *bytes, size_t bytes_len,
30693069
p += uint32_from_le_bytes(p, &sequence);
30703070
if (is_elements && !!(index & WALLY_TX_ISSUANCE_FLAG) && !is_coinbase_bytes(txhash, WALLY_TXHASH_LEN, index)) {
30713071
nonce = p;
3072-
p += WALLY_TX_ASSET_TAG_LEN;
3072+
p += SHA256_LEN;
30733073
entropy = p;
3074-
p += WALLY_TX_ASSET_TAG_LEN;
3074+
p += SHA256_LEN;
30753075
issuance_amount = p;
30763076
p += confidential_value_varint_from_bytes(p, &issuance_amount_len);
30773077
inflation_keys = p;
30783078
p += confidential_value_varint_from_bytes(p, &inflation_keys_len);
30793079
}
30803080
ret = tx_elements_input_init(txhash, WALLY_TXHASH_LEN, index, sequence,
30813081
script_len ? script : NULL, script_len, NULL,
3082-
nonce, nonce ? WALLY_TX_ASSET_TAG_LEN : 0,
3083-
entropy, entropy ? WALLY_TX_ASSET_TAG_LEN : 0,
3082+
nonce, nonce ? SHA256_LEN : 0,
3083+
entropy, entropy ? SHA256_LEN : 0,
30843084
issuance_amount_len ? issuance_amount : NULL, issuance_amount_len,
30853085
inflation_keys_len ? inflation_keys : NULL, inflation_keys_len,
30863086
NULL, 0, NULL, 0, NULL, &(*output)->inputs[i], is_elements);

0 commit comments

Comments
 (0)