25 return state.
DoS(100,
error(
"%s: Not Sapling version with Sapling data", __func__ ),
26 REJECT_INVALID,
"bad-txns-form-not-sapling");
30 if (!hasSaplingData) {
38 return state.
DoS(100,
error(
"%s: Sapling version with invalid data", __func__),
39 REJECT_INVALID,
"bad-txns-invalid-sapling");
53 if (tx.
sapData->vShieldedSpend.empty() && tx.
sapData->vShieldedOutput.empty() && tx.
sapData->valueBalance != 0) {
54 return state.
DoS(100,
error(
"%s: tx.sapData->valueBalance has no sources or sinks", __func__ ),
55 REJECT_INVALID,
"bad-txns-valuebalance-nonzero");
60 return state.
DoS(100,
error(
"%s: abs(tx.sapData->valueBalance) too large", __func__),
61 REJECT_INVALID,
"bad-txns-valuebalance-toolarge");
64 if (tx.
sapData->valueBalance < 0) {
66 nValueOut += -tx.
sapData->valueBalance;
69 return state.
DoS(100,
error(
"%s: txout total out of range", __func__ ),
70 REJECT_INVALID,
"bad-txns-txouttotal-toolarge");
81 return state.
DoS(100,
error(
"%s: txin total out of range", __func__ ),
82 REJECT_INVALID,
"bad-txns-txintotal-toolarge");
87 std::set<uint256> vSaplingNullifiers;
89 if (vSaplingNullifiers.count(spend_desc.
nullifier))
90 return state.
DoS(100,
error(
"%s: duplicate nullifiers", __func__ ),
91 REJECT_INVALID,
"bad-spend-description-nullifiers-duplicate");
93 vSaplingNullifiers.insert(spend_desc.
nullifier);
119 bool isInitBlockDownload)
121 const int DOS_LEVEL_BLOCK = 100;
123 const int DOS_LEVEL_MEMPOOL = 10;
126 auto dosLevelConstricting = isMined ? DOS_LEVEL_BLOCK : DOS_LEVEL_MEMPOOL;
129 auto dosLevelPotentiallyRelaxing = isMined ? DOS_LEVEL_BLOCK : (
130 isInitBlockDownload ? 0 : DOS_LEVEL_MEMPOOL);
137 return state.
DoS(dosLevelConstricting,
error(
"%s: Sapling not activated", __func__),
138 REJECT_INVALID,
"bad-txns-invalid-sapling-act");
146 dosLevelConstricting,
147 error(
"%s: Sapling version too low", __func__ ),
148 REJECT_INVALID,
"bad-tx-sapling-version-too-low");
156 dosLevelPotentiallyRelaxing,
157 error(
"%s: coinbase/coinstake has output/spend descriptions", __func__ ),
158 REJECT_INVALID,
"bad-cs-has-shielded-data");
161 if (hasShieldedData) {
165 return state.
DoS(100,
error(
"%s: Sapling version with invalid data", __func__),
166 REJECT_INVALID,
"bad-txns-exchange-addr-has-sapling");
173 }
catch (
const std::logic_error& ex) {
176 return state.
DoS(100,
error(
"%s: error computing signature hash", __func__ ),
177 REJECT_INVALID,
"error-computing-signature-hash");
192 dataToBeSigned.
begin())) {
195 dosLevelPotentiallyRelaxing,
196 error(
"%s: Sapling spend description invalid", __func__ ),
197 REJECT_INVALID,
"bad-txns-sapling-spend-description-invalid");
212 return state.
DoS(100,
error(
"%s: Sapling output description invalid", __func__ ),
213 REJECT_INVALID,
"bad-txns-sapling-output-description-invalid");
220 tx.
sapData->bindingSig.begin(),
221 dataToBeSigned.
begin())) {
224 dosLevelPotentiallyRelaxing,
225 error(
"%s: Sapling binding signature invalid", __func__ ),
226 REJECT_INVALID,
"bad-txns-sapling-binding-signature-invalid");
int64_t CAmount
Amount in PIV (Can be negative)
const CChainParams & Params()
Return the currently selected parameters.
CChainParams defines various tweakable parameters of a given instance of the PIVX system.
const Consensus::Params & GetConsensus() const
Serialized script, used inside transaction inputs and outputs.
The basic transaction that is broadcasted on the network and contained in blocks.
bool HasZerocoinSpendInputs() const
bool HasExchangeAddr() const
bool IsShieldedTx() const
bool HasZerocoinMintOutputs() const
Optional< SaplingTxData > sapData
bool isSaplingVersion() const
bool hasSaplingData() const
Capture information about block/transaction validation.
bool DoS(int level, bool ret=false, unsigned int chRejectCodeIn=0, std::string strRejectReasonIn="", bool corruptionIn=false, const std::string &strDebugMessageIn="")
A shielded output to a transaction.
uint256 cmu
The u-coordinate of the note commitment for the output note.
libzcash::GrothProof zkproof
A zero-knowledge proof using the output circuit.
uint256 cv
A value commitment to the value of the output note.
uint256 ephemeralKey
A Jubjub public key.
A shielded input to a transaction.
spend_auth_sig_t spendAuthSig
A signature authorizing this spend.
uint256 cv
A value commitment to the value of the input note.
libzcash::GrothProof zkproof
A zero-knowledge proof using the spend circuit.
uint256 anchor
A Merkle root of the Sapling note commitment tree at some block height in the past.
uint256 rk
The randomized public key for spendAuthSig.
uint256 nullifier
The nullifier of the input note.
uint256 SignatureHash(const CScript &scriptCode, const CTransaction &txTo, unsigned int nIn, int nHashType, const CAmount &amount, SigVersion sigversion, const PrecomputedTransactionData *cache)
const unsigned int NOT_AN_INPUT
Special case nIn for signing Sapling txs.
void librustzcash_sapling_verification_ctx_free(void *)
Frees a Sapling verification context returned from librustzcash_sapling_verification_ctx_init.
bool librustzcash_sapling_check_output(void *ctx, const unsigned char *cv, const unsigned char *cm, const unsigned char *ephemeralKey, const unsigned char *zkproof)
Check the validity of a Sapling Output description, accumulating the value commitment into the contex...
void * librustzcash_sapling_verification_ctx_init()
Creates a Sapling verification context.
bool librustzcash_sapling_final_check(void *ctx, int64_t valueBalance, const unsigned char *bindingSig, const unsigned char *sighashValue)
Finally checks the validity of the entire Sapling transaction given valueBalance and the binding sign...
bool librustzcash_sapling_check_spend(void *ctx, const unsigned char *cv, const unsigned char *anchor, const unsigned char *nullifier, const unsigned char *rk, const unsigned char *zkproof, const unsigned char *spendAuthSig, const unsigned char *sighashValue)
Check the validity of a Sapling Spend description, accumulating the value commitment into the context...
bool CheckTransactionWithoutProofVerification(const CTransaction &tx, CValidationState &state, CAmount &nValueOut)
bool CheckTransaction(const CTransaction &tx, CValidationState &state, CAmount &nValueOut)
Context-independent validity checks.
bool ContextualCheckTransaction(const CTransaction &tx, CValidationState &state, const CChainParams &chainparams, const int nHeight, const bool isMined, bool isInitBlockDownload)
Check a transaction contextually against a set of consensus rules valid at a given block height.
Parameters that influence chain consensus.
bool MoneyRange(const CAmount &nValue) const
bool NetworkUpgradeActive(int nHeight, Consensus::UpgradeIndex idx) const
Returns true if the given network upgrade is active as of the given block height.
bool error(const char *fmt, const Args &... args)