Commit Graph

63 Commits

Author SHA1 Message Date
Homu dea50714f9 Auto merge of #4892 - str4d:boosted, r=str4d
Replace boost::variant and boost::optional with standard library

Includes a commit cherry-picked from https://github.com/bitcoin/bitcoin/pull/20419.

Closes #4821. Closes #4822.
2020-12-17 02:42:55 +00:00
Jack Grigg d9928926f3 Migrate from boost::optional::get to boost::optional::value
std::optional only has std::optional::value.
2020-12-16 22:59:34 +00:00
Kris Nuttycombe e9b5d83709 Prefer explicit passing of CChainParams to the Params() global. 2020-12-15 08:23:09 -07:00
Kris Nuttycombe bff5476a19 Add comment in lieu of redundant overwinter version check & fix tests.
This also includes the following:

commit b12adf605640abba4cef6ddab1a2797b12cbf454
Author: Kris Nuttycombe <kris.nuttycombe@gmail.com>
Date:   Mon Aug 24 16:01:18 2020 -0600

    Add assertions to ensure that dependencies between active upgrades are respected.

    Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2020-08-25 20:07:06 -06:00
Jack Grigg efb4246ad3 Replace libsodium's crypto_sign with ed25519-zebra
crypto_sign_verify_detached is still used within the consensus rules
until Canopy activation. ed25519-zebra generates signatures that are
valid under both pre- and post-Canopy rules (for our honest usage),
so we can use it to generate transaction signatures now. Then once
Canopy activates, we can remove the remaining usages of crypto_sign.
2020-08-20 19:00:47 +01:00
Homu b6547929c9 Auto merge of #4593 - str4d:proofverifier-refactor, r=str4d
Refactor ProofVerifier

`ProofVerifier` was previously used to conditionally verify pre-Sapling Sprout
proofs (based on `ProofVerifier::Strict` or `ProofVerifier::Disabled` being
used), but hybrid Sprout proofs bypassed it (so were being verified multiple
times during block verification), and once `libsnark` was removed in
zcash/zcash#4060 `ProofVerifier::check` was doing nothing.

This PR refactors `ProofVerifier`, moving it out of the `libzcash` compilation
unit (so that it can depend on `primitives/transaction.h`), and moving Sprout
verification from `JSDescription::Verify` to `ProofVerifier::VerifySprout`.
Verification-skipping for Sprout proofs is re-introduced.

Additionally, the `ZCJoinSplit` global is removed from the codebase, and
`ZCJoinSplit::prove` is converted into a static function. We load the hybrid
Sprout parameters dynamically at proving time within the Rust code, and no
longer require a C++ global for any proving parameters.

As a side-effect, `libzcashconsensus.la` building with `--with-libs` is fixed,
as `primitives/transaction.cpp` no longer depends on `librustzcash.h`.
2020-08-07 12:16:59 +00:00
Homu 701adc38cb Auto merge of #4578 - therealyingtong:zip212-impl, r=str4d
ZIP212 implementation

Closes #4557.
(description by @ebfull, taken from #4575)

* The `SaplingNote` structure has a new enum called `zip212Enabled`. This
  member is private and reflects whether the note was or is being created
  using the derivation method of ZIP 212 (i.e., `BeforeZip212` or `AfterZip212`).
* The `SaplingNotePlaintext` structure has a new unsigned char member
  `leadbyte`. This member is private and contains the leading byte of the
  plaintext (e.g. `0x01`, `0x02`).
* The serialization of `SaplingNotePlaintext` sets `zip212Enabled` to
  `BeforeZip212` iff the serialized note plaintext version is not `0x01`.
* The `r`/`rcm` fields have been removed and replaced with a private field
  `rseed`. `SaplingNote` and `SaplingNotePlaintext` now have a helper method
  `rcm()` which returns the `rcm` either by deriving it with `rseed`
  (if `zip212Enabled` is `AfterZip212`) or returning `rseed` by interpreting
  `rseed` as `rcm`.
* All the methods of obtaining a `SaplingNote` account for these changes:
  - The `SaplingNote` constructor that is used by e.g. the transaction builder,
    and internally samples random `rcm`, now takes a `zip212Enabled` argument
    to decide whether to sample `rcm` the "old" way or the "new" way.
  - The bare constructor for `SaplingNote` is removed.
  - The other constructor which takes the raw contents of the note is only used
    in tests or in `Note.cpp`, but now also takes a `zip212Enabled` argument.
  - The other way of obtaining a note, by calling `SaplingNotePlaintext::note()`,
    has been adjusted.
* The `SaplingNotePlaintext` class now has an `generate_or_derive_esk()` method
  that either samples a random `esk` or derives it using the local `rseed`
  depending on the value of `leadbyte`.
* The encryption routine is modified to consult `generate_or_derive_esk()` and
  provide it to the note encryption object.
* The note encryption objects now take an optional `esk` as input and otherwise
  sample a random `esk` internally. This API functionality is preserved to allow
  for testing.
* The `SaplingNotePlaintext` decryption routines are modified:
  - The out and enc decryption routines now check that `epk` is consistent with
    the derived `esk`.
  -  The out decryption routine for plaintexts also checks that `esk` is
    consistent with what is derived by the note.
* The miner and transaction builder consult the activation of Canopy when
  creating `SaplingNote`s.
* The consensus rules are modified so that shielded outputs (miner rewards)
  must have `v2` note plaintexts after Canopy has activated.
2020-07-09 00:29:07 +00:00
Jack Grigg 7e2558d2e2 Make ZCJoinSplit::prove static and remove ZCJoinSplit globals
We don't support making pre-Sapling JoinSplit proofs, and we load the
parameters for post-Sapling JoinSplit proofs at proving time, so there
is no need for a global ZCJoinSplit to be passed through the APIs.
2020-07-08 13:59:47 +12:00
therealyingtong c4821ddceb Refactor bool is_zip_212 to enum Zip212Enabled
Co-authored by Kris Nuttycombe (@nuttycom)
2020-07-03 06:59:21 +08:00
therealyingtong f24e706079 Replace leadByte in SaplingNote with is_zip_212 2020-07-02 15:37:32 +08:00
therealyingtong 2a2fc2a16f Add gtests
Should accept Sprout shielding before NU4 but reject it afterwards
2020-07-01 23:31:41 +08:00
therealyingtong 7a1d119170 Add gtests for v2 plaintexts 2020-06-25 09:12:24 +08:00
Sean Bowe 8770a5c532 Add support for receiving v2 Sapling note plaintexts.
Co-authored by Ying Tong (yingtong@electriccoin.co)
2020-06-18 15:02:50 +08:00
Jack Grigg 4216319ee6 test: Assert that GetValidTransaction supports the given branch ID
Also includes a small documentation fix.
2020-04-09 15:43:18 +12:00
Jack Grigg f21de9d0d6 consensus: Check JoinSplit signatures against the previous network upgrade
We only check failing signatures against the previous epoch to minimise
the extra computational load on nodes.
2020-03-12 17:17:48 +13:00
Jack Grigg dc99cd74a0 test: Add Overwinter and Sapling support to GetValidTransaction() helper 2020-03-12 17:14:39 +13:00
Jack Grigg 06bd43b53c test: Explicitly check Sapling consensus rules apply to shielded coinbase 2020-03-06 15:24:38 +13:00
Jack Grigg 3b3382bb48 Adjust comments on ZIP 213 logic 2020-03-06 11:50:15 +13:00
Jack Grigg 80169c940f ZIP 213 consensus rules 2020-02-28 13:59:53 +13:00
Homu e10576434d Auto merge of #4258 - oxarbitrage:issue3575, r=str4d
Changing gtest to CamelCase

This is #3583 with merge conflicts fixed.

Closes #3575.
2020-02-11 13:47:26 +00:00
Jack Grigg 7bbd846f0f Apply a consistent ban policy within ContextualCheckTransaction 2020-02-06 14:30:37 +00:00
Alfredo Garcia ae0fb0b993 fix conflicts 2019-12-11 16:51:46 -03:00
Jack Grigg fe3cb8ec93
Remove makeGrothProof argument from JoinSplit::prove 2019-09-16 13:10:54 +01:00
Eirik Ogilvie-Wigley 9f70b74692 Do not add expiring soon threshold to expiry height of txs near NU activation 2019-08-05 11:50:05 -06:00
Eirik Ogilvie-Wigley 8068491d2c Fix check transaction tests 2019-08-04 14:35:47 -06:00
Eirik Ogilvie-Wigley ecfcb817ae Add test for Blossom default tx expiry delta 2019-07-31 14:34:48 -06:00
Eirik Ogilvie-Wigley 8865f4b6f6 Update expiry height for shorter block times 2019-07-30 01:16:37 -06:00
Dimitris Apostolou f57f76d789
Rename vjoinsplit to vJoinSplit 2019-06-16 19:13:49 +03:00
Jack Grigg 3ffc29b881
Globals: Explicitly pass const CChainParams& to IsInitialBlockDownload() 2019-05-23 20:03:34 +01:00
Jack Grigg be94721953
Globals: Explicitly pass const CChainParams& to ContextualCheckTransaction() 2019-05-23 17:48:28 +01:00
Eirik Ogilvie-Wigley 8a1d19307b Renaming and other minor cleanup 2019-01-29 21:18:10 -07:00
Eirik Ogilvie-Wigley c3e2de5959 Move reusable Sapling test setup to utiltest 2019-01-23 14:12:02 -07:00
avnish 47952a6db8 changed test names from _ to CamelCase 2018-10-10 08:48:52 +05:30
Larry Ruane 6206d86237 Test peer banning logic in both pre- and post-initial block download states 2018-09-12 13:30:01 -06:00
Sean Bowe 3d75e8b3e7 Move `extern params` to beginning of `test_checktransaction`. 2018-07-31 08:33:33 -06:00
Sean Bowe 291895fac7 Ensure sum of valueBalance and all vpub_new's does not exceed MAX_MONEY inside of CheckTransactionWithoutProofVerification. 2018-07-30 22:35:31 -06:00
Larry Ruane 772f87aaeb don't ban peers when loading pre-overwinter blocks 2018-07-26 12:29:04 -06:00
Jack Grigg 97b46f00cc
Add valueBalance to value balances, and enforce its consensus rules 2018-05-09 11:34:41 +01:00
Homu 1d4235dce7 Auto merge of #3239 - str4d:sapling-default-tx-version, r=str4d
Update CreateNewContextualCMutableTransaction for Sapling

Part of #3063.
2018-05-07 12:27:47 -07:00
Jack Grigg e1d41f21f3
Update tests for CreateNewContextualCMutableTransaction changes 2018-05-07 20:21:55 +01:00
Jack Grigg e1dbec49b7
Add test of Sapling transaction size boundary 2018-05-04 11:17:30 +01:00
Jack Grigg 15ec5525e3
Raise 100kB transaction size limit from Sapling activation
Closes #2864.
2018-05-04 11:17:30 +01:00
Jack Grigg b1608eed82
Add a constant for Overwinter's transaction version 2018-04-23 20:39:04 +01:00
Jack Grigg be12669982
Add consensus branch ID parameter to SignatureHash, remove SigVersion parameter
We do not need to be able to calculate multiple SignatureHash versions for a
single transaction format; instead, we use the transaction format to determine
the SigVersion.

The consensus branch ID *does* need to be passed in from the outside, as only
the caller knows the context in which the SignatureHash is being calculated
(ie. mempool acceptance vs. block validation).

JoinSplit signature verification has been moved into ContextualCheckTransaction,
where the consensus branch ID can be obtained.

The argument to the sign command for zcash-tx has been modified to take a height
in addition to the optional sigtype flags.
2018-02-20 04:22:20 +00:00
Pieter Wuille c86a1cb86e
BIP143: Verification logic
Includes simplifications by Eric Lombrozo.

Edited for Zcash merge by Ariel Gabizon.
2018-02-20 04:22:19 +00:00
Simon fa78211ed7 Add test to check malformed v1 transaction against Overwinter tx parser 2018-02-16 15:42:04 -08:00
Simon 072099d788 Implementation of Overwinter transaction format ZIP 202. 2018-02-16 10:10:15 -08:00
Daira Hopwood cb1246194e Update the error message string for tx version too low. ref #1600
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2016-10-22 13:26:44 +01:00
Jack Grigg 7ac924cdb7
Disallow v0 transactions as a consensus rule
Closes #1557
2016-10-22 00:40:50 -05:00
Sean Bowe 74f15a73a1 Make 100KB transaction size limit a consensus rule, rather than a standard rule. 2016-10-08 00:00:23 -06:00