fix for current codebase

This commit is contained in:
tequ
2025-06-17 21:45:05 +09:00
parent cb641e4733
commit 95e16b0eed
33 changed files with 36 additions and 36 deletions

438
include/xrpl/hook/Enum.h Normal file
View File

@@ -0,0 +1,438 @@
#include <map>
#include <set>
#include <string>
#include <vector>
#ifndef HOOKENUM_INCLUDED
#define HOOKENUM_INCLUDED 1
namespace ripple {
enum HookSetOperation : int8_t {
hsoINVALID = -1,
hsoNOOP = 0,
hsoCREATE = 1,
hsoINSTALL = 2,
hsoDELETE = 3,
hsoNSDELETE = 4,
hsoUPDATE = 5
};
enum HookSetFlags : uint8_t {
hsfOVERRIDE = 0b00000001U, // override or delete hook
hsfNSDELETE = 0b00000010U, // delete namespace
hsfCOLLECT = 0b00000100U, // allow collect calls on this hook
};
enum HookEmissionFlags : uint16_t {
hefSTRONG = 0x1,
hefCALLBACK = 0x2,
hefDOAAW = 0x4,
};
} // namespace ripple
namespace hook {
// RH TODO: put these somewhere better, and allow rules to be fed in
inline uint32_t
maxHookParameterKeySize(void)
{
return 32;
}
inline uint32_t
maxHookParameterValueSize(void)
{
return 256;
}
inline uint32_t
maxHookStateDataSize(void)
{
return 256U;
}
inline uint32_t
maxHookWasmSize(void)
{
return 0xFFFFU;
}
inline uint32_t
maxHookChainLength(void)
{
return 10;
}
inline uint32_t
maxNamespaces(void)
{
return 256;
}
// maximum number of entires in a namespace to delete with ns delete
inline uint32_t
maxNamespaceDelete(void)
{
return 256;
}
enum TSHFlags : uint8_t {
tshNONE = 0b000,
tshROLLBACK = 0b001,
tshCOLLECT = 0b010,
tshMIXED = 0b100,
};
namespace log {
/*
* Hook log-codes are not necessarily errors. Each type of Hook log line
* contains a code in round parens like so: HookSet(5)[rAcc...]: message The
* log-code gives an external tool an easy way to handle and report the status
* of a hook to end users and developers.
*/
enum hook_log_code : uint16_t {
/* HookSet log-codes */
AMENDMENT_DISABLED =
1, // attempt to HookSet when amendment is not yet enabled.
API_ILLEGAL = 2, // HookSet object contained HookApiVersion for existing
// HookDefinition
API_INVALID =
3, // HookSet object contained HookApiVersion for unrecognised hook API
API_MISSING =
4, // HookSet object did not contain HookApiVersion but should have
BLOCK_ILLEGAL = 5, // a block end instruction moves execution below depth 0
// {{}}`}` <= like this
CALL_ILLEGAL = 6, // wasm tries to call a non-whitelisted function
CALL_INDIRECT =
7, // wasm used call indirect instruction which is disallowed
CREATE_FLAG = 8, // create operation requires hsfOVERRIDE flag
DELETE_FIELD = 9, //
DELETE_FLAG = 10, // delete operation requires hsfOVERRIDE flag
DELETE_NOTHING = 11, // delete operation would delete nothing
EXPORTS_MISSING =
12, // hook did not export *any* functions (should be cbak, hook)
EXPORT_CBAK_FUNC =
13, // hook did not export correct func def int64_t cbak(uint32_t)
EXPORT_HOOK_FUNC =
14, // hook did not export correct func def int64_t hook(uint32_t)
EXPORT_MISSING =
15, // distinct from export*S*_missing, either hook or cbak is missing
FLAGS_INVALID = 16, // HookSet flags were invalid for specified operation
FUNCS_MISSING = 17, // hook did not include function code for any functions
FUNC_PARAM_INVALID = 18, // parameter types may only be i32 i64 u32 u64
FUNC_RETURN_COUNT = 19, // a function type is defined in the wasm which
// returns > 1 return value
FUNC_RETURN_INVALID =
20, // a function type does not return i32 i64 u32 or u64
FUNC_TYPELESS =
21, // hook defined hook/cbak but their type is not defined in wasm
FUNC_TYPE_INVALID =
22, // malformed and illegal wasm in the func type section
GRANTS_EMPTY = 23, // HookSet object contained an empty grants array (you
// should remove it)
GRANTS_EXCESS =
24, // HookSet object cotnained a grants array with too many grants
GRANTS_FIELD =
25, // HookSet object contained a grant without Authorize or HookHash
GRANTS_ILLEGAL = 26, // Hookset object contained grants array which
// contained a non Grant object
GUARD_IMPORT = 27, // guard import is missing
GUARD_MISSING = 28, // guard call missing at top of loop
GUARD_PARAMETERS =
29, // guard called but did not use constant expressions for params
HASH_OR_CODE =
30, // HookSet object can contain only one of CreateCode and HookHash
HOOKON_MISSING =
31, // HookSet object did not contain HookOn but should have
HOOKS_ARRAY_BAD =
32, // attempt to HookSet with a Hooks array containing a non-Hook obj
HOOKS_ARRAY_BLANK = 33, // all hook set objs were blank
HOOKS_ARRAY_EMPTY = 34, // attempt to HookSet with an empty Hooks array
HOOKS_ARRAY_MISSING = 35, // attempt to HookSet without a Hooks array
HOOKS_ARRAY_TOO_BIG = 36, // attempt to HookSet with a Hooks array beyond
// the chain size limit
HOOK_ADD = 37, // Informational: adding ltHook to directory
HOOK_DEF_MISSING = 38, // attempt to reference a hook definition (by hash)
// that is not on ledger
HOOK_DELETE = 39, // unable to delete ltHook from owner
HOOK_INVALID_FIELD =
40, // HookSetObj contained an illegal/unexpected field
HOOK_PARAMS_COUNT =
41, // hookset obj would create too many hook parameters
HOOK_PARAM_SIZE = 42, // hookset obj sets a parameter or value that exceeds
// max allowable size
IMPORTS_MISSING = 43, // hook must import guard, and accept/rollback
IMPORT_ILLEGAL = 44, // attempted import of a non-whitelisted function
IMPORT_MODULE_BAD =
45, // hook attempted to specify no or a bad import module
IMPORT_MODULE_ENV =
46, // hook attempted to specify import module not named env
IMPORT_NAME_BAD = 47, // import name was too short or too long
INSTALL_FLAG = 48, // install operation requires hsoOVERRIDE
INSTALL_MISSING = 49, // install operation specifies hookhash which doesn't
// exist on the ledger
INSTRUCTION_COUNT =
50, // worst case execution instruction count as computed by HookSet
INSTRUCTION_EXCESS =
51, // worst case execution instruction count was too large
MEMORY_GROW = 52, // memory.grow instruction is present but disallowed
NAMESPACE_MISSING = 53, // HookSet object lacked HookNamespace
NSDELETE = 54, // Informational: a namespace is being deleted
NSDELETE_ACCOUNT =
55, // nsdelete tried to delete ns from a non-existing account
NSDELETE_COUNT = 56, // namespace state count less than 0 / overflow
NSDELETE_DIR = 57, // could not delete directory node in ledger
NSDELETE_DIRECTORY =
58, // nsdelete operation failed to delete ns directory
NSDELETE_DIR_ENTRY =
59, // nsdelete operation failed due to bad entry in ns directory
NSDELETE_ENTRY =
60, // nsdelete operation failed due to missing hook state entry
NSDELETE_FIELD = 61,
NSDELETE_FLAGS = 62,
NSDELETE_NONSTATE = 63, // nsdelete operation failed due to the presence of
// a non-hookstate obj
NSDELETE_NOTHING = 64, // hsfNSDELETE provided but nothing to delete
OPERATION_INVALID =
65, // could not deduce an operation from the provided hookset obj
OVERRIDE_MISSING = 66, // HookSet object was trying to update or delete a
// hook but lacked hsfOVERRIDE
PARAMETERS_FIELD = 67, // HookParameters contained a HookParameter with an
// invalid key in it
PARAMETERS_ILLEGAL =
68, // HookParameters contained something other than a HookParameter
PARAMETERS_NAME = 69, // HookParameters contained a HookParameter which
// lacked ParameterName field
PARAM_HOOK_CBAK = 70, // hook and cbak must take exactly one u32 parameter
RETURN_HOOK_CBAK = 71, // hook and cbak must retunr i64
SHORT_HOOK = 72, // web assembly byte code ended abruptly
TYPE_INVALID =
73, // malformed and illegal wasm specifying an illegal local var type
WASM_BAD_MAGIC = 74, // wasm magic number missing or not wasm
WASM_INVALID = 75, // set hook operation would set invalid wasm
WASM_PARSE_LOOP = 76, // wasm section parsing resulted in an infinite loop
WASM_SMOKE_TEST =
77, // Informational: first attempt to load wasm into wasm runtime
WASM_TEST_FAILURE = 78, // the smoke test failed
WASM_TOO_BIG = 79, // set hook would exceed maximum hook size
WASM_TOO_SMALL = 80,
WASM_VALIDATION =
81, // a generic error while parsing wasm, usually leb128 overflow
HOOK_CBAK_DIFF_TYPES =
82, // hook and cbak function definitions were different
PARAMETERS_NAME_REPEATED = 83,
NESTING_LIMIT = 84, // the hook nested blocks/loops/ifs beyond 16 levels
SECTIONS_OUT_OF_SEQUENCE =
85, // the wasm contained sections out of sequence
CUSTOM_SECTION_DISALLOWED =
86, // the wasm contained a custom section (id=0)
INTERNAL_ERROR = 87, // an internal error described by the log text
// RH NOTE: only HookSet msgs got log codes, possibly all Hook log lines
// should get a code?
};
}; // namespace log
}; // namespace hook
namespace hook_api {
namespace keylet_code {
enum keylet_code : uint32_t {
HOOK = 1,
HOOK_STATE = 2,
ACCOUNT = 3,
AMENDMENTS = 4,
CHILD = 5,
SKIP = 6,
FEES = 7,
NEGATIVE_UNL = 8,
LINE = 9,
OFFER = 10,
QUALITY = 11,
EMITTED_DIR = 12,
TICKET = 13,
SIGNERS = 14,
CHECK = 15,
DEPOSIT_PREAUTH = 16,
UNCHECKED = 17,
OWNER_DIR = 18,
PAGE = 19,
ESCROW = 20,
PAYCHAN = 21,
EMITTED_TXN = 22,
NFT_OFFER = 23,
HOOK_DEFINITION = 24,
HOOK_STATE_DIR = 25,
LAST_KLTYPE_V0 = HOOK_DEFINITION,
LAST_KLTYPE_V1 = HOOK_STATE_DIR,
};
}
namespace compare_mode {
enum compare_mode : uint32_t { EQUAL = 1, LESS = 2, GREATER = 4 };
}
enum hook_return_code : int64_t {
SUCCESS =
0, // return codes > 0 are reserved for hook apis to return "success"
OUT_OF_BOUNDS =
-1, // could not read or write to a pointer to provided by hook
INTERNAL_ERROR = -2, // eg directory is corrupt
TOO_BIG = -3, // something you tried to store was too big
TOO_SMALL = -4, // something you tried to store or provide was too small
DOESNT_EXIST = -5, // something you requested wasn't found
NO_FREE_SLOTS =
-6, // when trying to load an object there is a maximum of 255 slots
INVALID_ARGUMENT = -7, // self explanatory
ALREADY_SET =
-8, // returned when a one-time parameter was already set by the hook
PREREQUISITE_NOT_MET =
-9, // returned if a required param wasn't set, before calling
FEE_TOO_LARGE = -10, // returned if the attempted operation would result in
// an absurd fee
EMISSION_FAILURE =
-11, // returned if an emitted tx was not accepted by rippled
TOO_MANY_NONCES = -12, // a hook has a maximum of 256 nonces
TOO_MANY_EMITTED_TXN =
-13, // a hook has emitted more than its stated number of emitted txn
NOT_IMPLEMENTED =
-14, // an api was called that is reserved for a future version
INVALID_ACCOUNT =
-15, // an api expected an account id but got something else
GUARD_VIOLATION =
-16, // a guarded loop or function iterated over its maximum
INVALID_FIELD = -17, // the field requested is returning sfInvalid
PARSE_ERROR = -18, // hook asked hookapi to parse something the contents of
// which was invalid
RC_ROLLBACK = -19, // hook should terminate due to a rollback() call
RC_ACCEPT = -20, // hook should temrinate due to an accept() call
NO_SUCH_KEYLET = -21, // invalid keylet or keylet type
NOT_AN_ARRAY =
-22, // if a count of an sle is requested but its not STI_ARRAY
NOT_AN_OBJECT =
-23, // if a subfield is requested from something that isn't an object
INVALID_FLOAT =
-10024, // specially selected value that will never be a valid exponent
DIVISION_BY_ZERO = -25,
MANTISSA_OVERSIZED = -26,
MANTISSA_UNDERSIZED = -27,
EXPONENT_OVERSIZED = -28,
EXPONENT_UNDERSIZED = -29,
XFL_OVERFLOW = -30, // if an operation with a float results in an overflow
NOT_IOU_AMOUNT = -31,
NOT_AN_AMOUNT = -32,
CANT_RETURN_NEGATIVE = -33,
NOT_AUTHORIZED = -34,
PREVIOUS_FAILURE_PREVENTS_RETRY = -35,
TOO_MANY_PARAMS = -36,
INVALID_TXN = -37,
RESERVE_INSUFFICIENT =
-38, // setting a new state object would exceed account reserve
COMPLEX_NOT_SUPPORTED = -39,
DOES_NOT_MATCH =
-40, // two keylets were required to be the same type but werent
INVALID_KEY = -41, // user supplied key was not valid
NOT_A_STRING = -42, // nul terminator missing from a string argument
MEM_OVERLAP = -43, // one or more specified buffers are the same memory
TOO_MANY_STATE_MODIFICATIONS = -44, // more than 5000 modified state
// entires in the combined hook chains
TOO_MANY_NAMESPACES = -45
};
enum ExitType : uint8_t {
UNSET = 0,
WASM_ERROR = 1,
ROLLBACK = 2,
ACCEPT = 3,
};
const uint16_t max_state_modifications = 256;
const uint8_t max_slots = 255;
const uint8_t max_nonce = 255;
const uint8_t max_emit = 255;
const uint8_t max_params = 16;
const double fee_base_multiplier = 1.1f;
// 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
static const std::map<std::string, std::vector<uint8_t>> import_whitelist{
{"_g", {0x7FU, 0x7FU, 0x7FU}},
{"accept", {0x7EU, 0x7FU, 0x7FU, 0x7EU}},
{"rollback", {0x7EU, 0x7FU, 0x7FU, 0x7EU}},
{"util_raddr", {0x7EU, 0x7FU, 0x7FU, 0x7FU, 0x7FU}},
{"util_accid", {0x7EU, 0x7FU, 0x7FU, 0x7FU, 0x7FU}},
{"util_verify", {0x7EU, 0x7FU, 0x7FU, 0x7FU, 0x7FU, 0x7FU, 0x7FU}},
{"util_sha512h", {0x7EU, 0x7FU, 0x7FU, 0x7FU, 0x7FU}},
{"util_keylet",
{0x7EU, 0x7FU, 0x7FU, 0x7FU, 0x7FU, 0x7FU, 0x7FU, 0x7FU, 0x7FU, 0x7FU}},
{"sto_validate", {0x7EU, 0x7FU, 0x7FU}},
{"sto_subfield", {0x7EU, 0x7FU, 0x7FU, 0x7FU}},
{"sto_subarray", {0x7EU, 0x7FU, 0x7FU, 0x7FU}},
{"sto_emplace", {0x7EU, 0x7FU, 0x7FU, 0x7FU, 0x7FU, 0x7FU, 0x7FU, 0x7FU}},
{"sto_erase", {0x7EU, 0x7FU, 0x7FU, 0x7FU, 0x7FU, 0x7FU}},
{"etxn_burden", {0x7EU}},
{"etxn_details", {0x7EU, 0x7FU, 0x7FU}},
{"etxn_fee_base", {0x7EU, 0x7FU, 0x7FU}},
{"etxn_reserve", {0x7EU, 0x7FU}},
{"etxn_generation", {0x7EU}},
{"etxn_nonce", {0x7EU, 0x7FU, 0x7FU}},
{"emit", {0x7EU, 0x7FU, 0x7FU, 0x7FU, 0x7FU}},
{"float_set", {0x7EU, 0x7FU, 0x7EU}},
{"float_multiply", {0x7EU, 0x7EU, 0x7EU}},
{"float_mulratio", {0x7EU, 0x7EU, 0x7FU, 0x7FU, 0x7FU}},
{"float_negate", {0x7EU, 0x7EU}},
{"float_compare", {0x7EU, 0x7EU, 0x7EU, 0x7FU}},
{"float_sum", {0x7EU, 0x7EU, 0x7EU}},
{"float_sto",
{0x7EU, 0x7FU, 0x7FU, 0x7FU, 0x7FU, 0x7FU, 0x7FU, 0x7EU, 0x7FU}},
{"float_sto_set", {0x7EU, 0x7FU, 0x7FU}},
{"float_invert", {0x7EU, 0x7EU}},
{"float_divide", {0x7EU, 0x7EU, 0x7EU}},
{"float_one", {0x7EU}},
{"float_mantissa", {0x7EU, 0x7EU}},
{"float_sign", {0x7EU, 0x7EU}},
{"float_int", {0x7EU, 0x7EU, 0x7FU, 0x7FU}},
{"float_log", {0x7EU, 0x7EU}},
{"float_root", {0x7EU, 0x7EU, 0x7FU}},
{"fee_base", {0x7EU}},
{"ledger_seq", {0x7EU}},
{"ledger_last_time", {0x7EU}},
{"ledger_last_hash", {0x7EU, 0x7FU, 0x7FU}},
{"ledger_nonce", {0x7EU, 0x7FU, 0x7FU}},
{"ledger_keylet", {0x7EU, 0x7FU, 0x7FU, 0x7FU, 0x7FU, 0x7FU, 0x7FU}},
{"hook_account", {0x7EU, 0x7FU, 0x7FU}},
{"hook_hash", {0x7EU, 0x7FU, 0x7FU, 0x7FU}},
{"hook_param_set", {0x7EU, 0x7FU, 0x7FU, 0x7FU, 0x7FU, 0x7FU, 0x7FU}},
{"hook_param", {0x7EU, 0x7FU, 0x7FU, 0x7FU, 0x7FU}},
{"hook_again", {0x7EU}},
{"hook_skip", {0x7EU, 0x7FU, 0x7FU, 0x7FU}},
{"hook_pos", {0x7EU}},
{"slot", {0x7EU, 0x7FU, 0x7FU, 0x7FU}},
{"slot_clear", {0x7EU, 0x7FU}},
{"slot_count", {0x7EU, 0x7FU}},
{"slot_set", {0x7EU, 0x7FU, 0x7FU, 0x7FU}},
{"slot_size", {0x7EU, 0x7FU}},
{"slot_subarray", {0x7EU, 0x7FU, 0x7FU, 0x7FU}},
{"slot_subfield", {0x7EU, 0x7FU, 0x7FU, 0x7FU}},
{"slot_type", {0x7EU, 0x7FU, 0x7FU}},
{"slot_float", {0x7EU, 0x7FU}},
{"state_set", {0x7EU, 0x7FU, 0x7FU, 0x7FU, 0x7FU}},
{"state_foreign_set",
{0x7EU, 0x7FU, 0x7FU, 0x7FU, 0x7FU, 0x7FU, 0x7FU, 0x7FU, 0x7FU}},
{"state", {0x7EU, 0x7FU, 0x7FU, 0x7FU, 0x7FU}},
{"state_foreign",
{0x7EU, 0x7FU, 0x7FU, 0x7FU, 0x7FU, 0x7FU, 0x7FU, 0x7FU, 0x7FU}},
{"trace", {0x7EU, 0x7FU, 0x7FU, 0x7FU, 0x7FU, 0x7FU}},
{"trace_num", {0x7EU, 0x7FU, 0x7FU, 0x7EU}},
{"trace_float", {0x7EU, 0x7FU, 0x7FU, 0x7EU}},
{"otxn_burden", {0x7EU}},
{"otxn_field", {0x7EU, 0x7FU, 0x7FU, 0x7FU}},
{"otxn_generation", {0x7EU}},
{"otxn_id", {0x7EU, 0x7FU, 0x7FU, 0x7FU}},
{"otxn_type", {0x7EU}},
{"otxn_slot", {0x7EU, 0x7FU}},
{"otxn_param", {0x7EU, 0x7FU, 0x7FU, 0x7FU, 0x7FU}},
{"meta_slot", {0x7EU, 0x7FU}}};
// featureHooks1
static const std::map<std::string, std::vector<uint8_t>> import_whitelist_1{
{"xpop_slot", {0x7EU, 0x7FU, 0x7FU}}};
}; // namespace hook_api
#endif

1538
include/xrpl/hook/Guard.h Normal file

File diff suppressed because it is too large Load Diff

323
include/xrpl/hook/Macro.h Normal file
View File

@@ -0,0 +1,323 @@
/**
* RH NOTE:
* This file contains macros for converting the hook api definitions into the
* currently used wasm runtime. Web assembly runtimes are more or less fungible,
* and at time of writing hooks has moved to WasmEdge from SSVM and before that
* from wasmer. After the first move it was decided there should be a relatively
* static interface for the definition and programming of the hook api itself,
* with the runtime-specific behaviour hidden away by templates or macros.
* Macros are more expressive and can themselves include templates so macros
* were then used.
*/
#define LPAREN (
#define RPAREN )
#define COMMA ,
#define EXPAND(...) __VA_ARGS__
#define CAT(a, ...) PRIMITIVE_CAT(a, __VA_ARGS__)
#define CAT2(L, R) CAT2_(L, R)
#define CAT2_(L, R) L##R
#define PRIMITIVE_CAT(a, ...) a##__VA_ARGS__
#define EMPTY()
#define DEFER(id) id EMPTY()
#define OBSTRUCT(...) __VA_ARGS__ DEFER(EMPTY)()
#define VA_NARGS_IMPL( \
_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, N, ...) \
N
#define VA_NARGS(__drop, ...) \
VA_NARGS_IMPL(__VA_ARGS__, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1)
#define FIRST(a, b) a
#define SECOND(a, b) b
#define STRIP_TYPES(...) FOR_VARS(SECOND, 0, __VA_ARGS__)
#define DELIM_0 ,
#define DELIM_1
#define DELIM_2 ;
#define DELIM(S) DELIM_##S
#define FOR_VAR_1(T, S, D) SEP(T, D)
#define FOR_VAR_2(T, S, a, b) FOR_VAR_1(T, S, a) DELIM(S) FOR_VAR_1(T, S, b)
#define FOR_VAR_3(T, S, a, ...) \
FOR_VAR_1(T, S, a) DELIM(S) FOR_VAR_2(T, S, __VA_ARGS__)
#define FOR_VAR_4(T, S, a, ...) \
FOR_VAR_1(T, S, a) DELIM(S) FOR_VAR_3(T, S, __VA_ARGS__)
#define FOR_VAR_5(T, S, a, ...) \
FOR_VAR_1(T, S, a) DELIM(S) FOR_VAR_4(T, S, __VA_ARGS__)
#define FOR_VAR_6(T, S, a, ...) \
FOR_VAR_1(T, S, a) DELIM(S) FOR_VAR_5(T, S, __VA_ARGS__)
#define FOR_VAR_7(T, S, a, ...) \
FOR_VAR_1(T, S, a) DELIM(S) FOR_VAR_6(T, S, __VA_ARGS__)
#define FOR_VAR_8(T, S, a, ...) \
FOR_VAR_1(T, S, a) DELIM(S) FOR_VAR_7(T, S, __VA_ARGS__)
#define FOR_VAR_9(T, S, a, ...) \
FOR_VAR_1(T, S, a) DELIM(S) FOR_VAR_8(T, S, __VA_ARGS__)
#define FOR_VAR_10(T, S, a, ...) \
FOR_VAR_1(T, S, a) DELIM(S) FOR_VAR_9(T, S, __VA_ARGS__)
#define FOR_VAR_11(T, S, a, ...) \
FOR_VAR_1(T, S, a) DELIM(S) FOR_VAR_10(T, S, __VA_ARGS__)
#define FOR_VAR_12(T, S, a, ...) \
FOR_VAR_1(T, S, a) DELIM(S) FOR_VAR_11(T, S, __VA_ARGS__)
#define FOR_VARS(T, S, ...) \
DEFER(CAT(FOR_VAR_, VA_NARGS(NULL, __VA_ARGS__)) \
CAT(LPAREN T COMMA S COMMA OBSTRUCT(__VA_ARGS__) RPAREN))
#define SEP(OP, D) EXPAND(OP CAT2(SEP_, D) RPAREN)
#define SEP_uint32_t LPAREN uint32_t COMMA
#define SEP_int32_t LPAREN int32_t COMMA
#define SEP_uint64_t LPAREN uint64_t COMMA
#define SEP_int64_t LPAREN int64_t COMMA
#define VAL_uint32_t WasmEdge_ValueGetI32(in[_stack++])
#define VAL_int32_t WasmEdge_ValueGetI32(in[_stack++])
#define VAL_uint64_t WasmEdge_ValueGetI64(in[_stack++])
#define VAL_int64_t WasmEdge_ValueGetI64(in[_stack++])
#define VAR_ASSIGN(T, V) T V = CAT(VAL_##T)
#define RET_uint32_t(return_code) WasmEdge_ValueGenI32(return_code)
#define RET_int32_t(return_code) WasmEdge_ValueGenI32(return_code)
#define RET_uint64_t(return_code) WasmEdge_ValueGenI64(return_code)
#define RET_int64_t(return_code) WasmEdge_ValueGenI64(return_code)
#define RET_ASSIGN(T, return_code) CAT2(RET_, T(return_code))
#define TYP_uint32_t WasmEdge_ValType_I32
#define TYP_int32_t WasmEdge_ValType_I32
#define TYP_uint64_t WasmEdge_ValType_I64
#define TYP_int64_t WasmEdge_ValType_I64
#define WASM_VAL_TYPE(T, b) CAT2(TYP_, T)
#define DECLARE_HOOK_FUNCTION(R, F, ...) \
R F(hook::HookContext& hookCtx, \
WasmEdge_CallingFrameContext const& frameCtx, \
__VA_ARGS__); \
extern WasmEdge_Result WasmFunction##F( \
void* data_ptr, \
const WasmEdge_CallingFrameContext* frameCtx, \
const WasmEdge_Value* in, \
WasmEdge_Value* out); \
extern WasmEdge_ValType WasmFunctionParams##F[]; \
extern WasmEdge_ValType WasmFunctionResult##F[]; \
extern WasmEdge_FunctionTypeContext* WasmFunctionType##F; \
extern WasmEdge_String WasmFunctionName##F;
#define DECLARE_HOOK_FUNCNARG(R, F) \
R F(hook::HookContext& hookCtx, \
WasmEdge_CallingFrameContext const& frameCtx); \
extern WasmEdge_Result WasmFunction##F( \
void* data_ptr, \
const WasmEdge_CallingFrameContext* frameCtx, \
const WasmEdge_Value* in, \
WasmEdge_Value* out); \
extern WasmEdge_ValType WasmFunctionResult##F[]; \
extern WasmEdge_FunctionTypeContext* WasmFunctionType##F; \
extern WasmEdge_String WasmFunctionName##F;
#define DEFINE_HOOK_FUNCTION(R, F, ...) \
WasmEdge_Result hook_api::WasmFunction##F( \
void* data_ptr, \
const WasmEdge_CallingFrameContext* frameCtx, \
const WasmEdge_Value* in, \
WasmEdge_Value* out) \
{ \
int _stack = 0; \
FOR_VARS(VAR_ASSIGN, 2, __VA_ARGS__); \
hook::HookContext* hookCtx = \
reinterpret_cast<hook::HookContext*>(data_ptr); \
R return_code = hook_api::F( \
*hookCtx, \
*const_cast<WasmEdge_CallingFrameContext*>(frameCtx), \
STRIP_TYPES(__VA_ARGS__)); \
if (return_code == RC_ROLLBACK || return_code == RC_ACCEPT) \
return WasmEdge_Result_Terminate; \
out[0] = RET_ASSIGN(R, return_code); \
return WasmEdge_Result_Success; \
}; \
WasmEdge_ValType hook_api::WasmFunctionParams##F[] = { \
FOR_VARS(WASM_VAL_TYPE, 0, __VA_ARGS__)}; \
WasmEdge_ValType hook_api::WasmFunctionResult##F[1] = { \
WASM_VAL_TYPE(R, dummy)}; \
WasmEdge_FunctionTypeContext* hook_api::WasmFunctionType##F = \
WasmEdge_FunctionTypeCreate( \
WasmFunctionParams##F, \
VA_NARGS(NULL, __VA_ARGS__), \
WasmFunctionResult##F, \
1); \
WasmEdge_String hook_api::WasmFunctionName##F = \
WasmEdge_StringCreateByCString(#F); \
R hook_api::F( \
hook::HookContext& hookCtx, \
WasmEdge_CallingFrameContext const& frameCtx, \
__VA_ARGS__)
#define DEFINE_HOOK_FUNCNARG(R, F) \
WasmEdge_Result hook_api::WasmFunction##F( \
void* data_ptr, \
const WasmEdge_CallingFrameContext* frameCtx, \
const WasmEdge_Value* in, \
WasmEdge_Value* out) \
{ \
hook::HookContext* hookCtx = \
reinterpret_cast<hook::HookContext*>(data_ptr); \
R return_code = hook_api::F( \
*hookCtx, *const_cast<WasmEdge_CallingFrameContext*>(frameCtx)); \
if (return_code == RC_ROLLBACK || return_code == RC_ACCEPT) \
return WasmEdge_Result_Terminate; \
out[0] = CAT2(RET_, R(return_code)); \
return WasmEdge_Result_Success; \
}; \
WasmEdge_ValType hook_api::WasmFunctionResult##F[1] = { \
WASM_VAL_TYPE(R, dummy)}; \
WasmEdge_FunctionTypeContext* hook_api::WasmFunctionType##F = \
WasmEdge_FunctionTypeCreate({}, 0, WasmFunctionResult##F, 1); \
WasmEdge_String hook_api::WasmFunctionName##F = \
WasmEdge_StringCreateByCString(#F); \
R hook_api::F( \
hook::HookContext& hookCtx, \
WasmEdge_CallingFrameContext const& frameCtx)
#define HOOK_SETUP() \
try \
{ \
[[maybe_unused]] ApplyContext& applyCtx = hookCtx.applyCtx; \
[[maybe_unused]] auto& view = applyCtx.view(); \
[[maybe_unused]] auto j = applyCtx.app.journal("View"); \
[[maybe_unused]] WasmEdge_MemoryInstanceContext* memoryCtx = \
WasmEdge_CallingFrameGetMemoryInstance(&frameCtx, 0); \
[[maybe_unused]] unsigned char* memory = \
WasmEdge_MemoryInstanceGetPointer(memoryCtx, 0, 0); \
[[maybe_unused]] const uint64_t memory_length = \
WasmEdge_MemoryInstanceGetPageSize(memoryCtx) * \
WasmEdge_kPageSize; \
if (!memoryCtx || !memory || !memory_length) \
return INTERNAL_ERROR;
#define HOOK_TEARDOWN() \
} \
catch (const std::exception& e) \
{ \
JLOG(hookCtx.applyCtx.app.journal("View").error()) \
<< "HookError[" << HC_ACC() << "]: " << __func__ \
<< " threw uncaught exception, what=" << e.what(); \
return INTERNAL_ERROR; \
}
#define WRITE_WASM_MEMORY( \
bytes_written, \
guest_dst_ptr, \
guest_dst_len, \
host_src_ptr, \
host_src_len, \
host_memory_ptr, \
guest_memory_length) \
{ \
int64_t bytes_to_write = std::min( \
static_cast<int64_t>(host_src_len), \
static_cast<int64_t>(guest_dst_len)); \
if (guest_dst_ptr + bytes_to_write > guest_memory_length) \
{ \
JLOG(j.warn()) << "HookError[" << HC_ACC() << "]: " << __func__ \
<< " tried to retreive blob of " << host_src_len \
<< " bytes past end of wasm memory"; \
return OUT_OF_BOUNDS; \
} \
if (!WasmEdge_ResultOK(WasmEdge_MemoryInstanceSetData( \
memoryCtx, \
reinterpret_cast<const uint8_t*>(host_src_ptr), \
guest_dst_ptr, \
bytes_to_write))) \
return INTERNAL_ERROR; \
bytes_written += bytes_to_write; \
}
#define WRITE_WASM_MEMORY_AND_RETURN( \
guest_dst_ptr, \
guest_dst_len, \
host_src_ptr, \
host_src_len, \
host_memory_ptr, \
guest_memory_length) \
{ \
int64_t bytes_written = 0; \
WRITE_WASM_MEMORY( \
bytes_written, \
guest_dst_ptr, \
guest_dst_len, \
host_src_ptr, \
host_src_len, \
host_memory_ptr, \
guest_memory_length); \
return bytes_written; \
}
// ptr = pointer inside the wasm memory space
#define NOT_IN_BOUNDS(ptr, len, memory_length) \
((static_cast<uint64_t>(ptr) >= static_cast<uint64_t>(memory_length)) || \
((static_cast<uint64_t>(ptr) + static_cast<uint64_t>(len)) > \
static_cast<uint64_t>(memory_length)))
#define HOOK_EXIT(read_ptr, read_len, error_code, exit_type) \
{ \
if (read_len > 256) \
read_len = 256; \
if (read_ptr) \
{ \
if (NOT_IN_BOUNDS(read_ptr, read_len, memory_length)) \
{ \
JLOG(j.warn()) << "HookError[" << HC_ACC() << "]: " \
<< "Tried to accept/rollback but specified " \
"memory outside of the wasm instance " \
<< "limit when specifying a reason string"; \
return OUT_OF_BOUNDS; \
} \
/* assembly script and some other languages use utf16 for strings \
*/ \
if (is_UTF16LE(read_ptr + memory, read_len)) \
{ \
uint8_t output[128]; \
int len = read_len / 2; /* is_UTF16LE will only return true if \
read_len is even */ \
for (int i = 0; i < len; ++i) \
output[i] = memory[read_ptr + i * 2]; \
hookCtx.result.exitReason = \
std::string((const char*)(output), (size_t)len); \
} \
else \
hookCtx.result.exitReason = std::string( \
(const char*)(memory + read_ptr), (size_t)read_len); \
} \
hookCtx.result.exitType = exit_type; \
hookCtx.result.exitCode = error_code; \
return ( \
exit_type == hook_api::ExitType::ACCEPT ? RC_ACCEPT \
: RC_ROLLBACK); \
}
#define WRITE_WASM_MEMORY_OR_RETURN_AS_INT64( \
write_ptr_in, write_len_in, data_ptr_in, data_len_in, is_account_in) \
{ \
uint8_t* data_ptr = (uint8_t*)(data_ptr_in); \
int data_len = (data_len_in); \
if (is_account_in) \
{ \
data_len--; \
data_ptr++; \
} \
if (data_len < 0 || data_len > (data_len_in) || \
data_ptr < (data_ptr_in)) \
return INTERNAL_ERROR; \
if (data_len == 0) \
return 0; \
if ((write_ptr_in) == 0) \
return data_as_int64(data_ptr, data_len); \
if (data_len > (write_len_in)) \
return TOO_SMALL; \
WRITE_WASM_MEMORY_AND_RETURN( \
(write_ptr_in), \
(write_len_in), \
data_ptr, \
data_len, \
memory, \
memory_length); \
}

523
include/xrpl/hook/Misc.h Normal file
View File

@@ -0,0 +1,523 @@
#ifndef HOOKMISC_INCLUDED
#define HOOKMISC_INCLUDED 1
#include <xrpl/basics/base_uint.h>
namespace ripple {
// RH TODO: there's definitely a mucher nicer way to do this, but it involves
// modifying the base_uint class and we don't want to do that yet.
static const std::array<ripple::uint256, 256> UINT256_BIT = {
ripple::uint256(
"0000000000000000000000000000000000000000000000000000000000000001"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000000000000002"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000000000000004"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000000000000008"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000000000000010"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000000000000020"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000000000000040"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000000000000080"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000000000000100"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000000000000200"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000000000000400"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000000000000800"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000000000001000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000000000002000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000000000004000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000000000008000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000000000010000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000000000020000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000000000040000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000000000080000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000000000100000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000000000200000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000000000400000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000000000800000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000000001000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000000002000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000000004000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000000008000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000000010000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000000020000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000000040000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000000080000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000000100000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000000200000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000000400000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000000800000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000001000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000002000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000004000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000008000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000010000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000020000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000040000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000080000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000100000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000200000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000400000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000000800000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000001000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000002000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000004000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000008000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000010000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000020000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000040000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000080000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000100000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000200000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000400000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000000800000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000001000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000002000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000004000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000008000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000010000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000020000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000040000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000080000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000100000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000200000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000400000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000000800000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000001000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000002000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000004000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000008000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000010000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000020000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000040000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000080000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000100000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000200000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000400000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000000800000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000001000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000002000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000004000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000008000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000010000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000020000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000040000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000080000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000100000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000200000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000400000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000000800000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000001000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000002000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000004000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000008000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000010000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000020000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000040000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000080000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000100000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000200000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000400000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000000800000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000001000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000002000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000004000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000008000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000010000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000020000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000040000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000080000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000100000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000200000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000400000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000000800000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000001000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000002000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000004000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000008000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000010000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000020000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000040000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000080000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000100000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000200000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000400000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000000800000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000001000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000002000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000004000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000008000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000010000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000020000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000040000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000080000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000100000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000200000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000400000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000000800000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000001000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000002000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000004000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000008000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000010000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000020000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000040000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000080000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000100000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000200000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000400000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000000800000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000001000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000002000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000004000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000008000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000010000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000020000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000040000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000080000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000100000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000200000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000400000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000000800000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000001000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000002000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000004000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000008000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000010000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000020000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000040000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000080000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000100000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000200000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000400000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000000800000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000001000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000002000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000004000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000008000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000010000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000020000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000040000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000080000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000100000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000200000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000400000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000000800000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000001000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000002000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000004000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000008000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000010000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000020000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000040000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000080000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000100000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000200000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000400000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000000800000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000001000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000002000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000004000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000008000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000010000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000020000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000040000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000080000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000100000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000200000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000400000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000000800000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000001000000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000002000000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000004000000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000008000000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000010000000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000020000000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000040000000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000080000000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000100000000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000200000000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000400000000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000000800000000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000001000000000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000002000000000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000004000000000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000008000000000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000010000000000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000020000000000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000040000000000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000080000000000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000100000000000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000200000000000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000400000000000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0000800000000000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0001000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0002000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0004000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0008000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0010000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0020000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0040000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0080000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0100000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0200000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0400000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"0800000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"1000000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"2000000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"4000000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256(
"8000000000000000000000000000000000000000000000000000000000000000")};
} // namespace ripple
#endif

View File

@@ -0,0 +1,93 @@
#include "Guard.h"
#include <fcntl.h>
#include <iostream>
#include <optional>
#include <ostream>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <string_view>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <unistd.h>
#include <vector>
int
main(int argc, char** argv)
{
const char* fin = 0;
if (argc > 2)
return fprintf(
stderr, "Guard Checker\n\tUsage: %s somefile.wasm\n", argv[0]);
else if (argc == 1)
fin = "-";
else
fin = argv[1];
int fd = 0;
if (strcmp(fin, "-") != 0)
fd = open(fin, O_RDONLY);
if (fd < 0)
return fprintf(stderr, "Could not open file for reading:`%s`\n", fin);
off_t len = fd == 0 ? 0 : lseek(fd, 0, SEEK_END);
if (fd != 0)
lseek(fd, 0, SEEK_SET);
int length_known = len > 0;
uint8_t hook_data[0x100000U];
uint8_t* ptr = hook_data;
size_t upto = 0;
fcntl(fd, F_SETFL, fcntl(0, F_GETFL) & ~O_NONBLOCK);
while (ptr - hook_data < sizeof(hook_data))
{
if (length_known)
{
if (upto >= len)
break;
}
else
len = upto + 1;
size_t bytes_read = read(fd, ptr + upto, len - upto);
if (!length_known && bytes_read == 0)
break;
if (bytes_read < 0)
return fprintf(
stderr,
"Error reading file `%s`, only %ld bytes could be read\n",
fin,
upto);
upto += bytes_read;
}
std::vector<uint8_t> hook(upto);
memcpy(hook.data(), hook_data, upto);
printf("Read %ld bytes from `%s` successfully...\n", upto, fin);
close(fd);
auto result = validateGuards(hook, std::cout, "", 3);
if (!result)
{
printf("Hook validation failed.\n");
return 1;
}
printf("\nHook validation successful!\n");
return 0;
}

View File

@@ -0,0 +1,4 @@
guard_checker: guard_checker.cpp Guard.h Enum.h
g++ -o guard_checker guard_checker.cpp --std=c++17 -g
install: guard_checker
cp guard_checker /usr/bin/

1091
include/xrpl/hook/xahau.h Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -21,7 +21,7 @@
#define RIPPLE_PROTOCOL_IMPORT_H_INCLUDED
// #include <ripple/basics/Log.h>
#include <xrpl/app/misc/Manifest.h>
#include <xrpld/app/misc/Manifest.h>
#include <xrpl/basics/StringUtilities.h>
#include <xrpl/basics/base64.h>
#include <xrpl/json/json_reader.h>