diff options
author | Özgür Kesim <oec-taler@kesim.org> | 2022-02-22 14:27:15 +0100 |
---|---|---|
committer | Özgür Kesim <oec-taler@kesim.org> | 2022-02-22 14:34:47 +0100 |
commit | 26158fc72505be6323282dc39509fd531c10a290 (patch) | |
tree | 117e5b7a580c056717a0303fc9f82c391207ff67 /src/exchangedb | |
parent | 0141a8216162a33b4656f95a2d5305843ca4aeba (diff) | |
download | exchange-26158fc72505be6323282dc39509fd531c10a290.tar.xz |
[age restriction] progress 16/n - refresh/reveal/link tests
Age restriction works now with withdraw, melt/refresh/reveal and link,
including tests.
However, there is still a problem with the tests: The melting operation
"refresh-melt-failing-age" that should fail (because of conflict), but
currently fails for other reasons. I decided to disable that particular
test (and the next) and submit the patch I have so far.
Diffstat (limited to 'src/exchangedb')
-rw-r--r-- | src/exchangedb/exchange-0001.sql | 11 | ||||
-rw-r--r-- | src/exchangedb/irbt_callbacks.c | 2 | ||||
-rw-r--r-- | src/exchangedb/plugin_exchangedb_postgres.c | 48 |
3 files changed, 39 insertions, 22 deletions
diff --git a/src/exchangedb/exchange-0001.sql b/src/exchangedb/exchange-0001.sql index 3f9979c06..0cef7d0db 100644 --- a/src/exchangedb/exchange-0001.sql +++ b/src/exchangedb/exchange-0001.sql @@ -311,7 +311,7 @@ CREATE TABLE IF NOT EXISTS known_coins (known_coin_id BIGINT GENERATED BY DEFAULT AS IDENTITY -- UNIQUE ,denominations_serial INT8 NOT NULL REFERENCES denominations (denominations_serial) ON DELETE CASCADE ,coin_pub BYTEA NOT NULL PRIMARY KEY CHECK (LENGTH(coin_pub)=32) - ,age_hash BYTEA CHECK (LENGTH(age_hash)=32) + ,age_commitment_hash BYTEA CHECK (LENGTH(age_commitment_hash)=32) ,denom_sig BYTEA NOT NULL ,remaining_val INT8 NOT NULL ,remaining_frac INT4 NOT NULL @@ -325,8 +325,8 @@ COMMENT ON COLUMN known_coins.coin_pub IS 'EdDSA public key of the coin'; COMMENT ON COLUMN known_coins.remaining_val IS 'Value of the coin that remains to be spent'; -COMMENT ON COLUMN known_coins.age_hash - IS 'Optional hash for age restrictions as per DD 24 (active if denom_type has the respective bit set)'; +COMMENT ON COLUMN known_coins.age_commitment_hash + IS 'Optional hash of the age commitment for age restrictions as per DD 24 (active if denom_type has the respective bit set)'; COMMENT ON COLUMN known_coins.denom_sig IS 'This is the signature of the exchange that affirms that the coin is a valid coin. The specific signature type depends on denom_type of the denomination.'; CREATE TABLE IF NOT EXISTS known_coins_default @@ -358,7 +358,7 @@ COMMENT ON COLUMN refresh_commitments.rc COMMENT ON COLUMN refresh_commitments.old_coin_pub IS 'Coin being melted in the refresh process.'; COMMENT ON COLUMN refresh_commitments.h_age_commitment - IS '(optional) age commitment that was involved in the minting process of the coin, may be NULL.'; + IS 'The (optional) age commitment that was involved in the minting process of the coin, may be NULL.'; CREATE TABLE IF NOT EXISTS refresh_commitments_default PARTITION OF refresh_commitments FOR VALUES WITH (MODULUS 1, REMAINDER 0); @@ -1259,6 +1259,7 @@ CREATE OR REPLACE FUNCTION exchange_do_melt( IN in_old_coin_pub BYTEA, IN in_old_coin_sig BYTEA, IN in_known_coin_id INT8, -- not used, but that's OK + IN in_h_age_commitment BYTEA, IN in_noreveal_index INT4, IN in_zombie_required BOOLEAN, OUT out_balance_ok BOOLEAN, @@ -1281,6 +1282,7 @@ INSERT INTO refresh_commitments ,old_coin_sig ,amount_with_fee_val ,amount_with_fee_frac + ,h_age_commitment ,noreveal_index ) VALUES @@ -1289,6 +1291,7 @@ INSERT INTO refresh_commitments ,in_old_coin_sig ,in_amount_with_fee_val ,in_amount_with_fee_frac + ,in_h_age_commitment ,in_noreveal_index) ON CONFLICT DO NOTHING; diff --git a/src/exchangedb/irbt_callbacks.c b/src/exchangedb/irbt_callbacks.c index cf0549420..3673c7be1 100644 --- a/src/exchangedb/irbt_callbacks.c +++ b/src/exchangedb/irbt_callbacks.c @@ -406,6 +406,8 @@ irbt_cb_table_refresh_commitments (struct PostgresClosure *pg, &td->details.refresh_commitments.noreveal_index), GNUNET_PQ_query_param_auto_from_type ( &td->details.refresh_commitments.old_coin_pub), + GNUNET_PQ_query_param_auto_from_type ( + &td->details.refresh_commitments.h_age_commitment), GNUNET_PQ_query_param_end }; diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index b5bf71e50..2f59401c6 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -611,7 +611,7 @@ prepare_statements (struct PostgresClosure *pg) ",out_zombie_bad AS zombie_required" ",out_noreveal_index AS noreveal_index" " FROM exchange_do_melt" - " ($1,$2,$3,$4,$5,$6,$7,$8,$9);", + " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10);", 9), /* Used in #postgres_do_refund() to refund a deposit. */ GNUNET_PQ_make_prepare ( @@ -730,7 +730,7 @@ prepare_statements (struct PostgresClosure *pg) "get_known_coin", "SELECT" " denominations.denom_pub_hash" - ",age_hash" + ",age_commitment_hash" ",denom_sig" " FROM known_coins" " JOIN denominations USING (denominations_serial)" @@ -784,7 +784,7 @@ prepare_statements (struct PostgresClosure *pg) " INSERT INTO known_coins " " (coin_pub" " ,denominations_serial" - " ,age_hash" + " ,age_commitment_hash" " ,denom_sig" " ,remaining_val" " ,remaining_frac" @@ -804,14 +804,14 @@ prepare_statements (struct PostgresClosure *pg) " FALSE AS existed" " ,known_coin_id" " ,NULL AS denom_pub_hash" - " ,NULL AS age_hash" + " ,NULL AS age_commitment_hash" " FROM ins " "UNION ALL " "SELECT " " TRUE AS existed" " ,known_coin_id" " ,denom_pub_hash" - " ,kc.age_hash" + " ,kc.age_commitment_hash" " FROM input_rows" " JOIN known_coins kc USING (coin_pub)" " JOIN denominations USING (denominations_serial)" @@ -873,6 +873,7 @@ prepare_statements (struct PostgresClosure *pg) ",denoms.denom_pub_hash" ",denoms.fee_refresh_val" ",denoms.fee_refresh_frac" + ",h_age_commitment" ",melt_serial_id" " FROM refresh_commitments" " JOIN known_coins kc" @@ -1188,7 +1189,7 @@ prepare_statements (struct PostgresClosure *pg) ",denoms.fee_deposit_val" ",denoms.fee_deposit_frac" ",denoms.denom_pub_hash" - ",kc.age_hash" + ",kc.age_commitment_hash" ",wallet_timestamp" ",refund_deadline" ",wire_deadline" @@ -2529,8 +2530,9 @@ prepare_statements (struct PostgresClosure *pg) ",amount_with_fee_frac" ",noreveal_index" ",old_coin_pub" + ",h_age_commitment" ") VALUES " - "($1, $2, $3, $4, $5, $6, $7);", + "($1, $2, $3, $4, $5, $6, $7, $8);", 7), GNUNET_PQ_make_prepare ( "insert_into_table_refresh_revealed_coins", @@ -4593,6 +4595,7 @@ postgres_do_melt ( GNUNET_PQ_query_param_auto_from_type (&refresh->coin.coin_pub), GNUNET_PQ_query_param_auto_from_type (&refresh->coin_sig), GNUNET_PQ_query_param_uint64 (&known_coin_id), + GNUNET_PQ_query_param_auto_from_type (&refresh->coin.h_age_commitment), GNUNET_PQ_query_param_uint32 (&refresh->noreveal_index), GNUNET_PQ_query_param_bool (*zombie_required), GNUNET_PQ_query_param_end @@ -5646,7 +5649,7 @@ postgres_get_known_coin (void *cls, GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash", &coin_info->denom_pub_hash), GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_auto_from_type ("age_hash", + GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash", &coin_info->h_age_commitment), &is_null), TALER_PQ_result_spec_denom_sig ("denom_sig", @@ -5747,7 +5750,7 @@ postgres_count_known_coins (void *cls, * @param[out] known_coin_id set to the unique row of the coin * @param[out] denom_hash set to the denomination hash of the existing * coin (for conflict error reporting) - * @param[out] age_hash set to the conflicting age hash on conflict + * @param[out] h_age_commitment set to the conflicting age commitment hash on conflict * @return database transaction status, non-negative on success */ static enum TALER_EXCHANGEDB_CoinKnownStatus @@ -5755,7 +5758,7 @@ postgres_ensure_coin_known (void *cls, const struct TALER_CoinPublicInfo *coin, uint64_t *known_coin_id, struct TALER_DenominationHashP *denom_hash, - struct TALER_AgeCommitmentHash *age_hash) + struct TALER_AgeCommitmentHash *h_age_commitment) { struct PostgresClosure *pg = cls; enum GNUNET_DB_QueryStatus qs; @@ -5779,8 +5782,8 @@ postgres_ensure_coin_known (void *cls, denom_hash), &is_denom_pub_hash_null), GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_auto_from_type ("age_hash", - age_hash), + GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash", + h_age_commitment), &is_age_hash_null), GNUNET_PQ_result_spec_end }; @@ -5814,10 +5817,10 @@ postgres_ensure_coin_known (void *cls, } if ( (! is_age_hash_null) && - (0 != GNUNET_memcmp (age_hash, + (0 != GNUNET_memcmp (h_age_commitment, &coin->h_age_commitment)) ) { - GNUNET_break (GNUNET_is_zero (age_hash)); + GNUNET_break (GNUNET_is_zero (h_age_commitment)); GNUNET_break_op (0); return TALER_EXCHANGEDB_CKS_AGE_CONFLICT; } @@ -6066,7 +6069,7 @@ postgres_get_melt (void *cls, &melt->session.coin_sig), GNUNET_PQ_result_spec_allow_null ( GNUNET_PQ_result_spec_auto_from_type ("h_age_commitment", - &melt->session.h_age_commitment), + &melt->session.coin.h_age_commitment), &h_age_commitment_is_null), TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee", &melt->session.amount_with_fee), @@ -6084,9 +6087,9 @@ postgres_get_melt (void *cls, params, rs); if (h_age_commitment_is_null) - memset (&melt->session.h_age_commitment, + memset (&melt->session.coin.h_age_commitment, 0, - sizeof(melt->session.h_age_commitment)); + sizeof(melt->session.coin.h_age_commitment)); melt->session.rc = *rc; return qs; @@ -6600,7 +6603,7 @@ add_coin_deposit (void *cls, GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash", &deposit->h_denom_pub), GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_auto_from_type ("age_hash", + GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash", &deposit->h_age_commitment), &is_null), GNUNET_PQ_result_spec_timestamp ("wallet_timestamp", @@ -6668,6 +6671,7 @@ add_coin_melt (void *cls, struct TALER_EXCHANGEDB_MeltListEntry *melt; struct TALER_EXCHANGEDB_TransactionList *tl; uint64_t serial_id; + bool hac_isnull; chc->have_deposit_or_melt = true; melt = GNUNET_new (struct TALER_EXCHANGEDB_MeltListEntry); @@ -6684,6 +6688,10 @@ add_coin_melt (void *cls, &melt->amount_with_fee), TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refresh", &melt->melt_fee), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_auto_from_type ("h_age_commitment", + &melt->h_age_commitment), + &hac_isnull), GNUNET_PQ_result_spec_uint64 ("melt_serial_id", &serial_id), GNUNET_PQ_result_spec_end @@ -6699,6 +6707,10 @@ add_coin_melt (void *cls, chc->failed = true; return; } + + if (hac_isnull) + memset (&melt->h_age_commitment, 0, sizeof(melt->h_age_commitment)); + } tl = GNUNET_new (struct TALER_EXCHANGEDB_TransactionList); tl->next = chc->head; |