1#include <xrpl/tx/transactors/token/ConfidentialMPTMirrorUpdate.h>
3#include <xrpl/basics/Slice.h>
4#include <xrpl/beast/utility/Journal.h>
5#include <xrpl/beast/utility/instrumentation.h>
6#include <xrpl/core/ServiceRegistry.h>
7#include <xrpl/ledger/ReadView.h>
8#include <xrpl/protocol/ConfidentialTransfer.h>
9#include <xrpl/protocol/Feature.h>
10#include <xrpl/protocol/Indexes.h>
11#include <xrpl/protocol/LedgerFormats.h>
12#include <xrpl/protocol/MPTIssue.h>
13#include <xrpl/protocol/Protocol.h>
14#include <xrpl/protocol/SField.h>
15#include <xrpl/protocol/STTx.h>
16#include <xrpl/protocol/TER.h>
17#include <xrpl/protocol/XRPAmount.h>
18#include <xrpl/tx/Transactor.h>
32 auto const account = ctx.
tx[sfAccount];
34 auto const holder = ctx.
tx[~sfHolder];
35 bool const hasHolder = holder.has_value();
43 if (account != issuer)
46 if (account == *holder)
52 if (account == issuer)
58 bool const hasAuditorAmount = ctx.
tx.
isFieldPresent(sfAuditorEncryptedAmount);
59 if (!hasIssuerAmount && !hasAuditorAmount)
67 if (hasAuditorAmount &&
95 auto const account = ctx.
tx[sfAccount];
101 auto const mptIssuanceID = ctx.
tx[sfMPTokenIssuanceID];
107 if (!sleIssuance->isFlag(lsfMPTCanHoldConfidentialBalance) ||
108 !sleIssuance->isFieldPresent(sfIssuerEncryptionKey))
113 auto const holder = ctx.
tx[~sfHolder];
114 bool const hasHolder = holder.has_value();
115 auto const issuer = sleIssuance->
getAccountID(sfIssuer);
116 if (hasHolder ? (issuer != account) : (issuer == account))
120 "xrpl::ConfidentialMPTMirrorUpdate::preclaim : invalid issuer holder combination");
126 auto const holderID = hasHolder ? *holder : account;
139 if (!sleMptoken->isFieldPresent(sfIssuerEncryptedBalance))
142 bool const hasIssuerAmount = ctx.
tx.
isFieldPresent(sfIssuerEncryptedAmount);
143 bool const hasAuditorAmount = ctx.
tx.
isFieldPresent(sfAuditorEncryptedAmount);
147 if (hasAuditorAmount && !sleIssuance->isFieldPresent(sfAuditorEncryptionKey))
154 if (hasAuditorAmount)
175 if (!sleMptoken->isFieldPresent(sfHolderEncryptionKey) ||
176 !sleMptoken->isFieldPresent(sfConfidentialBalanceSpending))
180 "xrpl::ConfidentialMPTMirrorUpdate::preclaim : an issuer mirror implies a holder "
181 "key and spending balance");
187 (*sleMptoken)[sfHolderEncryptionKey], holderID, mptIssuanceID);
188 if (!expectedZeroInbox)
192 "xrpl::ConfidentialMPTMirrorUpdate::preclaim : canonical zero encryption cannot "
193 "fail for an already-valid holder public key");
198 bool const inboxIsCanonicalZero = sleMptoken->isFieldPresent(sfConfidentialBalanceInbox) &&
199 Slice((*sleMptoken)[sfConfidentialBalanceInbox]) ==
Slice(*expectedZeroInbox);
200 if (!inboxIsCanonicalZero)
210 auto const mptIssuanceID =
ctx_.tx[sfMPTokenIssuanceID];
217 "xrpl::ConfidentialMPTMirrorUpdate::doApply : preclaim already validated the "
224 auto const holder =
ctx_.tx[~sfHolder];
225 auto const holderID = holder.value_or(
accountID_);
232 "xrpl::ConfidentialMPTMirrorUpdate::doApply : preclaim already validated the "
241 if (
ctx_.tx.isFieldPresent(sfIssuerEncryptedAmount))
243 (*sleMptoken)[sfIssuerEncryptedBalance] =
ctx_.tx[sfIssuerEncryptedAmount];
247 if (
ctx_.tx.isFieldPresent(sfAuditorEncryptedAmount))
249 (*sleMptoken)[sfAuditorEncryptedBalance] =
ctx_.tx[sfAuditorEncryptedAmount];
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 bool checkExtraFeatures(PreflightContext const &ctx)
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.
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, SLE::ConstRef before, SLE::ConstRef after) override
Inspect a single ledger entry modified by this transaction.
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.
std::shared_ptr< STLedgerEntry const > const & ConstRef
bool isFieldPresent(SField const &field) const
AccountID getAccountID(SField const &field) const
An immutable linear range of bytes.
static XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
AccountID const accountID_
Keylet mptoken(MPTID const &issuanceID, AccountID const &holder) noexcept
Keylet account(AccountID const &id) noexcept
AccountID root.
Keylet mptokenIssuance(MPTID const &issuanceID) noexcept
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.
bool isIssuerMirrorCurrent(SLE const &issuance, SLE const &mptoken)
Checks whether a holder's issuer mirror is encrypted under the issuance's currently registered issuer...
constexpr std::uint32_t kConfidentialFeeMultiplier
Extra base fee multiplier charged to confidential MPT transactions.
bool isAuditorMirrorCurrent(SLE const &issuance, SLE const &mptoken)
Checks whether a holder's auditor mirror is encrypted under the issuance's currently registered audit...
constexpr std::size_t kEcGamalEncryptedTotalLength
EC ElGamal ciphertext length: two compressed EC points concatenated.
bool isValidCiphertext(Slice const &buffer)
Verifies that a buffer contains two valid, parsable EC public keys.
TERSubset< CanCvtToNotTEC > NotTEC
void setAuditorMirrorEpoch(SLE const &issuance, SLE &mptoken)
Set the holder's auditor mirror epoch to match the issuance's current auditor key epoch.
void setIssuerMirrorEpoch(SLE const &issuance, SLE &mptoken)
Set the holder's issuer mirror epoch to match the issuance's current issuer key epoch.
constexpr std::size_t kEcEqualityProofLength
Length of compact equality proof.
TERSubset< CanCvtToTER > TER
State information when determining if a tx is likely to claim a fee.
State information when preflighting a tx.