exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

commit 7ea69935a917de5b28af2cfc7946dbccdde85f44
parent 9a68b1c633019dfe2c2072315be06570a105be52
Author: Christian Grothoff <grothoff@gnunet.org>
Date:   Wed, 14 May 2025 15:28:15 +0200

fix #9926

Diffstat:
Msrc/auditor/taler-helper-auditor-coins.c | 40++++++++++++++++++++--------------------
Msrc/exchangedb/0002-withdraw.sql | 10+++++-----
Msrc/exchangedb/pg_select_withdrawals_above_serial_id.c | 90++++++++++++++++++++++++++++++++++---------------------------------------------
Msrc/include/taler_exchangedb_plugin.h | 10+++++-----
4 files changed, 69 insertions(+), 81 deletions(-)

diff --git a/src/auditor/taler-helper-auditor-coins.c b/src/auditor/taler-helper-auditor-coins.c @@ -977,11 +977,11 @@ cleanup_denomination (void *cls, * * @param cls our `struct CoinContext` * @param rowid unique serial ID for the refresh session in our DB - * @param num_evs number of elements in @e h_blind_evs - * @param h_blind_evs array @e num_evs of blinded hashes of the coin's public keys - * @param denom_serials array @e num_evs of serial ID's of denominations in our DB + * @param num_denom_serials number of elements in @e denom_serials array + * @param denom_serials array with length @e num_denom_serials of serial ID's of denominations in our DB + * @param selected_h hash over the gamma-selected planchets * @param h_planchets running hash over all hashes of blinded planchets in the original withdraw request - * @param blinding_seed the master seed for CS denominations that was provided during withdraw; might be NULL + * @param blinding_seed the blinding seed for CS denominations that was provided during withdraw; might be NULL * @param age_proof_required true if the withdraw request required an age proof. * @param max_age if @e age_proof_required is true, the maximum age that was set on the coins. * @param noreveal_index if @e age_proof_required is true, the index that was returned by the exchange for the reveal phase. @@ -992,26 +992,26 @@ cleanup_denomination (void *cls, * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop */ static enum GNUNET_GenericReturnValue -withdraw_cb (void *cls, - uint64_t rowid, - size_t num_evs, - const struct TALER_BlindedCoinHashP *h_blind_evs, - const uint64_t *denom_serials, - const struct TALER_HashBlindedPlanchetsP *h_planchets, - const struct TALER_BlindingMasterSeedP *blinding_seed, - bool age_proof_required, - uint8_t max_age, - uint8_t noreveal_index, - const struct TALER_ReservePublicKeyP *reserve_pub, - const struct TALER_ReserveSignatureP *reserve_sig, - struct GNUNET_TIME_Timestamp execution_date, - const struct TALER_Amount *amount_with_fee) +withdraw_cb ( + void *cls, + uint64_t rowid, + size_t num_denom_serials, + const uint64_t *denom_serials, + const struct TALER_HashBlindedPlanchetsP *selected_h, + const struct TALER_HashBlindedPlanchetsP *h_planchets, + const struct TALER_BlindingMasterSeedP *blinding_seed, + bool age_proof_required, + uint8_t max_age, + uint8_t noreveal_index, + const struct TALER_ReservePublicKeyP *reserve_pub, + const struct TALER_ReserveSignatureP *reserve_sig, + struct GNUNET_TIME_Timestamp execution_date, + const struct TALER_Amount *amount_with_fee) { struct CoinContext *cc = cls; /* Note: some optimization potential here: lots of fields we could avoid fetching from the database with a custom function. */ - (void) h_blind_evs; (void) h_planchets; (void) blinding_seed; (void) reserve_pub; @@ -1023,7 +1023,7 @@ withdraw_cb (void *cls, TALER_ARL_USE_PP (coins_withdraw_serial_id)); /* should be monotonically increasing */ TALER_ARL_USE_PP (coins_withdraw_serial_id) = rowid + 1; - for (size_t i=0; i < num_evs; i++) + for (size_t i=0; i < num_denom_serials; i++) { struct DenominationSummary *ds; const struct TALER_EXCHANGEDB_DenominationKeyInformation *issue; diff --git a/src/exchangedb/0002-withdraw.sql b/src/exchangedb/0002-withdraw.sql @@ -26,16 +26,16 @@ DECLARE BEGIN PERFORM create_partitioned_table( 'CREATE TABLE %I' - '(withdraw_id BIGINT GENERATED BY DEFAULT AS IDENTITY' - ',planchets_h BYTEA CONSTRAINT planchets_h_length CHECK(LENGTH(planchets_h)=64)' + '(withdraw_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- FIXME: NOT NULL?? + ',planchets_h BYTEA CONSTRAINT planchets_h_length CHECK(LENGTH(planchets_h)=64)' -- FIXME: NOT NULL?? ',execution_date INT8 NOT NULL' ',amount_with_fee taler_amount NOT NULL' ',reserve_pub BYTEA NOT NULL CONSTRAINT reserve_pub_length CHECK(LENGTH(reserve_pub)=32)' ',reserve_sig BYTEA NOT NULL CONSTRAINT reserve_sig_length CHECK(LENGTH(reserve_sig)=64)' ',max_age SMALLINT CONSTRAINT max_age_positive CHECK(max_age>=0)' - ',noreveal_index SMALLINT CONSTRAINT noreveal_index_positive CHECK(noreveal_index>=0)' - ',selected_h BYTEA CONSTRAINT selected_h_length CHECK(LENGTH(selected_h)=64)' - ',blinding_seed BYTEA CONSTRAINT blinding_seed_length CHECK(LENGTH(blinding_seed)>=32)' + ',noreveal_index SMALLINT CONSTRAINT noreveal_index_positive CHECK(noreveal_index>=0)' -- FIXME: NOT NULL?? + ',selected_h BYTEA CONSTRAINT selected_h_length CHECK(LENGTH(selected_h)=64)' -- FIXME: NOT NULL?? + ',blinding_seed BYTEA CONSTRAINT blinding_seed_length CHECK(LENGTH(blinding_seed)>=32)' -- FIXME: NOT NULL?? ',cs_r_values BYTEA[]' ',cs_r_choices INT8' ',denom_serials INT8[] NOT NULL CONSTRAINT denom_serials_array_length CHECK(cardinality(denom_serials)=cardinality(denom_sigs))' diff --git a/src/exchangedb/pg_select_withdrawals_above_serial_id.c b/src/exchangedb/pg_select_withdrawals_above_serial_id.c @@ -72,43 +72,35 @@ withdraw_serial_helper_cb (void *cls, for (unsigned int i = 0; i<num_results; i++) { - size_t num_evs; - struct TALER_BlindedCoinHashP *h_blind_evs = NULL; - size_t num_denom_serials; - uint64_t *denom_serials = NULL; - struct TALER_ReservePublicKeyP reserve_pub; - struct TALER_ReserveSignatureP reserve_sig; - struct GNUNET_TIME_Timestamp execution_date; + uint64_t rowid; struct TALER_HashBlindedPlanchetsP h_planchets; - struct TALER_BlindingMasterSeedP blinding_seed; + struct GNUNET_TIME_Timestamp execution_date; struct TALER_Amount amount_with_fee; - uint64_t rowid; + struct TALER_ReservePublicKeyP reserve_pub; + struct TALER_ReserveSignatureP reserve_sig; uint16_t max_age; + bool no_max_age; uint16_t noreveal_index; bool no_noreveal_index; - bool no_max_age; + struct TALER_HashBlindedPlanchetsP selected_h; + bool no_selected_h; + struct TALER_BlindingMasterSeedP blinding_seed; bool no_blinding_seed; + size_t num_denom_serials; + uint64_t *denom_serials = NULL; struct GNUNET_PQ_ResultSpec rs[] = { - TALER_PQ_result_spec_array_blinded_coin_hash (pg->conn, - "h_blind_evs", - &num_evs, - &h_blind_evs), - GNUNET_PQ_result_spec_array_uint64 (pg->conn, - "denom_serials", - &num_denom_serials, - &denom_serials), - GNUNET_PQ_result_spec_auto_from_type ("reserve_pub", - &reserve_pub), - GNUNET_PQ_result_spec_auto_from_type ("reserve_sig", - &reserve_sig), - GNUNET_PQ_result_spec_auto_from_type ("h_planchets", + GNUNET_PQ_result_spec_uint64 ("withdraw_id", + &rowid), + GNUNET_PQ_result_spec_auto_from_type ("planchets_h", &h_planchets), GNUNET_PQ_result_spec_timestamp ("execution_date", &execution_date), TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee", &amount_with_fee), - GNUNET_PQ_result_spec_uint64 ("withdraw_id", - &rowid), + GNUNET_PQ_result_spec_auto_from_type ("reserve_pub", + &reserve_pub), + GNUNET_PQ_result_spec_auto_from_type ("reserve_sig", + &reserve_sig), GNUNET_PQ_result_spec_allow_null ( GNUNET_PQ_result_spec_uint16 ("max_age", &max_age), @@ -118,9 +110,20 @@ withdraw_serial_helper_cb (void *cls, &noreveal_index), &no_noreveal_index), GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_auto_from_type ("blinding_seed", - &blinding_seed), + GNUNET_PQ_result_spec_auto_from_type ( + "selected_h", + &selected_h), + &no_selected_h), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_auto_from_type ( + "blinding_seed", + &blinding_seed), &no_blinding_seed), + GNUNET_PQ_result_spec_array_uint64 ( + pg->conn, + "denom_serials", + &num_denom_serials, + &denom_serials), GNUNET_PQ_result_spec_end }; enum GNUNET_GenericReturnValue ret; @@ -135,21 +138,6 @@ withdraw_serial_helper_cb (void *cls, GNUNET_PQ_cleanup_result (rs); return; } - if (num_denom_serials != num_evs) - { - GNUNET_break (0); - rosc->status = GNUNET_SYSERR; - GNUNET_PQ_cleanup_result (rs); - return; - } - if (no_max_age != no_noreveal_index) - { - GNUNET_break (0); - rosc->status = GNUNET_SYSERR; - GNUNET_PQ_cleanup_result (rs); - return; - } - if ((! no_max_age) && ((255 <= noreveal_index) || (255 <= max_age))) { @@ -160,9 +148,9 @@ withdraw_serial_helper_cb (void *cls, } ret = rosc->cb (rosc->cb_cls, rowid, - num_evs, - h_blind_evs, + num_denom_serials, denom_serials, + no_selected_h ? NULL : &selected_h, &h_planchets, no_blinding_seed ? NULL : &blinding_seed, ! no_max_age, @@ -204,16 +192,16 @@ TEH_PG_select_withdrawals_above_serial_id ( "audit_get_withdraw_incr", "SELECT" " withdraw_id" - ",h_planchets" - ",blinding_seed" - ",h_blind_evs" + ",planchets_h" + ",execution_date" + ",amount_with_fee" + ",reserve_pub" + ",reserve_sig" ",max_age" ",noreveal_index" + ",selected_h" + ",blinding_seed" ",denom_serials" - ",reserve_sig" - ",reserve_pub" - ",execution_date" - ",amount_with_fee" " FROM withdraw" " WHERE withdraw_id>=$1" " ORDER BY withdraw_id ASC;"); diff --git a/src/include/taler_exchangedb_plugin.h b/src/include/taler_exchangedb_plugin.h @@ -3434,9 +3434,9 @@ typedef void * * @param cls closure * @param rowid unique serial ID for the refresh session in our DB - * @param num_evs number of elements in @e h_blind_evs - * @param h_blind_evs array @e num_evs of blinded hashes of the coin's public keys - * @param denom_serials array @e num_evs of serial ID's of denominations in our DB + * @param num_denom_serials number of elements in @e denom_serials array + * @param denom_serials array with length @e num_denom_serials of serial ID's of denominations in our DB + * @param selected_h hash over the gamma-selected planchets * @param h_planchets running hash over all hashes of blinded planchets in the original withdraw request * @param blinding_seed the blinding seed for CS denominations that was provided during withdraw; might be NULL * @param age_proof_required true if the withdraw request required an age proof. @@ -3452,9 +3452,9 @@ typedef enum GNUNET_GenericReturnValue (*TALER_EXCHANGEDB_WithdrawCallback)( void *cls, uint64_t rowid, - size_t num_evs, - const struct TALER_BlindedCoinHashP *h_blind_evs, + size_t num_denom_serials, const uint64_t *denom_serials, + const struct TALER_HashBlindedPlanchetsP *selected_h, const struct TALER_HashBlindedPlanchetsP *h_planchets, const struct TALER_BlindingMasterSeedP *blinding_seed, bool age_proof_required,