Commit Graph

207 Commits

Author SHA1 Message Date
Jack Grigg 509e7c7d79 Implement Orchard pool value tracking
The ZIP 209 rules preventing the Sprout and Sapling pool values from
going negative, are extended to the Orchard pool.
2021-06-21 01:40:49 +01:00
Jack Grigg 16317bc6af Use V2 history trees from NU5 onward 2021-06-18 12:35:53 +01:00
Jack Grigg 2d0b8b0da4 Copy authDigest in CTransaction::operator=(const CTransaction &tx)
This missing was causing `hashBlockCommitments` to be incorrectly computed
in mined blocks, due to the specific way the coinbase transaction gets
constructed. This went unnoticed when the default `authDigest` for legacy
transactions was the null hash, but was exposed when that changed to
`[0xFF; 32]`.
2021-06-18 11:20:29 +01:00
Jack Grigg bd4c0a8515 ZIP 244 hashBlockCommitments implementation
We will start storing two new hashes in the block index from v4.5.0:
- hashAuthDataRoot
- hashFinalOrchardRoot
2021-06-18 01:05:04 +01:00
Jack Grigg 4da2347e96 Rename hashLightClientRoot to hashBlockCommitments in block header 2021-06-18 01:05:04 +01:00
Kris Nuttycombe 2a2d87bac4 Move OrchardBundle to its own header file.
This is a prerequisite to the incremental merkle tree
work that otherwise would need to introduce a cyclic
dependency.
2021-06-17 12:37:04 -06:00
Jack Grigg af1b9c15bb Implement Orchard authorization batch validator
- Currently, only RedPallas signatures are batch-validated. We can extend
  this validator to cover Halo 2 proofs in the future.

- Signatures in a batch are not retried individually if the batch fails:
  - For per-transaction batching (when adding to the mempool), we don't
    care which signature within the transaction failed.
  - For per-block batching, we currently don't care which transaction
    failed. We might do so in future, at which point this behaviour can
    be easily changed.
2021-06-14 22:47:00 +01:00
str4d 0a4c4fa721 Improvements to CBlock::BuildAuthDataMerkleTree
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-06-14 17:45:59 +01:00
str4d 4e56985277
Document next_pow2 effects and algorithm source
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-06-14 17:40:43 +01:00
Jack Grigg 5ce1e649d3 Throw an exception instead of asserting if Rust tx parser fails
The Rust parser is stricter than the C++ parser, so we can reach errors
now non-contextually that previously were thrown by the consensus rules.

Various tests have been updated to check for these exceptions, as they
can no longer instantiate these transactions to pass to the consensus
rules. The tests use an unsafe constructor so they can still check the
consensus rules.
2021-06-13 07:57:39 +01:00
Jack Grigg 29ec54fad6 ZIP 244 hashAuthDataRoot computation 2021-06-12 20:03:53 +01:00
Jack Grigg bd1fd2eaca ZIP 244 transaction digests 2021-06-12 20:03:53 +01:00
Jack Grigg 1ef818103d CTransaction: Make new ZIP 225 fields non-const and private
Using `const_cast` to serialize into an otherwise-constant field is
undefined behaviour:

  https://github.com/zcash/zcash/issues/967#issuecomment-225467855

Instead, we should make CTransaction's members non-const and private,
and provide accessors. It's not practical to make this change everywhere
yet, but we can start by only introducing new fields in this way. We
will need to provide accessors for orchardBundle's properties in any
case, since we need to call across the Rust FFI.
2021-06-12 00:21:46 +01:00
Jack Grigg 88b3c377d1 Remove early return logic from transaction parsing
This also fixes a bug in `CTransaction::SerializationOp` where
`CTransaction::UpdateHash` was not being called for v5 transactions.
2021-06-11 22:56:01 +01:00
Jack Grigg bfc77d571e v5 transaction format parser
The majority of the parser is in C++, but Orchard bundles are parsed
exclusively by Rust.

The ZIP 244 test vectors are brought in here so we can start by testing
round-trip serialization.
2021-06-10 22:11:42 +01:00
Jack Grigg e8748f89d3 ZIP 225 tx format constants 2021-06-10 22:11:41 +01:00
Jack Grigg 22d97339b2 Extract SpendDescriptionV5 and OutputDescriptionV5 classes 2021-06-10 22:11:41 +01:00
Kris Nuttycombe c4305fc6f3 CurrentTxVersionInfo should return SPROUT_MIN_CURRENT_VERSION pre-overwinter. 2021-04-02 17:04:02 -06:00
Kris Nuttycombe a901b57d98 Address review comments. 2021-04-02 09:45:09 -06:00
Kris Nuttycombe d02a863c28
Apply suggestions from code review
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-03-15 14:32:29 -06:00
Kris Nuttycombe 05ecc47197 Use SPROUT_MAX_CURRENT_VERSION 2021-03-11 15:22:50 -07:00
Kris Nuttycombe e49fa53ea9 Add TxVersionInfo for feature/future-base transaction construction. 2021-03-10 08:55:21 -07:00
Jack Grigg 79ad5984b1 Remove JSDescription::h_sig
This removes the zcash/JoinSplit.hpp dependency from
primitives/transaction.cpp, and thus from libzcashconsensus.
2020-12-20 22:42:22 +00:00
Jack Grigg b1aa9365af Add JSDescriptionInfo for constructing JSDescriptions
This matches the existing transaction builder structs:
- SpendDescriptionInfo
- OutputDescriptionInfo
- TransparentInputInfo

It also removes the dependency of the transaction format on the proving
system.
2020-12-20 22:42:22 +00:00
Jack Grigg b521cb8932 scripted-diff: Migrate from boost::variant to std::variant
-BEGIN VERIFY SCRIPT-
sed -i 's/boost::variant/std::variant/' ./src/*.h ./src/*.cpp ./src/*/*.h* ./src/*/*.cpp ;
sed -i 's/boost::get<\(.*\)>(&/std::get_if<\1>(\&/' ./src/*.h ./src/*.cpp ./src/*/*.h ./src/*/*.cpp ./src/*/*/*.cpp ;
sed -i 's/boost::get</std::get</' ./src/*.h ./src/*.cpp ./src/*/*.h ./src/*/*.cpp ./src/*/*/*.cpp ;
sed -i 's/boost::apply_visitor(/std::visit(/' ./src/*.h ./src/*.cpp ./src/*/*.h ./src/*/*.cpp ;
sed -i 's/class \(.*\)\b \?: public boost::static_visitor<.*>/class \1/' ./src/*.h ./src/*.cpp ./src/*/*.h* ./src/*/*.cpp ;
sed -i ':a;N;$!ba;s/#include <boost\/variant\(\/.*\)\?.hpp>\n//' ./src/*.h ./src/*.cpp ./src/*/*.h ./src/*/*.cpp ;
sed -i ':a;N;$!ba;s/#include "boost\/variant\/.*.hpp"\n//' ./src/*/*.cpp ;
-END VERIFY SCRIPT-
2020-12-16 22:49:53 +00:00
Jack Grigg f68c79554f Add <variant> header to files that will need it 2020-12-16 22:48:21 +00:00
Homu 83a4ae49b6 Auto merge of #4886 - LarryRuane:getblocktemplate-shielded, r=str4d
improve getblocktemplate performance for shielded coinbase

Closes #4817. This improvement applies only when the `longpollid` argument is specified. This argument causes the `getblocktemplate` RPC to not return a template immediately, but instead to wait until either a new block arrives, or new transactions arrive in the mempool.
2020-12-16 21:56:27 +00:00
Larry Ruane 5f68253e58 improve getblocktemplate performance for shielded coinbase 2020-12-13 12:33:25 -07:00
Kris Nuttycombe 2e9bdc6789 Write down the folklore about nSequence 2020-12-08 07:14:42 -07: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
Kris Nuttycombe 0cdce269b5 Merge remote-tracking branch 'upstream/master' into bazel-patches 2020-08-14 14:30:15 -06:00
Kris Nuttycombe b383d6cada Merge remote-tracking branch 'upstream/master' into bazel-patches 2020-07-31 12:49:40 -06:00
Jack Grigg 042bd12a5c Move JSDescription::Verify to ProofVerifier::VerifySprout 2020-07-08 13:59:47 +12:00
Jack Grigg 35765ec9de Move ProofVerifier out of the libzcash namespace
It needs to be closer to the root of our dependency tree, so that it can
depend on the transaction format. The libzcash compilation unit is
further from the dependency tree root than the transaction format.
2020-07-08 13:59:47 +12: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
Taylor Hornby 39ca21845a Fix undefined behavior in gtest tests 2020-04-30 17:16:53 -06:00
Jack Grigg cf480fe402 Add ZIP 221 logic to block index
CBlockHeader.hashFinalSaplingRoot has been renamed to hashLightClient.

CBlockIndex now stores:
- hashLightClient as from the block header
- hashFinalSaplingRoot, which is accurate for all blocks prior to
  Heartwood activation, and all blocks from Heartwood activation onward
  that are connected at some point to the main chain in ConnectBlock().
- hashChainHistoryRoot, which is null prior to Heartwood activation, and
  set per ZIP 221 from Heartwood activation.

The new block index fields are only written to disk for client version
2.1.2 and above, which will be the first Heartwood-aware clients (even
if Heartwood doesn't have an activation height).
2020-04-08 08:49:01 +12:00
Alfredo Garcia 445ae593d6 change the cm member of OutputDescription to cmu 2020-02-26 17:43:50 -03:00
Homu ba20384845 Auto merge of #4218 - Eirik0:4158-fix-recursive-memusage, r=str4d
Include shielded transaction data in RecursiveDynamicUsage calculation

Fixes #4158
2020-02-07 14:19:31 +00:00
MarcoFalke cbdceb0b28
transaction_tests: Be more strict checking dust
* Don't allow off-by-one or more
* Make clear dust is coupled with minRelayTxFee
* Check rounding for odd values
2019-12-17 12:18:50 -06:00
Eirik Ogilvie-Wigley ecce2c9672 Account for malloc overhead 2019-11-14 16:21:37 -07:00
Eirik Ogilvie-Wigley 88dff18a09 Include shielded transaction data when calculating RecursiveDynamicUsage of transactions 2019-11-11 16:02:00 -07:00
Eirik Ogilvie-Wigley 61b7dfb6f0 Move duplicate macro to reusable location 2019-10-09 12:25:56 -06:00
Jack Grigg fe3cb8ec93
Remove makeGrothProof argument from JoinSplit::prove 2019-09-16 13:10:54 +01:00
Jack Grigg 34297c3dec
Always skip verification for old Sprout proofs 2019-08-22 15:42:40 +01:00
Daira Hopwood bc909a7a7f Replace http with https: in links to the MIT license.
Also change MIT/X11 to just MIT, since no distinction was intended.

Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2019-07-18 15:26:01 +01:00
Dimitris Apostolou f57f76d789
Rename vjoinsplit to vJoinSplit 2019-06-16 19:13:49 +03:00
Eirik Ogilvie-Wigley 00ed92343d Add out point for sapling note data 2018-07-25 20:47:40 -07:00
Sean Bowe 90073aeca5 Swap types in OutputDescription to use new NoteEncryption interfaces. 2018-06-14 12:08:37 -06:00
Ariel Gabizon e1a3461cc2 Improve/Fix variable names
ZCProof was too general. pubKeyHash was actually the JoinSplit pubkey
itself.
2018-06-09 20:27:35 -07:00
Jack Grigg a6bbb26e08
Replace boost::array with std::array 2018-05-26 00:12:57 +12:00
Sean Bowe b7a6c32178 Integrate Groth16 verification and proving. 2018-05-14 16:26:23 -06:00
Jack Grigg 0fe0ca7948
Add contextual comment for GetValueOut() and GetShieldedValueIn() 2018-05-10 09:34:19 -04:00
Jack Grigg 97b46f00cc
Add valueBalance to value balances, and enforce its consensus rules 2018-05-09 11:34:41 +01:00
Sean Bowe f2c6d214e5 Rename hashSaplingAnchorEnd to hashFinalSaplingRoot to match spec. 2018-05-07 14:37:46 -06:00
Sean Bowe 691a3fa2e9 Rename hashReserved to hashSaplingAnchorEnd. 2018-05-07 13:46:06 -06:00
Homu 9e5398686c Auto merge of #3206 - bitcartel:3194_polymorphic_note_class, r=str4d
Update note classes to be polymorphic

Closes #3194.  Lays foundation for introduction of Sapling notes through refactoring and creation of a class hierarchy for Sprout notes.  This PR updates some tests, but otherwise is a no-op.
2018-05-02 08:07:35 -07:00
Homu c6ab62191a Auto merge of #3205 - str4d:3173-missing-return, r=str4d
Return result of boost::apply_visitor

Not returning a value at the end of a non-void function is undefined behaviour.
Given that this managed to pass our full test suite, I guess that GCC looks for
un-returned values at the end of a function and uses them as the return value,
if the keyword is missing. Clang OTOH complains, which is how we spotted this:
https://ci.z.cash/#/builders/16/builds/282
2018-04-25 13:50:53 -07:00
Simon b230fe6836 Refactoring: Rename class libzcash::Note to libzcash::SproutNote. 2018-04-25 11:33:24 -07:00
Jack Grigg bf605b2644
Return result of boost::apply_visitor
Not returning a value at the end of a non-void function is undefined behaviour.
Given that this managed to pass our full test suite, I guess that GCC looks for
un-returned values at the end of a function and uses them as the return value,
if the keyword is missing. Clang OTOH complains, which is how we spotted this:
https://ci.z.cash/#/builders/16/builds/282
2018-04-24 23:04:09 +01:00
Homu f961e5c3c0 Auto merge of #3195 - str4d:3180-clang-warnings, r=str4d
Remove now-unshadowed serialization lines that do nothing

Previously we had both nVersion as a class parameter *and* a serialization
argument, and in several inherited serializers the latter was set to the former,
in order to pass the serialized object's version into underlying parsers. #3180
pulled in the upstream changes to clean this up, and in doing so these lines
became no-ops - setting the class parameter to itself. Clang throws warnings on
this, which turn into errors on the MacOS builder.

We can just remove these, because upstream already had done so in earlier PRs,
indicating that they were not being relied on by underlying parsers.
2018-04-24 14:03:57 -07:00
Jack Grigg b1608eed82
Add a constant for Overwinter's transaction version 2018-04-23 20:39:04 +01:00
Jack Grigg b4f7174a88
Implement SpendDescription and OutputDescription datastructures
Co-authored-by: George Tankersley <george@z.cash>
2018-04-23 20:39:00 +01:00
Jack Grigg 22ffe8ce44
Remove now-unshadowed serialization lines that do nothing
Previously we had both nVersion as a class parameter *and* a serialization
argument, and in several inherited serializers the latter was set to the former,
in order to pass the serialized object's version into underlying parsers. #3180
pulled in the upstream changes to clean this up, and in doing so these lines
became no-ops - setting the class parameter to itself. Clang throws warnings on
this, which turn into errors on the MacOS builder.

We can just remove these, because upstream already had done so in earlier PRs,
indicating that they were not being relied on by underlying parsers.
2018-04-20 09:48:33 +01:00
Jack Grigg 72540cee4a
Add Sapling v4 transactions to IsStandard 2018-04-19 16:25:04 +01:00
Jack Grigg b7e75b17af
Implement basic Sapling v4 transaction parser
Details of Sapling datatypes will be filled in later; for now, they are treated
as binary blobs.

Includes code cherry-picked from upstream commit:
    7030d9eb47254499bba14f1c00abc6bf493efd91
    BIP144: Serialization, hashes, relay (sender side)
2018-04-19 05:01:47 +01:00
Jack Grigg 987b8ee60e
Adjust consensus rules to require v4 transactions from Sapling activation 2018-04-19 05:01:47 +01:00
Pieter Wuille c7d71985c9
Add deserializing constructors to CTransaction and CMutableTransaction 2018-04-17 13:29:51 +01:00
Jack Grigg 68a1a592ca
Remove nType and nVersion from Zcash-specific code 2018-04-17 13:09:47 +01:00
Pieter Wuille 242f1421db
Get rid of nType and nVersion
Remove the nType and nVersion as parameters to all serialization methods
and functions. There is only one place where it's read and has an impact
(in CAddress), and even there it does not impact any of the recursively
invoked serializers.

Instead, the few places that need nType or nVersion are changed to read
it directly from the stream object, through GetType() and GetVersion()
methods which are added to all stream classes.
2018-04-17 13:09:28 +01:00
Pieter Wuille b8a6579366
Make GetSerializeSize a wrapper on top of CSizeComputer
Given that in default GetSerializeSize implementations created by
ADD_SERIALIZE_METHODS we're already using CSizeComputer(), get rid
of the specialized GetSerializeSize methods everywhere, and just use
CSizeComputer. This removes a lot of code which isn't actually used
anywhere.

For CCompactSize and CVarInt this actually removes a more efficient
size computing algorithm, which is brought back in a later commit.
2018-04-16 07:38:38 -06:00
Pieter Wuille 29a8ade782
Prevector type 2018-04-16 07:38:36 -06:00
mruddy 690d38f0f8
Resolve issue bitcoin/bitcoin#3166.
These changes decode valid SIGHASH types on signatures in assembly (asm) representations of scriptSig scripts.
This squashed commit incorporates substantial helpful feedback from jtimon, laanwj, and sipa.
2018-04-16 07:38:36 -06:00
Jay Graber 9bb37bf0d5 Implement transaction expiry for Overwinter 2018-02-23 00:12:03 -08:00
Ariel 7245f32835
update SignatureHash according to Overwinter spec
with help from str4d
2018-02-20 04:22:21 +00:00
Simon 072099d788 Implementation of Overwinter transaction format ZIP 202. 2018-02-16 10:10:15 -08:00
Per Grön f9200ca9c2 Fix linkage issue with consts in primitives/block.h
static does not mean the same thing when it's used within a class.
2018-01-23 07:43:51 +01:00
Homu c8ecd49574 Auto merge of #2159 - bitcartel:1.0.7_payment_disclosure, r=str4d
Payment disclosure (experimental feature)
2017-11-14 14:06:22 -08:00
Simon 45232b1961 Add payment disclosure as experimental feature. 2017-11-14 13:29:05 -08:00
Sean Bowe 1a9543d064 Remove crusty old "loadVerifyingKey"/"loadProvingKey" APIs and associated invariants. 2017-10-21 15:42:41 +03:00
zathras-crypto a11c4bbd26
Exempt unspendable transaction outputs from dust checks
Since unspendable outputs can't be spent, there is no threshold at which it would be uneconomic to spend them.

This primarily targets transaction outputs with `OP_RETURN`.

---

Initially based on:

commit 9cf0ae26350033d43d5dd3c95054c0d1b1641eda
Author: zathras-crypto <zathrasc@gmail.com>
Date:   Wed Mar 25 02:04:02 2015 -0700

Changes:

- cherry-picked on top of bitcoin:master
- added RPC test for fundrawtransaction
2017-03-02 13:26:34 -08:00
Simon ebe750a882 Part of #1969. Changing min fee calculation also changes the dust threshold. 2017-02-28 11:44:07 -08:00
zkbot 9f7bc6cba5 Auto merge of #1904 - str4d:1749-write-witness-cache-with-best-block, r=ebfull
Write witness caches when writing the best block

For steady-state operation, this reduces the average time between wallet disk
writes from once per block to once per hour.

On -rescan, witness caches are only written out at the end along with the best
block, increasing speed while ensuring that on-disk state is kept consistent.

Witness caches are now never recreated during a -reindex, on the assumption that
the blocks themselves are not changing (the chain is just being reconstructed),
and so the witnesses will remain valid.

Part of #1749.
2016-12-09 21:11:15 +00:00
Sean Bowe bc59f53722 Isolate verification to a `ProofVerifier` context object that allows verification behavior to be tuned by the caller. 2016-12-05 12:40:06 -07:00
Jack Grigg 03f83b9b0d
Write witness caches when writing the best block
For steady-state operation, this reduces the average time between wallet disk
writes from once per block to once per hour.

On -rescan, witness caches are only written out at the end along with the best
block, increasing speed while ensuring that on-disk state is kept consistent.

Witness caches are now never recreated during a -reindex, on the assumption that
the blocks themselves are not changing (the chain is just being reconstructed),
and so the witnesses will remain valid.

Part of #1749.
2016-11-30 14:04:37 +13:00
Simon 38276c6ba2 Add GenIdentity, an identity function for MappedShuffle.
We use this function in z_sendmany as part of the fix for #1779.
2016-11-05 14:17:19 -07:00
Simon 7c463780cf Fixes #1779 so that sending to multiple zaddrs no longer fails.
Commit 2eeb6b randomized the order of input and output notes,
but this is now known to prevent the chaining of multiple joinsplits
in a single transaction.  The root cause has yet to be determined.

This patch is a temporary fix and disables the shuffling of input
and output notes.  It also adds a chained joinsplit test to the
python qa test suite.
2016-11-04 23:23:48 -07:00
Daira Hopwood a5fd8da7ba Static assertion that standard and network min tx versions are consistent.
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2016-10-22 13:46:22 +01:00
zkbot a12eaa2bf2 Auto merge of #1581 - bitcartel:1464_ncc_2016_008, r=str4d
Fixes for NCC-2016-008

To close #1464 NCC-2016-088

- This PR
- https://github.com/zcash/libsnark/pull/8

Of the 101 issues in NCC-2016-088, 62 are in dependencies, and many of the remainder are duplicates of the CIDs fixed in this PR.

Commit log message is: CID Type (Type is from scan.coverity Type column)
2016-10-22 00:56:08 -04:00
Simon e11e61ddb1 Workaround g++ 5.x bug with brace enclosed initializer.
http://stackoverflow.com/questions/32912921/whats-wrong-with-this-inline-initialization-of-stdarray/32912976#32912976
2016-10-21 21:50:25 -07:00
zkbot c99a1c7e4f Auto merge of #1566 - daira:1557.make-v2-txns-standard, r=ageis
1557.make v2 txns standard

Make v2 transactions standard. This also corrects a rule about admitting large orphan transactions into the mempool, to account for v2-specific fields. ref #1557
2016-10-21 01:10:37 -04:00
Simon ccc0f9af42 Fixes CID 1352714 uninitialized scalar variable. 2016-10-20 11:41:28 -07:00
Simon fed6c83ccf Fixes CID 1352727 uninitialized scalar variable. 2016-10-20 11:40:22 -07:00
Simon 351b38fd5b Fixes CID 1352599 unitialized scalar variable 2016-10-20 11:35:51 -07:00
Daira Hopwood e923e3ae0f Make v2 transactions standard.
This also corrects a rule about admitting large orphan transactions into the mempool, to account for v2-specific fields.

Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2016-10-18 19:37:55 +01:00
Jack Grigg 3774c944f8
Refactor test code to better test JSDescription::Randomized() 2016-10-18 12:44:56 -05:00
Jack Grigg 7f0aa74666
Implement static method for creating a randomized JSDescription 2016-10-18 10:41:00 -05:00
Simon 33264f5b46 Remove GetTxid() from CTransaction and update test_txid 2016-09-07 15:12:09 -07:00
Simon 805344dcf4 Refactor: replace calls to GetTxid() with GetHash() 2016-09-07 15:12:09 -07:00
Simon 3bdb071cc3 Remove #1144 from transaction.cpp by reverting back to commit 942bc46. 2016-09-07 15:12:09 -07:00