1#include <xrpl/tx/transactors/token/ConfidentialMPTClawback.h>
3#include <xrpl/beast/utility/Journal.h>
4#include <xrpl/core/ServiceRegistry.h>
5#include <xrpl/ledger/ReadView.h>
6#include <xrpl/protocol/ConfidentialTransfer.h>
7#include <xrpl/protocol/Feature.h>
8#include <xrpl/protocol/Indexes.h>
9#include <xrpl/protocol/LedgerFormats.h>
10#include <xrpl/protocol/Protocol.h>
11#include <xrpl/protocol/SField.h>
12#include <xrpl/protocol/STTx.h>
13#include <xrpl/protocol/TER.h>
14#include <xrpl/protocol/XRPAmount.h>
15#include <xrpl/tx/Transactor.h>
28 auto const account = ctx.
tx[sfAccount];
35 if (account == ctx.
tx[sfHolder])
39 auto const clawAmount = ctx.
tx[sfMPTAmount];
60 auto const account = ctx.
tx[sfAccount];
65 auto const holder = ctx.
tx[sfHolder];
70 auto const mptIssuanceID = ctx.
tx[sfMPTokenIssuanceID];
76 if (sleIssuance->getAccountID(sfIssuer) != account)
80 if (!sleIssuance->isFieldPresent(sfIssuerEncryptionKey))
84 if (!sleIssuance->isFlag(lsfMPTCanClawback))
88 if (!sleIssuance->isFlag(lsfMPTCanHoldConfidentialBalance))
93 if (!sleHolderMPToken)
97 if (!sleHolderMPToken->isFieldPresent(sfIssuerEncryptedBalance))
101 if (!sleHolderMPToken->isFieldPresent(sfHolderEncryptionKey))
106 auto const amount = ctx.
tx[sfMPTAmount];
107 if (amount > (*sleIssuance)[~sfConfidentialOutstandingAmount].value_or(0) ||
108 amount > (*sleIssuance)[sfOutstandingAmount])
111 auto const contextHash =
119 (*sleIssuance)[sfIssuerEncryptionKey],
120 (*sleHolderMPToken)[sfIssuerEncryptedBalance],
127 auto const mptIssuanceID =
ctx_.tx[sfMPTokenIssuanceID];
128 auto const holder =
ctx_.tx[sfHolder];
133 if (!sleIssuance || !sleHolderMPToken)
136 auto const clawAmount =
ctx_.tx[sfMPTAmount];
138 auto const holderPubKey = (*sleHolderMPToken)[sfHolderEncryptionKey];
139 auto const issuerPubKey = (*sleIssuance)[sfIssuerEncryptionKey];
143 if (!encZeroForHolder)
147 if (!encZeroForIssuer)
151 (*sleHolderMPToken)[sfConfidentialBalanceInbox] = *encZeroForHolder;
152 (*sleHolderMPToken)[sfConfidentialBalanceSpending] = *encZeroForHolder;
153 (*sleHolderMPToken)[sfIssuerEncryptedBalance] = std::move(*encZeroForIssuer);
156 if (sleHolderMPToken->isFieldPresent(sfAuditorEncryptedBalance))
160 if (!sleIssuance->isFieldPresent(sfAuditorEncryptionKey))
163 auto const auditorPubKey = (*sleIssuance)[sfAuditorEncryptionKey];
167 if (!encZeroForAuditor)
170 (*sleHolderMPToken)[sfAuditorEncryptedBalance] = std::move(*encZeroForAuditor);
174 auto const oldCOA = (*sleIssuance)[sfConfidentialOutstandingAmount];
175 if (clawAmount > oldCOA)
177 (*sleIssuance)[sfConfidentialOutstandingAmount] = oldCOA - clawAmount;
180 auto const oldOA = (*sleIssuance)[sfOutstandingAmount];
181 if (clawAmount > oldOA)
183 (*sleIssuance)[sfOutstandingAmount] = oldOA - clawAmount;
A generic endpoint for log messages.
virtual SLE::pointer peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
virtual void update(SLE::ref sle)=0
Indicate changes to a peeked SLE.
static TER preclaim(PreclaimContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
static XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
void visitInvariantEntry(bool isDelete, std::shared_ptr< SLE const > const &before, std::shared_ptr< SLE const > const &after) override
bool finalizeInvariants(STTx const &tx, TER result, XRPAmount fee, ReadView const &view, beast::Journal const &j) override
Check transaction-specific post-conditions after all entries have been visited.
AccountID const & getIssuer() const
virtual bool exists(Keylet const &k) const =0
Determine if a state item exists.
virtual SLE::const_pointer read(Keylet const &k) const =0
Return the state item associated with a key.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
SeqProxy getSeqProxy() const
constexpr std::uint32_t value() const
static XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
Keylet mptokenIssuance(std::uint32_t seq, AccountID const &issuer) noexcept
Keylet mptoken(MPTID const &issuanceID, AccountID const &holder) noexcept
Keylet account(AccountID const &id) noexcept
AccountID root.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::optional< Buffer > encryptCanonicalZeroAmount(Slice const &pubKeySlice, AccountID const &account, MPTID const &mptId)
Generates the canonical zero encryption for a specific MPToken.
constexpr std::uint32_t kConfidentialFeeMultiplier
Extra base fee multiplier charged to confidential MPT transactions.
constexpr std::size_t kEcClawbackProofLength
Length of the ZKProof for ConfidentialMPTClawback.
TERSubset< CanCvtToNotTEC > NotTEC
uint256 getClawbackContextHash(AccountID const &account, uint192 const &issuanceID, std::uint32_t sequence, AccountID const &holder)
Generates the context hash for ConfidentialMPTClawback transactions.
TERSubset< CanCvtToTER > TER
void incrementConfidentialVersion(STObject &mptoken)
Increments the confidential balance version counter on an MPToken.
constexpr std::uint64_t kMaxMpTokenAmount
The maximum amount of MPTokenIssuance.
TER verifyClawbackProof(uint64_t const amount, Slice const &proof, Slice const &pubKeySlice, Slice const &ciphertext, uint256 const &contextHash)
Verifies a compact sigma clawback proof.
State information when determining if a tx is likely to claim a fee.
State information when preflighting a tx.