check refresh amounts add up correctly, fix linker issue

This commit is contained in:
Christian Grothoff 2016-06-15 20:09:09 +02:00
parent c38a7c5518
commit 8c7406cb42
3 changed files with 52 additions and 7 deletions

View File

@ -38,6 +38,7 @@ libtalerfakebank_la_LIBADD = \
-lgnunetjson \ -lgnunetjson \
-lgnunetutil \ -lgnunetutil \
-ljansson \ -ljansson \
-lmicrohttpd \
$(XLIB) $(XLIB)

View File

@ -186,7 +186,7 @@ struct Coin
struct TALER_EXCHANGE_DepositHandle *dh; struct TALER_EXCHANGE_DepositHandle *dh;
/** /**
* Array of denominations expected to get from melt * Array of denominations we expect to get from melt.
*/ */
struct TALER_Amount *denoms; struct TALER_Amount *denoms;
@ -691,14 +691,17 @@ refresh_coin (struct Coin *coin)
struct TALER_EXCHANGE_DenomPublicKey *dpks = NULL; struct TALER_EXCHANGE_DenomPublicKey *dpks = NULL;
const struct TALER_EXCHANGE_DenomPublicKey *curr_dpk; const struct TALER_EXCHANGE_DenomPublicKey *curr_dpk;
struct TALER_Amount curr; struct TALER_Amount curr;
struct TALER_Amount left;
unsigned int ndenoms = 0; unsigned int ndenoms = 0;
unsigned int ndenoms2 = 0; unsigned int ndenoms2 = 0;
unsigned int off; unsigned int off;
GNUNET_break (NULL == coin->denoms);
TALER_amount_get_zero (currency, &curr); TALER_amount_get_zero (currency, &curr);
left = coin->left;
off = 0; off = 0;
while (0 != TALER_amount_cmp (&curr, while (0 != TALER_amount_cmp (&curr,
&coin->left)) &left))
{ {
if (off >= refresh_pk_len) if (off >= refresh_pk_len)
{ {
@ -707,7 +710,7 @@ refresh_coin (struct Coin *coin)
break; break;
} }
curr_dpk = &refresh_pk[off]; curr_dpk = &refresh_pk[off];
while (-1 != TALER_amount_cmp (&coin->left, while (-1 != TALER_amount_cmp (&left,
&curr_dpk->value)) &curr_dpk->value))
{ {
GNUNET_array_append (denoms, GNUNET_array_append (denoms,
@ -716,9 +719,10 @@ refresh_coin (struct Coin *coin)
GNUNET_array_append (dpks, GNUNET_array_append (dpks,
ndenoms2, ndenoms2,
*curr_dpk); *curr_dpk);
TALER_amount_subtract (&coin->left, GNUNET_assert (GNUNET_SYSERR !=
&coin->left, TALER_amount_subtract (&left,
&curr_dpk->value); &left,
&curr_dpk->value));
} }
off++; off++;
} }
@ -1585,6 +1589,11 @@ main (int argc,
GNUNET_assert (GNUNET_SYSERR != ret); GNUNET_assert (GNUNET_SYSERR != ret);
if (GNUNET_NO == ret) if (GNUNET_NO == ret)
return 0; return 0;
if ( (0 != num_iterations) &&
(WARM_THRESHOLD >= num_iterations) )
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Number of iterations below WARM_THRESHOLD of %llu\n",
WARM_THRESHOLD);
if ( (NULL == exchange_uri) || if ( (NULL == exchange_uri) ||
(0 == strlen (exchange_uri) )) (0 == strlen (exchange_uri) ))
{ {

View File

@ -764,6 +764,7 @@ TALER_EXCHANGE_refresh_prepare (const struct TALER_CoinSpendPrivateKeyP *melt_pr
unsigned int i; unsigned int i;
unsigned int j; unsigned int j;
struct GNUNET_HashContext *hash_context; struct GNUNET_HashContext *hash_context;
struct TALER_Amount total;
/* build up melt data structure */ /* build up melt data structure */
for (i=0;i<TALER_CNC_KAPPA;i++) for (i=0;i<TALER_CNC_KAPPA;i++)
@ -799,9 +800,43 @@ TALER_EXCHANGE_refresh_prepare (const struct TALER_CoinSpendPrivateKeyP *melt_pr
md.fresh_coins[i] = GNUNET_new_array (fresh_pks_len, md.fresh_coins[i] = GNUNET_new_array (fresh_pks_len,
struct FreshCoinP); struct FreshCoinP);
for (j=0;j<fresh_pks_len;j++) for (j=0;j<fresh_pks_len;j++)
{
setup_fresh_coin (&md.fresh_coins[i][j], setup_fresh_coin (&md.fresh_coins[i][j],
&fresh_pks[j]); &fresh_pks[j]);
} }
}
/* verify that melt_amount is above total cost */
GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (melt_amount->currency,
&total));
for (j=0;j<fresh_pks_len;j++)
{
if ( (GNUNET_OK !=
TALER_amount_add (&total,
&total,
&fresh_pks[j].value)) ||
(GNUNET_OK !=
TALER_amount_add (&total,
&total,
&fresh_pks[j].fee_withdraw)) )
{
GNUNET_break (0);
free_melt_data (&md);
return NULL;
}
}
if (1 ==
TALER_amount_cmp (&total,
melt_amount) )
{
/* Eh, this operation is more expensive than the
@a melt_amount. This is not OK. */
GNUNET_break (0);
free_melt_data (&md);
return NULL;
}
/* now compute melt session hash */ /* now compute melt session hash */
hash_context = GNUNET_CRYPTO_hash_context_start (); hash_context = GNUNET_CRYPTO_hash_context_start ();