Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions include/xrpl/hook/Enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,12 @@ const uint8_t max_emit = 255;
const uint8_t max_params = 16;
const double fee_base_multiplier = 1.1f;

enum GuardRules : uint64_t {
HooksUpdate1 = 0x0001U,
Fix20250131 = 0x0002U,
AtomicEmit = 0x0004U,
};

// RH NOTE: Find descriptions of api functions in ./impl/applyHook.cpp and
// hookapi.h (include for hooks) this is a map of the api name to its return
// code (vec[0] and its parameters vec[>0]) as wasm type codes
Expand Down Expand Up @@ -434,5 +440,8 @@ static const std::map<std::string, std::vector<uint8_t>> import_whitelist{
// featureHooks1
static const std::map<std::string, std::vector<uint8_t>> import_whitelist_1{
{"xpop_slot", {0x7EU, 0x7FU, 0x7FU}}};
// featureAtomicEmit
static const std::map<std::string, std::vector<uint8_t>> import_whitelist_2{
{"emit_atomic", {0x7EU, 0x7FU, 0x7FU, 0x7FU, 0x7FU}}};
}; // namespace hook_api
#endif
33 changes: 24 additions & 9 deletions include/xrpl/hook/Guard.h
Original file line number Diff line number Diff line change
Expand Up @@ -634,15 +634,15 @@ check_guard(
}
else if (fc_type == 10) // memory.copy
{
if (rulesVersion & 0x02U)
if (rulesVersion & hook_api::GuardRules::Fix20250131)
GUARD_ERROR("Memory.copy instruction is not allowed.");

REQUIRE(2);
ADVANCE(2);
}
else if (fc_type == 11) // memory.fill
{
if (rulesVersion & 0x02U)
if (rulesVersion & hook_api::GuardRules::Fix20250131)
GUARD_ERROR("Memory.fill instruction is not allowed.");

ADVANCE(1);
Expand Down Expand Up @@ -1028,12 +1028,19 @@ validateGuards(
hook_api::import_whitelist.find(import_name) ==
hook_api::import_whitelist.end())
{
if (rulesVersion > 0 &&
if (rulesVersion & hook_api::GuardRules::HooksUpdate1 &&
hook_api::import_whitelist_1.find(import_name) !=
hook_api::import_whitelist_1.end())
{
// PASS, this is a version 1 api
}
else if (
rulesVersion & hook_api::GuardRules::AtomicEmit &&
hook_api::import_whitelist_2.find(import_name) !=
hook_api::import_whitelist_2.end())
{
// PASS, this is a version 2 api
}
else
{
GUARDLOG(hook::log::IMPORT_ILLEGAL)
Expand Down Expand Up @@ -1258,12 +1265,20 @@ validateGuards(
{
for (auto const& [import_idx, api_name] : usage->second)
{
auto const& api_signature =
hook_api::import_whitelist.find(api_name) !=
hook_api::import_whitelist.end()
? hook_api::import_whitelist.find(api_name)->second
: hook_api::import_whitelist_1.find(api_name)
->second;
auto findInWhitelist = [&](auto const& whitelist) {
auto it = whitelist.find(api_name);
return it != whitelist.end() ? &it->second
: nullptr;
};

auto const* sig =
findInWhitelist(hook_api::import_whitelist);
if (!sig)
sig = findInWhitelist(hook_api::import_whitelist_1);
if (!sig)
sig = findInWhitelist(hook_api::import_whitelist_2);

auto const& api_signature = *sig;

if (!first_signature)
{
Expand Down
5 changes: 4 additions & 1 deletion include/xrpl/hook/guard_checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ main(int argc, char** argv)

close(fd);

auto result = validateGuards(hook, std::cout, "", 3);
auto const allRules = hook_api::GuardRules::HooksUpdate1 +
hook_api::GuardRules::Fix20250131 + hook_api::GuardRules::AtomicEmit;

auto result = validateGuards(hook, std::cout, "", allRules);

if (!result)
{
Expand Down
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 = 106;
static constexpr std::size_t numFeatures = 107;

/** Amendments that this server supports and the default voting behavior.
Whether they are enabled depends on the Rules defined in the validated
Expand Down
1 change: 1 addition & 0 deletions include/xrpl/protocol/TER.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ enum TECcodes : TERUnderlyingType {
tecARRAY_TOO_LARGE = 196,
tecLOCKED = 197,
tecBAD_CREDENTIALS = 198,
tecHOOK_EMIT_FAILED = 199,
tecLAST_POSSIBLE_ENTRY = 255,
};

Expand Down
1 change: 1 addition & 0 deletions include/xrpl/protocol/detail/features.macro
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
// If you add an amendment here, then do not forget to increment `numFeatures`
// in include/xrpl/protocol/Feature.h.

XRPL_FEATURE(AtomicEmit, Supported::yes, VoteBehavior::DefaultNo)
XRPL_FEATURE(Batch, Supported::yes, VoteBehavior::DefaultNo)
XRPL_FEATURE(PermissionedDomains, Supported::no, VoteBehavior::DefaultNo)
XRPL_FEATURE(DynamicNFT, Supported::no, VoteBehavior::DefaultNo)
Expand Down
1 change: 1 addition & 0 deletions include/xrpl/protocol/detail/ledger_entries.macro
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ LEDGER_ENTRY(ltHOOK_DEFINITION, 'D', HookDefinition, hook_definition, ({
{sfHookCallbackFee, soeOPTIONAL},
{sfPreviousTxnID, soeOPTIONAL},
{sfPreviousTxnLgrSeq, soeOPTIONAL},
{sfHookAtomicEmitFee, soeOPTIONAL},
}))

/** A ledger object containing a hook-emitted transaction from a previous hook execution.
Expand Down
1 change: 1 addition & 0 deletions include/xrpl/protocol/detail/sfields.macro
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ TYPED_SFIELD(sfPrice, AMOUNT, 28)
TYPED_SFIELD(sfSignatureReward, AMOUNT, 29)
TYPED_SFIELD(sfMinAccountCreateAmount, AMOUNT, 30)
TYPED_SFIELD(sfLPTokenBalance, AMOUNT, 31)
TYPED_SFIELD(sfHookAtomicEmitFee, AMOUNT, 32)

// variable length (common)
TYPED_SFIELD(sfPublicKey, VL, 1)
Expand Down
6 changes: 4 additions & 2 deletions src/libxrpl/protocol/InnerObjectFormats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ InnerObjectFormats::InnerObjectFormats()
{sfHookCanEmit, soeOPTIONAL},
{sfHookApiVersion, soeREQUIRED},
{sfFlags, soeREQUIRED},
{sfFee, soeREQUIRED}});
{sfFee, soeREQUIRED},
{sfHookAtomicEmitFee, soeOPTIONAL}});

add(sfHook.jsonName,
sfHook.getCode(),
Expand All @@ -108,7 +109,8 @@ InnerObjectFormats::InnerObjectFormats()
{sfHookOn, soeOPTIONAL},
{sfHookCanEmit, soeOPTIONAL},
{sfHookApiVersion, soeOPTIONAL},
{sfFlags, soeOPTIONAL}});
{sfFlags, soeOPTIONAL},
{sfHookAtomicEmitFee, soeOPTIONAL}});

add(sfHookGrant.jsonName,
sfHookGrant.getCode(),
Expand Down
1 change: 1 addition & 0 deletions src/libxrpl/protocol/TER.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ transResults()
MAKE_ERROR(tecARRAY_TOO_LARGE, "Array is too large."),
MAKE_ERROR(tecLOCKED, "Fund is locked."),
MAKE_ERROR(tecBAD_CREDENTIALS, "Bad credentials."),
MAKE_ERROR(tecHOOK_EMIT_FAILED, "Failed to emit transactions from Hook."),

MAKE_ERROR(tefALREADY, "The exact transaction was already in this ledger."),
MAKE_ERROR(tefBAD_ADD_AUTH, "Not authorized to add account."),
Expand Down
Loading