Skip to content
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

[Validation] Introducing Sapling transaction network connection and validations. #1940

Merged

Conversation

furszy
Copy link

@furszy furszy commented Oct 24, 2020

Hopefully the last decouple from #1798.

Focused on introducing network flow connection and validations for shielded transactions (primitives and contextual checks), coins cache nullifier and anchor and a test case covering the invalid paths.

This work can be verified running 1798 functional tests suite. sapling_wallet_nullifiers.py, sapling_wallet.py, sapling_wallet_anchorfork.py , sapling_key_import_export.py are all running on top of this work, creating shielded txs, checking balances and generating blocks.

-- A future to do in the area is the mempool validations (nullifiers) connection (stated in 1798 but a little bit of redundancy here doesn't hurt) and continue adding more test coverage for the validation area. Plus, discuss the fee topic further on its own PR, can be dynamic and not fixed as is now. --

Commits coming from 1798:

  • PR decoupled from 1798, focused on introducing Sapling transaction network validations.
  • TransactionBuilder: Do not set the binding signature if there is no shielded spends/outs. —> 096b0ed
  • Validation: Connecting Sapling ContextualCheckTransaction. —> b37998c
  • Sapling transaction fixed fee check. —> cda336e
  • Add HaveShieldedRequirements checks in mempool, connectBlock and checkTxInputs —> 3dbd319
  • validation: sapling merkle tree and view state update connection. —> 382a99b
  • Sapling CheckTransaction connection. —> 3b40c6e
  • Sapling validation, CheckTransaction implemented. —> 7fd17ee
  • Solver return false for empty scripts. —> 3622a0d

@furszy furszy self-assigned this Oct 24, 2020
@furszy furszy added this to the 5.0.0 milestone Oct 25, 2020
@furszy furszy force-pushed the 2020_v5_sapling_validation_first_round branch from cbb9bba to a7f92be Compare October 26, 2020 21:25
@furszy
Copy link
Author

furszy commented Oct 26, 2020

rebased on master for #1942, making travis happy again.

Copy link

@random-zebra random-zebra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks awesome, but have some talking points... mostly around the validation of the transaction size.
Aside from the comments left in-line, I see that there's no change to MAX_STANDARD_TX_SIZE.
This means that a Sapling tx, bigger than 100kB, will never be relayed, and will be valid only inside a block.
We should probably define a new constant MAX_STANDARD_SHIELDED_TX_SIZE and check standard-ness of sapling txes against that.

src/sapling/sapling_validation.cpp Outdated Show resolved Hide resolved
src/sapling/sapling_validation.cpp Outdated Show resolved Hide resolved
src/sapling/sapling_validation.cpp Outdated Show resolved Hide resolved
src/sapling/sapling_validation.cpp Show resolved Hide resolved
src/sapling/sapling_validation.cpp Outdated Show resolved Hide resolved
src/sapling/sapling_validation.cpp Outdated Show resolved Hide resolved
src/consensus/consensus.h Show resolved Hide resolved
src/validation.cpp Outdated Show resolved Hide resolved
Comment on lines +1596 to +1620
// Sapling: are the sapling spends' requirements met in tx(valid anchors/nullifiers)?
if (!view.HaveShieldedRequirements(tx))
return state.DoS(100, error("%s: spends requirements not met", __func__),
REJECT_INVALID, "bad-txns-sapling-requirements-not-met");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(a0e9360)
This can probably be skipped here.
We are going to call CheckInputs below (line 1632), which calls CheckTxInputs (which performs this check).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking more about it... this is indeed a redundancy, and it is also true for the previous check, for regular utxos:

            if (!view.HaveInputs(tx))
                return state.DoS(100, error("ConnectBlock() : inputs missing/spent"),
                    REJECT_INVALID, "bad-txns-inputs-missingorspent");

Researching it in upstream, it seems to be solved by this refactoring: bitcoin#8498.
It's probably better to leave this as is for now, and remove both redundancies in a separate PR.

src/validation.cpp Outdated Show resolved Hide resolved
@furszy furszy force-pushed the 2020_v5_sapling_validation_first_round branch from f293b8d to b9150ef Compare October 27, 2020 19:18
@furszy
Copy link
Author

furszy commented Oct 27, 2020

Awesome feedback 👌👌. PR updated with all of the comments. Including the new constant definition for the shielded txs size standard-ness check.

random-zebra
random-zebra previously approved these changes Oct 28, 2020
Copy link

@random-zebra random-zebra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comment, but none is blocking. So utACK b9150ef here. Great job 🥃

src/sapling/sapling_validation.cpp Outdated Show resolved Hide resolved
Comment on lines +1596 to +1620
// Sapling: are the sapling spends' requirements met in tx(valid anchors/nullifiers)?
if (!view.HaveShieldedRequirements(tx))
return state.DoS(100, error("%s: spends requirements not met", __func__),
REJECT_INVALID, "bad-txns-sapling-requirements-not-met");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking more about it... this is indeed a redundancy, and it is also true for the previous check, for regular utxos:

            if (!view.HaveInputs(tx))
                return state.DoS(100, error("ConnectBlock() : inputs missing/spent"),
                    REJECT_INVALID, "bad-txns-inputs-missingorspent");

Researching it in upstream, it seems to be solved by this refactoring: bitcoin#8498.
It's probably better to leave this as is for now, and remove both redundancies in a separate PR.

@@ -74,6 +74,7 @@ static const unsigned int DEFAULT_LIMITFREERELAY = 30;
/** The maximum size for transactions we're willing to relay/mine */
static const unsigned int MAX_STANDARD_TX_SIZE = 100000;
static const unsigned int MAX_ZEROCOIN_TX_SIZE = 150000;
static const unsigned int MAX_STANDARD_SHIELDED_TX_SIZE = MAX_TX_SIZE_AFTER_SAPLING;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sets the maximum size for "standard" shielded txes, to the maximum available by consensus.
In other words, there would not be any non-standard (due to its size) shielded transaction.
Not sure we really want to set it this high.
But we can discuss the proper value of this constant in another PR.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good

@random-zebra random-zebra dismissed their stale review October 28, 2020 16:00

Needs rebase.

@furszy furszy force-pushed the 2020_v5_sapling_validation_first_round branch from b9150ef to a3c4d2d Compare October 28, 2020 16:42
@furszy
Copy link
Author

furszy commented Oct 28, 2020

nit applied 👍 + rebased on master again. Ready to get merged.

Copy link

@random-zebra random-zebra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re-utACK a3c4d2d

Copy link
Collaborator

@Fuzzbawls Fuzzbawls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK a3c4d2d

@furszy furszy merged commit 2a192ea into PIVX-Project:master Oct 30, 2020
@furszy furszy deleted the 2020_v5_sapling_validation_first_round branch November 29, 2022 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants