]> Git Repo - VerusCoin.git/commitdiff
Change ciphertext length to match protocol spec, and refactor the use of constants.
authorSean Bowe <[email protected]>
Thu, 5 May 2016 00:25:38 +0000 (18:25 -0600)
committerSean Bowe <[email protected]>
Fri, 6 May 2016 03:02:03 +0000 (21:02 -0600)
src/gtest/test_noteencryption.cpp
src/primitives/transaction.cpp
src/primitives/transaction.h
src/test/transaction_tests.cpp
src/wallet/rpcwallet.cpp
src/zcash/IncrementalMerkleTree.hpp
src/zcash/NoteEncryption.cpp
src/zcash/NoteEncryption.hpp
src/zcash/Zcash.h [new file with mode: 0644]
src/zcbenchmarks.cpp
src/zerocash/PourTransaction.cpp

index 3ce2f5e0434b729d6a55f8c0a8393ff6c6d40b26..bd4ca38ff1990f8d21835d05940a65e6da0174ae 100644 (file)
@@ -5,6 +5,7 @@
 
 #include "zcash/NoteEncryption.hpp"
 #include "zcash/prf.h"
+#include "crypto/sha256.h"
 
 class TestNoteDecryption : public ZCNoteDecryption {
 public:
@@ -28,8 +29,8 @@ TEST(noteencryption, api)
         ASSERT_TRUE(b.get_epk() != c.get_epk());
     }
 
-    boost::array<unsigned char, 216> message;
-    for (unsigned char i = 0; i < 216; i++) {
+    boost::array<unsigned char, 201> message;
+    for (unsigned char i = 0; i < 201; i++) {
         // Fill the message with dummy data
         message[i] = (unsigned char) i;
     }
index 1899c1b0c7c2153326d769fe0cfb21048b5425e4..20ba9a9c263f9cd786ecc6ce182c8033b8f460be 100644 (file)
@@ -35,8 +35,8 @@ boost::array<uint256, N> unsigned_char_vector_array_to_uint256_array(const boost
 CPourTx::CPourTx(ZerocashParams& params,
             const CScript& scriptPubKey,
             const uint256& anchor,
-            const boost::array<PourInput, NUM_POUR_INPUTS>& inputs,
-            const boost::array<PourOutput, NUM_POUR_OUTPUTS>& outputs,
+            const boost::array<PourInput, ZC_NUM_JS_INPUTS>& inputs,
+            const boost::array<PourOutput, ZC_NUM_JS_OUTPUTS>& outputs,
             CAmount vpub_old,
             CAmount vpub_new) : scriptSig(), scriptPubKey(scriptPubKey), vpub_old(vpub_old), vpub_new(vpub_new), anchor(anchor)
 {
@@ -55,9 +55,9 @@ CPourTx::CPourTx(ZerocashParams& params,
                            vpub_old,
                            vpub_new);
 
-    boost::array<std::vector<unsigned char>, NUM_POUR_INPUTS> serials_bv;
-    boost::array<std::vector<unsigned char>, NUM_POUR_OUTPUTS> commitments_bv;
-    boost::array<std::vector<unsigned char>, NUM_POUR_INPUTS> macs_bv;
+    boost::array<std::vector<unsigned char>, ZC_NUM_JS_INPUTS> serials_bv;
+    boost::array<std::vector<unsigned char>, ZC_NUM_JS_OUTPUTS> commitments_bv;
+    boost::array<std::vector<unsigned char>, ZC_NUM_JS_INPUTS> macs_bv;
 
     proof = pourtx.unpack(serials_bv, commitments_bv, macs_bv, ciphertexts, ephemeralKey);
     serials = unsigned_char_vector_array_to_uint256_array(serials_bv);
@@ -80,9 +80,9 @@ bool CPourTx::Verify(ZerocashParams& params) const {
         std::vector<unsigned char>(anchor.begin(), anchor.end()),
         vpub_old,
         vpub_new,
-        uint256_to_array<NUM_POUR_INPUTS>(serials),
-        uint256_to_array<NUM_POUR_OUTPUTS>(commitments),
-        uint256_to_array<NUM_POUR_INPUTS>(macs),
+        uint256_to_array<ZC_NUM_JS_INPUTS>(serials),
+        uint256_to_array<ZC_NUM_JS_OUTPUTS>(commitments),
+        uint256_to_array<ZC_NUM_JS_INPUTS>(macs),
         proof
     );
 }
index c29e4ff348fbe12bd86197de06c15c72f1a357ac..fca2d46ccf842b6a434cad9f64f2c5a01f3c2228 100644 (file)
 #include "zerocash/PourOutput.h"
 
 #include "zcash/NoteEncryption.hpp"
+#include "zcash/Zcash.h"
 
 using namespace libzerocash;
 
-static const unsigned int NUM_POUR_INPUTS = 2;
-static const unsigned int NUM_POUR_OUTPUTS = 2;
-
 class CPourTx
 {
 public:
@@ -50,20 +48,20 @@ public:
     // are derived from the secrets placed in the bucket
     // and the secret spend-authority key known by the
     // spender.
-    boost::array<uint256, NUM_POUR_INPUTS> serials;
+    boost::array<uint256, ZC_NUM_JS_INPUTS> serials;
 
     // Bucket commitments are introduced into the commitment
     // tree, blinding the public about the values and
     // destinations involved in the Pour. The presence of a
     // commitment in the bucket commitment tree is required
     // to spend it.
-    boost::array<uint256, NUM_POUR_OUTPUTS> commitments;
+    boost::array<uint256, ZC_NUM_JS_OUTPUTS> commitments;
 
     // Ciphertexts
     // These contain trapdoors, values and other information
     // that the recipient needs, including a memo field. It
     // is encrypted using the scheme implemented in crypto/NoteEncryption.cpp
-    boost::array<ZCNoteEncryption::Ciphertext, NUM_POUR_OUTPUTS> ciphertexts;
+    boost::array<ZCNoteEncryption::Ciphertext, ZC_NUM_JS_OUTPUTS> ciphertexts;
 
     // Ephemeral key
     uint256 ephemeralKey;
@@ -71,7 +69,7 @@ public:
     // MACs
     // The verification of the pour requires these MACs
     // to be provided as an input.
-    boost::array<uint256, NUM_POUR_INPUTS> macs;
+    boost::array<uint256, ZC_NUM_JS_INPUTS> macs;
 
     // Pour proof
     // This is a zk-SNARK which ensures that this pour is valid.
@@ -82,8 +80,8 @@ public:
     CPourTx(ZerocashParams& params,
             const CScript& scriptPubKey,
             const uint256& rt,
-            const boost::array<PourInput, NUM_POUR_INPUTS>& inputs,
-            const boost::array<PourOutput, NUM_POUR_OUTPUTS>& outputs,
+            const boost::array<PourInput, ZC_NUM_JS_INPUTS>& inputs,
+            const boost::array<PourOutput, ZC_NUM_JS_OUTPUTS>& outputs,
             CAmount vpub_old,
             CAmount vpub_new
     );
index 6192a2652fd14c275e35f3052973ee730548a00e..cb617a60106b2c6125ed450899a421a71f055d0f 100644 (file)
@@ -336,11 +336,11 @@ BOOST_AUTO_TEST_CASE(test_basic_pour_verification)
 
     // create CPourTx
     CScript scriptPubKey;
-    boost::array<PourInput, NUM_POUR_INPUTS> inputs = {
+    boost::array<PourInput, ZC_NUM_JS_INPUTS> inputs = {
         PourInput(coin, addr, path),
         PourInput(INCREMENTAL_MERKLE_TREE_DEPTH) // dummy input of zero value
     };
-    boost::array<PourOutput, NUM_POUR_OUTPUTS> outputs = {
+    boost::array<PourOutput, ZC_NUM_JS_OUTPUTS> outputs = {
         PourOutput(50),
         PourOutput(50)
     };
index d0c76439f1a8564db7641dc36712bfef28d11e29..df8a5eeecd6111db447656b517da9418547a762e 100644 (file)
@@ -2610,7 +2610,7 @@ Value zc_raw_pour(const json_spirit::Array& params, bool fHelp)
         vpourin.push_back(PourInput(input_coin, zcaddress, path));
     }
 
-    while (vpourin.size() < NUM_POUR_INPUTS) {
+    while (vpourin.size() < ZC_NUM_JS_INPUTS) {
         vpourin.push_back(PourInput(INCREMENTAL_MERKLE_TREE_DEPTH));
     }
 
@@ -2637,12 +2637,12 @@ Value zc_raw_pour(const json_spirit::Array& params, bool fHelp)
         vpourout.push_back(output);
     }
 
-    while (vpourout.size() < NUM_POUR_OUTPUTS) {
+    while (vpourout.size() < ZC_NUM_JS_OUTPUTS) {
         vpourout.push_back(PourOutput(0));
     }
 
     // TODO
-    if (vpourout.size() != NUM_POUR_INPUTS || vpourin.size() != NUM_POUR_OUTPUTS) {
+    if (vpourout.size() != ZC_NUM_JS_INPUTS || vpourin.size() != ZC_NUM_JS_OUTPUTS) {
         throw runtime_error("unsupported pour input/output counts");
     }
 
index ff31cc50b3f4a1e6794e778368ea558ee30c77fe..2b0bd054293500f12f2ae080120fb5c5352e9196 100644 (file)
@@ -8,8 +8,7 @@
 #include "uint256.h"
 #include "serialize.h"
 
-static const unsigned int INCREMENTAL_MERKLE_TREE_DEPTH = 20;
-static const unsigned int INCREMENTAL_MERKLE_TREE_DEPTH_TESTING = 4;
+#include "Zcash.h"
 
 namespace libzcash {
 
index cabecd201e19261fc24b05aaf869774a7f0abbd5..40181776346fe1f3abc105564fe9deea5defae48 100644 (file)
@@ -165,7 +165,7 @@ uint256 random_uint256()
     return ret;
 }
 
-template class NoteEncryption<ZC_V_SIZE + ZC_RHO_SIZE + ZC_R_SIZE + ZC_MEMO_SIZE>;
-template class NoteDecryption<ZC_V_SIZE + ZC_RHO_SIZE + ZC_R_SIZE + ZC_MEMO_SIZE>;
+template class NoteEncryption<ZCASH_NOTEPLAINTEXT_LEADING + ZCASH_V_SIZE + ZCASH_RHO_SIZE + ZCASH_R_SIZE + ZCASH_MEMO_SIZE>;
+template class NoteDecryption<ZCASH_NOTEPLAINTEXT_LEADING + ZCASH_V_SIZE + ZCASH_RHO_SIZE + ZCASH_R_SIZE + ZCASH_MEMO_SIZE>;
 
 }
\ No newline at end of file
index 36197c3d398fb7ca8baaac968a217124fcba611d..c6228dcc2030fdf7ddc48f5facca8e1b2e20fce4 100644 (file)
@@ -9,7 +9,7 @@ https://github.com/zcash/zips/blob/master/protocol/protocol.pdf
 #include <boost/array.hpp>
 #include "uint256.h"
 
-#include "zerocash/Zerocash.h"
+#include "zcash/Zcash.h"
 
 namespace libzcash {
 
@@ -73,7 +73,7 @@ uint256 random_uint256();
 
 }
 
-typedef libzcash::NoteEncryption<ZC_V_SIZE + ZC_RHO_SIZE + ZC_R_SIZE + ZC_MEMO_SIZE> ZCNoteEncryption;
-typedef libzcash::NoteDecryption<ZC_V_SIZE + ZC_RHO_SIZE + ZC_R_SIZE + ZC_MEMO_SIZE> ZCNoteDecryption;
+typedef libzcash::NoteEncryption<ZCASH_NOTEPLAINTEXT_LEADING + ZCASH_V_SIZE + ZCASH_RHO_SIZE + ZCASH_R_SIZE + ZCASH_MEMO_SIZE> ZCNoteEncryption;
+typedef libzcash::NoteDecryption<ZCASH_NOTEPLAINTEXT_LEADING + ZCASH_V_SIZE + ZCASH_RHO_SIZE + ZCASH_R_SIZE + ZCASH_MEMO_SIZE> ZCNoteDecryption;
 
-#endif /* ZC_NOTE_ENCRYPTION_H_ */
\ No newline at end of file
+#endif /* ZC_NOTE_ENCRYPTION_H_ */
diff --git a/src/zcash/Zcash.h b/src/zcash/Zcash.h
new file mode 100644 (file)
index 0000000..e0ad342
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef _ZCCONSTANTS_H_
+#define _ZCCONSTANTS_H_
+
+#define ZC_NUM_JS_INPUTS 2
+#define ZC_NUM_JS_OUTPUTS 2
+#define INCREMENTAL_MERKLE_TREE_DEPTH 20
+#define INCREMENTAL_MERKLE_TREE_DEPTH_TESTING 4
+
+// TODO: these constants should be 'ZC'
+// for consistency, but I didn't want to
+// interfere with the old constants
+#define ZCASH_NOTEPLAINTEXT_LEADING 1
+#define ZCASH_V_SIZE 8
+#define ZCASH_RHO_SIZE 32
+#define ZCASH_R_SIZE 32
+#define ZCASH_MEMO_SIZE 128
+
+#endif // _ZCCONSTANTS_H_
index 8fc04217bd04225025358841066b829e35b95197..c2b635319a22cd5512e7affdde7356c2e493dcef 100644 (file)
@@ -2,6 +2,7 @@
 
 #include <unistd.h>
 #include <boost/filesystem.hpp>
+#include "zcash/Zcash.h"
 #include "zerocash/ZerocashParams.h"
 #include "coins.h"
 #include "util.h"
@@ -69,19 +70,16 @@ double benchmark_create_joinsplit()
     std::vector<PourInput> vpourin;
     std::vector<PourOutput> vpourout;
 
-    while (vpourin.size() < NUM_POUR_INPUTS) {
+    while (vpourin.size() < ZC_NUM_JS_INPUTS) {
         vpourin.push_back(PourInput(INCREMENTAL_MERKLE_TREE_DEPTH));
     }
 
-    while (vpourout.size() < NUM_POUR_OUTPUTS) {
+    while (vpourout.size() < ZC_NUM_JS_OUTPUTS) {
         vpourout.push_back(PourOutput(0));
     }
 
     /* Get the anchor of an empty commitment tree. */
-    IncrementalMerkleTree blank_tree(INCREMENTAL_MERKLE_TREE_DEPTH);
-    std::vector<unsigned char> newrt_v(32);
-    blank_tree.getRootValue(newrt_v);
-    uint256 anchor = uint256(newrt_v);
+    uint256 anchor = ZCIncrementalMerkleTree().root();
 
     timer_start();
     CPourTx pourtx(*pzerocashParams,
index 8af2845b757e10ed32642e785f4d5c76858873d9..a5a70b40e52baca266a171853bb918d51a6f6035 100644 (file)
@@ -301,10 +301,11 @@ void PourTransaction::init(uint16_t version_num,
         std::vector<unsigned char> memo(ZC_MEMO_SIZE, 0x00);
         plaintext_internals.insert(plaintext_internals.end(), memo.begin(), memo.end());
 
-        assert(plaintext_internals.size() == 216);
+        // This is all going away.
+        assert(plaintext_internals.size() >= 201);
 
-        boost::array<unsigned char, 216> pt;
-        memcpy(&pt[0], &plaintext_internals[0], 216);
+        boost::array<unsigned char, 201> pt;
+        memcpy(&pt[0], &plaintext_internals[0], 201);
 
         this->ciphertext_1 = encryptor.encrypt(addr_1_new.getEncryptionPublicKey(),
                                                pt);
@@ -318,10 +319,11 @@ void PourTransaction::init(uint16_t version_num,
         std::vector<unsigned char> memo(ZC_MEMO_SIZE, 0x00);
         plaintext_internals.insert(plaintext_internals.end(), memo.begin(), memo.end());
 
-        assert(plaintext_internals.size() == 216);
+        // This is all going away.
+        assert(plaintext_internals.size() >= 201);
 
-        boost::array<unsigned char, 216> pt;
-        memcpy(&pt[0], &plaintext_internals[0], 216);
+        boost::array<unsigned char, 201> pt;
+        memcpy(&pt[0], &plaintext_internals[0], 201);
 
         this->ciphertext_2 = encryptor.encrypt(addr_2_new.getEncryptionPublicKey(),
                                                pt);
This page took 0.048416 seconds and 4 git commands to generate.