PIVX Core  5.6.99
P2P Digital Currency
sapling_transaction.h
Go to the documentation of this file.
1 // Copyright (c) 2016-2020 The ZCash developers
2 // Copyright (c) 2020-2021 The PIVX Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef PIVX_SAPLING_SAPLING_TRANSACTION_H
7 #define PIVX_SAPLING_SAPLING_TRANSACTION_H
8 
9 #include "serialize.h"
10 #include "streams.h"
11 #include "uint256.h"
12 #include "consensus/consensus.h"
13 
14 #include "sapling/noteencryption.h"
15 #include "sapling/sapling.h"
16 
17 #include <boost/variant.hpp>
18 
19 // transaction.h comment: spending taddr output requires CTxIn >= 148 bytes and typical taddr txout is 34 bytes
20 #define CTXIN_SPEND_DUST_SIZE 149
21 #define CTXOUT_REGULAR_SIZE 34
22 
23 // These constants are defined in the protocol § 7.1:
24 // https://zips.z.cash/protocol/protocol.pdf#txnencoding
25 #define OUTPUTDESCRIPTION_SIZE 948
26 #define SPENDDESCRIPTION_SIZE 384
27 #define BINDINGSIG_SIZE 64
28 
29 namespace libzcash {
30  static constexpr size_t GROTH_PROOF_SIZE = (
31  48 + // π_A
32  96 + // π_B
33  48); // π_C
34 
35  typedef std::array<unsigned char, GROTH_PROOF_SIZE> GrothProof;
36 }
37 
42 {
43 public:
44  typedef std::array<unsigned char, 64> spend_auth_sig_t;
45 
52 
54 
55  SERIALIZE_METHODS(SpendDescription, obj) { READWRITE(obj.cv, obj.anchor, obj.nullifier, obj.rk, obj.zkproof, obj.spendAuthSig); }
56 
57  friend bool operator==(const SpendDescription& a, const SpendDescription& b)
58  {
59  return (
60  a.cv == b.cv &&
61  a.anchor == b.anchor &&
62  a.nullifier == b.nullifier &&
63  a.rk == b.rk &&
64  a.zkproof == b.zkproof &&
66  );
67  }
68 
69  friend bool operator!=(const SpendDescription& a, const SpendDescription& b)
70  {
71  return !(a == b);
72  }
73 };
74 
79 {
80 public:
87 
89 
90  SERIALIZE_METHODS(OutputDescription, obj) { READWRITE(obj.cv, obj.cmu, obj.ephemeralKey, obj.encCiphertext, obj.outCiphertext, obj.zkproof); }
91 
92  friend bool operator==(const OutputDescription& a, const OutputDescription& b)
93  {
94  return (
95  a.cv == b.cv &&
96  a.cmu == b.cmu &&
97  a.ephemeralKey == b.ephemeralKey &&
100  a.zkproof == b.zkproof
101  );
102  }
103 
104  friend bool operator!=(const OutputDescription& a, const OutputDescription& b)
105  {
106  return !(a == b);
107  }
108 };
109 
111 {
112 public:
113  typedef std::array<unsigned char, BINDINGSIG_SIZE> binding_sig_t;
114 
116  std::vector<SpendDescription> vShieldedSpend;
117  std::vector<OutputDescription> vShieldedOutput;
119 
120  SERIALIZE_METHODS(SaplingTxData, obj) { READWRITE(obj.valueBalance, obj.vShieldedSpend, obj.vShieldedOutput, obj.bindingSig); }
121 
124 
125  bool hasBindingSig() const
126  {
127  return std::any_of(bindingSig.begin(), bindingSig.end(),
128  [](const unsigned char& c){ return c != 0; });
129  }
130 };
131 
132 
133 #endif // PIVX_SAPLING_SAPLING_TRANSACTION_H
int64_t CAmount
Amount in PIV (Can be negative)
Definition: amount.h:13
A shielded output to a transaction.
uint256 cmu
The u-coordinate of the note commitment for the output note.
friend bool operator==(const OutputDescription &a, const OutputDescription &b)
libzcash::SaplingOutCiphertext outCiphertext
A ciphertext component for the encrypted output note.
libzcash::GrothProof zkproof
A zero-knowledge proof using the output circuit.
SERIALIZE_METHODS(OutputDescription, obj)
friend bool operator!=(const OutputDescription &a, const OutputDescription &b)
libzcash::SaplingEncCiphertext encCiphertext
A ciphertext component for the encrypted output note.
uint256 cv
A value commitment to the value of the output note.
uint256 ephemeralKey
A Jubjub public key.
SaplingTxData(const SaplingTxData &from)
bool hasBindingSig() const
binding_sig_t bindingSig
std::array< unsigned char, BINDINGSIG_SIZE > binding_sig_t
SERIALIZE_METHODS(SaplingTxData, obj)
std::vector< OutputDescription > vShieldedOutput
std::vector< SpendDescription > vShieldedSpend
A shielded input to a transaction.
spend_auth_sig_t spendAuthSig
A signature authorizing this spend.
std::array< unsigned char, 64 > spend_auth_sig_t
uint256 cv
A value commitment to the value of the input note.
friend bool operator!=(const SpendDescription &a, const SpendDescription &b)
libzcash::GrothProof zkproof
A zero-knowledge proof using the spend circuit.
friend bool operator==(const SpendDescription &a, const SpendDescription &b)
uint256 anchor
A Merkle root of the Sapling note commitment tree at some block height in the past.
uint256 rk
The randomized public key for spendAuthSig.
SERIALIZE_METHODS(SpendDescription, obj)
uint256 nullifier
The nullifier of the input note.
256-bit opaque blob.
Definition: uint256.h:138
std::array< unsigned char, GROTH_PROOF_SIZE > GrothProof
std::array< unsigned char, ZC_SAPLING_ENCCIPHERTEXT_SIZE > SaplingEncCiphertext
std::array< unsigned char, ZC_SAPLING_OUTCIPHERTEXT_SIZE > SaplingOutCiphertext
#define READWRITE(...)
Definition: serialize.h:183
const uint256 UINT256_ZERO
constant uint256 instances
Definition: uint256.h:175