firo icon indicating copy to clipboard operation
firo copied to clipboard

Likely incorrect code in spend validation

Open daira opened this issue 9 years ago • 7 comments

https://github.com/zcoinofficial/zcoin/blob/master/src/main.cpp#L835

if (pubcoinId < 1 && pubcoinId == INT_MAX) { // IT BEGINS WITH 1
    return state.DoS(100, error("CTransaction::CheckTransaction() : Error: nSequence is not correct format"));
}

The condition cannot be true.

Some of the other code around this point probably needs more thorough review; there are several stale comments, for example.

daira avatar Feb 18 '17 13:02 daira

Thank you, it should be ||

nopslide avatar Feb 18 '17 16:02 nopslide

Note that the whole of the validation code for Zerocoin spends is duplicated for each denomination. The copies for denominations other than ZQ_LOVELACE have just pubCoin < 1 in the corresponding condition. Why would anyone write it this way -- why not loop over the denominations?

daira avatar Feb 18 '17 17:02 daira

The stale comments seem to have come from Tutorial.cpp in libzerocash. [Edit: I meant libzerocoin.]

daira avatar Feb 18 '17 23:02 daira

@daira it should come from libzerocoin ?

nopslide avatar Feb 19 '17 01:02 nopslide

Potential integer overflow in code above: https://github.com/zcoinofficial/zcoin/pull/73#issuecomment-280890654

In main.cpp: https://github.com/zcoinofficial/zcoin/pull/73/files#diff-7ec3c68a81efff79b6ca22ac1f1eabbaR833

Also, when using unsigned int, should the comparison be against UINT_MAX rather than INT_MAX ? https://github.com/zcoinofficial/zcoin/pull/73/files#diff-7ec3c68a81efff79b6ca22ac1f1eabbaR1009

bitcartel avatar Feb 19 '17 02:02 bitcartel

The main issue I pointed out was fixed in 0359bcb2ead7feac5a3a5f6c6581b1b54cda8dd1, but the integer overflow @bitcartel mentioned has not been fixed, the validation code is still duplicated per denomination, and the stale comments are still there.

daira avatar May 07 '17 17:05 daira

Closing as all issues raised in this thread have been rectified.

riordant avatar Apr 23 '18 14:04 riordant