xrpld
Loading...
Searching...
No Matches
InvariantCheck.h
1#pragma once
2
3#include <xrpl/basics/base_uint.h>
4#include <xrpl/beast/utility/Journal.h>
5#include <xrpl/ledger/ReadView.h>
6#include <xrpl/protocol/AccountID.h>
7#include <xrpl/protocol/STLedgerEntry.h>
8#include <xrpl/protocol/STTx.h>
9#include <xrpl/protocol/TER.h>
10#include <xrpl/protocol/XRPAmount.h>
11#include <xrpl/tx/invariants/AMMInvariant.h>
12#include <xrpl/tx/invariants/CosignerInvariant.h>
13#include <xrpl/tx/invariants/DirectoryInvariant.h>
14#include <xrpl/tx/invariants/FreezeInvariant.h>
15#include <xrpl/tx/invariants/LoanBrokerInvariant.h>
16#include <xrpl/tx/invariants/LoanInvariant.h>
17#include <xrpl/tx/invariants/MPTInvariant.h>
18#include <xrpl/tx/invariants/NFTInvariant.h>
19#include <xrpl/tx/invariants/PermissionedDEXInvariant.h>
20#include <xrpl/tx/invariants/PermissionedDomainInvariant.h>
21#include <xrpl/tx/invariants/SponsorshipInvariant.h>
22#include <xrpl/tx/invariants/VaultInvariant.h>
23
24#include <boost/multiprecision/cpp_int.hpp>
25
26#include <cstdint>
27#include <map>
28#include <set>
29#include <string>
30#include <tuple>
31#include <utility>
32#include <vector>
33
34namespace xrpl {
35
36#if GENERATING_DOCS
73{
74public:
75 explicit InvariantChecker_PROTOTYPE() = default;
76
93 void
95
112 bool
114 STTx const& tx,
115 TER const tec,
116 XRPAmount const fee,
117 ReadView const& view,
118 beast::Journal const& j);
119};
120#endif
121
129{
130public:
131 void
133
134 static bool
135 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&);
136};
137
147{
148 boost::multiprecision::int128_t drops_ = 0;
149
150public:
151 void
153
154 [[nodiscard]] bool
155 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
156};
157
167{
169
170public:
171 void
173
174 [[nodiscard]] bool
175 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
176};
177
189{
190 // Pair is <before, after>. Before is used for most of the checks, so that
191 // if, for example, an object ID field is cleared, but the object is not
192 // deleted, it can still be found. After is used specifically for any checks
193 // that are expected as part of the deletion, such as zeroing out the
194 // balance.
196
197public:
198 void
200
201 bool
202 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&);
203};
204
213{
214 bool bad_ = false;
215
216public:
217 void
219
220 [[nodiscard]] bool
221 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
222};
223
229{
230 bool typeMismatch_ = false;
231 bool invalidTypeAdded_ = false;
232
233public:
234 void
236
237 [[nodiscard]] bool
238 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
239};
240
248{
249 bool xrpTrustLine_ = false;
250
251public:
252 void
254
255 [[nodiscard]] bool
256 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
257};
258
267{
269
270public:
271 void
273
274 [[nodiscard]] bool
275 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
276};
277
286{
287 bool bad_ = false;
288
289public:
290 void
292
293 [[nodiscard]] bool
294 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
295};
296
302{
303 bool bad_ = false;
304
305public:
306 void
308
309 [[nodiscard]] bool
310 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
311};
312
319{
322 bool pseudoAccount_ = false;
324
325public:
326 void
328
329 [[nodiscard]] bool
330 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
331};
332
343{
349
354
355public:
356 void
358
359 [[nodiscard]] bool
360 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
361};
362
383{
385
386 // Entries newly linked into owner directories, keyed by the directory
387 // owner. Whether an owner is a pseudo-account is decided in finalize,
388 // where the view is available.
390
391public:
392 void
394
395 bool
396 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&);
397};
398
407{
408 // Pair is <before, after>.
410
411public:
412 void
414
415 bool
416 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&);
417};
418
424{
426
427public:
428 void
430
431 [[nodiscard]] bool
432 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
433};
434
435/*
436 * Verify that when an object with an associated pseudo-account is deleted,
437 * its pseudo-account is also deleted.
438 *
439 * The reverse (pseudo-account deleted → object deleted) is enforced by
440 * AccountRootsDeletedClean via getPseudoAccountFields().
441 */
443{
444public:
445 void
447
448 [[nodiscard]] bool
449 finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&) const;
450
451private:
453};
454// additional invariant checks can be declared above and then added to this
455// tuple
476 ValidAMM,
480 ValidLoan,
490
499inline InvariantChecks
501{
502 return InvariantChecks{};
503}
504
505} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
Invariant: a deleted account must not have any objects left.
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
void visitEntry(bool, SLE::ConstRef, SLE::ConstRef)
std::vector< std::pair< SLE::const_pointer, SLE::const_pointer > > accountsDeleted_
Invariant: we cannot remove an account ledger entry.
void visitEntry(bool, SLE::ConstRef, SLE::ConstRef)
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &) const
bool finalize(STTx const &tx, TER const tec, XRPAmount const fee, ReadView const &view, beast::Journal const &j)
called after all ledger entries have been visited to determine the final status of the check.
void visitEntry(bool isDelete, SLE::ConstRef before, SLE::ConstRef after)
called for each ledger entry in the current transaction.
Invariant: corresponding modified ledger entries should match in type and added entries should be a v...
void visitEntry(bool, SLE::ConstRef, SLE::ConstRef)
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &) const
Invariant: Validates counts of NFTokens after all transaction types.
Invariant: offers should be for non-negative amounts and must not be XRP to XRP.
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &) const
void visitEntry(bool, SLE::ConstRef, SLE::ConstRef)
Invariant: Trust lines with deep freeze flag are not allowed if normal freeze flag is not set.
void visitEntry(bool, SLE::ConstRef, SLE::ConstRef)
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &) const
Invariants: Some fields are unmodifiable.
std::set< std::pair< SLE::const_pointer, SLE::const_pointer > > changedEntries_
void visitEntry(bool, SLE::ConstRef, SLE::ConstRef)
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
Invariant: Trust lines using XRP are not allowed.
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &) const
void visitEntry(bool, SLE::ConstRef, SLE::ConstRef)
Invariant: an escrow entry must take a value between 0 and kInitialXRP drops exclusive.
void visitEntry(bool, SLE::ConstRef, SLE::ConstRef)
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &) const
std::vector< SLE::const_pointer > deletedObjSles_
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &) const
void visitEntry(bool, SLE::ConstRef, SLE::ConstRef)
A view into a ledger.
Definition ReadView.h:41
std::shared_ptr< STLedgerEntry const > const & ConstRef
std::shared_ptr< STLedgerEntry const > const_pointer
Invariant: Sponsoring account relationships tracked consistently.
Invariant: Sponsored owner counts are balanced.
Invariant: We should never charge a transaction a negative fee or a fee that is larger than what the ...
void visitEntry(bool, SLE::ConstRef, SLE::ConstRef)
static bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
Invariant: frozen trust line balance change is not allowed.
Verify that MPT/XRP STAmounts are canonical in any ledger entries left after the transaction applies.
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &) const
std::vector< SLE::const_pointer > afterEntries_
void visitEntry(bool, SLE::ConstRef, SLE::ConstRef)
Invariant: Token holder's trustline/MPT balance cannot be invalid after Clawback.
std::uint32_t mptokensChanged_
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &) const
std::uint32_t trustlinesChanged_
void visitEntry(bool, SLE::ConstRef, SLE::ConstRef)
Invariants: Confidential MPToken consistency.
Invariants: Loan brokers are internally consistent.
Invariants: Loans are internally consistent.
Verify public MPT amount and outstanding amount accounting.
Invariant: Validates several invariants for NFToken pages.
Invariant: a new account root must be the consequence of a payment, must have the right starting sequ...
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &) const
void visitEntry(bool, SLE::ConstRef, SLE::ConstRef)
Invariants: Permissioned Domains must have some rules and AcceptedCredentials must have length betwee...
Invariants: Pseudo-accounts have valid and consistent properties.
void visitEntry(bool, SLE::ConstRef, SLE::ConstRef)
std::vector< std::string > errors_
std::map< AccountID, std::vector< uint256 > > ownerDirAdditions_
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
Invariants for TransactionProposal ledger entries.
Invariants: Vault object and MPTokenIssuance for vault shares.
Invariant: An account XRP balance must be in XRP and take a value between 0 and kInitialXRP drops,...
void visitEntry(bool, SLE::ConstRef, SLE::ConstRef)
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &) const
Invariant: A transaction must not create XRP and should only destroy the XRP fee.
boost::multiprecision::int128_t drops_
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &) const
void visitEntry(bool, SLE::ConstRef, SLE::ConstRef)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
InvariantChecks getInvariantChecks()
get a tuple of all invariant checks
std::tuple< TransactionFeeCheck, AccountRootsNotDeleted, AccountRootsDeletedClean, LedgerEntryTypesMatch, XRPBalanceChecks, XRPNotCreated, NoXRPTrustLines, NoDeepFreezeTrustLinesWithoutFreeze, TransfersNotFrozen, NoBadOffers, NoZeroEscrow, ValidNewAccountRoot, ValidNFTokenPage, NFTokenCountTracking, ValidClawback, ValidMPTIssuance, ValidPermissionedDomain, ValidPermissionedDEX, ValidBookDirectory, ValidAMM, NoModifiedUnmodifiableFields, ValidPseudoAccounts, ValidLoanBroker, ValidLoan, ValidVault, ValidConfidentialMPToken, ValidMPTBalanceChanges, ValidAmounts, ValidMPTTransfer, ObjectHasPseudoAccount, ValidTransactionProposal, SponsorshipOwnerCountsMatch, SponsorshipAccountCountMatchesField > InvariantChecks
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
Definition View.cpp:668
TERSubset< CanCvtToTER > TER
Definition TER.h:657