Skip to content

Commit

Permalink
RXI-1397 flag check for credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
oleks-rip committed Jan 17, 2025
1 parent 9e4a7d5 commit 23bda8d
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/xrpl/protocol/Feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ namespace detail {
// Feature.cpp. Because it's only used to reserve storage, and determine how
// large to make the FeatureBitset, it MAY be larger. It MUST NOT be less than
// the actual number of amendments. A LogicError on startup will verify this.
static constexpr std::size_t numFeatures = 85;
static constexpr std::size_t numFeatures = 86;

/** Amendments that this server supports and the default voting behavior.
Whether they are enabled depends on the Rules defined in the validated
Expand Down
2 changes: 2 additions & 0 deletions include/xrpl/protocol/detail/features.macro
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
// If you add an amendment here, then do not forget to increment `numFeatures`
// in include/xrpl/protocol/Feature.h.

// fix1782: Check flags in Credential transactions
XRPL_FIX (1782, Supported::yes, VoteBehavior::DefaultNo)
XRPL_FEATURE(PermissionedDomains, Supported::no, VoteBehavior::DefaultNo)
XRPL_FEATURE(DynamicNFT, Supported::yes, VoteBehavior::DefaultNo)
XRPL_FEATURE(Credentials, Supported::yes, VoteBehavior::DefaultNo)
Expand Down
39 changes: 39 additions & 0 deletions src/test/app/Credentials_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,43 @@ struct Credentials_test : public beast::unit_test::suite
}
}

void
testFlags(FeatureBitset features)
{
using namespace test::jtx;

const char credType[] = "abcde";
Account const issuer{"issuer"};
Account const subject{"subject"};

{
using namespace jtx;
Env env{*this, features};

env.fund(XRP(5000), subject, issuer);
env.close();

{
bool const enabled = features[fix1782];
testcase(
std::string("Tets flag, fix ") +
(enabled ? "enabled" : "disabled"));

ter const expected(
enabled ? TER(temINVALID_FLAG) : TER(tesSUCCESS));
env(credentials::create(subject, issuer, credType),
txflags(tfTransferable),
expected);
env(credentials::accept(subject, issuer, credType),
txflags(tfSellNFToken),
expected);
env(credentials::deleteCred(subject, subject, issuer, credType),
txflags(tfPassive),
expected);
}
}
}

void
run() override
{
Expand All @@ -1069,6 +1106,8 @@ struct Credentials_test : public beast::unit_test::suite
testAcceptFailed(all);
testDeleteFailed(all);
testFeatureFailed(all - featureCredentials);
testFlags(all - fix1782);
testFlags(all);
testRPC();
}
};
Expand Down
18 changes: 18 additions & 0 deletions src/xrpld/app/tx/detail/Credentials.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ CredentialCreate::preflight(PreflightContext const& ctx)
auto const& tx = ctx.tx;
auto& j = ctx.j;

if (ctx.rules.enabled(fix1782) && (tx.getFlags() & tfUniversalMask))
{
JLOG(ctx.j.debug()) << "CredentialCreate: invalid flags.";
return temINVALID_FLAG;
}

if (!tx[sfSubject])
{
JLOG(j.trace()) << "Malformed transaction: Invalid Subject";
Expand Down Expand Up @@ -209,6 +215,12 @@ CredentialDelete::preflight(PreflightContext const& ctx)
if (auto const ret = preflight1(ctx); !isTesSuccess(ret))
return ret;

if (ctx.rules.enabled(fix1782) && (ctx.tx.getFlags() & tfUniversalMask))
{
JLOG(ctx.j.debug()) << "CredentialDelete: invalid flags.";
return temINVALID_FLAG;
}

auto const subject = ctx.tx[~sfSubject];
auto const issuer = ctx.tx[~sfIssuer];

Expand Down Expand Up @@ -289,6 +301,12 @@ CredentialAccept::preflight(PreflightContext const& ctx)
if (auto const ret = preflight1(ctx); !isTesSuccess(ret))
return ret;

if (ctx.rules.enabled(fix1782) && (ctx.tx.getFlags() & tfUniversalMask))
{
JLOG(ctx.j.debug()) << "CredentialAccept: invalid flags.";
return temINVALID_FLAG;
}

if (!ctx.tx[sfIssuer])
{
JLOG(ctx.j.trace()) << "Malformed transaction: Issuer field zeroed.";
Expand Down

0 comments on commit 23bda8d

Please sign in to comment.