-
Notifications
You must be signed in to change notification settings - Fork 725
[BUG] Zerocoin: fix spend validation and remove obsolete sporks #2484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Zerocoin: fix spend validation and remove obsolete sporks #2484
Conversation
c50eb44 to
810d589
Compare
considering that a tx can contain multiple spends
as this was meant to be checked only if IsBlockChainSynced. As zerocoin public spends are no longer accepted (both in main-net/testnet) we can just remove it.
Zerocoin spends values are already returned by GetValueIn below
SPORK_16 value is still checked in: - AcceptToMemoryPool (but there's a static check at lines 418-421) - ConnectBlock (but there's a height-based check at lines 1562-1564, and an additional height-based check inside CheckBlock)
...calls in ConnectBlock when possible. The check at line 2798 in CheckBlock ensures that no zc tx (either mint or spend) is accepted in the chain after v5 activation. `ContainsZerocoins`/`HasZerocoinSpendInputs` are expensive functions, especially when they return `false` (as they need to go through all inputs and outputs). Therefore avoid the duplicated check in ConnectBlock, and, instead, use the shortcut operator to skip HasZerocoinSpendInputs call after v5 enforcement.
as we already checking it via ContextualCheckBlock --> ContextualCheckTransaction --> ContextualCheckZerocoinTx
810d589 to
f7a93cd
Compare
furszy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review ACK f7a93cd.
Going to try a fresh sync now.
Fuzzbawls
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK a5a20e8
Full sync on mainnet confirmed
furszy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK a5a20e8
Took a while to sync on a small VPS (and had a disk space abortion that ended up on a chain reindex..).
#2425 introduced two bugs which are preventing a successful chain sync from scratch on
master:It abstracted a piece of code in
ParseAndValidateZerocoinSpend, which is only parsing/validating a single zerocoin spend per tx, while a transaction could contain multiple spends. Fix it by returning an optional list ofCoinSpendValue, instead of a singleton.It re-introduced in the validation the (unused-at-the-time) function
CheckPublicCoinSpendVersion, which is now failing at the first block with (version 3) public spends.As all spork-based checks, this was supposed to be skipped when
fInitialBlockDownload.Zerocoin transactions are no longer accepted (in both nets) in the mempool, as well as inside blocks (after v5 enforcement), so we can just remove this obsolete function.
The third commit fixes a very old bug: a zerocoin spend tx
nValueInis counted twice in ConnectBlock (first directly, after the coinspend parsing/validation, and then viaCCoinsViewCache::GetValueIn).Then, since we are at it, we can deprecate
SPORK_16_ZEROCOIN_MAINTENANCE_MODEandSPORK_18_ZEROCOIN_PUBLICSPEND_V4, which are now unused/unneeded.The last three commits are performance optimizations to avoid multiple calls to
ContainsZerocoins()/HasZerocoinSpendInputs()inConnectBlock, when possible.