Enforce zk-SNARK validity during consensus.
This commit is contained in:
parent
0a87fc4ad0
commit
03bff15fe2
|
@ -30,8 +30,9 @@ private:
|
|||
std::string strRejectReason;
|
||||
unsigned char chRejectCode;
|
||||
bool corruptionPossible;
|
||||
bool pourVerify;
|
||||
public:
|
||||
CValidationState() : mode(MODE_VALID), nDoS(0), chRejectCode(0), corruptionPossible(false) {}
|
||||
CValidationState() : mode(MODE_VALID), nDoS(0), chRejectCode(0), corruptionPossible(false), pourVerify(true) {}
|
||||
bool DoS(int level, bool ret = false,
|
||||
unsigned char chRejectCodeIn=0, std::string strRejectReasonIn="",
|
||||
bool corruptionIn=false) {
|
||||
|
@ -44,6 +45,12 @@ public:
|
|||
mode = MODE_INVALID;
|
||||
return ret;
|
||||
}
|
||||
bool SetPerformPourVerification(bool pourVerifyIn) {
|
||||
pourVerify = pourVerifyIn;
|
||||
}
|
||||
bool PerformPourVerification() {
|
||||
return pourVerify;
|
||||
}
|
||||
bool Invalid(bool ret = false,
|
||||
unsigned char _chRejectCode=0, std::string _strRejectReason="") {
|
||||
return DoS(0, ret, _chRejectCode, _strRejectReason);
|
||||
|
|
11
src/main.cpp
11
src/main.cpp
|
@ -945,6 +945,17 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state)
|
|||
if (txin.prevout.IsNull())
|
||||
return state.DoS(10, error("CheckTransaction(): prevout is null"),
|
||||
REJECT_INVALID, "bad-txns-prevout-null");
|
||||
|
||||
// Ensure that zk-SNARKs verify
|
||||
|
||||
if (state.PerformPourVerification()) {
|
||||
BOOST_FOREACH(const CPourTx &pour, tx.vpour) {
|
||||
if (!pour.Verify(*pzerocashParams)) {
|
||||
return state.DoS(100, error("CheckTransaction(): pour does not verify"),
|
||||
REJECT_INVALID, "bad-txns-pour-verification-failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -227,6 +227,7 @@ BOOST_AUTO_TEST_CASE(sighash_from_data)
|
|||
stream >> tx;
|
||||
|
||||
CValidationState state;
|
||||
state.SetPerformPourVerification(false); // don't verify the snark
|
||||
BOOST_CHECK_MESSAGE(CheckTransaction(tx, state), strTest);
|
||||
BOOST_CHECK(state.IsValid());
|
||||
|
||||
|
|
|
@ -391,6 +391,9 @@ BOOST_AUTO_TEST_CASE(test_simple_pour_invalidity)
|
|||
// pours.
|
||||
CMutableTransaction newTx(tx);
|
||||
CValidationState state;
|
||||
|
||||
state.SetPerformPourVerification(false); // don't verify the snark
|
||||
|
||||
// No pours, vin and vout, means it should be invalid.
|
||||
BOOST_CHECK(!CheckTransaction(newTx, state));
|
||||
BOOST_CHECK(state.GetRejectReason() == "bad-txns-vin-empty");
|
||||
|
|
Loading…
Reference in New Issue