Skip to content

Commit b1e091c

Browse files
committed
DomainID authorization check moved to doApply
1 parent df8761d commit b1e091c

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

src/xrpld/app/tx/detail/VaultDeposit.cpp

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,27 @@ VaultDeposit::preclaim(PreclaimContext const& ctx)
7171
if (isFrozen(ctx.view, account, share))
7272
return tecFROZEN;
7373

74-
if (vault->getFlags() == tfVaultPrivate && account != vault->at(sfOwner))
74+
if ((vault->getFlags() & tfVaultPrivate) && account != vault->at(sfOwner))
7575
{
76+
// The authorization check below is based on DomainID stored in
77+
// MPTokenIssuance. Had the vault shares been a regular MPToken, we
78+
// would allow authorization granted by the issuer explicitly, but Vault
79+
// does not have an MPT issuer (instead it uses pseudo-account, which is
80+
// blackholed and cannot create any transactions).
81+
//
82+
// We also need to do similar check inside doApply(), in order to remove
83+
// expired credentials and/or adjust authorization flag on tokens owned
84+
// by DomainID (i.e. with lsfMPTDomainCheck flag). This is why we
85+
// suppress authorization errors if domainId is set.
86+
uint256 domainId = beast::zero;
7687
auto const err = requireAuth(
77-
ctx.view, MPTIssue(vault->at(sfMPTokenIssuanceID)), account);
78-
return err;
88+
ctx.view,
89+
MPTIssue(vault->at(sfMPTokenIssuanceID)),
90+
account,
91+
&domainId);
7992

80-
// The above will perform authorization check based on DomainID stored
81-
// in MPTokenIssuance. Had this been a regular MPToken, it would also
82-
// allow use of authorization granted by the issuer explicitly, but
83-
// Vault does not have an MPT issuer (instead it uses pseudo-account).
84-
//
85-
// If we passed the above check then we also need to do similar check
86-
// inside doApply(), in order to check for expired credentials.
93+
if (domainId == beast::zero)
94+
return err;
8795
}
8896

8997
return tesSUCCESS;
@@ -120,7 +128,7 @@ VaultDeposit::doApply()
120128

121129
MPTIssue const mptIssue(mptIssuanceID);
122130
// Note, vault owner is always authorized
123-
if (account_ != vault->at(sfOwner) && (vault->getFlags() & tfVaultPrivate))
131+
if ((vault->getFlags() & tfVaultPrivate) && account_ != vault->at(sfOwner))
124132
{
125133
if (auto const err = enforceMPTokenAuthorization(
126134
ctx_.view(), mptIssue, account_, mPriorBalance, j_);

src/xrpld/ledger/View.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,8 @@ requireAuth(ReadView const& view, Issue const& issue, AccountID const& account);
654654
requireAuth(
655655
ReadView const& view,
656656
MPTIssue const& mptIssue,
657-
AccountID const& account);
657+
AccountID const& account,
658+
uint256* domainId = nullptr);
658659

659660
/** Check if the account lacks required authorization.
660661
*

src/xrpld/ledger/detail/View.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2183,7 +2183,8 @@ TER
21832183
requireAuth(
21842184
ReadView const& view,
21852185
MPTIssue const& mptIssue,
2186-
AccountID const& account)
2186+
AccountID const& account,
2187+
uint256* domainId)
21872188
{
21882189
auto const mptID = keylet::mptIssuance(mptIssue.getMptID());
21892190
auto const sleIssuance = view.read(mptID);
@@ -2220,7 +2221,12 @@ requireAuth(
22202221
if (auto const err =
22212222
credentials::validDomain(view, *maybeDomainID, account);
22222223
!isTesSuccess(err))
2224+
{
2225+
if (err != tecINVALID_DOMAIN && domainId != nullptr)
2226+
(*domainId) = *maybeDomainID;
2227+
22232228
return err;
2229+
}
22242230

22252231
// We are authorized by permissioned domain.
22262232
return tesSUCCESS;
@@ -2237,7 +2243,7 @@ enforceMPTokenAuthorization(
22372243
auto const mptIssuanceID = mptIssue.getMptID();
22382244
auto const sleIssuance = view.read(keylet::mptIssuance(mptIssuanceID));
22392245
if (!sleIssuance)
2240-
return tefINTERNAL; // Should have called requireAuth earlier
2246+
return tefINTERNAL;
22412247

22422248
XRPL_ASSERT(
22432249
sleIssuance->getFieldU32(sfFlags) & lsfMPTRequireAuth,

0 commit comments

Comments
 (0)