Skip to content

Commit

Permalink
Add missing headers, and simplify STTx::checkSign interface
Browse files Browse the repository at this point in the history
* For downstream projects that depend on xrpl library
  • Loading branch information
ximinez committed Jan 29, 2024
1 parent 22cdb57 commit 9d09404
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 23 deletions.
30 changes: 17 additions & 13 deletions Builds/CMake/RippledCore.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -244,57 +244,61 @@ install (
src/ripple/protocol/Indexes.h
src/ripple/protocol/InnerObjectFormats.h
src/ripple/protocol/Issue.h
src/ripple/protocol/json_get_or_throw.h
src/ripple/protocol/KeyType.h
src/ripple/protocol/Keylet.h
src/ripple/protocol/KeyType.h
src/ripple/protocol/KnownFormats.h
src/ripple/protocol/LedgerFormats.h
src/ripple/protocol/LedgerHeader.h
src/ripple/protocol/NFTSyntheticSerializer.h
src/ripple/protocol/NFTokenID.h
src/ripple/protocol/NFTokenOfferID.h
src/ripple/protocol/NFTSyntheticSerializer.h
src/ripple/protocol/PayChan.h
src/ripple/protocol/Protocol.h
src/ripple/protocol/PublicKey.h
src/ripple/protocol/Quality.h
src/ripple/protocol/QualityFunction.h
src/ripple/protocol/Quality.h
src/ripple/protocol/Rate.h
src/ripple/protocol/RippleLedgerHash.h
src/ripple/protocol/Rules.h
src/ripple/protocol/SecretKey.h
src/ripple/protocol/Seed.h
src/ripple/protocol/SeqProxy.h
src/ripple/protocol/serialize.h
src/ripple/protocol/Serializer.h
src/ripple/protocol/SField.h
src/ripple/protocol/Sign.h
src/ripple/protocol/SOTemplate.h
src/ripple/protocol/STAccount.h
src/ripple/protocol/STAmount.h
src/ripple/protocol/STIssue.h
src/ripple/protocol/STArray.h
src/ripple/protocol/STBase.h
src/ripple/protocol/STBitString.h
src/ripple/protocol/STBlob.h
src/ripple/protocol/STExchange.h
src/ripple/protocol/STInteger.h
src/ripple/protocol/STIssue.h
src/ripple/protocol/STLedgerEntry.h
src/ripple/protocol/STObject.h
src/ripple/protocol/STParsedJSON.h
src/ripple/protocol/STPathSet.h
src/ripple/protocol/STTx.h
src/ripple/protocol/XChainAttestations.h
src/ripple/protocol/STXChainBridge.h
src/ripple/protocol/STValidation.h
src/ripple/protocol/STVector256.h
src/ripple/protocol/SecretKey.h
src/ripple/protocol/Seed.h
src/ripple/protocol/SeqProxy.h
src/ripple/protocol/Serializer.h
src/ripple/protocol/Sign.h
src/ripple/protocol/STXChainBridge.h
src/ripple/protocol/SystemParameters.h
src/ripple/protocol/TER.h
src/ripple/protocol/TxFlags.h
src/ripple/protocol/TxFormats.h
src/ripple/protocol/TxMeta.h
src/ripple/protocol/UintTypes.h
src/ripple/protocol/XChainAttestations.h
src/ripple/protocol/digest.h
src/ripple/protocol/json_get_or_throw.h
src/ripple/protocol/jss.h
src/ripple/protocol/serialize.h
src/ripple/protocol/messages.h
src/ripple/protocol/nft.h
src/ripple/protocol/nftPageMask.h
src/ripple/protocol/st.h
src/ripple/protocol/tokens.h
DESTINATION include/ripple/protocol)
install (
Expand Down
4 changes: 2 additions & 2 deletions src/ripple/app/tx/impl/SetSignerList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ signerCountBasedOwnerCountDelta(std::size_t entryCount, Rules const& rules)
// be in the range from 1 to 8 (or 32 if ExpandedSignerList is enabled).
// We've got a lot of room to grow.
assert(entryCount >= STTx::minMultiSigners);
assert(entryCount <= STTx::maxMultiSigners(&rules));
assert(entryCount <= STTx::maxMultiSigners(STTx::getSigningRules(rules)));
return 2 + static_cast<int>(entryCount);
}

Expand Down Expand Up @@ -252,7 +252,7 @@ SetSignerList::validateQuorumAndSignerEntries(
{
std::size_t const signerCount = signers.size();
if ((signerCount < STTx::minMultiSigners) ||
(signerCount > STTx::maxMultiSigners(&rules)))
(signerCount > STTx::maxMultiSigners(STTx::getSigningRules(rules))))
{
JLOG(j.trace()) << "Too many or too few signers in signer list.";
return temMALFORMED;
Expand Down
43 changes: 37 additions & 6 deletions src/ripple/protocol/STTx.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,36 @@ class STTx final : public STObject, public CountedObject<STTx>
public:
static std::size_t const minMultiSigners = 1;

// Bit flag enum to avoid callers to maxMultiSigners, including
// checkSign, to need to know about or construct Rules. Expandable
// for future use cases. Since this is only used internally, the
// number of bits can be expanded as necessary.
enum SigningRules : std::uint8_t {
none = 0x0,
// featureExpandedSignerList
expandedSignerList = 0x01,

// return the max value
maximum = 0x80,
};

static SigningRules
getSigningRules(Rules const& rules)
{
if (rules.enabled(featureExpandedSignerList))
return expandedSignerList;
return none;
}

// if rules are not supplied then the largest possible value is returned
static std::size_t
maxMultiSigners(Rules const* rules = 0)
maxMultiSigners(SigningRules rules = maximum)
{
if (rules && !rules->enabled(featureExpandedSignerList))
return 8;
// Skip flag checks if returning the max
if ((rules & maximum) || (rules & expandedSignerList))
return 32;

return 32;
return 8;
}

STTx() = delete;
Expand Down Expand Up @@ -116,14 +138,23 @@ class STTx final : public STObject, public CountedObject<STTx>
void
sign(PublicKey const& publicKey, SecretKey const& secretKey);

enum class RequireFullyCanonicalSig : bool { no, yes };

/** Check the signature.
@return `true` if valid signature. If invalid, the error message string.
*/
enum class RequireFullyCanonicalSig : bool { no, yes };
Expected<void, std::string>
checkSign(RequireFullyCanonicalSig requireCanonicalSig, Rules const& rules)
const;

Expected<void, std::string>
/** Check the signature.
@return `true` if valid signature. If invalid, the error message string.
*/
checkSign(
RequireFullyCanonicalSig requireCanonicalSig,
SigningRules const& rules) const;

// SQL Functions with metadata.
static std::string const&
getMetaSQLInsertReplaceHeader();
Expand All @@ -146,7 +177,7 @@ class STTx final : public STObject, public CountedObject<STTx>
Expected<void, std::string>
checkMultiSign(
RequireFullyCanonicalSig requireCanonicalSig,
Rules const& rules) const;
SigningRules const& rules) const;

STBase*
copy(std::size_t n, void* buf) const override;
Expand Down
12 changes: 10 additions & 2 deletions src/ripple/protocol/impl/STTx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@ Expected<void, std::string>
STTx::checkSign(
RequireFullyCanonicalSig requireCanonicalSig,
Rules const& rules) const
{
return checkSign(requireCanonicalSig, getSigningRules(rules));
}

Expected<void, std::string>
STTx::checkSign(
RequireFullyCanonicalSig requireCanonicalSig,
SigningRules const& rules) const
{
try
{
Expand Down Expand Up @@ -349,7 +357,7 @@ STTx::checkSingleSign(RequireFullyCanonicalSig requireCanonicalSig) const
Expected<void, std::string>
STTx::checkMultiSign(
RequireFullyCanonicalSig requireCanonicalSig,
Rules const& rules) const
SigningRules const& rules) const
{
// Make sure the MultiSigners are present. Otherwise they are not
// attempting multi-signing and we just have a bad SigningPubKey.
Expand All @@ -365,7 +373,7 @@ STTx::checkMultiSign(

// There are well known bounds that the number of signers must be within.
if (signers.size() < minMultiSigners ||
signers.size() > maxMultiSigners(&rules))
signers.size() > maxMultiSigners(rules))
return Unexpected("Invalid Signers array size.");

// We can ease the computational load inside the loop a bit by
Expand Down

0 comments on commit 9d09404

Please sign in to comment.