Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
10 changes: 7 additions & 3 deletions include/xrpl/ledger/helpers/CredentialHelpers.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#pragma once

#include <xrpl/basics/Slice.h>
#include <xrpl/basics/base_uint.h>
#include <xrpl/basics/chrono.h>
#include <xrpl/beast/utility/Journal.h>
#include <xrpl/ledger/ApplyView.h>
#include <xrpl/ledger/ReadView.h>
#include <xrpl/ledger/entries/PermissionedDomainEntry.h>
#include <xrpl/protocol/AccountID.h>
#include <xrpl/protocol/Rules.h>
#include <xrpl/protocol/STArray.h>
Expand Down Expand Up @@ -48,7 +48,7 @@ valid(STTx const& tx, ReadView const& view, AccountID const& src, beast::Journal
// in preclaim and it returns tecEXPIRED, you should call verifyValidDomain in
// doApply. This will ensure that expired credentials are deleted.
TER
validDomain(ReadView const& view, UInt256 domainID, AccountID const& subject);
validDomain(PermissionedDomainEntryR const& domain, AccountID const& subject);

// This function is only called when we are about to return tecNO_PERMISSION
// because all the checks for the DepositPreauth authorization failed.
Expand All @@ -69,7 +69,11 @@ checkArray(STArray const& credentials, unsigned maxSize, beast::Journal j);
// Check expired credentials and for credentials matching DomainID of the ledger
// object
TER
verifyValidDomain(ApplyView& view, AccountID const& account, UInt256 domainID, beast::Journal j);
verifyValidDomain(
ApplyView& view,
AccountID const& account,
PermissionedDomainEntryR const& domain,
beast::Journal j);
Comment on lines +72 to +76

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something we should address @mvadari ?


/**
* @brief Check whether src is authorized to deposit to dst.
Expand Down
20 changes: 12 additions & 8 deletions src/libxrpl/ledger/helpers/CredentialHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <xrpl/beast/utility/Journal.h>
#include <xrpl/ledger/ApplyView.h>
#include <xrpl/ledger/ReadView.h>
#include <xrpl/ledger/entries/PermissionedDomainEntry.h>
#include <xrpl/ledger/helpers/AccountRootHelpers.h>
#include <xrpl/protocol/AccountID.h>
#include <xrpl/protocol/Feature.h>
Expand Down Expand Up @@ -205,16 +206,16 @@ valid(STTx const& tx, ReadView const& view, AccountID const& src, beast::Journal
}

TER
validDomain(ReadView const& view, UInt256 domainID, AccountID const& subject)
validDomain(PermissionedDomainEntryR const& domain, AccountID const& subject)
{
// Note, permissioned domain objects can be deleted at any time
auto const slePD = view.read(keylet::permissionedDomain(domainID));
if (!slePD)
if (!domain)
return tecOBJECT_NOT_FOUND;

auto const& view = domain.readView();
auto const closeTime = view.header().parentCloseTime;
bool foundExpired = false;
for (auto const& h : slePD->getFieldArray(sfAcceptedCredentials))
for (auto const& h : domain->getFieldArray(sfAcceptedCredentials))
{
auto const issuer = h.getAccountID(sfIssuer);
auto const type = h.getFieldVL(sfCredentialType);
Expand Down Expand Up @@ -332,16 +333,19 @@ checkArray(STArray const& credentials, unsigned maxSize, beast::Journal j)
} // namespace credentials

TER
verifyValidDomain(ApplyView& view, AccountID const& account, UInt256 domainID, beast::Journal j)
verifyValidDomain(
ApplyView& view,
AccountID const& account,
PermissionedDomainEntryR const& domain,
beast::Journal j)
{
auto const slePD = view.read(keylet::permissionedDomain(domainID));
if (!slePD)
if (!domain)
return tecOBJECT_NOT_FOUND;

// Collect all matching credentials on a side, so we can remove expired ones
// We may finish the loop with this collection empty, it's fine.
STVector256 credentials;
for (auto const& h : slePD->getFieldArray(sfAcceptedCredentials))
for (auto const& h : domain->getFieldArray(sfAcceptedCredentials))
{
auto const issuer = h.getAccountID(sfIssuer);
auto const type = h.getFieldVL(sfCredentialType);
Expand Down
7 changes: 5 additions & 2 deletions src/libxrpl/ledger/helpers/MPTokenHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <xrpl/ledger/ApplyView.h>
#include <xrpl/ledger/ReadView.h>
#include <xrpl/ledger/View.h>
#include <xrpl/ledger/entries/PermissionedDomainEntry.h>
#include <xrpl/ledger/helpers/AccountRootHelpers.h>
#include <xrpl/ledger/helpers/CredentialHelpers.h>
#include <xrpl/ledger/helpers/DirectoryHelpers.h>
Expand Down Expand Up @@ -452,7 +453,8 @@ requireAuth(
sleIssuance->isFlag(lsfMPTRequireAuth),
"xrpl::requireAuth : issuance requires authorization");
// ter = tefINTERNAL | tecOBJECT_NOT_FOUND | tecNO_AUTH | tecEXPIRED
auto const ter = credentials::validDomain(view, *maybeDomainID, account);
PermissionedDomainEntryR const domain(*maybeDomainID, view);
auto const ter = credentials::validDomain(domain, account);
if (isTesSuccess(ter))
{
return ter; // Note: sleToken might be null
Expand Down Expand Up @@ -505,7 +507,8 @@ enforceMPTokenAuthorization(
if (!maybeDomainID.has_value())
return false; // LCOV_EXCL_LINE

auto const ter = verifyValidDomain(ctx.view, account, *maybeDomainID, j);
PermissionedDomainEntryR const domain(*maybeDomainID, ctx.view);
auto const ter = verifyValidDomain(ctx.view, account, domain, j);
if (isTesSuccess(ter))
return true;
if (ter == tecEXPIRED)
Expand Down
9 changes: 5 additions & 4 deletions src/libxrpl/ledger/helpers/PermissionedDEXHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <xrpl/beast/utility/Zero.h>
#include <xrpl/beast/utility/instrumentation.h>
#include <xrpl/ledger/ReadView.h>
#include <xrpl/ledger/entries/PermissionedDomainEntry.h>
#include <xrpl/ledger/helpers/CredentialHelpers.h>
#include <xrpl/protocol/AccountID.h>
#include <xrpl/protocol/Feature.h>
Expand All @@ -31,15 +32,15 @@ accountInDomain(ReadView const& view, AccountID const& account, Domain const& do
// LCOV_EXCL_STOP
}

auto const sleDomain = view.read(keylet::permissionedDomain(domainID));
if (!sleDomain)
PermissionedDomainEntryR const domain(domainID, view);
if (!domain)
return false;

// domain owner is in the domain
if (sleDomain->getAccountID(sfOwner) == account)
if (domain->getAccountID(sfOwner) == account)
return true;

auto const& credentials = sleDomain->getFieldArray(sfAcceptedCredentials);
auto const& credentials = domain->getFieldArray(sfAcceptedCredentials);

bool const inDomain = std::ranges::any_of(credentials, [&](auto const& credential) {
auto const sleCred = view.read(
Expand Down
4 changes: 3 additions & 1 deletion src/libxrpl/ledger/helpers/VaultHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <xrpl/beast/utility/instrumentation.h>
#include <xrpl/ledger/ReadView.h>
#include <xrpl/ledger/View.h>
#include <xrpl/ledger/entries/PermissionedDomainEntry.h>
#include <xrpl/ledger/helpers/CredentialHelpers.h>
#include <xrpl/protocol/AccountID.h>
#include <xrpl/protocol/Indexes.h>
Expand Down Expand Up @@ -320,7 +321,8 @@ checkVaultDomain(
if (!maybeDomainID)
return tecNO_AUTH;

auto const err = credentials::validDomain(view, *maybeDomainID, subject);
PermissionedDomainEntryR const domain(*maybeDomainID, view);
auto const err = credentials::validDomain(domain, subject);
if (err == tecEXPIRED && suppressExpired == SuppressExpired::Yes)
return tesSUCCESS;

Expand Down
9 changes: 5 additions & 4 deletions src/libxrpl/tx/transactors/dex/OfferCreate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <xrpl/ledger/PaymentSandbox.h>
#include <xrpl/ledger/Sandbox.h>
#include <xrpl/ledger/View.h>
#include <xrpl/ledger/entries/PermissionedDomainEntry.h>
#include <xrpl/ledger/helpers/AccountRootHelpers.h>
#include <xrpl/ledger/helpers/CredentialHelpers.h>
#include <xrpl/ledger/helpers/DirectoryHelpers.h>
Expand Down Expand Up @@ -245,7 +246,7 @@ OfferCreate::preclaim(PreclaimContext const& ctx)
if (ctx.view.rules().enabled(fixCleanup3_4_0))
{
auto const domainID = ctx.tx[sfDomainID];
auto const sleDomain = ctx.view.read(keylet::permissionedDomain(domainID));
PermissionedDomainEntryR const sleDomain(domainID, ctx.view);
if (!sleDomain)
return tecNO_PERMISSION;

Expand All @@ -257,7 +258,7 @@ OfferCreate::preclaim(PreclaimContext const& ctx)
{
// validDomain returns tecNO_AUTH when no matching credential is
// found. Map it to tecNO_PERMISSION to preserve existing behavior.
if (auto const err = credentials::validDomain(ctx.view, domainID, id);
if (auto const err = credentials::validDomain(sleDomain, id);
!isTesSuccess(err) && err != tecEXPIRED)
return tecNO_PERMISSION;
}
Expand Down Expand Up @@ -1032,13 +1033,13 @@ OfferCreate::doApply()
if (ctx_.tx.isFieldPresent(sfDomainID) && ctx_.view().rules().enabled(fixCleanup3_4_0))
{
auto const domainID = ctx_.tx[sfDomainID];
auto const sleDomain = ctx_.view().read(keylet::permissionedDomain(domainID));
PermissionedDomainEntryR const sleDomain(domainID, ctx_.view());
if (!sleDomain)
return tecINTERNAL; // LCOV_EXCL_LINE

if (sleDomain->getAccountID(sfOwner) != accountID_)
{
if (auto const err = verifyValidDomain(ctx_.view(), accountID_, domainID, j_);
if (auto const err = verifyValidDomain(ctx_.view(), accountID_, sleDomain, j_);
!isTesSuccess(err))
return err;
}
Expand Down
4 changes: 3 additions & 1 deletion src/libxrpl/tx/transactors/lending/LoanSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <xrpl/core/ServiceRegistry.h>
#include <xrpl/ledger/ApplyView.h>
#include <xrpl/ledger/View.h>
#include <xrpl/ledger/entries/PermissionedDomainEntry.h>
#include <xrpl/ledger/helpers/AccountRootHelpers.h>
#include <xrpl/ledger/helpers/CredentialHelpers.h>
#include <xrpl/ledger/helpers/LendingHelpers.h>
Expand Down Expand Up @@ -477,7 +478,8 @@ LoanSet::doApply()
JLOG(j_.warn()) << "Private LoanBroker must have a DomainID.";
return tecNO_AUTH;
}
if (auto const ter = verifyValidDomain(view, borrower, *domainID, j_); !isTesSuccess(ter))
PermissionedDomainEntryR const domain(*domainID, view);
if (auto const ter = verifyValidDomain(view, borrower, domain, j_); !isTesSuccess(ter))
{
if (ter == tecNO_PERMISSION)
{
Expand Down
9 changes: 5 additions & 4 deletions src/libxrpl/tx/transactors/payment/Payment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <xrpl/core/ServiceRegistry.h>
#include <xrpl/ledger/PaymentSandbox.h>
#include <xrpl/ledger/ReadView.h>
#include <xrpl/ledger/entries/PermissionedDomainEntry.h>
#include <xrpl/ledger/helpers/AccountRootHelpers.h>
#include <xrpl/ledger/helpers/CredentialHelpers.h>
#include <xrpl/ledger/helpers/MPTokenHelpers.h>
Expand Down Expand Up @@ -481,7 +482,7 @@ Payment::preclaim(PreclaimContext const& ctx)
if (ctx.view.rules().enabled(fixCleanup3_4_0))
{
auto const domainID = ctx.tx[sfDomainID];
auto const sleDomain = ctx.view.read(keylet::permissionedDomain(domainID));
PermissionedDomainEntryR const sleDomain(domainID, ctx.view);
if (!sleDomain)
return tecNO_PERMISSION;

Expand All @@ -493,7 +494,7 @@ Payment::preclaim(PreclaimContext const& ctx)
return tesSUCCESS;
// validDomain returns tecNO_AUTH when no matching credential is
// found. Map it to tecNO_PERMISSION to preserve existing behavior.
if (auto const err = credentials::validDomain(ctx.view, domainID, acct);
if (auto const err = credentials::validDomain(sleDomain, acct);
!isTesSuccess(err) && err != tecEXPIRED)
return tecNO_PERMISSION;
return tesSUCCESS;
Expand Down Expand Up @@ -526,14 +527,14 @@ Payment::doApply()
if (ctx_.tx.isFieldPresent(sfDomainID) && ctx_.view().rules().enabled(fixCleanup3_4_0))
{
auto const domainID = ctx_.tx[sfDomainID];
auto const sleDomain = ctx_.view().read(keylet::permissionedDomain(domainID));
PermissionedDomainEntryR const sleDomain(domainID, ctx_.view());
if (!sleDomain)
return tecINTERNAL; // LCOV_EXCL_LINE

auto const cleanupFor = [&](AccountID const& acct) -> TER {
if (sleDomain->getAccountID(sfOwner) == acct)
return tesSUCCESS;
return verifyValidDomain(ctx_.view(), acct, domainID, j_);
return verifyValidDomain(ctx_.view(), acct, sleDomain, j_);
};

auto const destination = ctx_.tx[sfDestination];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <xrpl/basics/Log.h>
#include <xrpl/beast/utility/Zero.h>
#include <xrpl/beast/utility/instrumentation.h>
#include <xrpl/ledger/ReadView.h>
#include <xrpl/ledger/entries/PermissionedDomainEntry.h>
#include <xrpl/ledger/helpers/AccountRootHelpers.h>
#include <xrpl/protocol/Indexes.h>
#include <xrpl/protocol/SField.h>
Expand All @@ -28,7 +30,7 @@ TER
PermissionedDomainDelete::preclaim(PreclaimContext const& ctx)
{
auto const domain = ctx.tx.getFieldH256(sfDomainID);
auto const sleDomain = ctx.view.read(keylet::permissionedDomain(domain));
PermissionedDomainEntryR const sleDomain(domain, ctx.view);

if (!sleDomain)
return tecNO_ENTRY;
Expand All @@ -52,10 +54,10 @@ PermissionedDomainDelete::doApply()
ctx_.tx.isFieldPresent(sfDomainID),
"xrpl::PermissionedDomainDelete::doApply : required field present");

auto const slePd = view().peek(keylet::permissionedDomain(ctx_.tx.at(sfDomainID)));
PermissionedDomainEntryW slePd(ctx_.tx.at(sfDomainID), view());
auto const page = (*slePd)[sfOwnerNode];

if (!view().dirRemove(keylet::ownerDir(accountID_), page, slePd->key(), true))
if (!view().dirRemove(keylet::ownerDir(accountID_), page, slePd.key(), true))
{
// LCOV_EXCL_START
JLOG(j_.fatal()) << "Unable to delete permissioned domain directory entry.";
Expand All @@ -67,8 +69,8 @@ PermissionedDomainDelete::doApply()
XRPL_ASSERT(
ownerSle && ownerSle->getFieldU32(sfOwnerCount) > 0,
"xrpl::PermissionedDomainDelete::doApply : nonzero owner count");
decreaseOwnerCountForObject(view(), ownerSle, slePd, 1, ctx_.journal);
view().erase(slePd);
decreaseOwnerCountForObject(view(), ownerSle, slePd.mutableRawSle(), 1, ctx_.journal);
slePd.erase();

return tesSUCCESS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

#include <xrpl/beast/utility/Zero.h>
#include <xrpl/core/ServiceRegistry.h>
#include <xrpl/ledger/entries/PermissionedDomainEntry.h>
#include <xrpl/ledger/helpers/AccountRootHelpers.h>
#include <xrpl/ledger/helpers/CredentialHelpers.h>
#include <xrpl/ledger/helpers/DirectoryHelpers.h>
#include <xrpl/protocol/Feature.h>
#include <xrpl/protocol/Indexes.h>
#include <xrpl/protocol/Keylet.h>
#include <xrpl/protocol/Protocol.h>
#include <xrpl/protocol/SField.h>
#include <xrpl/protocol/STLedgerEntry.h>
Expand All @@ -18,7 +18,6 @@
#include <xrpl/protocol/XRPAmount.h>
#include <xrpl/tx/Transactor.h>

#include <memory>
#include <utility>

namespace xrpl {
Expand Down Expand Up @@ -63,8 +62,7 @@ PermissionedDomainSet::preclaim(PreclaimContext const& ctx)

if (ctx.tx.isFieldPresent(sfDomainID))
{
auto const sleDomain =
ctx.view.read(keylet::permissionedDomain(ctx.tx.getFieldH256(sfDomainID)));
PermissionedDomainEntryR const sleDomain(ctx.tx.getFieldH256(sfDomainID), ctx.view);
if (!sleDomain)
return tecNO_ENTRY;
if (sleDomain->getAccountID(sfOwner) != account)
Expand Down Expand Up @@ -98,12 +96,11 @@ PermissionedDomainSet::doApply()
if (ctx_.tx.isFieldPresent(sfDomainID))
{
// Modify existing permissioned domain.
auto const slePd =
view().peek(keylet::permissionedDomain(ctx_.tx.getFieldH256(sfDomainID)));
PermissionedDomainEntryW slePd(ctx_.tx.getFieldH256(sfDomainID), view());
if (!slePd)
return tefINTERNAL; // LCOV_EXCL_LINE
slePd->peekFieldArray(sfAcceptedCredentials) = std::move(sortedLE);
view().update(slePd);
slePd.update();
}
else
{
Expand All @@ -118,21 +115,21 @@ PermissionedDomainSet::doApply()
bool const fixEnabled = view().rules().enabled(fixCleanup3_1_3);
auto const seq = fixEnabled ? ctx_.tx.getSeqProxy()
: SeqProxy::rawSequence(ctx_.tx.getFieldU32(sfSequence));
Keylet const pdKeylet = keylet::permissionedDomain(accountID_, seq);
auto const slePd = std::make_shared<SLE>(pdKeylet);
PermissionedDomainEntryW slePd(accountID_, seq, view());
slePd.newSLE();

slePd->setAccountID(sfOwner, accountID_);
slePd->setFieldU32(sfSequence, seq.value());
slePd->peekFieldArray(sfAcceptedCredentials) = std::move(sortedLE);
auto const page =
view().dirInsert(keylet::ownerDir(accountID_), pdKeylet, describeOwnerDir(accountID_));
auto const page = view().dirInsert(
keylet::ownerDir(accountID_), slePd.keylet(), describeOwnerDir(accountID_));
if (!page)
return tecDIR_FULL; // LCOV_EXCL_LINE

slePd->setFieldU64(sfOwnerNode, *page);
// If we succeeded, the new entry counts against the creator's reserve.
increaseOwnerCount(view(), ownerSle, {}, 1, ctx_.journal);
view().insert(slePd);
slePd.insert();
}

return tesSUCCESS;
Expand Down
3 changes: 2 additions & 1 deletion src/libxrpl/tx/transactors/token/MPTokenIssuanceSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <xrpl/beast/utility/instrumentation.h>
#include <xrpl/core/ServiceRegistry.h>
#include <xrpl/ledger/ReadView.h>
#include <xrpl/ledger/entries/PermissionedDomainEntry.h>
#include <xrpl/protocol/ConfidentialTransfer.h>
#include <xrpl/protocol/Feature.h>
#include <xrpl/protocol/Indexes.h>
Expand Down Expand Up @@ -183,7 +184,7 @@ MPTokenIssuanceSet::preclaim(PreclaimContext const& ctx)

if (*domain != beast::kZero)
{
auto const sleDomain = ctx.view.read(keylet::permissionedDomain(*domain));
PermissionedDomainEntryR const sleDomain(*domain, ctx.view);
if (!sleDomain)
return tecOBJECT_NOT_FOUND;
}
Expand Down
Loading
Loading