commit fb3b92ebd09e3e91849646ad243725361a46f383
parent 7cee89ad70fb758ebb7a9007f4fe2ce5dc16c70e
Author: Özgür Kesim <oec@codeblau.de>
Date: Sun, 8 Nov 2026 13:15:58 +0100
[testing] check the MELT history entries of melted coins (#11916)
transfer_pubs must match those derived from refresh_seed, ev_sigs those of the reveal.
Diffstat:
3 files changed, 227 insertions(+), 9 deletions(-)
diff --git a/src/testing/test_exchange_api.c b/src/testing/test_exchange_api.c
@@ -402,6 +402,13 @@ run (void *cls,
"refresh-reveal-1",
MHD_HTTP_CONFLICT,
NULL),
+ /* revealed melt: transfer_pubs and ev_sigs in the history;
+ 5 - 1 (deposit) - 3.17 (melt: 3 * 1.01 + 0.11 + 0.03 fee) */
+ TALER_TESTING_cmd_coin_history (
+ "coin-history-melted",
+ "refresh-withdraw-coin-1",
+ "EUR:0.83",
+ MHD_HTTP_OK),
/**
* Refresh like a client that does not yet include the transfer
@@ -438,6 +445,11 @@ run (void *cls,
"refresh-reveal-legacy-idempotency",
"refresh-melt-legacy",
MHD_HTTP_OK),
+ TALER_TESTING_cmd_coin_history (
+ "coin-history-melted-legacy",
+ "refresh-withdraw-coin-legacy",
+ "EUR:1.83",
+ MHD_HTTP_OK),
TALER_TESTING_cmd_end ()
};
diff --git a/src/testing/testing_api_cmd_coin_history.c b/src/testing/testing_api_cmd_coin_history.c
@@ -152,6 +152,41 @@ history_entry_cmp (
if (0 != GNUNET_memcmp (&h1->details.melt.h_age_commitment,
&h2->details.melt.h_age_commitment))
return 1;
+ if (0 != GNUNET_memcmp (&h1->details.melt.rc,
+ &h2->details.melt.rc))
+ return 1;
+ /* presence of noreveal_index and transfer_pubs is checked,
+ and transfer_pubs are verified, in check_melt_entries() */
+ if (h1->details.melt.noreveal_index !=
+ h2->details.melt.noreveal_index)
+ return 1;
+ /* the blinded signatures are exactly those of the reveal,
+ and absent if the melt was not (yet) revealed */
+ if ( (NULL == h1->details.melt.ev_sigs) !=
+ (NULL == h2->details.melt.ev_sigs) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Melt history %s ev_sigs\n",
+ (NULL == h2->details.melt.ev_sigs)
+ ? "lacks the revealed"
+ : "has unexpected");
+ return 1;
+ }
+ if (NULL != h1->details.melt.ev_sigs)
+ {
+ if (h1->details.melt.num_fresh_coins !=
+ h2->details.melt.num_fresh_coins)
+ return 1;
+ for (size_t j = 0; j < h1->details.melt.num_fresh_coins; j++)
+ if (0 != TALER_blinded_denom_sig_cmp (
+ &h1->details.melt.ev_sigs[j],
+ &h2->details.melt.ev_sigs[j]))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Melt history has ev_sigs other than the reveal\n");
+ return 1;
+ }
+ }
/* Note: most other fields are not initialized
in the trait as they are hard to extract from
the API */
@@ -312,6 +347,8 @@ analyze_command (void *cls,
cmd->label);
return; /* command does nothing for coins */
}
+ if (TALER_EXCHANGE_CTT_NONE == he->type)
+ continue; /* operation was rejected, coin unaffected */
for (unsigned int i = 0; i<history_length; i++)
{
if (found[i])
@@ -339,6 +376,68 @@ analyze_command (void *cls,
/**
+ * Check the details of the melt entries of a coin history: they must
+ * have a noreveal index and transfer public keys, and the latter must be
+ * those the client derived for the batch at the noreveal index. The
+ * blinded signatures are checked against the reveal in
+ * history_entry_cmp().
+ *
+ * @param ss our state, with the coin's private key
+ * @param hlen length of @a rhist
+ * @param rhist the parsed coin history
+ * @return true if all melt entries are consistent
+ */
+static bool
+check_melt_entries (
+ const struct HistoryState *ss,
+ unsigned int hlen,
+ const struct TALER_EXCHANGE_CoinHistoryEntry rhist[static hlen])
+{
+ for (unsigned int i = 0; i < hlen; i++)
+ {
+ const struct TALER_EXCHANGE_CoinHistoryEntry *rh = &rhist[i];
+ size_t n = rh->details.melt.num_fresh_coins;
+
+ if (TALER_EXCHANGE_CTT_MELT != rh->type)
+ continue;
+ if ( (rh->details.melt.no_noreveal_index) ||
+ (NULL == rh->details.melt.transfer_pubs) ||
+ (0 == n) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Melt history entry lacks noreveal_index or transfer_pubs\n");
+ return false;
+ }
+ {
+ struct TALER_KappaPrivateRefreshBatchSeedsP kappa_seeds;
+ struct TALER_PlanchetMasterSecretP ps[n];
+ struct TALER_TransferPublicKeyP tp[n];
+
+ TALER_refresh_expand_seed_to_kappa_batch_seeds (
+ &rh->details.melt.refresh_seed,
+ ss->coin_priv,
+ &kappa_seeds);
+ TALER_refresh_expand_batch_seed_to_transfer_data (
+ &kappa_seeds.tuple[rh->details.melt.noreveal_index],
+ &ss->coin_pub,
+ n,
+ ps,
+ tp);
+ if (0 != memcmp (tp,
+ rh->details.melt.transfer_pubs,
+ sizeof (tp)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Melt history has wrong transfer_pubs\n");
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+
+/**
* Check that the coin balance and HTTP response code are
* both acceptable.
*
@@ -397,6 +496,7 @@ coin_history_cb (struct HistoryState *ss,
struct TALER_Amount total_in;
struct TALER_Amount total_out;
struct TALER_Amount hbal;
+ bool failed = false;
dk = TALER_EXCHANGE_get_denomination_key_by_hash (
TALER_TESTING_get_keys (is),
@@ -426,6 +526,13 @@ coin_history_cb (struct HistoryState *ss,
TALER_TESTING_interpreter_fail (ss->is);
return;
}
+ if (! check_melt_entries (ss,
+ hlen,
+ rhist))
+ {
+ failed = true;
+ goto cleanup;
+ }
if (0 >
TALER_amount_subtract (&hbal,
&total_in,
@@ -438,15 +545,15 @@ coin_history_cb (struct HistoryState *ss,
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Coin debits: %s\n",
TALER_amount2s (&total_out));
- TALER_TESTING_interpreter_fail (ss->is);
- return;
+ failed = true;
+ goto cleanup;
}
if (0 != TALER_amount_cmp (&hbal,
&rs->details.ok.balance))
{
GNUNET_break (0);
- TALER_TESTING_interpreter_fail (ss->is);
- return;
+ failed = true;
+ goto cleanup;
}
(void) ac;
TALER_TESTING_iterate (is,
@@ -458,8 +565,8 @@ coin_history_cb (struct HistoryState *ss,
json_dumpf (rs->hr.reply,
stderr,
JSON_INDENT (2));
- TALER_TESTING_interpreter_fail (ss->is);
- return;
+ failed = true;
+ goto cleanup;
}
#if 1
for (unsigned int i = 0; i<hlen; i++)
@@ -469,14 +576,22 @@ coin_history_cb (struct HistoryState *ss,
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"History entry at index %u of type %d not justified by command history\n",
i,
- rs->details.ok.history[i].type);
+ rhist[i].type);
json_dumpf (rs->hr.reply,
stderr,
JSON_INDENT (2));
+ failed = true;
+ goto cleanup;
+ }
+#endif
+cleanup:
+ TALER_EXCHANGE_free_coin_history (hlen,
+ rhist);
+ if (failed)
+ {
TALER_TESTING_interpreter_fail (ss->is);
return;
}
-#endif
}
TALER_TESTING_interpreter_next (is);
}
@@ -557,7 +672,7 @@ history_traits (void *cls,
{
struct HistoryState *hs = cls;
struct TALER_TESTING_Trait traits[] = {
- TALER_TESTING_make_trait_coin_pub (index,
+ TALER_TESTING_make_trait_coin_pub (0,
&hs->coin_pub),
TALER_TESTING_trait_end ()
};
diff --git a/src/testing/testing_api_cmd_refresh.c b/src/testing/testing_api_cmd_refresh.c
@@ -429,6 +429,81 @@ do_reveal_retry (void *cls)
/**
+ * Release the blinded signatures recorded in the expected
+ * coin history entry of a melt.
+ *
+ * @param[in,out] ms melt command state
+ */
+static void
+free_expected_ev_sigs (struct MeltState *ms)
+{
+ if (NULL == ms->che.details.melt.ev_sigs)
+ return;
+ for (size_t i = 0; i < ms->che.details.melt.num_fresh_coins; i++)
+ TALER_blinded_denom_sig_free (&ms->che.details.melt.ev_sigs[i]);
+ GNUNET_free (ms->che.details.melt.ev_sigs);
+ ms->che.details.melt.num_fresh_coins = 0;
+}
+
+
+/**
+ * Record the blinded signatures of a successful reveal in the expected
+ * coin history entry of the melt, see history_entry_cmp().
+ *
+ * @param[in,out] ms melt command state
+ * @param reply body of the /reveal-melt response
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+record_revealed_ev_sigs (struct MeltState *ms,
+ const json_t *reply)
+{
+ const json_t *j_ev_sigs;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_array_const ("ev_sigs",
+ &j_ev_sigs),
+ GNUNET_JSON_spec_end ()
+ };
+ struct TALER_BlindedDenominationSignature *ev_sigs;
+ size_t num;
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (reply,
+ spec,
+ NULL, NULL))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ num = json_array_size (j_ev_sigs);
+ 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 (0);
+ GNUNET_free (ev_sigs);
+ return GNUNET_SYSERR;
+ }
+ }
+ free_expected_ev_sigs (ms);
+ ms->che.details.melt.ev_sigs = ev_sigs;
+ ms->che.details.melt.num_fresh_coins = num;
+ return GNUNET_OK;
+}
+
+
+/**
* "refresh reveal" request callback; it checks that the response
* code is expected and copies into its command's state the data
* coming from the exchange, namely the fresh coins.
@@ -489,6 +564,13 @@ reveal_cb (struct RevealMeltState *rrs,
switch (hr->http_status)
{
case MHD_HTTP_OK:
+ if (GNUNET_OK !=
+ record_revealed_ev_sigs (melt_cmd->cls,
+ hr->reply))
+ {
+ TALER_TESTING_interpreter_fail (rrs->is);
+ return;
+ }
rrs->num_fresh_coins = rmr->details.ok.num_coins;
rrs->psa = GNUNET_new_array (rrs->num_fresh_coins,
struct TALER_PlanchetMasterSecretP);
@@ -762,6 +844,11 @@ melt_cb (struct MeltState *ms,
hr->reply);
return;
}
+ if (MHD_HTTP_OK != hr->http_status)
+ {
+ /* the exchange rejected the operation, the coin is unaffected */
+ ms->che.type = TALER_EXCHANGE_CTT_NONE;
+ }
if ( (MHD_HTTP_CONFLICT == hr->http_status) &&
(TALER_EC_EXCHANGE_GENERIC_COIN_CONFLICTING_DENOMINATION_KEY ==
hr->ec) )
@@ -784,6 +871,9 @@ melt_cb (struct MeltState *ms,
{
ms->noreveal_index = mr->details.ok.noreveal_index;
ms->rc = mr->details.ok.rc;
+ /* for the coin history check */
+ ms->che.details.melt.rc = ms->rc;
+ ms->che.details.melt.noreveal_index = ms->noreveal_index;
ms->rc_version = mr->details.ok.rc_version;
if (ms->rc_version !=
(ms->legacy_commitment
@@ -1074,6 +1164,7 @@ melt_cleanup (void *cls,
TALER_denom_ewv_free (&rms->blinding_values[i]);
GNUNET_free (rms->blinding_values);
}
+ free_expected_ev_sigs (rms);
GNUNET_free (rms->melt_fresh_amounts);
GNUNET_free (rms);
}