Remove plaintext check from AddSaplingSpend
Co-authored by Sean Bowe (ewillbefull@gmail.com)
This commit is contained in:
parent
19d4c47b66
commit
ee83424c6f
|
@ -496,103 +496,3 @@ TEST(TransactionBuilder, CheckSaplingTxVersion)
|
|||
// Revert to default
|
||||
UpdateNetworkUpgradeParameters(Consensus::UPGRADE_OVERWINTER, Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT);
|
||||
}
|
||||
|
||||
TEST(TransactionBuilder, RejectsInvalidNotePlaintextVersion)
|
||||
{
|
||||
SelectParams(CBaseChainParams::REGTEST);
|
||||
int overwinterActivationHeight = 5;
|
||||
int saplingActivationHeight = 30;
|
||||
int canopyActivationHeight = 70;
|
||||
UpdateNetworkUpgradeParameters(Consensus::UPGRADE_OVERWINTER, overwinterActivationHeight);
|
||||
UpdateNetworkUpgradeParameters(Consensus::UPGRADE_SAPLING, saplingActivationHeight);
|
||||
UpdateNetworkUpgradeParameters(Consensus::UPGRADE_CANOPY, canopyActivationHeight);
|
||||
auto consensusParams = Params().GetConsensus();
|
||||
|
||||
auto sk = libzcash::SaplingSpendingKey::random();
|
||||
auto expsk = sk.expanded_spending_key();
|
||||
auto pk = sk.default_address();
|
||||
|
||||
SaplingMerkleTree tree;
|
||||
|
||||
{
|
||||
// non-0x01 received before Canopy activation height
|
||||
auto builder = TransactionBuilder(consensusParams, canopyActivationHeight - 1);
|
||||
libzcash::SaplingNote note(pk, 50000, true);
|
||||
try {
|
||||
builder.AddSaplingSpend(expsk, note, uint256(), tree.witness());
|
||||
} catch (std::runtime_error const & err) {
|
||||
EXPECT_EQ(err.what(), std::string("TransactionBuilder: invalid note plaintext version"));
|
||||
} catch(...) {
|
||||
FAIL() << "Expected std::runtime_error";
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// non-0x02 received past (Canopy activation height + grace period)
|
||||
auto builder = TransactionBuilder(consensusParams, canopyActivationHeight + ZIP212_GRACE_PERIOD);
|
||||
libzcash::SaplingNote note(pk, 50000, false);
|
||||
try {
|
||||
builder.AddSaplingSpend(expsk, note, uint256(), tree.witness());
|
||||
} catch (std::runtime_error const & err) {
|
||||
EXPECT_EQ(err.what(), std::string("TransactionBuilder: invalid note plaintext version"));
|
||||
} catch(...) {
|
||||
FAIL() << "Expected std::runtime_error";
|
||||
}
|
||||
}
|
||||
|
||||
// Revert to default
|
||||
RegtestDeactivateCanopy();
|
||||
RegtestDeactivateSapling();
|
||||
}
|
||||
|
||||
TEST(TransactionBuilder, AcceptsValidNotePlaintextVersion)
|
||||
{
|
||||
SelectParams(CBaseChainParams::REGTEST);
|
||||
int overwinterActivationHeight = 5;
|
||||
int saplingActivationHeight = 30;
|
||||
int canopyActivationHeight = 70;
|
||||
UpdateNetworkUpgradeParameters(Consensus::UPGRADE_OVERWINTER, overwinterActivationHeight);
|
||||
UpdateNetworkUpgradeParameters(Consensus::UPGRADE_SAPLING, saplingActivationHeight);
|
||||
UpdateNetworkUpgradeParameters(Consensus::UPGRADE_CANOPY, canopyActivationHeight);
|
||||
auto consensusParams = Params().GetConsensus();
|
||||
|
||||
auto sk = libzcash::SaplingSpendingKey::random();
|
||||
auto expsk = sk.expanded_spending_key();
|
||||
auto pk = sk.default_address();
|
||||
|
||||
SaplingMerkleTree tree;
|
||||
|
||||
{
|
||||
// 0x01 received before Canopy activation height
|
||||
auto builder = TransactionBuilder(consensusParams, canopyActivationHeight - 1);
|
||||
libzcash::SaplingNote note(pk, 50000, false);
|
||||
ASSERT_NO_THROW(builder.AddSaplingSpend(expsk, note, uint256(), tree.witness()));
|
||||
}
|
||||
|
||||
{
|
||||
// {0x01,0x02} received after Canopy activation and before grace period has elapsed
|
||||
unsigned char is_zip_212[] = {false, true};
|
||||
int height1 = canopyActivationHeight - 1;
|
||||
int height2 = canopyActivationHeight + (ZIP212_GRACE_PERIOD) - 2;
|
||||
int heights[] = {height1, height2};
|
||||
|
||||
for (int i = 0; i < sizeof(is_zip_212); i++) {
|
||||
for (int j = 0; j < sizeof(heights) / sizeof(int); j++) {
|
||||
auto builder = TransactionBuilder(consensusParams, heights[j]);
|
||||
libzcash::SaplingNote note(pk, 50000, is_zip_212[i]);
|
||||
ASSERT_NO_THROW(builder.AddSaplingSpend(expsk, note, uint256(), tree.witness()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// 0x02 received past (Canopy activation height + grace period)
|
||||
auto builder = TransactionBuilder(consensusParams, canopyActivationHeight + ZIP212_GRACE_PERIOD - 1);
|
||||
libzcash::SaplingNote note(pk, 50000, true);
|
||||
ASSERT_NO_THROW(builder.AddSaplingSpend(expsk, note, uint256(), tree.witness()));
|
||||
}
|
||||
|
||||
// Revert to default
|
||||
RegtestDeactivateCanopy();
|
||||
RegtestDeactivateSapling();
|
||||
}
|
||||
|
|
|
@ -143,16 +143,6 @@ void TransactionBuilder::AddSaplingSpend(
|
|||
throw std::runtime_error("TransactionBuilder cannot add Sapling spend to pre-Sapling transaction");
|
||||
}
|
||||
|
||||
unsigned char leadbyte = 0x01;
|
||||
if (note.get_is_zip_212() == true) {
|
||||
leadbyte = 0x02;
|
||||
}
|
||||
|
||||
// ZIP212: check that note plaintext lead byte is valid at height
|
||||
if (!libzcash::plaintext_version_is_valid(consensusParams, nHeight + 1, leadbyte)) {
|
||||
throw std::runtime_error("TransactionBuilder: invalid note plaintext version");
|
||||
}
|
||||
|
||||
// Consistency check: all anchors must equal the first one
|
||||
if (spends.size() > 0 && spends[0].anchor != anchor) {
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, "Anchor does not match previously-added Sapling spends.");
|
||||
|
@ -173,11 +163,7 @@ void TransactionBuilder::AddSaplingOutput(
|
|||
throw std::runtime_error("TransactionBuilder cannot add Sapling output to pre-Sapling transaction");
|
||||
}
|
||||
|
||||
bool is_zip_212 = false;
|
||||
if (Params().GetConsensus().NetworkUpgradeActive(nHeight + 1, Consensus::UPGRADE_CANOPY)) {
|
||||
is_zip_212 = true;
|
||||
}
|
||||
auto note = libzcash::SaplingNote(to, value, is_zip_212);
|
||||
auto note = libzcash::SaplingNote(to, value, Params().GetConsensus().NetworkUpgradeActive(nHeight + 1, Consensus::UPGRADE_CANOPY));
|
||||
outputs.emplace_back(ovk, note, memo);
|
||||
mtx.valueBalance -= value;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue