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

Naming improvements #3322

Merged
merged 1 commit into from Jun 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
26 changes: 13 additions & 13 deletions src/gtest/test_joinsplit.cpp
Expand Up @@ -39,7 +39,7 @@ void test_full_api(ZCJoinSplit* js)
uint256 randomSeed;
uint64_t vpub_old = 10;
uint64_t vpub_new = 0;
uint256 pubKeyHash = random_uint256();
uint256 joinSplitPubKey = random_uint256();
std::array<uint256, 2> macs;
std::array<uint256, 2> nullifiers;
std::array<uint256, 2> commitments;
Expand Down Expand Up @@ -68,7 +68,7 @@ void test_full_api(ZCJoinSplit* js)
output_notes,
ciphertexts,
ephemeralKey,
pubKeyHash,
joinSplitPubKey,
randomSeed,
macs,
nullifiers,
Expand All @@ -79,13 +79,13 @@ void test_full_api(ZCJoinSplit* js)
);
}

auto sprout_proof = boost::get<ZCProof>(proof);
auto sprout_proof = boost::get<PHGRProof>(proof);

// Verify the transaction:
ASSERT_TRUE(js->verify(
sprout_proof,
verifier,
pubKeyHash,
joinSplitPubKey,
randomSeed,
macs,
nullifiers,
Expand All @@ -97,7 +97,7 @@ void test_full_api(ZCJoinSplit* js)

// Recipient should decrypt
// Now the recipient should spend the money again
auto h_sig = js->h_sig(randomSeed, nullifiers, pubKeyHash);
auto h_sig = js->h_sig(randomSeed, nullifiers, joinSplitPubKey);
ZCNoteDecryption decryptor(recipient_key.receiving_key());

auto note_pt = SproutNotePlaintext::decrypt(
Expand All @@ -120,7 +120,7 @@ void test_full_api(ZCJoinSplit* js)
vpub_old = 0;
vpub_new = 1;
rt = tree.root();
pubKeyHash = random_uint256();
joinSplitPubKey = random_uint256();

{
std::array<JSInput, 2> inputs = {
Expand All @@ -146,7 +146,7 @@ void test_full_api(ZCJoinSplit* js)
output_notes,
ciphertexts,
ephemeralKey,
pubKeyHash,
joinSplitPubKey,
randomSeed,
macs,
nullifiers,
Expand All @@ -157,13 +157,13 @@ void test_full_api(ZCJoinSplit* js)
);
}

sprout_proof = boost::get<ZCProof>(proof);
sprout_proof = boost::get<PHGRProof>(proof);

// Verify the transaction:
ASSERT_TRUE(js->verify(
sprout_proof,
verifier,
pubKeyHash,
joinSplitPubKey,
randomSeed,
macs,
nullifiers,
Expand All @@ -186,7 +186,7 @@ void invokeAPI(
) {
uint256 ephemeralKey;
uint256 randomSeed;
uint256 pubKeyHash = random_uint256();
uint256 joinSplitPubKey = random_uint256();
std::array<uint256, 2> macs;
std::array<uint256, 2> nullifiers;
std::array<uint256, 2> commitments;
Expand All @@ -201,7 +201,7 @@ void invokeAPI(
output_notes,
ciphertexts,
ephemeralKey,
pubKeyHash,
joinSplitPubKey,
randomSeed,
macs,
nullifiers,
Expand Down Expand Up @@ -241,9 +241,9 @@ TEST(joinsplit, h_sig)
import pyblake2
import binascii

def hSig(randomSeed, nf1, nf2, pubKeyHash):
def hSig(randomSeed, nf1, nf2, joinSplitPubKey):
return pyblake2.blake2b(
data=(randomSeed + nf1 + nf2 + pubKeyHash),
data=(randomSeed + nf1 + nf2 + joinSplitPubKey),
digest_size=32,
person=b"ZcashComputehSig"
).digest()
Expand Down
8 changes: 4 additions & 4 deletions src/gtest/test_proofs.cpp
Expand Up @@ -241,7 +241,7 @@ TEST(proofs, sqrt_fq2)

TEST(proofs, size_is_expected)
{
ZCProof p;
PHGRProof p;
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss << p;

Expand Down Expand Up @@ -444,7 +444,7 @@ TEST(proofs, zksnark_serializes_properly)
auto vkprecomp = libsnark::r1cs_ppzksnark_verifier_process_vk(kp.vk);

for (size_t i = 0; i < 20; i++) {
auto badproof = ZCProof::random_invalid();
auto badproof = PHGRProof::random_invalid();
auto proof = badproof.to_libsnark_proof<libsnark::r1cs_ppzksnark_proof<curve_pp>>();

auto verifierEnabled = ProofVerifier::Strict();
Expand Down Expand Up @@ -496,12 +496,12 @@ TEST(proofs, zksnark_serializes_properly)
proof
));

ZCProof compressed_proof_0(proof);
PHGRProof compressed_proof_0(proof);

CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss << compressed_proof_0;

ZCProof compressed_proof_1;
PHGRProof compressed_proof_1;
ss >> compressed_proof_1;

ASSERT_TRUE(compressed_proof_0 == compressed_proof_1);
Expand Down
8 changes: 4 additions & 4 deletions src/gtest/test_transaction.cpp
Expand Up @@ -31,7 +31,7 @@ TEST(Transaction, JSDescriptionRandomized) {
auto witness = merkleTree.witness();

// create JSDescription
uint256 pubKeyHash;
uint256 joinSplitPubKey;
std::array<libzcash::JSInput, ZC_NUM_JS_INPUTS> inputs = {
libzcash::JSInput(witness, note, k),
libzcash::JSInput() // dummy input of zero value
Expand All @@ -46,7 +46,7 @@ TEST(Transaction, JSDescriptionRandomized) {
{
auto jsdesc = JSDescription::Randomized(
false,
*params, pubKeyHash, rt,
*params, joinSplitPubKey, rt,
inputs, outputs,
inputMap, outputMap,
0, 0, false);
Expand All @@ -63,7 +63,7 @@ TEST(Transaction, JSDescriptionRandomized) {
{
auto jsdesc = JSDescription::Randomized(
false,
*params, pubKeyHash, rt,
*params, joinSplitPubKey, rt,
inputs, outputs,
inputMap, outputMap,
0, 0, false, nullptr, GenZero);
Expand All @@ -77,7 +77,7 @@ TEST(Transaction, JSDescriptionRandomized) {
{
auto jsdesc = JSDescription::Randomized(
false,
*params, pubKeyHash, rt,
*params, joinSplitPubKey, rt,
inputs, outputs,
inputMap, outputMap,
0, 0, false, nullptr, GenMax);
Expand Down
28 changes: 14 additions & 14 deletions src/primitives/transaction.cpp
Expand Up @@ -14,7 +14,7 @@
JSDescription::JSDescription(
bool makeGrothProof,
ZCJoinSplit& params,
const uint256& pubKeyHash,
const uint256& joinSplitPubKey,
const uint256& anchor,
const std::array<libzcash::JSInput, ZC_NUM_JS_INPUTS>& inputs,
const std::array<libzcash::JSOutput, ZC_NUM_JS_OUTPUTS>& outputs,
Expand All @@ -33,7 +33,7 @@ JSDescription::JSDescription(
notes,
ciphertexts,
ephemeralKey,
pubKeyHash,
joinSplitPubKey,
randomSeed,
macs,
nullifiers,
Expand All @@ -49,7 +49,7 @@ JSDescription::JSDescription(
JSDescription JSDescription::Randomized(
bool makeGrothProof,
ZCJoinSplit& params,
const uint256& pubKeyHash,
const uint256& joinSplitPubKey,
const uint256& anchor,
std::array<libzcash::JSInput, ZC_NUM_JS_INPUTS>& inputs,
std::array<libzcash::JSOutput, ZC_NUM_JS_OUTPUTS>& outputs,
Expand All @@ -73,7 +73,7 @@ JSDescription JSDescription::Randomized(

return JSDescription(
makeGrothProof,
params, pubKeyHash, anchor, inputs, outputs,
params, joinSplitPubKey, anchor, inputs, outputs,
vpub_old, vpub_new, computeProof,
esk // payment disclosure
);
Expand All @@ -83,23 +83,23 @@ class SproutProofVerifier : public boost::static_visitor<bool>
{
ZCJoinSplit& params;
libzcash::ProofVerifier& verifier;
const uint256& pubKeyHash;
const uint256& joinSplitPubKey;
const JSDescription& jsdesc;

public:
SproutProofVerifier(
ZCJoinSplit& params,
libzcash::ProofVerifier& verifier,
const uint256& pubKeyHash,
const uint256& joinSplitPubKey,
const JSDescription& jsdesc
) : params(params), jsdesc(jsdesc), verifier(verifier), pubKeyHash(pubKeyHash) {}
) : params(params), jsdesc(jsdesc), verifier(verifier), joinSplitPubKey(joinSplitPubKey) {}

bool operator()(const libzcash::ZCProof& proof) const
bool operator()(const libzcash::PHGRProof& proof) const
{
return params.verify(
proof,
verifier,
pubKeyHash,
joinSplitPubKey,
jsdesc.randomSeed,
jsdesc.macs,
jsdesc.nullifiers,
Expand All @@ -112,7 +112,7 @@ class SproutProofVerifier : public boost::static_visitor<bool>

bool operator()(const libzcash::GrothProof& proof) const
{
uint256 h_sig = params.h_sig(jsdesc.randomSeed, jsdesc.nullifiers, pubKeyHash);
uint256 h_sig = params.h_sig(jsdesc.randomSeed, jsdesc.nullifiers, joinSplitPubKey);

return librustzcash_sprout_verify(
proof.begin(),
Expand All @@ -133,15 +133,15 @@ class SproutProofVerifier : public boost::static_visitor<bool>
bool JSDescription::Verify(
ZCJoinSplit& params,
libzcash::ProofVerifier& verifier,
const uint256& pubKeyHash
const uint256& joinSplitPubKey
) const {
auto pv = SproutProofVerifier(params, verifier, pubKeyHash, *this);
auto pv = SproutProofVerifier(params, verifier, joinSplitPubKey, *this);
return boost::apply_visitor(pv, proof);
}

uint256 JSDescription::h_sig(ZCJoinSplit& params, const uint256& pubKeyHash) const
uint256 JSDescription::h_sig(ZCJoinSplit& params, const uint256& joinSplitPubKey) const
{
return params.h_sig(randomSeed, nullifiers, pubKeyHash);
return params.h_sig(randomSeed, nullifiers, joinSplitPubKey);
}

std::string COutPoint::ToString() const
Expand Down
12 changes: 6 additions & 6 deletions src/primitives/transaction.h
Expand Up @@ -154,7 +154,7 @@ class SproutProofSerializer : public boost::static_visitor<>
public:
SproutProofSerializer(Stream& s, bool useGroth) : s(s), useGroth(useGroth) {}

void operator()(const libzcash::ZCProof& proof) const
void operator()(const libzcash::PHGRProof& proof) const
{
if (useGroth) {
throw std::ios_base::failure("Invalid Sprout proof for transaction format (expected GrothProof, found PHGRProof)");
Expand Down Expand Up @@ -186,7 +186,7 @@ inline void SerReadWriteSproutProof(Stream& s, T& proof, bool useGroth, CSerActi
::Unserialize(s, grothProof);
proof = grothProof;
} else {
libzcash::ZCProof pghrProof;
libzcash::PHGRProof pghrProof;
::Unserialize(s, pghrProof);
proof = pghrProof;
}
Expand Down Expand Up @@ -245,7 +245,7 @@ class JSDescription
JSDescription(
bool makeGrothProof,
ZCJoinSplit& params,
const uint256& pubKeyHash,
const uint256& joinSplitPubKey,
const uint256& rt,
const std::array<libzcash::JSInput, ZC_NUM_JS_INPUTS>& inputs,
const std::array<libzcash::JSOutput, ZC_NUM_JS_OUTPUTS>& outputs,
Expand All @@ -258,7 +258,7 @@ class JSDescription
static JSDescription Randomized(
bool makeGrothProof,
ZCJoinSplit& params,
const uint256& pubKeyHash,
const uint256& joinSplitPubKey,
const uint256& rt,
std::array<libzcash::JSInput, ZC_NUM_JS_INPUTS>& inputs,
std::array<libzcash::JSOutput, ZC_NUM_JS_OUTPUTS>& outputs,
Expand All @@ -275,11 +275,11 @@ class JSDescription
bool Verify(
ZCJoinSplit& params,
libzcash::ProofVerifier& verifier,
const uint256& pubKeyHash
const uint256& joinSplitPubKey
) const;

// Returns the calculated h_sig
uint256 h_sig(ZCJoinSplit& params, const uint256& pubKeyHash) const;
uint256 h_sig(ZCJoinSplit& params, const uint256& joinSplitPubKey) const;

ADD_SERIALIZE_METHODS;

Expand Down
2 changes: 1 addition & 1 deletion src/test/sighash_tests.cpp
Expand Up @@ -188,7 +188,7 @@ void static RandomTransaction(CMutableTransaction &tx, bool fSingle, uint32_t co
randombytes_buf(zkproof.begin(), zkproof.size());
jsdesc.proof = zkproof;
} else {
jsdesc.proof = libzcash::ZCProof::random_invalid();
jsdesc.proof = libzcash::PHGRProof::random_invalid();
}
jsdesc.macs[0] = GetRandHash();
jsdesc.macs[1] = GetRandHash();
Expand Down
16 changes: 8 additions & 8 deletions src/test/transaction_tests.cpp
Expand Up @@ -360,7 +360,7 @@ BOOST_AUTO_TEST_CASE(test_basic_joinsplit_verification)
auto witness = merkleTree.witness();

// create JSDescription
uint256 pubKeyHash;
uint256 joinSplitPubKey;
std::array<libzcash::JSInput, ZC_NUM_JS_INPUTS> inputs = {
libzcash::JSInput(witness, note, k),
libzcash::JSInput() // dummy input of zero value
Expand All @@ -373,8 +373,8 @@ BOOST_AUTO_TEST_CASE(test_basic_joinsplit_verification)
auto verifier = libzcash::ProofVerifier::Strict();

{
JSDescription jsdesc(false, *pzcashParams, pubKeyHash, rt, inputs, outputs, 0, 0);
BOOST_CHECK(jsdesc.Verify(*pzcashParams, verifier, pubKeyHash));
JSDescription jsdesc(false, *pzcashParams, joinSplitPubKey, rt, inputs, outputs, 0, 0);
BOOST_CHECK(jsdesc.Verify(*pzcashParams, verifier, joinSplitPubKey));

CDataStream ss(SER_DISK, CLIENT_VERSION);
ss << jsdesc;
Expand All @@ -383,20 +383,20 @@ BOOST_AUTO_TEST_CASE(test_basic_joinsplit_verification)
ss >> jsdesc_deserialized;

BOOST_CHECK(jsdesc_deserialized == jsdesc);
BOOST_CHECK(jsdesc_deserialized.Verify(*pzcashParams, verifier, pubKeyHash));
BOOST_CHECK(jsdesc_deserialized.Verify(*pzcashParams, verifier, joinSplitPubKey));
}

{
// Ensure that the balance equation is working.
BOOST_CHECK_THROW(JSDescription(false, *pzcashParams, pubKeyHash, rt, inputs, outputs, 10, 0), std::invalid_argument);
BOOST_CHECK_THROW(JSDescription(false, *pzcashParams, pubKeyHash, rt, inputs, outputs, 0, 10), std::invalid_argument);
BOOST_CHECK_THROW(JSDescription(false, *pzcashParams, joinSplitPubKey, rt, inputs, outputs, 10, 0), std::invalid_argument);
BOOST_CHECK_THROW(JSDescription(false, *pzcashParams, joinSplitPubKey, rt, inputs, outputs, 0, 10), std::invalid_argument);
}

{
// Ensure that it won't verify if the root is changed.
auto test = JSDescription(false, *pzcashParams, pubKeyHash, rt, inputs, outputs, 0, 0);
auto test = JSDescription(false, *pzcashParams, joinSplitPubKey, rt, inputs, outputs, 0, 0);
test.anchor = GetRandHash();
BOOST_CHECK(!test.Verify(*pzcashParams, verifier, pubKeyHash));
BOOST_CHECK(!test.Verify(*pzcashParams, verifier, joinSplitPubKey));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/wallet/rpcwallet.cpp
Expand Up @@ -2638,11 +2638,11 @@ UniValue zc_sample_joinsplit(const UniValue& params, bool fHelp)

LOCK(cs_main);

uint256 pubKeyHash;
uint256 joinSplitPubKey;
uint256 anchor = ZCIncrementalMerkleTree().root();
JSDescription samplejoinsplit(true,
*pzcashParams,
pubKeyHash,
joinSplitPubKey,
anchor,
{JSInput(), JSInput()},
{JSOutput(), JSOutput()},
Expand Down