1#include <xrpl/tx/transactors/token/ConfidentialMPTHolderKeyUpdate.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/TER.h>
16#include <xrpl/protocol/TxFlags.h>
17#include <xrpl/protocol/XRPAmount.h>
18#include <xrpl/tx/Transactor.h>
35 return tfConfidentialMPTHolderKeyUpdateMask;
41 bool const rotation = ctx.
tx.
isFlag(tfHolderKeyRotation);
42 bool const recovery = ctx.
tx.
isFlag(tfHolderKeyRecovery);
43 bool const cancel = ctx.
tx.
isFlag(tfCancelRecovery);
46 static constexpr auto modeFlags = tfHolderKeyRotation | tfHolderKeyRecovery | tfCancelRecovery;
55 bool const hasSpending = ctx.
tx.
isFieldPresent(sfConfidentialBalanceSpending);
63 if (hasHolderKey || hasSpending || hasInbox || hasProof)
70 if (!hasHolderKey || !hasProof)
75 if (rotation && (!hasSpending || !hasInbox))
78 if (recovery && (hasSpending || hasInbox))
109 auto const account = ctx.
tx[sfAccount];
110 auto const mptIssuanceID = ctx.
tx[sfMPTokenIssuanceID];
116 if (!sleIssuance->isFlag(lsfMPTCanHoldConfidentialBalance))
123 if (!sleMptoken->isFieldPresent(sfHolderEncryptionKey) ||
124 !sleMptoken->isFieldPresent(sfConfidentialBalanceSpending) ||
125 !sleMptoken->isFieldPresent(sfConfidentialBalanceInbox))
130 if (ctx.
tx.
isFlag(tfCancelRecovery))
133 if (!sleMptoken->isFieldPresent(sfRecoveryKey))
139 if (ctx.
tx[sfHolderEncryptionKey] == (*sleMptoken)[sfHolderEncryptionKey])
143 if (ctx.
tx.
isFlag(tfHolderKeyRecovery) && sleMptoken->isFieldPresent(sfRecoveryKey))
152 auto const mptIssuanceID =
ctx_.tx[sfMPTokenIssuanceID];
158 "xrpl::ConfidentialMPTHolderKeyUpdate::doApply : preclaim already validated the "
164 if (
ctx_.tx.isFlag(tfCancelRecovery))
168 sleMptoken->makeFieldAbsent(sfRecoveryKey);
173 auto const newPubKey =
ctx_.tx[sfHolderEncryptionKey];
175 if (
ctx_.tx.isFlag(tfHolderKeyRotation))
179 (*sleMptoken)[sfHolderEncryptionKey] = newPubKey;
180 (*sleMptoken)[sfConfidentialBalanceSpending] =
ctx_.tx[sfConfidentialBalanceSpending];
181 (*sleMptoken)[sfConfidentialBalanceInbox] =
ctx_.tx[sfConfidentialBalanceInbox];
182 sleMptoken->makeFieldAbsent(sfRecoveryKey);
185 else if (
ctx_.tx.isFlag(tfHolderKeyRecovery))
190 (*sleMptoken)[sfRecoveryKey] = newPubKey;
195 UNREACHABLE(
"xrpl::ConfidentialMPTHolderKeyUpdate::doApply : invalid mode");
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.
void visitInvariantEntry(bool isDelete, SLE::ConstRef before, SLE::ConstRef after) override
Inspect a single ledger entry modified by this transaction.
static bool checkExtraFeatures(PreflightContext const &ctx)
static std::uint32_t getFlagsMask(PreflightContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
static TER preclaim(PreclaimContext 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 XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
AccountID const & getIssuer() const
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 isFlag(std::uint32_t) const
bool isFieldPresent(SField const &field) const
std::uint32_t getFlags() const
static XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
AccountID const accountID_
Keylet mptoken(MPTID const &issuanceID, AccountID const &holder) noexcept
Keylet mptokenIssuance(MPTID const &issuanceID) noexcept
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
constexpr std::uint32_t kConfidentialFeeMultiplier
Extra base fee multiplier charged to confidential MPT transactions.
bool isValidCompressedECPoint(Slice const &buffer)
Verifies that a buffer contains a valid, parsable compressed EC point.
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
TERSubset< CanCvtToTER > TER
void incrementConfidentialVersion(STObject &mptoken)
Increments the confidential balance version counter on an MPToken.
State information when determining if a tx is likely to claim a fee.
State information when preflighting a tx.