diff --git a/src/libxrpl/tx/Transactor.cpp b/src/libxrpl/tx/Transactor.cpp index 2745079f6e..c387c3a586 100644 --- a/src/libxrpl/tx/Transactor.cpp +++ b/src/libxrpl/tx/Transactor.cpp @@ -160,16 +160,28 @@ Transactor::preflight1(PreflightContext const& ctx, std::uint32_t flagMask) return temINVALID_FLAG; } - if (!hasSponsor && hasSponsorFlags) + if (!hasSponsor) { - JLOG(ctx.j.debug()) << "preflight1: sponsor flags without sponsor definition"; - return temINVALID_FLAG; - } + if (hasSponsorFlags) + { + JLOG(ctx.j.debug()) << "preflight1: sponsor flags without sponsor definition"; + return temINVALID_FLAG; + } - if (!hasSponsor && hasSponsorSig) + if (hasSponsorSig) + { + JLOG(ctx.j.debug()) << "preflight1: sponsor signature without sponsor definition"; + return temMALFORMED; + } + } + else if (hasSponsorFlags) { - JLOG(ctx.j.debug()) << "preflight1: sponsor signature without sponsor definition"; - return temMALFORMED; + auto const sponsorFlags = ctx.tx.getFieldU32(sfSponsorFlags); + if ((sponsorFlags & ~(spfSponsorFee | spfSponsorReserve)) || sponsorFlags == 0) + { + JLOG(ctx.j.debug()) << "preflight1: invalid sponsor flags"; + return temINVALID_FLAG; + } } if (auto const ret = preflight0(ctx, flagMask)) @@ -218,6 +230,13 @@ Transactor::preflight1(PreflightContext const& ctx, std::uint32_t flagMask) return temMALFORMED; } + // if (hasSponsor && hasSponsorFlags && + // ctx.tx.getFieldU32(sfSponsorFlags) == 0) + // { + // JLOG(ctx.j.debug()) << "preflight1: sponsor with no sponsorship flags"; + // return temINVALID_FLAG; + // } + return tesSUCCESS; } diff --git a/src/test/app/Sponsor_test.cpp b/src/test/app/Sponsor_test.cpp index e3e230479f..9f56a5c8a5 100644 --- a/src/test/app/Sponsor_test.cpp +++ b/src/test/app/Sponsor_test.cpp @@ -360,7 +360,7 @@ public: env.close(); // Invalid Sponsor Account (Account = Sponsor.Account) - env(noop(alice), sponsor::as(alice), ter(temMALFORMED)); + env(noop(alice), sponsor::as(alice, spfSponsorFee), ter(temMALFORMED)); // Invalid Sponsor Account // (SponsorSignature is specified but Sponsor.Account is not specified) @@ -378,6 +378,9 @@ public: sponsor::as(sponsor, (spfSponsorFee | spfSponsorReserve) + 1), ter(temINVALID_FLAG)); + // SponsorFlags=0 with valid sponsor (no sponsorship purpose) + env(noop(alice), sponsor::as(sponsor, 0), ter(temINVALID_FLAG)); + // Invalid Flags without sponsor auto tx = noop(alice); tx[sfSponsorFlags.jsonName] = spfSponsorFee | spfSponsorReserve;