Skip to content

Commit

Permalink
Sapling: add option to skip ProveAndSing in TransactionBuilder::Build
Browse files Browse the repository at this point in the history
adding dummy proofs and signatures instead

Github-Pull: #2065
Rebased-From: 5d8ba3d
  • Loading branch information
random-zebra authored and Fuzzbawls committed Dec 19, 2020
1 parent ff2dec2 commit 0aa9439
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 3 deletions.
63 changes: 61 additions & 2 deletions src/sapling/transaction_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,66 @@ TransactionBuilderResult TransactionBuilder::ProveAndSign()
return TransactionBuilderResult(CTransaction(mtx));
}

TransactionBuilderResult TransactionBuilder::Build()
TransactionBuilderResult TransactionBuilder::AddDummySignatures()
{
if (!spends.empty() || !outputs.empty()) {
// Add Dummy Sapling OutputDescriptions
OutputDescription dummyOD;
dummyOD.cv = UINT256_MAX;
dummyOD.cmu = UINT256_MAX;
dummyOD.ephemeralKey = UINT256_MAX;
dummyOD.encCiphertext = {{0xff}};
dummyOD.outCiphertext = {{0xff}};
dummyOD.zkproof = {{0xff}};
for (unsigned int i = 0; i < outputs.size(); i++) {
mtx.sapData->vShieldedOutput.push_back(dummyOD);
}
// Add Dummy Sapling SpendDescriptions
SpendDescription dummySD;
dummySD.cv = UINT256_MAX;
dummySD.anchor = UINT256_MAX;
dummySD.nullifier = UINT256_MAX;
dummySD.rk = UINT256_MAX;
dummySD.zkproof = {{0xff}};
dummySD.spendAuthSig = {{0xff}};
for (unsigned int i = 0; i < spends.size(); i++) {
mtx.sapData->vShieldedSpend.push_back(dummySD);
}
// Add Dummy Binding sig
mtx.sapData->bindingSig = {{0xff}};
}

// Add Dummmy Transparent signatures
CTransaction txNewConst(mtx);
for (int nIn = 0; nIn < (int) mtx.vin.size(); nIn++) {
auto tIn = tIns[nIn];
SignatureData sigdata;
if (!ProduceSignature(DummySignatureCreator(keystore), tIn.scriptPubKey, sigdata, SIGVERSION_SAPLING, false)) {
return TransactionBuilderResult("Failed to sign transaction");
} else {
UpdateTransaction(mtx, nIn, sigdata);
}
}

return TransactionBuilderResult(CTransaction(mtx));
}

void TransactionBuilder::ClearProofsAndSignatures()
{
// Clear Sapling output descriptions
mtx.sapData->vShieldedOutput.clear();

// Clear Sapling spend descriptions
mtx.sapData->vShieldedSpend.clear();

// Clear Binding sig
mtx.sapData->bindingSig = {{0}};

// Clear Transparent signatures
for (CTxIn& in : mtx.vin) in.scriptSig = CScript();
}

TransactionBuilderResult TransactionBuilder::Build(bool fDummySig)
{
//
// Consistency checks
Expand Down Expand Up @@ -378,5 +437,5 @@ TransactionBuilderResult TransactionBuilder::Build()
}
}

return ProveAndSign();
return fDummySig ? AddDummySignatures() : ProveAndSign();
}
6 changes: 5 additions & 1 deletion src/sapling/transaction_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,13 @@ class TransactionBuilder

void SendChangeTo(CTxDestination& changeAddr);

TransactionBuilderResult Build();
TransactionBuilderResult Build(bool fDummySig = false);
// Add Sapling Spend/Output descriptions, binding sig, and transparent signatures
TransactionBuilderResult ProveAndSign();
// Add dummy Sapling Spend/Output descriptions, binding sig, and transparent signatures
TransactionBuilderResult AddDummySignatures();
// Remove Sapling Spend/Output descriptions, binding sig, and transparent signatures
void ClearProofsAndSignatures();
};

#endif /* TRANSACTION_BUILDER_H */
1 change: 1 addition & 0 deletions src/uint256.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,6 @@ arith_uint512 UintToArith512(const uint512 &);
/** constant uint256 instances */
const uint256 UINT256_ZERO = uint256();
const uint256 UINT256_ONE = uint256("0000000000000000000000000000000000000000000000000000000000000001");
const uint256 UINT256_MAX = uint256("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");

#endif // PIVX_UINT256_H

0 comments on commit 0aa9439

Please sign in to comment.