commit a03c24e990b73afdf35dec0efed03ed5ac5e1b13
parent 560d10148b036677f41f624def3d4c95f966e886
Author: Özgür Kesim <oec@codeblau.de>
Date: Sun, 25 Oct 2026 16:15:25 +0100
[exchangedb] store the commitment version of a melt (#11862)
New column refresh.rc_version (exchange-0020): old rows 1, v27 rows 0,
new rows 2.
Diffstat:
14 files changed, 236 insertions(+), 3 deletions(-)
diff --git a/meson.build b/meson.build
@@ -285,7 +285,7 @@ if not get_option('only-doc')
['libtalertemplating', '1:1:1'],
['libtalerbank', '7:0:0'],
['libtalerkyclogic', '3:0:0'],
- ['libtalerexchangedb', '4:0:0'],
+ ['libtalerexchangedb', '5:0:0'],
['libtalerauditordb', '1:0:0'],
['libtalerexchange', '25:0:0'],
['libtalerauditor', '1:0:1'],
diff --git a/src/exchange/taler-exchange-httpd_post-melt.c b/src/exchange/taler-exchange-httpd_post-melt.c
@@ -951,6 +951,10 @@ phase_check_coin_signature (
k_transfer_pubs.batch[k] = mc->request.transfer_pubs[k];
}
+ mc->request.refresh.rc_version
+ = mc->request.refresh.is_v27_refresh
+ ? TALER_REFRESH_COMMITMENT_VERSION_LEGACY_V27
+ : TALER_REFRESH_COMMITMENT_VERSION_CURRENT;
if (mc->request.refresh.is_v27_refresh)
TALER_refresh_get_commitment_legacy_v27 (
&mc->request.refresh.rc,
diff --git a/src/exchangedb/do_refresh.c b/src/exchangedb/do_refresh.c
@@ -36,6 +36,7 @@ TALER_EXCHANGEDB_do_refresh (
bool *balance_ok,
struct TALER_Amount *coin_balance)
{
+ uint32_t rc_version = refresh->rc_version;
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (&refresh->rc),
GNUNET_PQ_query_param_timestamp (timestamp),
@@ -70,6 +71,7 @@ TALER_EXCHANGEDB_do_refresh (
GNUNET_PQ_query_param_auto_from_type (&refresh->coin_sig),
GNUNET_PQ_query_param_uint32 (&refresh->noreveal_index), /* 15 */
GNUNET_PQ_query_param_bool (*zombie_required),
+ GNUNET_PQ_query_param_uint32 (&rc_version),
GNUNET_PQ_query_param_end
};
bool coin_found;
@@ -98,6 +100,9 @@ TALER_EXCHANGEDB_do_refresh (
};
enum GNUNET_DB_QueryStatus qs;
+ GNUNET_assert (refresh->is_v27_refresh ==
+ (TALER_REFRESH_COMMITMENT_VERSION_LEGACY_V27 ==
+ refresh->rc_version));
PREPARE (pg,
"do_refresh",
"SELECT "
@@ -109,7 +114,7 @@ TALER_EXCHANGEDB_do_refresh (
",out_noreveal_index AS noreveal_index"
",out_coin_balance AS coin_balance"
" FROM exchange_do_refresh"
- " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16);");
+ " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17);");
qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
"do_refresh",
params,
diff --git a/src/exchangedb/do_refresh.sql b/src/exchangedb/do_refresh.sql
@@ -34,6 +34,7 @@ CREATE FUNCTION exchange_do_refresh(
IN in_old_coin_sig BYTEA,
IN in_noreveal_index INT4,
IN in_zombie_required BOOLEAN,
+ IN in_rc_version INT4,
OUT out_coin_found BOOLEAN,
OUT out_balance_ok BOOLEAN,
OUT out_zombie_bad BOOLEAN,
@@ -134,6 +135,7 @@ INSERT INTO exchange.refresh
,selected_h
,denom_sigs
,denom_serials
+ ,rc_version
)
VALUES
(in_rc
@@ -151,6 +153,7 @@ INSERT INTO exchange.refresh
,in_selected_h
,in_denom_sigs
,in_denom_serials
+ ,in_rc_version
)
ON CONFLICT DO NOTHING;
diff --git a/src/exchangedb/get_refresh.c b/src/exchangedb/get_refresh.c
@@ -42,6 +42,7 @@ TALER_EXCHANGEDB_get_refresh (
struct GNUNET_CRYPTO_CSPublicRPairP *cs_r_values = NULL;
struct TALER_TransferPublicKeyP *transfer_pubs = NULL;
uint64_t *denom_serials = NULL;
+ uint32_t rc_version;
struct GNUNET_PQ_ResultSpec rs[] = {
GNUNET_PQ_result_spec_uint64 ("refresh_id",
&refresh->refresh_id),
@@ -94,6 +95,8 @@ TALER_EXCHANGEDB_get_refresh (
&denom_sigs),
GNUNET_PQ_result_spec_bool ("revealed",
&refresh->revealed),
+ GNUNET_PQ_result_spec_uint32 ("rc_version",
+ &rc_version),
GNUNET_PQ_result_spec_end
};
enum GNUNET_DB_QueryStatus qs;
@@ -120,6 +123,7 @@ TALER_EXCHANGEDB_get_refresh (
",denom_serials"
",denom_sigs"
",revealed"
+ ",rc_version"
" FROM refresh"
" JOIN known_coins kc"
" ON (old_coin_pub = kc.coin_pub)"
@@ -152,6 +156,31 @@ TALER_EXCHANGEDB_get_refresh (
GNUNET_PQ_cleanup_result (rs);
return GNUNET_DB_STATUS_HARD_ERROR;
}
+ switch (rc_version)
+ {
+ case TALER_REFRESH_COMMITMENT_VERSION_LEGACY_V27:
+ case TALER_REFRESH_COMMITMENT_VERSION_LEGACY_VDOLDPLUS_BROKEN:
+ case TALER_REFRESH_COMMITMENT_VERSION_CURRENT:
+ break;
+ default:
+ GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "got unknown rc_version %u in refresh from DB\n",
+ (unsigned int) rc_version);
+ GNUNET_PQ_cleanup_result (rs);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ refresh->rc_version = (enum TALER_RefreshCommitmentVersion) rc_version;
+ if (no_transfer_pubs !=
+ (TALER_REFRESH_COMMITMENT_VERSION_LEGACY_V27 == refresh->rc_version))
+ {
+ GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "rc_version %u inconsistent with transfer_pubs in refresh from DB\n",
+ (unsigned int) rc_version);
+ GNUNET_PQ_cleanup_result (rs);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
if (no_transfer_pubs)
{
refresh->is_v27_refresh = true;
diff --git a/src/exchangedb/insert_records_by_table.c b/src/exchangedb/insert_records_by_table.c
@@ -882,6 +882,8 @@ irbt_cb_table_refresh (struct TALER_EXCHANGEDB_PostgresContext *pg,
td->details.refresh.num_coins,
td->details.refresh.denom_sigs,
pg->conn),
+ GNUNET_PQ_query_param_uint32 (
+ &td->details.refresh.rc_version),
GNUNET_PQ_query_param_end
};
enum GNUNET_DB_QueryStatus qs;
@@ -904,8 +906,9 @@ irbt_cb_table_refresh (struct TALER_EXCHANGEDB_PostgresContext *pg,
",cs_r_choices"
",denom_serials"
",denom_sigs"
+ ",rc_version"
") VALUES "
- "($1, $2, $3, $4, $5, $6,$7,$8,$9,$10,$11,$12,$13,$14,$15);");
+ "($1, $2, $3, $4, $5, $6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16);");
qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
"insert_records_by_table_into_table_refresh",
params);
diff --git a/src/exchangedb/iterate_records_by_table.c b/src/exchangedb/iterate_records_by_table.c
@@ -973,6 +973,9 @@ lrbt_cb_table_refresh (void *cls,
"denom_sigs",
&num_denom_sigs,
&td.details.refresh.denom_sigs),
+ GNUNET_PQ_result_spec_uint32 (
+ "rc_version",
+ &td.details.refresh.rc_version),
GNUNET_PQ_result_spec_end
};
@@ -3217,6 +3220,7 @@ TALER_EXCHANGEDB_iterate_records_by_table (
",cs_r_choices"
",denom_serials"
",denom_sigs"
+ ",rc_version"
" FROM refresh"
" WHERE refresh_id > $1"
" ORDER BY refresh_id ASC;");
diff --git a/src/exchangedb/sql-schema/exchange-0020.sql b/src/exchangedb/sql-schema/exchange-0020.sql
@@ -0,0 +1,72 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2026 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+
+BEGIN;
+
+SELECT _v.register_patch('exchange-0020', NULL, NULL);
+
+SET search_path TO exchange;
+
+
+-- Record which version of the refresh commitment (see #11862 and
+-- enum TALER_RefreshCommitmentVersion) the client used for the melt,
+-- so that the reveal can recompute the commitment the same way:
+--
+-- 0 v27 clients, without transfer public keys
+-- 1 vDOLDPLUS clients that sent the transfer public keys but did
+-- not include them in the hash
+-- 2 current version, with the transfer public keys in the hash
+--
+-- Existing rows are from v27 clients (no transfer public keys) or from
+-- vDOLDPLUS clients before the fix; new rows default to the current
+-- version.
+
+CREATE FUNCTION alter_table_refresh20()
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ ALTER TABLE refresh
+ ADD COLUMN rc_version INT4 NOT NULL DEFAULT (1);
+ COMMENT ON COLUMN refresh.rc_version
+ IS 'Version of the refresh commitment rc: 0 for v27 (no transfer public keys), 1 for vDOLDPLUS without the transfer public keys in the hash, 2 with them';
+ UPDATE refresh
+ SET rc_version=0
+ WHERE transfer_pubs IS NULL;
+ ALTER TABLE refresh
+ ALTER COLUMN rc_version SET DEFAULT (2);
+
+ -- Auditor sync revisits melts that were pending when first copied.
+ CREATE INDEX refresh_pending_reveal_idx ON refresh (refresh_id)
+ WHERE NOT revealed;
+END
+$$;
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('refresh20'
+ ,'exchange-0020'
+ ,'alter'
+ ,TRUE
+ ,FALSE);
+
+COMMIT;
diff --git a/src/exchangedb/sql-schema/meson.build b/src/exchangedb/sql-schema/meson.build
@@ -196,6 +196,7 @@ generated_sql = [
['exchange-0017.sql', ['exchange-0017.sql']],
['exchange-0018.sql', ['exchange-0018.sql']],
['exchange-0019.sql', ['exchange-0019.sql']],
+ ['exchange-0020.sql', ['exchange-0020.sql']],
['tops-0001.sql', ['tops-0001.sql']],
]
diff --git a/src/exchangedb/test_coin_history.c b/src/exchangedb/test_coin_history.c
@@ -514,6 +514,7 @@ check_other_spends (struct TALER_EXCHANGEDB_PostgresContext *pg)
&rf.denom_sigs[i]);
rf.noreveal_index = 1;
rf.is_v27_refresh = true;
+ rf.rc_version = TALER_REFRESH_COMMITMENT_VERSION_LEGACY_V27;
rf.no_blinding_seed = true;
qs = TALER_EXCHANGEDB_do_refresh (pg,
&rf,
diff --git a/src/exchangedb/test_recoup_refresh.c b/src/exchangedb/test_recoup_refresh.c
@@ -102,6 +102,7 @@ melt (struct TALER_EXCHANGEDB_PostgresContext *pg,
rf.denom_sigs = &denom_sig;
rf.noreveal_index = 0;
rf.is_v27_refresh = true;
+ rf.rc_version = TALER_REFRESH_COMMITMENT_VERSION_LEGACY_V27;
rf.no_blinding_seed = true;
GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
TALER_EXCHANGEDB_do_refresh (pg,
diff --git a/src/exchangedb/test_refresh.c b/src/exchangedb/test_refresh.c
@@ -89,6 +89,7 @@ make_refresh (uint32_t seed,
rf->noreveal_index = 1;
/* v27 refresh: the client provides no transfer public keys */
rf->is_v27_refresh = true;
+ rf->rc_version = TALER_REFRESH_COMMITMENT_VERSION_LEGACY_V27;
rf->no_blinding_seed = ! with_seed;
if (with_seed)
{
@@ -361,6 +362,8 @@ check_refresh (struct TALER_EXCHANGEDB_PostgresContext *pg)
free_refresh (&got); free_refresh (&rf); TDB_coin_free (&coin));
FAILIF_C (! got.is_v27_refresh,
free_refresh (&got); free_refresh (&rf); TDB_coin_free (&coin));
+ FAILIF_C (TALER_REFRESH_COMMITMENT_VERSION_LEGACY_V27 != got.rc_version,
+ free_refresh (&got); free_refresh (&rf); TDB_coin_free (&coin));
free_refresh (&got);
/* the coin was debited */
@@ -702,6 +705,103 @@ check_iterate (struct TALER_EXCHANGEDB_PostgresContext *pg)
/**
+ * vDOLDPLUS melts keep the version of their refresh commitment, which
+ * must agree with the presence of the transfer public keys. New rows
+ * default to the current version.
+ *
+ * @param pg the database context
+ * @return 0 on success
+ */
+static int
+check_rc_version (struct TALER_EXCHANGEDB_PostgresContext *pg)
+{
+ static const enum TALER_RefreshCommitmentVersion versions[] = {
+ TALER_REFRESH_COMMITMENT_VERSION_LEGACY_VDOLDPLUS_BROKEN,
+ TALER_REFRESH_COMMITMENT_VERSION_CURRENT
+ };
+
+ FAILIF (1 != TDB_count (pg,
+ "FROM information_schema.columns"
+ " WHERE table_name='refresh'"
+ " AND column_name='rc_version'"
+ " AND column_default='2'"));
+ for (unsigned int i = 0; i < sizeof (versions) / sizeof (versions[0]); i++)
+ {
+ struct TALER_CoinPublicInfo coin;
+ struct TALER_EXCHANGEDB_Refresh_vDOLDPLUS rf;
+ struct TALER_EXCHANGEDB_Refresh_vDOLDPLUS got;
+ struct RefreshStatus st;
+ char *hex;
+
+ TDB_coin (pg,
+ &denom,
+ 50 + i,
+ &coin,
+ NULL);
+ make_refresh (50 + i,
+ "1",
+ &coin,
+ false,
+ &rf);
+ rf.is_v27_refresh = false;
+ rf.rc_version = versions[i];
+ rf.transfer_pubs = GNUNET_new_array (rf.num_coins,
+ struct TALER_TransferPublicKeyP);
+ TDB_fill (rf.transfer_pubs,
+ sizeof (*rf.transfer_pubs) * rf.num_coins,
+ 50 + i);
+ FAILIF_C (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ run_refresh (pg,
+ &rf,
+ false,
+ &st),
+ free_refresh (&rf); TDB_coin_free (&coin));
+ FAILIF_C (! st.balance_ok,
+ free_refresh (&rf); TDB_coin_free (&coin));
+ memset (&got,
+ 0,
+ sizeof (got));
+ FAILIF_C (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ TALER_EXCHANGEDB_get_refresh (pg,
+ &rf.rc,
+ &got),
+ free_refresh (&rf); TDB_coin_free (&coin));
+ FAILIF_C (versions[i] != got.rc_version,
+ free_refresh (&got); free_refresh (&rf); TDB_coin_free (&coin));
+ FAILIF_C (got.is_v27_refresh,
+ free_refresh (&got); free_refresh (&rf); TDB_coin_free (&coin));
+ FAILIF_C ( (NULL == got.transfer_pubs) ||
+ (0 != GNUNET_memcmp (&got.transfer_pubs[0],
+ &rf.transfer_pubs[0])),
+ free_refresh (&got); free_refresh (&rf); TDB_coin_free (&coin));
+ free_refresh (&got);
+
+ /* a row whose version contradicts its transfer public keys is refused */
+ hex = TDB_hex (&rf.rc,
+ sizeof (rf.rc));
+ FAILIF_C (GNUNET_OK !=
+ TDB_exec (pg,
+ "UPDATE refresh SET rc_version=0"
+ " WHERE rc=decode('%s','hex');",
+ hex),
+ GNUNET_free (hex); free_refresh (&rf); TDB_coin_free (&coin));
+ GNUNET_free (hex);
+ memset (&got,
+ 0,
+ sizeof (got));
+ FAILIF_C (GNUNET_DB_STATUS_HARD_ERROR !=
+ TALER_EXCHANGEDB_get_refresh (pg,
+ &rf.rc,
+ &got),
+ free_refresh (&rf); TDB_coin_free (&coin));
+ free_refresh (&rf);
+ TDB_coin_free (&coin);
+ }
+ return 0;
+}
+
+
+/**
* The checks to run, in order.
*/
static const struct TDB_Test tests[] = {
@@ -719,6 +819,8 @@ static const struct TDB_Test tests[] = {
&check_revealed },
{ "refresh-iterate",
&check_iterate },
+ { "refresh-rc-version",
+ &check_rc_version },
{ NULL, NULL }
};
diff --git a/src/include/exchange-database/iterate_records_by_table.h b/src/include/exchange-database/iterate_records_by_table.h
@@ -332,6 +332,7 @@ struct TALER_EXCHANGEDB_TableData
size_t num_coins;
uint64_t *denom_serials;
struct TALER_BlindedDenominationSignature *denom_sigs;
+ uint32_t rc_version;
} refresh;
struct
diff --git a/src/include/exchangedb_lib.h b/src/include/exchangedb_lib.h
@@ -698,6 +698,13 @@ struct TALER_EXCHANGEDB_Refresh_vDOLDPLUS
bool is_v27_refresh;
/**
+ * Version of the refresh commitment @e rc that the client used.
+ * #TALER_REFRESH_COMMITMENT_VERSION_LEGACY_V27 if and only if
+ * @e is_v27_refresh is true.
+ */
+ enum TALER_RefreshCommitmentVersion rc_version;
+
+ /**
* Public seed from which the refresh nonces (v27) or transfer secrets (vDOLDPLUS)
* per coin candidate were derived from.
*/