Commit | Line | Data |
---|---|---|
369df065 SB |
1 | #ifndef _ZCJOINSPLIT_H_ |
2 | #define _ZCJOINSPLIT_H_ | |
3 | ||
4 | #include "Zcash.h" | |
5 | #include "Address.hpp" | |
6 | #include "Note.hpp" | |
7 | #include "IncrementalMerkleTree.hpp" | |
8 | #include "NoteEncryption.hpp" | |
9 | ||
10 | #include "uint256.h" | |
defe37a6 | 11 | #include "uint252.h" |
369df065 SB |
12 | |
13 | #include <boost/array.hpp> | |
14 | ||
15 | namespace libzcash { | |
16 | ||
17 | class JSInput { | |
18 | public: | |
19 | ZCIncrementalWitness witness; | |
20 | Note note; | |
21 | SpendingKey key; | |
22 | ||
23 | JSInput(); | |
24 | JSInput(ZCIncrementalWitness witness, | |
25 | Note note, | |
26 | SpendingKey key) : witness(witness), note(note), key(key) { } | |
27 | ||
28 | uint256 nullifier() const { | |
29 | return note.nullifier(key); | |
30 | } | |
31 | }; | |
32 | ||
33 | class JSOutput { | |
34 | public: | |
35 | PaymentAddress addr; | |
36 | uint64_t value; | |
37 | ||
38 | JSOutput(); | |
39 | JSOutput(PaymentAddress addr, uint64_t value) : addr(addr), value(value) { } | |
40 | ||
defe37a6 | 41 | Note note(const uint252& phi, const uint256& r, size_t i, const uint256& h_sig) const; |
369df065 SB |
42 | }; |
43 | ||
44 | template<size_t NumInputs, size_t NumOutputs> | |
45 | class JoinSplit { | |
46 | public: | |
47 | static JoinSplit<NumInputs, NumOutputs>* Generate(); | |
48 | static JoinSplit<NumInputs, NumOutputs>* Unopened(); | |
49 | static uint256 h_sig(const uint256& randomSeed, | |
50 | const boost::array<uint256, NumInputs>& nullifiers, | |
51 | const uint256& pubKeyHash | |
52 | ); | |
53 | ||
54 | // TODO: #789 | |
55 | virtual void setProvingKeyPath(std::string) = 0; | |
56 | virtual void loadProvingKey() = 0; | |
57 | ||
58 | virtual void saveProvingKey(std::string path) = 0; | |
59 | virtual void loadVerifyingKey(std::string path) = 0; | |
60 | virtual void saveVerifyingKey(std::string path) = 0; | |
61 | ||
9285bba8 | 62 | virtual boost::array<unsigned char, ZKSNARK_PROOF_SIZE> prove( |
369df065 SB |
63 | const boost::array<JSInput, NumInputs>& inputs, |
64 | const boost::array<JSOutput, NumOutputs>& outputs, | |
65 | boost::array<Note, NumOutputs>& out_notes, | |
66 | boost::array<ZCNoteEncryption::Ciphertext, NumOutputs>& out_ciphertexts, | |
67 | uint256& out_ephemeralKey, | |
68 | const uint256& pubKeyHash, | |
69 | uint256& out_randomSeed, | |
70 | boost::array<uint256, NumInputs>& out_hmacs, | |
71 | boost::array<uint256, NumInputs>& out_nullifiers, | |
72 | boost::array<uint256, NumOutputs>& out_commitments, | |
73 | uint64_t vpub_old, | |
74 | uint64_t vpub_new, | |
75 | const uint256& rt | |
76 | ) = 0; | |
77 | ||
78 | virtual bool verify( | |
9285bba8 | 79 | const boost::array<unsigned char, ZKSNARK_PROOF_SIZE>& proof, |
369df065 SB |
80 | const uint256& pubKeyHash, |
81 | const uint256& randomSeed, | |
82 | const boost::array<uint256, NumInputs>& hmacs, | |
83 | const boost::array<uint256, NumInputs>& nullifiers, | |
84 | const boost::array<uint256, NumOutputs>& commitments, | |
85 | uint64_t vpub_old, | |
86 | uint64_t vpub_new, | |
87 | const uint256& rt | |
88 | ) = 0; | |
89 | ||
90 | protected: | |
91 | JoinSplit() {} | |
92 | }; | |
93 | ||
94 | } | |
95 | ||
96 | typedef libzcash::JoinSplit<ZC_NUM_JS_INPUTS, | |
97 | ZC_NUM_JS_OUTPUTS> ZCJoinSplit; | |
98 | ||
99 | #endif // _ZCJOINSPLIT_H_ |