commit 7cee89ad70fb758ebb7a9007f4fe2ce5dc16c70e
parent fac62a8376e7925dd60611fe7a122a21b3cd2013
Author: Özgür Kesim <oec@codeblau.de>
Date: Sun, 8 Nov 2026 16:44:04 +0100
[lib] v46: decode the new MELT history fields (#11916)
TALER_EXCHANGE_free_coin_history() releases them. libtalerexchange 26:0:0: since master, TALER_EXCHANGE_RevealMeltInput has rc_version.
Diffstat:
4 files changed, 288 insertions(+), 28 deletions(-)
diff --git a/meson.build b/meson.build
@@ -287,7 +287,7 @@ if not get_option('only-doc')
['libtalerkyclogic', '3:0:0'],
['libtalerexchangedb', '5:0:0'],
['libtalerauditordb', '1:0:0'],
- ['libtalerexchange', '25:0:0'],
+ ['libtalerexchange', '26:0:0'],
['libtalerauditor', '1:0:1'],
['libtalertesting', '5:0:0'],
['libtalertwistertesting', '0:1:0'],
diff --git a/src/include/taler/exchange/get-coins-COIN_PUB-history.h b/src/include/taler/exchange/get-coins-COIN_PUB-history.h
@@ -149,6 +149,59 @@ struct TALER_EXCHANGE_CoinHistoryEntry
struct TALER_AgeCommitmentHashP h_age_commitment;
bool no_hac;
struct TALER_Amount melt_fee;
+
+ /**
+ * Index the exchange chose not to have revealed,
+ * only valid if @e no_noreveal_index is false (since v46).
+ */
+ uint32_t noreveal_index;
+
+ /**
+ * True if the exchange did not provide @e noreveal_index.
+ */
+ bool no_noreveal_index;
+
+ /**
+ * Seed provided by the client in the melt request, from which
+ * the client derived the transfer keys of all batches.
+ */
+ struct TALER_PublicRefreshMasterSeedP refresh_seed;
+
+ /**
+ * Blinding seed of the melt request, only valid if
+ * @e no_blinding_seed is false (Clause-Schnorr denominations).
+ */
+ struct TALER_BlindingMasterSeedP blinding_seed;
+
+ /**
+ * True if the melt request had no @e blinding_seed.
+ */
+ bool no_blinding_seed;
+
+ /**
+ * Number of fresh coins requested by the melt.
+ */
+ size_t num_fresh_coins;
+
+ /**
+ * Hashes of the denominations of the @e num_fresh_coins fresh
+ * coins, in the order of the melt request.
+ */
+ struct TALER_DenominationHashP *denoms_h;
+
+ /**
+ * The @e num_fresh_coins transfer public keys of the batch at
+ * @e noreveal_index, NULL if the exchange did not provide them
+ * (before v46, or if the melt request had none).
+ */
+ struct TALER_TransferPublicKeyP *transfer_pubs;
+
+ /**
+ * The @e num_fresh_coins blinded denomination signatures over the
+ * fresh coins, NULL if the coin was not (yet) revealed or the
+ * exchange is older than v46.
+ */
+ struct TALER_BlindedDenominationSignature *ev_sigs;
} melt;
struct
@@ -258,9 +311,11 @@ struct TALER_EXCHANGE_CoinHistoryEntry
* @param[out] total_in set to total amount credited to the coin in @a history
* @param[out] total_out set to total amount debited from the coin in @a history
* @param rlen length of the @a rhistory array
- * @param[out] rhistory array where to write the parsed @a history
+ * @param[out] rhistory array where to write the parsed @a history;
+ * on success, the caller must release it with
+ * TALER_EXCHANGE_free_coin_history()
* @return #GNUNET_OK if @a history is valid,
- * #GNUNET_SYSERR if not
+ * #GNUNET_SYSERR if not (nothing to release then)
*/
enum GNUNET_GenericReturnValue
TALER_EXCHANGE_parse_coin_history (
@@ -275,6 +330,20 @@ TALER_EXCHANGE_parse_coin_history (
/**
+ * Release the memory held by the entries of a coin history
+ * parsed by TALER_EXCHANGE_parse_coin_history(). The array
+ * itself is not freed.
+ *
+ * @param rlen length of the @a rhistory array
+ * @param[in,out] rhistory the parsed history
+ */
+void
+TALER_EXCHANGE_free_coin_history (
+ unsigned int rlen,
+ struct TALER_EXCHANGE_CoinHistoryEntry rhistory[static rlen]);
+
+
+/**
* Verify that @a coin_sig does NOT appear in the @a history of a coin's
* transactions and thus whatever transaction is authorized by @a coin_sig is
* a conflict with @a proof.
diff --git a/src/lib/exchange_api_get-coins-COIN_PUB-history.c b/src/lib/exchange_api_get-coins-COIN_PUB-history.c
@@ -241,21 +241,42 @@ help_deposit (struct CoinHistoryParseContext *pc,
/**
- * Handle melt entry in the coin's history.
+ * Release the memory held by the melt details of @a rh.
+ *
+ * @param[in,out] rh a melt entry of a coin history
+ */
+static void
+free_melt (struct TALER_EXCHANGE_CoinHistoryEntry *rh)
+{
+ if (NULL != rh->details.melt.ev_sigs)
+ {
+ for (size_t i = 0; i < rh->details.melt.num_fresh_coins; i++)
+ TALER_blinded_denom_sig_free (&rh->details.melt.ev_sigs[i]);
+ GNUNET_free (rh->details.melt.ev_sigs);
+ }
+ GNUNET_free (rh->details.melt.transfer_pubs);
+ GNUNET_free (rh->details.melt.denoms_h);
+}
+
+
+/**
+ * Parse and check the details of a melt entry in the coin's history.
+ * On failure, nothing remains allocated in @a rh.
*
* @param[in,out] pc overall context
* @param[out] rh history entry to initialize
* @param amount main amount of this operation
* @param transaction JSON details for the operation
- * @return #GNUNET_SYSERR on error,
- * #GNUNET_OK to add, #GNUNET_NO to subtract
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
static enum GNUNET_GenericReturnValue
-help_melt (struct CoinHistoryParseContext *pc,
- struct TALER_EXCHANGE_CoinHistoryEntry *rh,
- const struct TALER_Amount *amount,
- json_t *transaction)
+parse_melt (struct CoinHistoryParseContext *pc,
+ struct TALER_EXCHANGE_CoinHistoryEntry *rh,
+ const struct TALER_Amount *amount,
+ json_t *transaction)
{
+ size_t num_transfer_pubs = 0;
+ const json_t *j_ev_sigs = NULL;
struct GNUNET_JSON_Specification spec[] = {
TALER_JSON_spec_amount_any ("melt_fee",
&rh->details.melt.melt_fee),
@@ -267,9 +288,35 @@ help_melt (struct CoinHistoryParseContext *pc,
&rh->details.melt.no_hac),
GNUNET_JSON_spec_fixed_auto ("coin_sig",
&rh->details.melt.sig),
+ GNUNET_JSON_spec_fixed_auto ("refresh_seed",
+ &rh->details.melt.refresh_seed),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_fixed_auto ("blinding_seed",
+ &rh->details.melt.blinding_seed),
+ &rh->details.melt.no_blinding_seed),
+ TALER_JSON_spec_array_of_denom_pub_h ("denoms_h",
+ &rh->details.melt.num_fresh_coins,
+ &rh->details.melt.denoms_h),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_uint32 ("noreveal_index",
+ &rh->details.melt.noreveal_index),
+ &rh->details.melt.no_noreveal_index),
+ GNUNET_JSON_spec_mark_optional (
+ TALER_JSON_spec_array_of_data ("transfer_pubs",
+ sizeof (struct TALER_TransferPublicKeyP),
+ &num_transfer_pubs,
+ (void **) &rh->details.melt.transfer_pubs),
+ NULL),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_array_const ("ev_sigs",
+ &j_ev_sigs),
+ NULL),
GNUNET_JSON_spec_end ()
};
+ rh->details.melt.denoms_h = NULL;
+ rh->details.melt.transfer_pubs = NULL;
+ rh->details.melt.ev_sigs = NULL;
if (GNUNET_OK !=
GNUNET_JSON_parse (transaction,
spec,
@@ -278,6 +325,56 @@ help_melt (struct CoinHistoryParseContext *pc,
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
+ /* from here on, the allocated arrays belong to @a rh */
+ if ( (! rh->details.melt.no_noreveal_index) &&
+ (rh->details.melt.noreveal_index >= TALER_CNC_KAPPA) )
+ {
+ GNUNET_break_op (0);
+ free_melt (rh);
+ return GNUNET_SYSERR;
+ }
+ /* transfer_pubs and ev_sigs have one entry per fresh coin */
+ if ( (NULL != rh->details.melt.transfer_pubs) &&
+ (num_transfer_pubs != rh->details.melt.num_fresh_coins) )
+ {
+ GNUNET_break_op (0);
+ free_melt (rh);
+ return GNUNET_SYSERR;
+ }
+ if (NULL != j_ev_sigs)
+ {
+ size_t num = rh->details.melt.num_fresh_coins;
+ struct TALER_BlindedDenominationSignature *ev_sigs;
+
+ if (json_array_size (j_ev_sigs) != num)
+ {
+ GNUNET_break_op (0);
+ free_melt (rh);
+ return GNUNET_SYSERR;
+ }
+ ev_sigs = GNUNET_new_array (GNUNET_NZL (num),
+ struct TALER_BlindedDenominationSignature);
+ {
+ struct GNUNET_JSON_Specification sspec[] = {
+ TALER_JSON_spec_array_of_blinded_denom_sigs (NULL,
+ num,
+ ev_sigs),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (j_ev_sigs,
+ sspec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ GNUNET_free (ev_sigs);
+ free_melt (rh);
+ return GNUNET_SYSERR;
+ }
+ }
+ rh->details.melt.ev_sigs = ev_sigs;
+ }
/* check that melt fee matches our expectations from /keys! */
if ( (GNUNET_YES !=
@@ -288,6 +385,7 @@ help_melt (struct CoinHistoryParseContext *pc,
&pc->dk->fees.refresh)) )
{
GNUNET_break_op (0);
+ free_melt (rh);
return GNUNET_SYSERR;
}
if (GNUNET_OK !=
@@ -303,8 +401,35 @@ help_melt (struct CoinHistoryParseContext *pc,
&rh->details.melt.sig))
{
GNUNET_break_op (0);
+ free_melt (rh);
return GNUNET_SYSERR;
}
+ return GNUNET_OK;
+}
+
+
+/**
+ * Handle melt entry in the coin's history.
+ *
+ * @param[in,out] pc overall context
+ * @param[out] rh history entry to initialize
+ * @param amount main amount of this operation
+ * @param transaction JSON details for the operation
+ * @return #GNUNET_SYSERR on error,
+ * #GNUNET_OK to add, #GNUNET_NO to subtract
+ */
+static enum GNUNET_GenericReturnValue
+help_melt (struct CoinHistoryParseContext *pc,
+ struct TALER_EXCHANGE_CoinHistoryEntry *rh,
+ const struct TALER_Amount *amount,
+ json_t *transaction)
+{
+ if (GNUNET_OK !=
+ parse_melt (pc,
+ rh,
+ amount,
+ transaction))
+ return GNUNET_SYSERR;
return GNUNET_YES;
}
@@ -800,16 +925,32 @@ help_reserve_open_deposit (struct CoinHistoryParseContext *pc,
}
-enum GNUNET_GenericReturnValue
-TALER_EXCHANGE_parse_coin_history (
+/**
+ * Parses and verifies a coin's transaction history, see
+ * TALER_EXCHANGE_parse_coin_history(). Expects @a rhistory to be
+ * zeroed; on failure, entries may hold memory the caller must release.
+ *
+ * @param keys /keys data of the exchange
+ * @param dk denomination key of the coin
+ * @param history JSON array with the coin's history
+ * @param coin_pub public key of the coin
+ * @param[out] total_in set to total amount credited to the coin in @a history
+ * @param[out] total_out set to total amount debited from the coin in @a history
+ * @param len length of the @a rhistory array, equal to the length of @a history
+ * @param[out] rhistory array where to write the parsed @a history
+ * @return #GNUNET_OK if @a history is valid,
+ * #GNUNET_SYSERR if not
+ */
+static enum GNUNET_GenericReturnValue
+parse_coin_history (
const struct TALER_EXCHANGE_Keys *keys,
const struct TALER_EXCHANGE_DenomPublicKey *dk,
const json_t *history,
const struct TALER_CoinSpendPublicKeyP *coin_pub,
struct TALER_Amount *total_in,
struct TALER_Amount *total_out,
- unsigned int rlen,
- struct TALER_EXCHANGE_CoinHistoryEntry rhistory[static rlen])
+ size_t len,
+ struct TALER_EXCHANGE_CoinHistoryEntry rhistory[static len])
{
const struct
{
@@ -853,19 +994,7 @@ TALER_EXCHANGE_parse_coin_history (
.total_out = total_out,
.total_in = total_in
};
- size_t len;
- if (NULL == history)
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- len = json_array_size (history);
- if (0 == len)
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
*total_in = dk->value;
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (total_in->currency,
@@ -960,6 +1089,68 @@ TALER_EXCHANGE_parse_coin_history (
}
+enum GNUNET_GenericReturnValue
+TALER_EXCHANGE_parse_coin_history (
+ const struct TALER_EXCHANGE_Keys *keys,
+ const struct TALER_EXCHANGE_DenomPublicKey *dk,
+ const json_t *history,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ struct TALER_Amount *total_in,
+ struct TALER_Amount *total_out,
+ unsigned int rlen,
+ struct TALER_EXCHANGE_CoinHistoryEntry rhistory[static rlen])
+{
+ size_t len;
+
+ if (NULL == history)
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ len = json_array_size (history);
+ if ( (0 == len) ||
+ (len > rlen) )
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ memset (rhistory,
+ 0,
+ sizeof (rhistory[0]) * len);
+ if (GNUNET_OK !=
+ parse_coin_history (keys,
+ dk,
+ history,
+ coin_pub,
+ total_in,
+ total_out,
+ len,
+ rhistory))
+ {
+ TALER_EXCHANGE_free_coin_history ((unsigned int) len,
+ rhistory);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+}
+
+
+void
+TALER_EXCHANGE_free_coin_history (
+ unsigned int rlen,
+ struct TALER_EXCHANGE_CoinHistoryEntry rhistory[static rlen])
+{
+ for (unsigned int i = 0; i < rlen; i++)
+ {
+ struct TALER_EXCHANGE_CoinHistoryEntry *rh = &rhistory[i];
+
+ if (TALER_EXCHANGE_CTT_MELT != rh->type)
+ continue;
+ free_melt (rh);
+ }
+}
+
+
/**
* We received an #MHD_HTTP_OK response. Handle the JSON response.
*
diff --git a/src/lib/exchange_api_handle.c b/src/lib/exchange_api_handle.c
@@ -35,12 +35,12 @@
* Which version of the Taler protocol is implemented
* by this library? Used to determine compatibility.
*/
-#define EXCHANGE_PROTOCOL_CURRENT 45
+#define EXCHANGE_PROTOCOL_CURRENT 46
/**
* How many versions are we backwards compatible with?
*/
-#define EXCHANGE_PROTOCOL_AGE 3
+#define EXCHANGE_PROTOCOL_AGE 4
/**
* Set to 1 for extra debug logging.