Skip to content

Commit

Permalink
validation: add OP_VAULT validation weight
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesob committed Sep 22, 2023
1 parent dcf1442 commit 207b33e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/script/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2169,6 +2169,14 @@ std::optional<ScriptError> GenericTransactionSignatureChecker<T>::CheckVaultTrig
{
assert(execdata.m_curr_witversion);

// Implement the sigops/witnesssize ratio test.
// Passing with an upgradable public key version is also counted.

This comment has been minimized.

Copy link
@jamesob

jamesob Sep 23, 2023

Author

Copypasta'd comments to be removed.

assert(execdata.m_validation_weight_left_init);
execdata.m_validation_weight_left -= VALIDATION_WEIGHT_PER_TAPTWEAKCHECK;
if (execdata.m_validation_weight_left < 0) {
return SCRIPT_ERR_TAPSCRIPT_VALIDATION_WEIGHT;
}

if (!this->txdata) {
HandleMissingData(m_mdb);
return SCRIPT_ERR_UNKNOWN_ERROR;
Expand Down Expand Up @@ -2209,7 +2217,7 @@ std::optional<ScriptError> GenericTransactionSignatureChecker<T>::CheckVaultTrig
}
const XOnlyPubKey val_pk{Span{val_sPK}.subspan(2)};

auto tapleaf_hash = ComputeTapleafHash(
const auto tapleaf_hash = ComputeTapleafHash(
control[0] & TAPROOT_LEAF_MASK, flu_script);
const uint256 merkle_root = ComputeTaprootMerkleRoot(control, tapleaf_hash);
const auto expected_pk = (*execdata.m_internal_key).CreateTapTweak(&merkle_root);
Expand Down
4 changes: 4 additions & 0 deletions src/script/script.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ static constexpr unsigned int ANNEX_TAG = 0x50;
// Validation weight per passing signature (Tapscript only, see BIP 342).
static constexpr int64_t VALIDATION_WEIGHT_PER_SIGOP_PASSED{50};

// Validation weight per passing taptweak generation (Tapscript only, see BIP 345).
// Related bench: bench/opvault.cpp.
static constexpr int64_t VALIDATION_WEIGHT_PER_TAPTWEAKCHECK{60};

// How much weight budget is added to the witness size (Tapscript only, see BIP 342).
static constexpr int64_t VALIDATION_WEIGHT_OFFSET{50};

Expand Down

0 comments on commit 207b33e

Please sign in to comment.