Skip to content

Commit cfd5320

Browse files
committed
WIP: Make requireAuth recursive if the sender is a vault
1 parent 8efc486 commit cfd5320

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/test/app/Vault_test.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,6 +1768,18 @@ class Vault_test : public beast::unit_test::suite
17681768
.amount = asset(100)});
17691769
env(tx, ter(tecNO_AUTH));
17701770

1771+
// Withdrawal to other (authorized) accounts doesn't work.
1772+
// Issuer would have to VaultClawback
1773+
tx[sfDestination] = issuer.human();
1774+
env(tx, ter(tecNO_AUTH));
1775+
tx[sfDestination] = owner.human();
1776+
env(tx, ter(tecNO_AUTH));
1777+
env.close();
1778+
1779+
// Issuer reauthorizes
1780+
mptt.authorize({.account = issuer, .holder = depositor});
1781+
env.close();
1782+
17711783
// Withdrawal to other (authorized) accounts works
17721784
tx[sfDestination] = issuer.human();
17731785
env(tx);
@@ -1776,6 +1788,13 @@ class Vault_test : public beast::unit_test::suite
17761788
env.close();
17771789
}
17781790

1791+
// Re-unauthorize
1792+
mptt.authorize(
1793+
{.account = issuer,
1794+
.holder = depositor,
1795+
.flags = tfMPTUnauthorize});
1796+
env.close();
1797+
17791798
{
17801799
// Cannot deposit some more
17811800
auto tx = vault.deposit(

src/xrpld/ledger/detail/View.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2544,6 +2544,24 @@ requireAuth(
25442544
!isTesSuccess(err))
25452545
return err;
25462546
}
2547+
2548+
// requireAuth is also recursive if the _account_ is a vault
2549+
auto const sleAccount = view.read(keylet::account(account));
2550+
if (!sleAccount)
2551+
return tefINTERNAL; // LCOV_EXCL_LINE
2552+
2553+
if (sleAccount->isFieldPresent(sfVaultID))
2554+
{
2555+
auto const sleVault =
2556+
view.read(keylet::vault(sleAccount->getFieldH256(sfVaultID)));
2557+
if (!sleVault)
2558+
return tefINTERNAL; // LCOV_EXCL_LINE
2559+
auto const ownerAcct = sleVault->getAccountID(sfOwner);
2560+
if (auto const err =
2561+
requireAuth(view, mptIssue, ownerAcct, authType, depth + 1);
2562+
!isTesSuccess(err))
2563+
return err;
2564+
}
25472565
}
25482566

25492567
auto const mptokenID = keylet::mptoken(mptID.key, account);

0 commit comments

Comments
 (0)