Skip to content

Commit 901faac

Browse files
committed
tx: add and use constants for explicit and empty confidential commitments
1 parent f4e61f2 commit 901faac

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

include/wally_transaction.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,14 @@ extern "C" {
4444

4545
#define WALLY_SIGHASH_MASK 0x1f /* Mask for determining ALL/NONE/SINGLE */
4646

47-
#define WALLY_TX_ASSET_CT_VALUE_PREFIX_A 8
48-
#define WALLY_TX_ASSET_CT_VALUE_PREFIX_B 9
49-
#define WALLY_TX_ASSET_CT_ASSET_PREFIX_A 10
50-
#define WALLY_TX_ASSET_CT_ASSET_PREFIX_B 11
51-
#define WALLY_TX_ASSET_CT_NONCE_PREFIX_A 2
52-
#define WALLY_TX_ASSET_CT_NONCE_PREFIX_B 3
47+
#define WALLY_TX_ASSET_CT_EMPTY_PREFIX 0x00
48+
#define WALLY_TX_ASSET_CT_EXPLICIT_PREFIX 0x01
49+
#define WALLY_TX_ASSET_CT_VALUE_PREFIX_A 0x08
50+
#define WALLY_TX_ASSET_CT_VALUE_PREFIX_B 0x09
51+
#define WALLY_TX_ASSET_CT_ASSET_PREFIX_A 0x0a
52+
#define WALLY_TX_ASSET_CT_ASSET_PREFIX_B 0x0b
53+
#define WALLY_TX_ASSET_CT_NONCE_PREFIX_A 0x02
54+
#define WALLY_TX_ASSET_CT_NONCE_PREFIX_B 0x03
5355

5456
#define WALLY_TX_ASSET_TAG_LEN 32
5557
#define WALLY_TX_ASSET_CT_VALUE_LEN 33 /* version byte + 32 bytes */

src/script.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ static size_t get_commitment_len(const unsigned char *bytes,
193193
{
194194
if (!bytes || !*bytes)
195195
return sizeof(uint8_t); /* Null commitment */
196-
if (*bytes == 1) {
196+
if (*bytes == WALLY_TX_ASSET_CT_EXPLICIT_PREFIX) {
197197
/* Explicit value (unblinded) */
198198
if (prefixA == WALLY_TX_ASSET_CT_VALUE_PREFIX_A)
199199
return WALLY_TX_ASSET_CT_VALUE_UNBLIND_LEN; /* uint64 value */
@@ -209,7 +209,7 @@ static size_t confidential_commitment_varint_from_bytes(const unsigned char *byt
209209
bool ct_value)
210210
{
211211
switch (*bytes) {
212-
case 1:
212+
case WALLY_TX_ASSET_CT_EXPLICIT_PREFIX:
213213
*v = ct_value ? WALLY_TX_ASSET_CT_VALUE_UNBLIND_LEN : WALLY_TX_ASSET_CT_LEN;
214214
return *v;
215215
case WALLY_TX_ASSET_CT_VALUE_PREFIX_A:

src/transaction.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2414,11 +2414,11 @@ static int analyze_tx(const unsigned char *bytes, size_t bytes_len,
24142414

24152415
#define ensure_commitment(dst, explicit_siz, prefix_a, prefix_b) \
24162416
switch (*dst) { \
2417-
case 0: \
2417+
case WALLY_TX_ASSET_CT_EMPTY_PREFIX: \
24182418
ensure_n(sizeof(uint8_t)); \
24192419
p++; \
24202420
break; \
2421-
case 1: \
2421+
case WALLY_TX_ASSET_CT_EXPLICIT_PREFIX: \
24222422
ensure_n(explicit_siz); \
24232423
p += explicit_siz; \
24242424
break; \

src/wasm_package/const.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,17 @@ export const WALLY_SIGHASH_NONE = 0x02;
164164
export const WALLY_SIGHASH_RANGEPROOF = 0x40 ; /* Liquid/Elements only */
165165
export const WALLY_SIGHASH_SINGLE = 0x03;
166166
export const WALLY_TX_ASSET_CT_ASSET_LEN = 33; /* version byte + 32 bytes */
167-
export const WALLY_TX_ASSET_CT_ASSET_PREFIX_A = 10;
168-
export const WALLY_TX_ASSET_CT_ASSET_PREFIX_B = 11;
167+
export const WALLY_TX_ASSET_CT_ASSET_PREFIX_A = 0x0a;
168+
export const WALLY_TX_ASSET_CT_ASSET_PREFIX_B = 0x0b;
169+
export const WALLY_TX_ASSET_CT_EMPTY_PREFIX = 0x00;
170+
export const WALLY_TX_ASSET_CT_EXPLICIT_PREFIX = 0x01;
169171
export const WALLY_TX_ASSET_CT_LEN = 33 ; /* version byte + 32 bytes */
170172
export const WALLY_TX_ASSET_CT_NONCE_LEN = 33; /* version byte + 32 bytes */
171-
export const WALLY_TX_ASSET_CT_NONCE_PREFIX_A = 2;
172-
export const WALLY_TX_ASSET_CT_NONCE_PREFIX_B = 3;
173+
export const WALLY_TX_ASSET_CT_NONCE_PREFIX_A = 0x02;
174+
export const WALLY_TX_ASSET_CT_NONCE_PREFIX_B = 0x03;
173175
export const WALLY_TX_ASSET_CT_VALUE_LEN = 33; /* version byte + 32 bytes */
174-
export const WALLY_TX_ASSET_CT_VALUE_PREFIX_A = 8;
175-
export const WALLY_TX_ASSET_CT_VALUE_PREFIX_B = 9;
176+
export const WALLY_TX_ASSET_CT_VALUE_PREFIX_A = 0x08;
177+
export const WALLY_TX_ASSET_CT_VALUE_PREFIX_B = 0x09;
176178
export const WALLY_TX_ASSET_CT_VALUE_UNBLIND_LEN = 9; /* version byte + 8 bytes */
177179
export const WALLY_TX_ASSET_TAG_LEN = 32;
178180
export const WALLY_TX_DUMMY_NULL = 0x1; /* An empty witness item */

0 commit comments

Comments
 (0)