View Issue Details

IDProjectCategoryView StatusLast Update
0006170Talerexchangepublic2021-09-02 16:14
Reporterfefe Assigned ToChristian Grothoff Resolution deadline
ImplementerReviewer 
Release signed byDeployed by 
VerifierCommunicator 
Data protection authority notification requiredNo  
CSIRT notification requiredNo  
Estimated effort (hours)Actual effort (hours)0 
Fast-trackNo
Work packagenone
PrioritynormalSeverityminorReproducibilityN/A
Status closedResolutionfixed 
Product Version0.7.0 
Target Version0.7.1Fixed in Version0.7.1 
Summary0006170: confusing code in verify_reserve_balance
Description1026 /* Check our reserve summary balance calculation shows that
1027 the reserve balance is acceptable (i.e. non-negative) */
1028 GNUNET_assert (GNUNET_OK ==
1029 TALER_amount_add (&balance,
1030 &rs->total_in,
1031 &rs->a_balance));

This does balance = rs->total_in + rs->a_balance. While I have an idea what total_in means, what is a_balance?
Maybe rename it to balance_at_prev_audit or so?

1032 if (GNUNET_SYSERR ==
1033 TALER_amount_subtract (&nbalance,
1034 &balance,
1035 &rs->total_out))
1036 {

Practically all other TALER_amount_subtract are in an assert that wants to make sure they did not return GNUNET_SYSERR.
Why is this one different? And if the return was a SYSERR, why are we reacting not by logging an error but by doing some calculations? In fact the code looks like this is the expected code path.

I'm confused by this. Please explain (and add comments in the code).
TagsNo tags attached.

Required notifications

Address or linkRemarkAdded byNotifiedActions

Activities

fefe

2020-04-08 14:16

reporter   ~0015583

Apparently subtract returns SYSERR of a-b would be negative.
However it also returns SYSERR of the normalization failed.
Maybe we meant the first case and forgot about the second one?

fefe

2020-04-08 14:17

reporter   ~0015584

TALER_amount_subtract also returns SYSERR if the currency was invalid.

Christian Grothoff

2020-04-08 15:00

manager   ~0015585

The intended case was "if result was negative". I actually forgot that we have the other two possibilities ;-).
I'll try to clean up the code (later, still busy with 0006164).

fefe

2020-04-08 15:05

reporter   ~0015586

There is another instance of the pattern further down in the function:

1208 if (GNUNET_SYSERR ==
1209 TALER_amount_subtract (&r,
1210 &total_escrow_balance,
1211 &rs->total_out))
1212 {
1213 /* We could not reduce our total balance, i.e. exchange allowed IN TOTAL (!)
1214 to be withdrawn more than it was IN TOTAL ever given (exchange balance
1215 went negative!). Woopsie. Calculate how badly it went and log. */

This time there is a proper comment explaining what is happening.

Recommendation: Add another return value for "value would become negative" instead of reusing SYSERR.

Christian Grothoff

2020-04-08 15:43

manager   ~0015587

Yes, at least. The TALER_amount_subtract() API's use of SYSERR for 'negative result' is one that actually has bitten me before...

Christian Grothoff

2020-04-08 16:27

manager   ~0015590

Last edited: 2020-04-08 16:28

"a" in "a_balance" was supposed to be for "auditor_". But happy to rename as suggested, that is even clearer: 50bc862a..1554cc31

Christian Grothoff

2020-04-08 21:57

manager   ~0015597

1554cc31..84a40be0 introduces new return types for amount addition and subtraction, plus modifies the auditor to clearly distinguish between the different cases where applicable.

Christian Grothoff

2021-09-02 16:14

manager   ~0018266

Fix committed to master branch.

Issue History

Date ModifiedUsernameFieldChange
2020-04-08 14:14fefeNew Issue
2020-04-08 14:14fefeStatusnew => assigned
2020-04-08 14:14fefeAssigned To => Christian Grothoff
2020-04-08 14:16fefeNote Added: 0015583
2020-04-08 14:17fefeNote Added: 0015584
2020-04-08 15:00Christian GrothoffNote Added: 0015585
2020-04-08 15:05fefeNote Added: 0015586
2020-04-08 15:43Christian GrothoffNote Added: 0015587
2020-04-08 16:27Christian GrothoffNote Added: 0015590
2020-04-08 16:28Christian GrothoffNote Edited: 0015590
2020-04-08 21:57Christian GrothoffNote Added: 0015597
2020-04-08 21:57Christian GrothoffStatusassigned => informing
2020-04-08 21:57Christian GrothoffResolutionopen => fixed
2020-04-08 21:57Christian GrothoffFixed in Version => 0.7.1
2020-04-08 21:58Christian GrothoffTarget Version => 0.7.1
2021-08-24 14:23Christian GrothoffStatusinforming => closed
2021-09-02 16:13Christian Grothoff
2021-09-02 16:14Christian GrothoffNote Added: 0018266