Skip to content

Commit

Permalink
Merge pull request #6046 from nuttycom/bug/disabled_orchard_batch_val…
Browse files Browse the repository at this point in the history
…idation2

Replace "Disabled" Orchard AuthValidator with std::nullopt
  • Loading branch information
nuttycom committed Jul 4, 2022
2 parents 2e6a251 + 4600079 commit a2d0f15
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
16 changes: 9 additions & 7 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@ bool ContextualCheckShieldedInputs(
const PrecomputedTransactionData& txdata,
CValidationState &state,
const CCoinsViewCache &view,
orchard::AuthValidator& orchardAuth,
std::optional<orchard::AuthValidator>& orchardAuth,
const Consensus::Params& consensus,
uint32_t consensusBranchId,
bool nu5Active,
Expand Down Expand Up @@ -1380,7 +1380,9 @@ bool ContextualCheckShieldedInputs(
}

// Queue Orchard bundle to be batch-validated.
tx.GetOrchardBundle().QueueAuthValidation(orchardAuth, dataToBeSigned);
if (orchardAuth.has_value()) {
tx.GetOrchardBundle().QueueAuthValidation(orchardAuth.value(), dataToBeSigned);
}

return true;
}
Expand Down Expand Up @@ -2001,7 +2003,7 @@ bool AcceptToMemoryPool(

// This will be a single-transaction batch, which is still more efficient as every
// Orchard bundle contains at least two signatures.
auto orchardAuth = orchard::AuthValidator::Batch();
std::optional<orchard::AuthValidator> orchardAuth = orchard::AuthValidator::Batch();

// Check shielded input signatures.
if (!ContextualCheckShieldedInputs(
Expand All @@ -2018,8 +2020,8 @@ bool AcceptToMemoryPool(
return false;
}

// Check Orchard bundle authorizations.
if (!orchardAuth.Validate()) {
// Check Orchard bundle authorizations. `orchardAuth` here is known to be non-null
if (!orchardAuth.value().Validate()) {
return state.DoS(100, false, REJECT_INVALID, "bad-orchard-bundle-authorization");
}

Expand Down Expand Up @@ -3073,7 +3075,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
auto verifier = fExpensiveChecks ? ProofVerifier::Strict() : ProofVerifier::Disabled();

// Disable Orchard batch signature validation if possible.
auto orchardAuth = fExpensiveChecks ?
std::optional<orchard::AuthValidator> orchardAuth = fExpensiveChecks ?
orchard::AuthValidator::Batch() : orchard::AuthValidator::Disabled();

// If in initial block download, and this block is an ancestor of a checkpoint,
Expand Down Expand Up @@ -3516,7 +3518,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
REJECT_INVALID, "bad-cb-amount");

// Ensure Orchard signatures are valid (if we are checking them)
if (!orchardAuth.Validate()) {
if (orchardAuth.has_value() && !orchardAuth.value().Validate()) {
return state.DoS(100,
error("ConnectBlock(): an Orchard bundle within the block is invalid"),
REJECT_INVALID, "bad-orchard-bundle-authorization");
Expand Down
2 changes: 1 addition & 1 deletion src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ bool ContextualCheckShieldedInputs(
const PrecomputedTransactionData& txdata,
CValidationState &state,
const CCoinsViewCache &view,
orchard::AuthValidator& orchardAuth,
std::optional<orchard::AuthValidator>& orchardAuth,
const Consensus::Params& consensus,
uint32_t consensusBranchId,
bool nu5Active,
Expand Down
4 changes: 2 additions & 2 deletions src/rust/include/rust/orchard.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ class AuthValidator

/// Creates a validation context that performs no validation. This can be
/// used when avoiding duplicate effort such as during reindexing.
static AuthValidator Disabled() {
return AuthValidator();
static std::optional<AuthValidator> Disabled() {
return std::nullopt;
}

/// Queues an Orchard bundle for validation.
Expand Down

0 comments on commit a2d0f15

Please sign in to comment.