Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions src/transactions/SignatureChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,19 @@ SignatureChecker::SignatureChecker(
: mProtocolVersion{protocolVersion}
, mContentsHash{contentsHash}
, mSignatures{signatures}
, mIsOverlayValidation{isOverlayValidation}
, mEnforceVerifyBudget{
isOverlayValidation ||
protocolVersionStartsFrom(protocolVersion,
TX_ED25519_VERIFY_BUDGET_PROTOCOL_VERSION)}
Comment thread
bboston7 marked this conversation as resolved.
{
mUsedSignatures.resize(mSignatures.size());
}

bool
SignatureChecker::isOverlayValidation() const
{
return mIsOverlayValidation;
}

bool
SignatureChecker::isOverVerificationBudget() const
{
return mIsOverlayValidation &&
mTxEd25519Verifications >= OVERLAY_TX_ED25519_VERIFY_BUDGET;
return mEnforceVerifyBudget &&
mTxEd25519Verifications >= TX_ED25519_VERIFY_BUDGET;
}

bool
Expand Down
13 changes: 10 additions & 3 deletions src/transactions/SignatureChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ class SignatureChecker
void disableCacheMetricsTracking();
#endif // BUILD_TESTS

bool isOverlayValidation() const;
static constexpr uint32_t OVERLAY_TX_ED25519_VERIFY_BUDGET = 1000;
// Maximum number of ed25519 signature verifications a single
// SignatureChecker will perform. Enforced during overlay validation at all
// protocol versions, and on all validation and apply paths starting from
// TX_ED25519_VERIFY_BUDGET_PROTOCOL_VERSION.
static constexpr uint32_t TX_ED25519_VERIFY_BUDGET = 1000;

// Reset and return the counts of signature checks performed as part of
// transaction `checkValid` or apply flow. The first element of the pair is
Expand All @@ -57,9 +60,13 @@ class SignatureChecker
Hash const& mContentsHash;
xdr::xvector<DecoratedSignature, 20> const& mSignatures;
bool mTrackCacheMetrics{true};
bool mIsOverlayValidation{false};

// Whether this checker enforces TX_ED25519_VERIFY_BUDGET.
bool const mEnforceVerifyBudget;

std::vector<bool> mUsedSignatures;

// Number of ed25519 verifications performed by this checker
uint32_t mTxEd25519Verifications{0};

bool isOverVerificationBudget() const;
Expand Down
3 changes: 3 additions & 0 deletions src/util/ProtocolVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ constexpr ProtocolVersion EMPTY_TX_SET_PROTOCOL_VERSION =
constexpr ProtocolVersion INVOKE_HOST_FUNCTION_V2_PROTOCOL_VERSION =
ProtocolVersion::V_28;

constexpr ProtocolVersion TX_ED25519_VERIFY_BUDGET_PROTOCOL_VERSION =
ProtocolVersion::V_28;

#ifdef CAP_0085_EXECUTABLE_REF
constexpr ProtocolVersion EXTERNAL_EXECUTABLE_REF_PROTOCOL_VERSION =
ProtocolVersion::V_28;
Expand Down
Loading