Skip to content

Commit 1502d8b

Browse files
committed
WIP: Make requireAuth recursive if the sender is a vault
1 parent 6f5f460 commit 1502d8b

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
@@ -2548,6 +2548,24 @@ requireAuth(
25482548
!isTesSuccess(err))
25492549
return err;
25502550
}
2551+
2552+
// requireAuth is also recursive if the _account_ is a vault
2553+
auto const sleAccount = view.read(keylet::account(account));
2554+
if (!sleAccount)
2555+
return tefINTERNAL; // LCOV_EXCL_LINE
2556+
2557+
if (sleAccount->isFieldPresent(sfVaultID))
2558+
{
2559+
auto const sleVault =
2560+
view.read(keylet::vault(sleAccount->getFieldH256(sfVaultID)));
2561+
if (!sleVault)
2562+
return tefINTERNAL; // LCOV_EXCL_LINE
2563+
auto const ownerAcct = sleVault->getAccountID(sfOwner);
2564+
if (auto const err =
2565+
requireAuth(view, mptIssue, ownerAcct, authType, depth + 1);
2566+
!isTesSuccess(err))
2567+
return err;
2568+
}
25512569
}
25522570

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

0 commit comments

Comments
 (0)