Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace boost::array with std::array #3237

Merged
merged 2 commits into from Jun 7, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 22 additions & 20 deletions src/gtest/test_joinsplit.cpp
Expand Up @@ -16,6 +16,8 @@
#include "zcash/NoteEncryption.hpp"
#include "zcash/IncrementalMerkleTree.hpp"

#include <array>

using namespace libzcash;

extern ZCJoinSplit* params;
Expand All @@ -38,25 +40,25 @@ void test_full_api(ZCJoinSplit* js)
uint64_t vpub_old = 10;
uint64_t vpub_new = 0;
uint256 pubKeyHash = random_uint256();
boost::array<uint256, 2> macs;
boost::array<uint256, 2> nullifiers;
boost::array<uint256, 2> commitments;
std::array<uint256, 2> macs;
std::array<uint256, 2> nullifiers;
std::array<uint256, 2> commitments;
uint256 rt = tree.root();
boost::array<ZCNoteEncryption::Ciphertext, 2> ciphertexts;
std::array<ZCNoteEncryption::Ciphertext, 2> ciphertexts;
SproutProof proof;

{
boost::array<JSInput, 2> inputs = {
std::array<JSInput, 2> inputs = {
JSInput(), // dummy input
JSInput() // dummy input
};

boost::array<JSOutput, 2> outputs = {
std::array<JSOutput, 2> outputs = {
JSOutput(recipient_addr, 10),
JSOutput() // dummy output
};

boost::array<SproutNote, 2> output_notes;
std::array<SproutNote, 2> output_notes;

// Perform the proof
proof = js->prove(
Expand Down Expand Up @@ -121,20 +123,20 @@ void test_full_api(ZCJoinSplit* js)
pubKeyHash = random_uint256();

{
boost::array<JSInput, 2> inputs = {
std::array<JSInput, 2> inputs = {
JSInput(), // dummy input
JSInput(witness_recipient, decrypted_note, recipient_key)
};

SproutSpendingKey second_recipient = SproutSpendingKey::random();
SproutPaymentAddress second_addr = second_recipient.address();

boost::array<JSOutput, 2> outputs = {
std::array<JSOutput, 2> outputs = {
JSOutput(second_addr, 9),
JSOutput() // dummy output
};

boost::array<SproutNote, 2> output_notes;
std::array<SproutNote, 2> output_notes;

// Perform the proof
proof = js->prove(
Expand Down Expand Up @@ -176,21 +178,21 @@ void test_full_api(ZCJoinSplit* js)
// to test exceptions
void invokeAPI(
ZCJoinSplit* js,
const boost::array<JSInput, 2>& inputs,
const boost::array<JSOutput, 2>& outputs,
const std::array<JSInput, 2>& inputs,
const std::array<JSOutput, 2>& outputs,
uint64_t vpub_old,
uint64_t vpub_new,
const uint256& rt
) {
uint256 ephemeralKey;
uint256 randomSeed;
uint256 pubKeyHash = random_uint256();
boost::array<uint256, 2> macs;
boost::array<uint256, 2> nullifiers;
boost::array<uint256, 2> commitments;
boost::array<ZCNoteEncryption::Ciphertext, 2> ciphertexts;
std::array<uint256, 2> macs;
std::array<uint256, 2> nullifiers;
std::array<uint256, 2> commitments;
std::array<ZCNoteEncryption::Ciphertext, 2> ciphertexts;

boost::array<SproutNote, 2> output_notes;
std::array<SproutNote, 2> output_notes;

SproutProof proof = js->prove(
false,
Expand All @@ -213,8 +215,8 @@ void invokeAPI(

void invokeAPIFailure(
ZCJoinSplit* js,
const boost::array<JSInput, 2>& inputs,
const boost::array<JSOutput, 2>& outputs,
const std::array<JSInput, 2>& inputs,
const std::array<JSOutput, 2>& outputs,
uint64_t vpub_old,
uint64_t vpub_new,
const uint256& rt,
Expand Down Expand Up @@ -540,7 +542,7 @@ TEST(joinsplit, note_plaintexts)
random_uint256()
);

boost::array<unsigned char, ZC_MEMO_SIZE> memo;
std::array<unsigned char, ZC_MEMO_SIZE> memo;

SproutNotePlaintext note_pt(note, memo);

Expand Down
3 changes: 2 additions & 1 deletion src/gtest/test_noteencryption.cpp
@@ -1,6 +1,7 @@
#include <gtest/gtest.h>
#include "sodium.h"

#include <array>
#include <stdexcept>

#include "zcash/NoteEncryption.hpp"
Expand Down Expand Up @@ -29,7 +30,7 @@ TEST(noteencryption, api)
ASSERT_TRUE(b.get_epk() != c.get_epk());
}

boost::array<unsigned char, ZC_NOTEPLAINTEXT_SIZE> message;
std::array<unsigned char, ZC_NOTEPLAINTEXT_SIZE> message;
for (size_t i = 0; i < ZC_NOTEPLAINTEXT_SIZE; i++) {
// Fill the message with dummy data
message[i] = (unsigned char) i;
Expand Down
4 changes: 3 additions & 1 deletion src/gtest/test_paymentdisclosure.cpp
Expand Up @@ -7,6 +7,8 @@
#include "zcash/Address.hpp"
#include "wallet/wallet.h"
#include "amount.h"

#include <array>
#include <memory>
#include <string>
#include <set>
Expand Down Expand Up @@ -167,7 +169,7 @@ TEST(paymentdisclosure, mainnet) {
}

// Convert signature buffer to boost array
boost::array<unsigned char, 64> arrayPayloadSig;
std::array<unsigned char, 64> arrayPayloadSig;
memcpy(arrayPayloadSig.data(), &payloadSig[0], 64);

// Payment disclosure blob to pass around
Expand Down
18 changes: 10 additions & 8 deletions src/gtest/test_transaction.cpp
Expand Up @@ -4,6 +4,8 @@
#include "zcash/Note.hpp"
#include "zcash/Address.hpp"

#include <array>

extern ZCJoinSplit* params;
extern int GenZero(int n);
extern int GenMax(int n);
Expand All @@ -30,16 +32,16 @@ TEST(Transaction, JSDescriptionRandomized) {

// create JSDescription
uint256 pubKeyHash;
boost::array<libzcash::JSInput, ZC_NUM_JS_INPUTS> inputs = {
std::array<libzcash::JSInput, ZC_NUM_JS_INPUTS> inputs = {
libzcash::JSInput(witness, note, k),
libzcash::JSInput() // dummy input of zero value
};
boost::array<libzcash::JSOutput, ZC_NUM_JS_OUTPUTS> outputs = {
std::array<libzcash::JSOutput, ZC_NUM_JS_OUTPUTS> outputs = {
libzcash::JSOutput(addr, 50),
libzcash::JSOutput(addr, 50)
};
boost::array<size_t, ZC_NUM_JS_INPUTS> inputMap;
boost::array<size_t, ZC_NUM_JS_OUTPUTS> outputMap;
std::array<size_t, ZC_NUM_JS_INPUTS> inputMap;
std::array<size_t, ZC_NUM_JS_OUTPUTS> outputMap;

{
auto jsdesc = JSDescription::Randomized(
Expand All @@ -66,8 +68,8 @@ TEST(Transaction, JSDescriptionRandomized) {
inputMap, outputMap,
0, 0, false, nullptr, GenZero);

boost::array<size_t, ZC_NUM_JS_INPUTS> expectedInputMap {1, 0};
boost::array<size_t, ZC_NUM_JS_OUTPUTS> expectedOutputMap {1, 0};
std::array<size_t, ZC_NUM_JS_INPUTS> expectedInputMap {1, 0};
std::array<size_t, ZC_NUM_JS_OUTPUTS> expectedOutputMap {1, 0};
EXPECT_EQ(expectedInputMap, inputMap);
EXPECT_EQ(expectedOutputMap, outputMap);
}
Expand All @@ -80,8 +82,8 @@ TEST(Transaction, JSDescriptionRandomized) {
inputMap, outputMap,
0, 0, false, nullptr, GenMax);

boost::array<size_t, ZC_NUM_JS_INPUTS> expectedInputMap {0, 1};
boost::array<size_t, ZC_NUM_JS_OUTPUTS> expectedOutputMap {0, 1};
std::array<size_t, ZC_NUM_JS_INPUTS> expectedInputMap {0, 1};
std::array<size_t, ZC_NUM_JS_OUTPUTS> expectedOutputMap {0, 1};
EXPECT_EQ(expectedInputMap, inputMap);
EXPECT_EQ(expectedOutputMap, outputMap);
}
Expand Down
5 changes: 3 additions & 2 deletions src/paymentdisclosure.h
Expand Up @@ -14,6 +14,7 @@
// For JSOutPoint
#include "wallet/wallet.h"

#include <array>
#include <cstdint>
#include <string>

Expand Down Expand Up @@ -113,11 +114,11 @@ struct PaymentDisclosurePayload {

struct PaymentDisclosure {
PaymentDisclosurePayload payload;
boost::array<unsigned char, 64> payloadSig;
std::array<unsigned char, 64> payloadSig;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: either maintain column alignment, or remove all the extra spacing. (Does not block.)

// We use boost array because serialize doesn't like char buffer, otherwise we could do: unsigned char payloadSig[64];

PaymentDisclosure() {};
PaymentDisclosure(const PaymentDisclosurePayload payload, const boost::array<unsigned char, 64> sig) : payload(payload), payloadSig(sig) {};
PaymentDisclosure(const PaymentDisclosurePayload payload, const std::array<unsigned char, 64> sig) : payload(payload), payloadSig(sig) {};
PaymentDisclosure(const uint256& joinSplitPubKey, const PaymentDisclosureKey& key, const PaymentDisclosureInfo& info, const std::string& message);

ADD_SERIALIZE_METHODS;
Expand Down
14 changes: 7 additions & 7 deletions src/primitives/transaction.cpp
Expand Up @@ -16,15 +16,15 @@ JSDescription::JSDescription(
ZCJoinSplit& params,
const uint256& pubKeyHash,
const uint256& anchor,
const boost::array<libzcash::JSInput, ZC_NUM_JS_INPUTS>& inputs,
const boost::array<libzcash::JSOutput, ZC_NUM_JS_OUTPUTS>& outputs,
const std::array<libzcash::JSInput, ZC_NUM_JS_INPUTS>& inputs,
const std::array<libzcash::JSOutput, ZC_NUM_JS_OUTPUTS>& outputs,
CAmount vpub_old,
CAmount vpub_new,
bool computeProof,
uint256 *esk // payment disclosure
) : vpub_old(vpub_old), vpub_new(vpub_new), anchor(anchor)
{
boost::array<libzcash::SproutNote, ZC_NUM_JS_OUTPUTS> notes;
std::array<libzcash::SproutNote, ZC_NUM_JS_OUTPUTS> notes;

proof = params.prove(
makeGrothProof,
Expand All @@ -51,10 +51,10 @@ JSDescription JSDescription::Randomized(
ZCJoinSplit& params,
const uint256& pubKeyHash,
const uint256& anchor,
boost::array<libzcash::JSInput, ZC_NUM_JS_INPUTS>& inputs,
boost::array<libzcash::JSOutput, ZC_NUM_JS_OUTPUTS>& outputs,
boost::array<size_t, ZC_NUM_JS_INPUTS>& inputMap,
boost::array<size_t, ZC_NUM_JS_OUTPUTS>& outputMap,
std::array<libzcash::JSInput, ZC_NUM_JS_INPUTS>& inputs,
std::array<libzcash::JSOutput, ZC_NUM_JS_OUTPUTS>& outputs,
std::array<size_t, ZC_NUM_JS_INPUTS>& inputMap,
std::array<size_t, ZC_NUM_JS_OUTPUTS>& outputMap,
CAmount vpub_old,
CAmount vpub_new,
bool computeProof,
Expand Down
33 changes: 17 additions & 16 deletions src/primitives/transaction.h
Expand Up @@ -14,7 +14,8 @@
#include "uint256.h"
#include "consensus/consensus.h"

#include <boost/array.hpp>
#include <array>

#include <boost/variant.hpp>

#include "zcash/NoteEncryption.hpp"
Expand Down Expand Up @@ -42,7 +43,7 @@ static_assert(SAPLING_TX_VERSION <= SAPLING_MAX_TX_VERSION,
class SpendDescription
{
public:
typedef boost::array<unsigned char, 64> spend_auth_sig_t;
typedef std::array<unsigned char, 64> spend_auth_sig_t;

uint256 cv; //!< A value commitment to the value of the input note.
uint256 anchor; //!< A Merkle root of the Sapling note commitment tree at some block height in the past.
Expand Down Expand Up @@ -102,8 +103,8 @@ static constexpr size_t SAPLING_OUT_CIPHERTEXT_SIZE = (
class OutputDescription
{
public:
typedef boost::array<unsigned char, SAPLING_ENC_CIPHERTEXT_SIZE> sapling_enc_ct_t; // TODO: Replace with actual type
typedef boost::array<unsigned char, SAPLING_OUT_CIPHERTEXT_SIZE> sapling_out_ct_t; // TODO: Replace with actual type
typedef std::array<unsigned char, SAPLING_ENC_CIPHERTEXT_SIZE> sapling_enc_ct_t; // TODO: Replace with actual type
typedef std::array<unsigned char, SAPLING_OUT_CIPHERTEXT_SIZE> sapling_out_ct_t; // TODO: Replace with actual type

uint256 cv; //!< A value commitment to the value of the output note.
uint256 cm; //!< The note commitment for the output note.
Expand Down Expand Up @@ -209,14 +210,14 @@ class JSDescription
// are derived from the secrets placed in the note
// and the secret spend-authority key known by the
// spender.
boost::array<uint256, ZC_NUM_JS_INPUTS> nullifiers;
std::array<uint256, ZC_NUM_JS_INPUTS> nullifiers;

// Note commitments are introduced into the commitment
// tree, blinding the public about the values and
// destinations involved in the JoinSplit. The presence of
// a commitment in the note commitment tree is required
// to spend it.
boost::array<uint256, ZC_NUM_JS_OUTPUTS> commitments;
std::array<uint256, ZC_NUM_JS_OUTPUTS> commitments;

// Ephemeral key
uint256 ephemeralKey;
Expand All @@ -225,15 +226,15 @@ class JSDescription
// 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, ZC_NUM_JS_OUTPUTS> ciphertexts = {{ {{0}} }};
std::array<ZCNoteEncryption::Ciphertext, ZC_NUM_JS_OUTPUTS> ciphertexts = {{ {{0}} }};

// Random seed
uint256 randomSeed;

// MACs
// The verification of the JoinSplit requires these MACs
// to be provided as an input.
boost::array<uint256, ZC_NUM_JS_INPUTS> macs;
std::array<uint256, ZC_NUM_JS_INPUTS> macs;

// JoinSplit proof
// This is a zk-SNARK which ensures that this JoinSplit is valid.
Expand All @@ -246,8 +247,8 @@ class JSDescription
ZCJoinSplit& params,
const uint256& pubKeyHash,
const uint256& rt,
const boost::array<libzcash::JSInput, ZC_NUM_JS_INPUTS>& inputs,
const boost::array<libzcash::JSOutput, ZC_NUM_JS_OUTPUTS>& outputs,
const std::array<libzcash::JSInput, ZC_NUM_JS_INPUTS>& inputs,
const std::array<libzcash::JSOutput, ZC_NUM_JS_OUTPUTS>& outputs,
CAmount vpub_old,
CAmount vpub_new,
bool computeProof = true, // Set to false in some tests
Expand All @@ -259,10 +260,10 @@ class JSDescription
ZCJoinSplit& params,
const uint256& pubKeyHash,
const uint256& rt,
boost::array<libzcash::JSInput, ZC_NUM_JS_INPUTS>& inputs,
boost::array<libzcash::JSOutput, ZC_NUM_JS_OUTPUTS>& outputs,
boost::array<size_t, ZC_NUM_JS_INPUTS>& inputMap,
boost::array<size_t, ZC_NUM_JS_OUTPUTS>& outputMap,
std::array<libzcash::JSInput, ZC_NUM_JS_INPUTS>& inputs,
std::array<libzcash::JSOutput, ZC_NUM_JS_OUTPUTS>& outputs,
std::array<size_t, ZC_NUM_JS_INPUTS>& inputMap,
std::array<size_t, ZC_NUM_JS_OUTPUTS>& outputMap,
CAmount vpub_old,
CAmount vpub_new,
bool computeProof = true, // Set to false in some tests
Expand Down Expand Up @@ -511,8 +512,8 @@ class CTransaction
CTransaction(const CMutableTransaction &tx, bool evilDeveloperFlag);

public:
typedef boost::array<unsigned char, 64> joinsplit_sig_t;
typedef boost::array<unsigned char, 64> binding_sig_t;
typedef std::array<unsigned char, 64> joinsplit_sig_t;
typedef std::array<unsigned char, 64> binding_sig_t;

// Transactions that include a list of JoinSplits are >= version 2.
static const int32_t SPROUT_MIN_CURRENT_VERSION = 1;
Expand Down