mirror of
https://github.com/Xahau/xahaud.git
synced 2026-03-12 07:32:26 +00:00
Compare commits
12 Commits
batch
...
HookAPISer
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8f244d888d | ||
|
|
3c49f80013 | ||
|
|
090e4ad25e | ||
|
|
7a0c914ce9 | ||
|
|
d712345c84 | ||
|
|
12e1afb694 | ||
|
|
c355ad9971 | ||
|
|
01e7ee4f03 | ||
|
|
222772d99b | ||
|
|
9e6135ba42 | ||
|
|
f0329b4054 | ||
|
|
5a9baed9d0 |
15
.github/actions/xahau-ga-dependencies/action.yml
vendored
15
.github/actions/xahau-ga-dependencies/action.yml
vendored
@@ -134,10 +134,17 @@ runs:
|
||||
- name: Export custom recipes
|
||||
shell: bash
|
||||
run: |
|
||||
conan export external/snappy --version 1.1.10 --user xahaud --channel stable
|
||||
conan export external/soci --version 4.0.3 --user xahaud --channel stable
|
||||
conan export external/wasmedge --version 0.11.2 --user xahaud --channel stable
|
||||
|
||||
# Export snappy if not already exported
|
||||
conan list snappy/1.1.10@xahaud/stable 2>/dev/null | (grep -q "not found" && exit 1 || exit 0) || \
|
||||
conan export external/snappy --version 1.1.10 --user xahaud --channel stable
|
||||
|
||||
# Export soci if not already exported
|
||||
conan list soci/4.0.3@xahaud/stable 2>/dev/null | (grep -q "not found" && exit 1 || exit 0) || \
|
||||
conan export external/soci --version 4.0.3 --user xahaud --channel stable
|
||||
|
||||
# Export wasmedge if not already exported
|
||||
conan list wasmedge/0.11.2@xahaud/stable 2>/dev/null | (grep -q "not found" && exit 1 || exit 0) || \
|
||||
conan export external/wasmedge --version 0.11.2 --user xahaud --channel stable
|
||||
- name: Install dependencies
|
||||
shell: bash
|
||||
env:
|
||||
|
||||
24
.github/workflows/guard-checker-build.yml
vendored
Normal file
24
.github/workflows/guard-checker-build.yml
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
name: Guard Checker Build
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
guard-checker-build:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- run-on: ubuntu-latest
|
||||
- run-on: macos-latest
|
||||
runs-on: ${{ matrix.run-on }}
|
||||
name: Guard Checker Build - ${{ matrix.run-on }}
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v6
|
||||
|
||||
- name: Build Guard Checker
|
||||
run: |
|
||||
cd include/xrpl/hook
|
||||
make guard_checker
|
||||
16
.github/workflows/verify-generated-headers.yml
vendored
16
.github/workflows/verify-generated-headers.yml
vendored
@@ -18,12 +18,26 @@ jobs:
|
||||
generator: bash ./hook/generate_sfcodes.sh
|
||||
- target: hook/tts.h
|
||||
generator: ./hook/generate_tts.sh
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-24.04
|
||||
env:
|
||||
CLANG_VERSION: 18
|
||||
name: ${{ matrix.target }}
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install clang-format
|
||||
run: |
|
||||
codename=$( lsb_release --codename --short )
|
||||
sudo tee /etc/apt/sources.list.d/llvm.list >/dev/null <<EOF
|
||||
deb http://apt.llvm.org/${codename}/ llvm-toolchain-${codename}-${CLANG_VERSION} main
|
||||
deb-src http://apt.llvm.org/${codename}/ llvm-toolchain-${codename}-${CLANG_VERSION} main
|
||||
EOF
|
||||
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add
|
||||
sudo apt-get update
|
||||
sudo apt-get install clang-format-${CLANG_VERSION}
|
||||
sudo ln -sf /usr/bin/clang-format-${CLANG_VERSION} /usr/local/bin/clang-format
|
||||
|
||||
- name: Verify ${{ matrix.target }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
12
.github/workflows/xahau-ga-macos.yml
vendored
12
.github/workflows/xahau-ga-macos.yml
vendored
@@ -43,14 +43,22 @@ jobs:
|
||||
# To isolate environments for each Runner, instead of installing globally with brew,
|
||||
# use mise to isolate environments for each Runner directory.
|
||||
- name: Setup toolchain (mise)
|
||||
uses: jdx/mise-action@v2
|
||||
uses: jdx/mise-action@v3.6.1
|
||||
with:
|
||||
cache: false
|
||||
install: true
|
||||
mise_toml: |
|
||||
[tools]
|
||||
cmake = "3.25.3"
|
||||
python = "3.12"
|
||||
pipx = "latest"
|
||||
conan = "2"
|
||||
ninja = "latest"
|
||||
ccache = "latest"
|
||||
|
||||
- name: Install tools via mise
|
||||
run: |
|
||||
mise install
|
||||
mise use cmake@3.25.3 python@3.12 pipx@latest conan@2 ninja@latest ccache@latest
|
||||
mise reshim
|
||||
echo "$HOME/.local/share/mise/shims" >> "$GITHUB_PATH"
|
||||
|
||||
|
||||
2
.mise.toml
Normal file
2
.mise.toml
Normal file
@@ -0,0 +1,2 @@
|
||||
[tools]
|
||||
clang-format = "18"
|
||||
@@ -10,6 +10,9 @@ Loop: test.jtx test.toplevel
|
||||
Loop: test.jtx test.unit_test
|
||||
test.unit_test == test.jtx
|
||||
|
||||
Loop: xrpl.hook xrpld.app
|
||||
xrpld.app > xrpl.hook
|
||||
|
||||
Loop: xrpl.protocol xrpld.app
|
||||
xrpld.app > xrpl.protocol
|
||||
|
||||
|
||||
@@ -140,6 +140,7 @@ test.toplevel > test.csf
|
||||
test.toplevel > xrpl.json
|
||||
test.unit_test > xrpl.basics
|
||||
xrpl.hook > xrpl.basics
|
||||
xrpl.hook > xrpl.protocol
|
||||
xrpl.json > xrpl.basics
|
||||
xrpl.protocol > xrpl.basics
|
||||
xrpl.protocol > xrpl.json
|
||||
@@ -154,7 +155,6 @@ xrpld.app > xrpl.basics
|
||||
xrpld.app > xrpld.conditions
|
||||
xrpld.app > xrpld.consensus
|
||||
xrpld.app > xrpld.perflog
|
||||
xrpld.app > xrpl.hook
|
||||
xrpld.app > xrpl.json
|
||||
xrpld.app > xrpl.resource
|
||||
xrpld.conditions > xrpl.basics
|
||||
|
||||
@@ -60,7 +60,7 @@ git-subtree. See those directories' README files for more details.
|
||||
- [Xrpl Documentation](https://xrpl.org)
|
||||
- [Xahau Documentation](https://xahau.network/)
|
||||
- [Hooks Technical Documentation](https://xrpl-hooks.readme.io/)
|
||||
- **Explorers**: Explore the Xahau ledger using various explorers:
|
||||
- **Explorers**: Explore the Xahau Network using various explorers:
|
||||
- [xahauexplorer.com](https://xahauexplorer.com)
|
||||
- [xahscan.com](https://xahscan.com)
|
||||
- [xahau.xrpl.org](https://xahau.xrpl.org)
|
||||
|
||||
@@ -62,11 +62,11 @@ For these complaints or reports, please [contact our support team](mailto:bugs@x
|
||||
### The following type of security problems are excluded
|
||||
|
||||
1. **In scope**. Only bugs in software under the scope of the program qualify. Currently, that means `xahaud` and `xahau-lib`.
|
||||
2. **Relevant**. A security issue, posing a danger to user funds, privacy or the operation of the Xahau Ledger.
|
||||
2. **Relevant**. A security issue, posing a danger to user funds, privacy or the operation of the Xahau Network.
|
||||
3. **Original and previously unknown**. Bugs that are already known and discussed in public do not qualify. Previously reported bugs, even if publicly unknown, are not eligible.
|
||||
4. **Specific**. We welcome general security advice or recommendations, but we cannot pay bounties for that.
|
||||
5. **Fixable**. There has to be something we can do to permanently fix the problem. Note that bugs in other people’s software may still qualify in some cases. For example, if you find a bug in a library that we use which can compromise the security of software that is in scope and we can get it fixed, you may qualify for a bounty.
|
||||
6. **Unused**. If you use the exploit to attack the Xahau Ledger, you do not qualify for a bounty. If you report a vulnerability used in an ongoing or past attack and there is specific, concrete evidence that suggests you are the attacker we reserve the right not to pay a bounty.
|
||||
6. **Unused**. If you use the exploit to attack the Xahau Network, you do not qualify for a bounty. If you report a vulnerability used in an ongoing or past attack and there is specific, concrete evidence that suggests you are the attacker we reserve the right not to pay a bounty.
|
||||
|
||||
Please note: Reports that are lacking any proof (such as screenshots or other data), detailed information or details on how to reproduce any unexpected result will be investigated but will not be eligible for any reward.
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ sto_erase(
|
||||
uint32_t field_id);
|
||||
|
||||
extern int64_t
|
||||
etxn_burden(void);
|
||||
etxn_burden();
|
||||
|
||||
extern int64_t
|
||||
etxn_details(uint32_t write_ptr, uint32_t write_len);
|
||||
@@ -94,7 +94,7 @@ extern int64_t
|
||||
etxn_reserve(uint32_t count);
|
||||
|
||||
extern int64_t
|
||||
etxn_generation(void);
|
||||
etxn_generation();
|
||||
|
||||
extern int64_t
|
||||
etxn_nonce(uint32_t write_ptr, uint32_t write_len);
|
||||
@@ -149,7 +149,7 @@ extern int64_t
|
||||
float_divide(int64_t float1, int64_t float2);
|
||||
|
||||
extern int64_t
|
||||
float_one(void);
|
||||
float_one();
|
||||
|
||||
extern int64_t
|
||||
float_mantissa(int64_t float1);
|
||||
@@ -167,13 +167,13 @@ extern int64_t
|
||||
float_root(int64_t float1, uint32_t n);
|
||||
|
||||
extern int64_t
|
||||
fee_base(void);
|
||||
fee_base();
|
||||
|
||||
extern int64_t
|
||||
ledger_seq(void);
|
||||
ledger_seq();
|
||||
|
||||
extern int64_t
|
||||
ledger_last_time(void);
|
||||
ledger_last_time();
|
||||
|
||||
extern int64_t
|
||||
ledger_last_hash(uint32_t write_ptr, uint32_t write_len);
|
||||
@@ -213,13 +213,13 @@ hook_param(
|
||||
uint32_t read_len);
|
||||
|
||||
extern int64_t
|
||||
hook_again(void);
|
||||
hook_again();
|
||||
|
||||
extern int64_t
|
||||
hook_skip(uint32_t read_ptr, uint32_t read_len, uint32_t flags);
|
||||
|
||||
extern int64_t
|
||||
hook_pos(void);
|
||||
hook_pos();
|
||||
|
||||
extern int64_t
|
||||
slot(uint32_t write_ptr, uint32_t write_len, uint32_t slot);
|
||||
@@ -299,19 +299,19 @@ extern int64_t
|
||||
trace_float(uint32_t read_ptr, uint32_t read_len, int64_t float1);
|
||||
|
||||
extern int64_t
|
||||
otxn_burden(void);
|
||||
otxn_burden();
|
||||
|
||||
extern int64_t
|
||||
otxn_field(uint32_t write_ptr, uint32_t write_len, uint32_t field_id);
|
||||
|
||||
extern int64_t
|
||||
otxn_generation(void);
|
||||
otxn_generation();
|
||||
|
||||
extern int64_t
|
||||
otxn_id(uint32_t write_ptr, uint32_t write_len, uint32_t flags);
|
||||
|
||||
extern int64_t
|
||||
otxn_type(void);
|
||||
otxn_type();
|
||||
|
||||
extern int64_t
|
||||
otxn_slot(uint32_t slot_no);
|
||||
|
||||
@@ -4,7 +4,7 @@ set -eu
|
||||
SCRIPT_DIR=$(dirname "$0")
|
||||
SCRIPT_DIR=$(cd "$SCRIPT_DIR" && pwd)
|
||||
|
||||
APPLY_HOOK="$SCRIPT_DIR/../src/xrpld/app/hook/applyHook.h"
|
||||
APPLY_HOOK="$SCRIPT_DIR/../include/xrpl/hook/hook_api.macro"
|
||||
|
||||
{
|
||||
echo '// For documentation please see: https://xrpl-hooks.readme.io/reference/'
|
||||
@@ -19,127 +19,36 @@ APPLY_HOOK="$SCRIPT_DIR/../src/xrpld/app/hook/applyHook.h"
|
||||
return s;
|
||||
}
|
||||
|
||||
function emit(ret, name, argc, argt, argn) {
|
||||
attr = (name == "_g") ? " __attribute__((noduplicate))" : "";
|
||||
if (!first)
|
||||
printf("\n");
|
||||
first = 0;
|
||||
printf("extern %s%s\n", ret, attr);
|
||||
if (argc == 0) {
|
||||
printf("%s(void);\n", name);
|
||||
return;
|
||||
}
|
||||
if (argc <= 3) {
|
||||
line = argt[1] " " argn[1];
|
||||
for (i = 2; i <= argc; ++i)
|
||||
line = line ", " argt[i] " " argn[i];
|
||||
printf("%s(%s);\n", name, line);
|
||||
return;
|
||||
}
|
||||
printf("%s(\n", name);
|
||||
for (i = 1; i <= argc; ++i) {
|
||||
sep = (i < argc) ? "," : ");";
|
||||
printf(" %s %s%s\n", argt[i], argn[i], sep);
|
||||
}
|
||||
}
|
||||
|
||||
function process(buffer, kind, payload, parts, n, i, arg, tokens, argc, argt, argn) {
|
||||
if (kind == "func")
|
||||
sub(/^DECLARE_HOOK_FUNCTION[[:space:]]*\(/, "", buffer);
|
||||
else
|
||||
sub(/^DECLARE_HOOK_FUNCNARG[[:space:]]*\(/, "", buffer);
|
||||
buffer = trim(buffer);
|
||||
sub(/\)[[:space:]]*$/, "", buffer);
|
||||
n = split(buffer, parts, ",");
|
||||
for (i = 1; i <= n; ++i)
|
||||
parts[i] = trim(parts[i]);
|
||||
ret = parts[1];
|
||||
name = parts[2];
|
||||
argc = 0;
|
||||
delete argt;
|
||||
delete argn;
|
||||
for (i = 3; i <= n; ++i) {
|
||||
arg = parts[i];
|
||||
if (arg == "")
|
||||
continue;
|
||||
split(arg, tokens, /[[:space:]]+/);
|
||||
if (length(tokens) < 2)
|
||||
continue;
|
||||
++argc;
|
||||
argt[argc] = tokens[1];
|
||||
argn[argc] = tokens[2];
|
||||
}
|
||||
emit(ret, name, argc, argt, argn);
|
||||
}
|
||||
|
||||
BEGIN {
|
||||
first = 1;
|
||||
in_block = 0;
|
||||
in_macro = 0;
|
||||
}
|
||||
|
||||
{
|
||||
line = $0;
|
||||
if (in_block) {
|
||||
if (line ~ /\*\//) {
|
||||
sub(/.*\*\//, "", line);
|
||||
in_block = 0;
|
||||
}
|
||||
else
|
||||
next;
|
||||
}
|
||||
while (line ~ /\/\*/) {
|
||||
if (line ~ /\/\*.*\*\//) {
|
||||
gsub(/\/\*.*\*\//, "", line);
|
||||
}
|
||||
else {
|
||||
sub(/\/\*.*/, "", line);
|
||||
in_block = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
sub(/\/\/.*$/, "", line);
|
||||
line = trim(line);
|
||||
if (line == "")
|
||||
next;
|
||||
|
||||
if (!in_macro && line ~ /^DECLARE_HOOK_FUNCTION\(/) {
|
||||
buffer = line;
|
||||
kind = "func";
|
||||
if (line ~ /\);[[:space:]]*$/) {
|
||||
sub(/\);[[:space:]]*$/, "", buffer);
|
||||
process(buffer, kind);
|
||||
}
|
||||
else
|
||||
in_macro = 1;
|
||||
|
||||
# Skip block comments
|
||||
if (line ~ /\/\*/) {
|
||||
next;
|
||||
}
|
||||
if (!in_macro && line ~ /^DECLARE_HOOK_FUNCNARG\(/) {
|
||||
buffer = line;
|
||||
kind = "narg";
|
||||
if (line ~ /\);[[:space:]]*$/) {
|
||||
sub(/\);[[:space:]]*$/, "", buffer);
|
||||
process(buffer, kind);
|
||||
|
||||
# Look for comment lines that start with // and contain function signature
|
||||
if (line ~ /^[[:space:]]*\/\/[[:space:]]*[a-zA-Z_][a-zA-Z0-9_]*[[:space:]]+[a-zA-Z_][a-zA-Z0-9_]*[[:space:]]*\(/) {
|
||||
# Remove leading // and trim
|
||||
sub(/^[[:space:]]*\/\/[[:space:]]*/, "", line);
|
||||
line = trim(line);
|
||||
|
||||
# Check if function name is "_g" to add attribute
|
||||
if (line ~ /[[:space:]]+_g[[:space:]]*\(/) {
|
||||
# Insert __attribute__((noduplicate)) before _g
|
||||
sub(/[[:space:]]+_g/, " __attribute__((noduplicate)) _g", line);
|
||||
}
|
||||
else
|
||||
in_macro = 1;
|
||||
next;
|
||||
|
||||
# printf("\n");
|
||||
|
||||
printf("extern %s\n\n", line);
|
||||
}
|
||||
if (in_macro) {
|
||||
buffer = buffer " " line;
|
||||
if (line ~ /\);[[:space:]]*$/) {
|
||||
sub(/\);[[:space:]]*$/, "", buffer);
|
||||
process(buffer, kind);
|
||||
in_macro = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
END {
|
||||
printf("\n");
|
||||
}
|
||||
' "$APPLY_HOOK"
|
||||
|
||||
echo '#define HOOK_EXTERN'
|
||||
echo '#endif // HOOK_EXTERN'
|
||||
}
|
||||
} | (
|
||||
cd "$SCRIPT_DIR/.."
|
||||
clang-format --style=file -
|
||||
)
|
||||
|
||||
@@ -138,14 +138,14 @@ public:
|
||||
template <typename U>
|
||||
requires std::convertible_to<U, T>
|
||||
constexpr Expected(U&& r)
|
||||
: Base(boost::outcome_v2::in_place_type_t<T>{}, std::forward<U>(r))
|
||||
: Base(boost::outcome_v2::success(T(std::forward<U>(r))))
|
||||
{
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
requires std::convertible_to<U, E> && (!std::is_reference_v<U>)
|
||||
constexpr Expected(Unexpected<U> e)
|
||||
: Base(boost::outcome_v2::in_place_type_t<E>{}, std::move(e.value()))
|
||||
: Base(boost::outcome_v2::failure(E(std::move(e.value()))))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -230,7 +230,8 @@ public:
|
||||
|
||||
template <typename U>
|
||||
requires std::convertible_to<U, E> && (!std::is_reference_v<U>)
|
||||
constexpr Expected(Unexpected<U> e) : Base(E(std::move(e.value())))
|
||||
constexpr Expected(Unexpected<U> e)
|
||||
: Base(boost::outcome_v2::failure(E(std::move(e.value()))))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,28 @@
|
||||
#include <vector>
|
||||
#ifndef HOOKENUM_INCLUDED
|
||||
#define HOOKENUM_INCLUDED 1
|
||||
|
||||
#ifndef GUARD_CHECKER_BUILD
|
||||
#include <xrpl/basics/base_uint.h>
|
||||
#include <xrpl/protocol/Feature.h>
|
||||
#include <xrpl/protocol/Rules.h>
|
||||
#else
|
||||
// Override uint256, Feature and Rules for guard checker build
|
||||
#define uint256 std::string
|
||||
#define featureHooksUpdate1 "1"
|
||||
#define fix20250131 "1"
|
||||
namespace hook_api {
|
||||
struct Rules
|
||||
{
|
||||
constexpr bool
|
||||
enabled(const uint256& feature) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
} // namespace hook_api
|
||||
#endif
|
||||
|
||||
namespace ripple {
|
||||
enum HookSetOperation : int8_t {
|
||||
hsoINVALID = -1,
|
||||
@@ -278,7 +300,17 @@ enum keylet_code : uint32_t {
|
||||
NFT_OFFER = 23,
|
||||
HOOK_DEFINITION = 24,
|
||||
HOOK_STATE_DIR = 25,
|
||||
CRON = 26
|
||||
CRON = 26,
|
||||
AMM = 27,
|
||||
BRIDGE = 28,
|
||||
XCHAIN_OWNED_CLAIM_ID = 29,
|
||||
XCHAIN_OWNED_CREATE_ACCOUNT_CLAIM_ID = 30,
|
||||
DID = 31,
|
||||
ORACLE = 32,
|
||||
MPTOKEN_ISSUANCE = 33,
|
||||
MPTOKEN = 34,
|
||||
CREDENTIAL = 35,
|
||||
PERMISSIONED_DOMAIN = 36,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -367,110 +399,59 @@ const uint8_t max_emit = 255;
|
||||
const uint8_t max_params = 16;
|
||||
const double fee_base_multiplier = 1.1f;
|
||||
|
||||
#define I32 0x7FU
|
||||
#define I64 0x7EU
|
||||
|
||||
#define HOOK_WRAP_PARAMS(...) __VA_ARGS__
|
||||
#define HOOK_API_DEFINITION(RETURN_TYPE, FUNCTION_NAME, PARAMS_TUPLE) \
|
||||
{ \
|
||||
#FUNCTION_NAME, \
|
||||
{ \
|
||||
RETURN_TYPE, HOOK_WRAP_PARAMS PARAMS_TUPLE \
|
||||
} \
|
||||
}
|
||||
|
||||
using APIWhitelist = std::map<std::string, std::vector<uint8_t>>;
|
||||
|
||||
// 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 APIWhitelist import_whitelist{
|
||||
// clang-format off
|
||||
HOOK_API_DEFINITION(I32, _g, (I32, I32)),
|
||||
HOOK_API_DEFINITION(I64, accept, (I32, I32, I64)),
|
||||
HOOK_API_DEFINITION(I64, rollback, (I32, I32, I64)),
|
||||
HOOK_API_DEFINITION(I64, util_raddr, (I32, I32, I32, I32)),
|
||||
HOOK_API_DEFINITION(I64, util_accid, (I32, I32, I32, I32)),
|
||||
HOOK_API_DEFINITION(I64, util_verify, (I32, I32, I32, I32, I32, I32)),
|
||||
HOOK_API_DEFINITION(I64, util_sha512h, (I32, I32, I32, I32)),
|
||||
HOOK_API_DEFINITION(I64, util_keylet, (I32, I32, I32, I32, I32, I32, I32, I32, I32)),
|
||||
HOOK_API_DEFINITION(I64, sto_validate, (I32, I32)),
|
||||
HOOK_API_DEFINITION(I64, sto_subfield, (I32, I32, I32)),
|
||||
HOOK_API_DEFINITION(I64, sto_subarray, (I32, I32, I32)),
|
||||
HOOK_API_DEFINITION(I64, sto_emplace, (I32, I32, I32, I32, I32, I32, I32)),
|
||||
HOOK_API_DEFINITION(I64, sto_erase, (I32, I32, I32, I32, I32)),
|
||||
HOOK_API_DEFINITION(I64, etxn_burden, ()),
|
||||
HOOK_API_DEFINITION(I64, etxn_details, (I32, I32)),
|
||||
HOOK_API_DEFINITION(I64, etxn_fee_base, (I32, I32)),
|
||||
HOOK_API_DEFINITION(I64, etxn_reserve, (I32)),
|
||||
HOOK_API_DEFINITION(I64, etxn_generation, ()),
|
||||
HOOK_API_DEFINITION(I64, etxn_nonce, (I32, I32)),
|
||||
HOOK_API_DEFINITION(I64, emit, (I32, I32, I32, I32)),
|
||||
HOOK_API_DEFINITION(I64, float_set, (I32, I64)),
|
||||
HOOK_API_DEFINITION(I64, float_multiply, (I64, I64)),
|
||||
HOOK_API_DEFINITION(I64, float_mulratio, (I64, I32, I32, I32)),
|
||||
HOOK_API_DEFINITION(I64, float_negate, (I64)),
|
||||
HOOK_API_DEFINITION(I64, float_compare, (I64, I64, I32)),
|
||||
HOOK_API_DEFINITION(I64, float_sum, (I64, I64)),
|
||||
HOOK_API_DEFINITION(I64, float_sto, (I32, I32, I32, I32, I32, I32, I64, I32)),
|
||||
HOOK_API_DEFINITION(I64, float_sto_set, (I32, I32)),
|
||||
HOOK_API_DEFINITION(I64, float_invert, (I64)),
|
||||
HOOK_API_DEFINITION(I64, float_divide, (I64, I64)),
|
||||
HOOK_API_DEFINITION(I64, float_one, ()),
|
||||
HOOK_API_DEFINITION(I64, float_mantissa, (I64)),
|
||||
HOOK_API_DEFINITION(I64, float_sign, (I64)),
|
||||
HOOK_API_DEFINITION(I64, float_int, (I64, I32, I32)),
|
||||
HOOK_API_DEFINITION(I64, float_log, (I64)),
|
||||
HOOK_API_DEFINITION(I64, float_root, (I64, I32)),
|
||||
HOOK_API_DEFINITION(I64, fee_base, ()),
|
||||
HOOK_API_DEFINITION(I64, ledger_seq, ()),
|
||||
HOOK_API_DEFINITION(I64, ledger_last_time, ()),
|
||||
HOOK_API_DEFINITION(I64, ledger_last_hash, (I32, I32)),
|
||||
HOOK_API_DEFINITION(I64, ledger_nonce, (I32, I32)),
|
||||
HOOK_API_DEFINITION(I64, ledger_keylet, (I32, I32, I32, I32, I32, I32)),
|
||||
HOOK_API_DEFINITION(I64, hook_account, (I32, I32)),
|
||||
HOOK_API_DEFINITION(I64, hook_hash, (I32, I32, I32)),
|
||||
HOOK_API_DEFINITION(I64, hook_param_set, (I32, I32, I32, I32, I32, I32)),
|
||||
HOOK_API_DEFINITION(I64, hook_param, (I32, I32, I32, I32)),
|
||||
HOOK_API_DEFINITION(I64, hook_again, ()),
|
||||
HOOK_API_DEFINITION(I64, hook_skip, (I32, I32, I32)),
|
||||
HOOK_API_DEFINITION(I64, hook_pos, ()),
|
||||
HOOK_API_DEFINITION(I64, slot, (I32, I32, I32)),
|
||||
HOOK_API_DEFINITION(I64, slot_clear, (I32)),
|
||||
HOOK_API_DEFINITION(I64, slot_count, (I32)),
|
||||
HOOK_API_DEFINITION(I64, slot_set, (I32, I32, I32)),
|
||||
HOOK_API_DEFINITION(I64, slot_size, (I32)),
|
||||
HOOK_API_DEFINITION(I64, slot_subarray, (I32, I32, I32)),
|
||||
HOOK_API_DEFINITION(I64, slot_subfield, (I32, I32, I32)),
|
||||
HOOK_API_DEFINITION(I64, slot_type, (I32, I32)),
|
||||
HOOK_API_DEFINITION(I64, slot_float, (I32)),
|
||||
HOOK_API_DEFINITION(I64, state_set, (I32, I32, I32, I32)),
|
||||
HOOK_API_DEFINITION(I64, state_foreign_set, (I32, I32, I32, I32, I32, I32, I32, I32)),
|
||||
HOOK_API_DEFINITION(I64, state, (I32, I32, I32, I32)),
|
||||
HOOK_API_DEFINITION(I64, state_foreign, (I32, I32, I32, I32, I32, I32, I32, I32)),
|
||||
HOOK_API_DEFINITION(I64, trace, (I32, I32, I32, I32, I32)),
|
||||
HOOK_API_DEFINITION(I64, trace_num, (I32, I32, I64)),
|
||||
HOOK_API_DEFINITION(I64, trace_float, (I32, I32, I64)),
|
||||
HOOK_API_DEFINITION(I64, otxn_burden, ()),
|
||||
HOOK_API_DEFINITION(I64, otxn_field, (I32, I32, I32)),
|
||||
HOOK_API_DEFINITION(I64, otxn_generation, ()),
|
||||
HOOK_API_DEFINITION(I64, otxn_id, (I32, I32, I32)),
|
||||
HOOK_API_DEFINITION(I64, otxn_type, ()),
|
||||
HOOK_API_DEFINITION(I64, otxn_slot, (I32)),
|
||||
HOOK_API_DEFINITION(I64, otxn_param, (I32, I32, I32, I32)),
|
||||
HOOK_API_DEFINITION(I64, meta_slot, (I32)),
|
||||
// clang-format on
|
||||
};
|
||||
inline APIWhitelist
|
||||
getImportWhitelist(Rules const& rules)
|
||||
{
|
||||
APIWhitelist whitelist;
|
||||
|
||||
// featureHooks1
|
||||
static const APIWhitelist import_whitelist_1{
|
||||
// clang-format off
|
||||
HOOK_API_DEFINITION(I64, xpop_slot, (I32, I32)),
|
||||
// clang-format on
|
||||
};
|
||||
#pragma push_macro("HOOK_API_DEFINITION")
|
||||
#undef HOOK_API_DEFINITION
|
||||
|
||||
#define int64_t 0x7EU
|
||||
#define int32_t 0x7FU
|
||||
#define uint32_t 0x7FU
|
||||
|
||||
#define HOOK_WRAP_PARAMS(...) __VA_ARGS__
|
||||
|
||||
#define HOOK_API_DEFINITION( \
|
||||
RETURN_TYPE, FUNCTION_NAME, PARAMS_TUPLE, AMENDMENT) \
|
||||
if (AMENDMENT == uint256{} || rules.enabled(AMENDMENT)) \
|
||||
whitelist[#FUNCTION_NAME] = { \
|
||||
RETURN_TYPE, HOOK_WRAP_PARAMS PARAMS_TUPLE};
|
||||
|
||||
#include "hook_api.macro"
|
||||
|
||||
#undef HOOK_API_DEFINITION
|
||||
#undef HOOK_WRAP_PARAMS
|
||||
#undef int64_t
|
||||
#undef int32_t
|
||||
#undef uint32_t
|
||||
#pragma pop_macro("HOOK_API_DEFINITION")
|
||||
|
||||
return whitelist;
|
||||
}
|
||||
|
||||
#undef HOOK_API_DEFINITION
|
||||
#undef I32
|
||||
#undef I64
|
||||
|
||||
enum GuardRulesVersion : uint64_t {
|
||||
GuardRuleFix20250131 = 0x00000001,
|
||||
};
|
||||
|
||||
inline uint64_t
|
||||
getGuardRulesVersion(Rules const& rules)
|
||||
{
|
||||
uint64_t version = 0;
|
||||
if (rules.enabled(fix20250131))
|
||||
version |= GuardRuleFix20250131;
|
||||
return version;
|
||||
}
|
||||
|
||||
}; // namespace hook_api
|
||||
#endif
|
||||
|
||||
@@ -634,7 +634,7 @@ check_guard(
|
||||
}
|
||||
else if (fc_type == 10) // memory.copy
|
||||
{
|
||||
if (rulesVersion & 0x02U)
|
||||
if (rulesVersion & hook_api::GuardRuleFix20250131)
|
||||
GUARD_ERROR("Memory.copy instruction is not allowed.");
|
||||
|
||||
REQUIRE(2);
|
||||
@@ -642,7 +642,7 @@ check_guard(
|
||||
}
|
||||
else if (fc_type == 11) // memory.fill
|
||||
{
|
||||
if (rulesVersion & 0x02U)
|
||||
if (rulesVersion & hook_api::GuardRuleFix20250131)
|
||||
GUARD_ERROR("Memory.fill instruction is not allowed.");
|
||||
|
||||
ADVANCE(1);
|
||||
@@ -826,6 +826,7 @@ validateGuards(
|
||||
std::vector<uint8_t> const& wasm,
|
||||
GuardLog guardLog,
|
||||
std::string guardLogAccStr,
|
||||
hook_api::APIWhitelist const import_whitelist,
|
||||
/* RH NOTE:
|
||||
* rules version is a bit field, so rule update 1 is 0x01, update 2 is 0x02
|
||||
* and update 3 is 0x04 ideally at rule version 3 all bits so far are set
|
||||
@@ -835,7 +836,7 @@ validateGuards(
|
||||
* might have unforeseen consequences, without also rolling back further
|
||||
* changes that are fine.
|
||||
*/
|
||||
uint64_t rulesVersion = 0)
|
||||
uint64_t rulesVersion = 0x00)
|
||||
{
|
||||
uint64_t byteCount = wasm.size();
|
||||
|
||||
@@ -1020,31 +1021,24 @@ validateGuards(
|
||||
int type_idx = parseLeb128(wasm, i, &i);
|
||||
CHECK_SHORT_HOOK();
|
||||
|
||||
auto it = import_whitelist.find(import_name);
|
||||
auto it_end = import_whitelist.end();
|
||||
bool found_in_whitelist = (it != it_end);
|
||||
|
||||
if (import_name == "_g")
|
||||
{
|
||||
guard_import_number = func_upto;
|
||||
}
|
||||
else if (
|
||||
hook_api::import_whitelist.find(import_name) ==
|
||||
hook_api::import_whitelist.end())
|
||||
if (!found_in_whitelist)
|
||||
{
|
||||
if (rulesVersion > 0 &&
|
||||
hook_api::import_whitelist_1.find(import_name) !=
|
||||
hook_api::import_whitelist_1.end())
|
||||
{
|
||||
// PASS, this is a version 1 api
|
||||
}
|
||||
else
|
||||
{
|
||||
GUARDLOG(hook::log::IMPORT_ILLEGAL)
|
||||
<< "Malformed transaction. "
|
||||
<< "Hook attempted to import a function that does "
|
||||
"not "
|
||||
<< "appear in the hook_api function set: `"
|
||||
<< import_name << "`"
|
||||
<< "\n";
|
||||
return {};
|
||||
}
|
||||
GUARDLOG(hook::log::IMPORT_ILLEGAL)
|
||||
<< "Malformed transaction. "
|
||||
<< "Hook attempted to import a function that does "
|
||||
"not "
|
||||
<< "appear in the hook_api function set: `"
|
||||
<< import_name << "`"
|
||||
<< "\n";
|
||||
return {};
|
||||
}
|
||||
|
||||
// add to import map
|
||||
@@ -1259,11 +1253,7 @@ 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;
|
||||
import_whitelist.find(api_name)->second;
|
||||
|
||||
if (!first_signature)
|
||||
{
|
||||
|
||||
347
include/xrpl/hook/HookAPI.h
Normal file
347
include/xrpl/hook/HookAPI.h
Normal file
@@ -0,0 +1,347 @@
|
||||
#ifndef HOOK_API_INCLUDED
|
||||
#define HOOK_API_INCLUDED 1
|
||||
|
||||
#include <xrpld/app/misc/Transaction.h>
|
||||
#include <xrpl/hook/Enum.h>
|
||||
|
||||
namespace hook {
|
||||
using namespace ripple;
|
||||
using HookReturnCode = hook_api::hook_return_code;
|
||||
|
||||
using Bytes = std::vector<std::uint8_t>;
|
||||
|
||||
struct HookContext; // defined in applyHook.h
|
||||
|
||||
class HookAPI
|
||||
{
|
||||
public:
|
||||
explicit HookAPI(HookContext& ctx) : hookCtx(ctx)
|
||||
{
|
||||
}
|
||||
|
||||
/// control APIs
|
||||
// _g
|
||||
// accept
|
||||
// rollback
|
||||
|
||||
/// util APIs
|
||||
Expected<std::string, HookReturnCode>
|
||||
util_raddr(Bytes const& accountID) const;
|
||||
|
||||
Expected<Bytes, HookReturnCode>
|
||||
util_accid(std::string raddress) const;
|
||||
|
||||
Expected<bool, HookReturnCode>
|
||||
util_verify(Slice const& data, Slice const& sig, Slice const& key) const;
|
||||
|
||||
uint256
|
||||
util_sha512h(Slice const& data) const;
|
||||
|
||||
// util_keylet()
|
||||
|
||||
/// sto APIs
|
||||
Expected<bool, HookReturnCode>
|
||||
sto_validate(Bytes const& data) const;
|
||||
|
||||
Expected<std::pair<uint32_t, uint32_t>, HookReturnCode>
|
||||
sto_subfield(Bytes const& data, uint32_t field_id) const;
|
||||
|
||||
Expected<std::pair<uint32_t, uint32_t>, HookReturnCode>
|
||||
sto_subarray(Bytes const& data, uint32_t index_id) const;
|
||||
|
||||
Expected<Bytes, HookReturnCode>
|
||||
sto_emplace(
|
||||
Bytes const& source_object,
|
||||
std::optional<Bytes> const& field_object,
|
||||
uint32_t field_id) const;
|
||||
|
||||
// sto_erase(): same as sto_emplace with field_object = nullopt
|
||||
|
||||
/// etxn APIs
|
||||
Expected<std::shared_ptr<Transaction>, HookReturnCode>
|
||||
emit(Slice const& txBlob) const;
|
||||
|
||||
Expected<uint64_t, HookReturnCode>
|
||||
etxn_burden() const;
|
||||
|
||||
Expected<uint64_t, HookReturnCode>
|
||||
etxn_fee_base(Slice const& txBlob) const;
|
||||
|
||||
Expected<uint64_t, HookReturnCode>
|
||||
etxn_details(uint8_t* out_ptr) const;
|
||||
|
||||
Expected<uint64_t, HookReturnCode>
|
||||
etxn_reserve(uint64_t count) const;
|
||||
|
||||
uint32_t
|
||||
etxn_generation() const;
|
||||
|
||||
Expected<uint256, HookReturnCode>
|
||||
etxn_nonce() const;
|
||||
|
||||
/// float APIs
|
||||
Expected<uint64_t, HookReturnCode>
|
||||
float_set(int32_t exponent, int64_t mantissa) const;
|
||||
|
||||
Expected<uint64_t, HookReturnCode>
|
||||
float_multiply(uint64_t float1, uint64_t float2) const;
|
||||
|
||||
Expected<uint64_t, HookReturnCode>
|
||||
float_mulratio(
|
||||
uint64_t float1,
|
||||
uint32_t round_up,
|
||||
uint32_t numerator,
|
||||
uint32_t denominator) const;
|
||||
|
||||
uint64_t
|
||||
float_negate(uint64_t float1) const;
|
||||
|
||||
Expected<uint64_t, HookReturnCode>
|
||||
float_compare(uint64_t float1, uint64_t float2, uint32_t mode) const;
|
||||
|
||||
Expected<uint64_t, HookReturnCode>
|
||||
float_sum(uint64_t float1, uint64_t float2) const;
|
||||
|
||||
Expected<Bytes, HookReturnCode>
|
||||
float_sto(
|
||||
std::optional<Currency> currency,
|
||||
std::optional<AccountID> issuer,
|
||||
uint64_t float1,
|
||||
uint32_t field_code,
|
||||
uint32_t write_len) const;
|
||||
|
||||
Expected<uint64_t, HookReturnCode>
|
||||
float_sto_set(Bytes const& data) const;
|
||||
|
||||
Expected<uint64_t, HookReturnCode>
|
||||
float_invert(uint64_t float1) const;
|
||||
|
||||
Expected<uint64_t, HookReturnCode>
|
||||
float_divide(uint64_t float1, uint64_t float2) const;
|
||||
|
||||
uint64_t
|
||||
float_one() const;
|
||||
|
||||
Expected<uint64_t, HookReturnCode>
|
||||
float_mantissa(uint64_t float1) const;
|
||||
|
||||
uint64_t
|
||||
float_sign(uint64_t float1) const;
|
||||
|
||||
Expected<uint64_t, HookReturnCode>
|
||||
float_int(uint64_t float1, uint32_t decimal_places, uint32_t absolute)
|
||||
const;
|
||||
|
||||
Expected<uint64_t, HookReturnCode>
|
||||
float_log(uint64_t float1) const;
|
||||
|
||||
Expected<uint64_t, HookReturnCode>
|
||||
float_root(uint64_t float1, uint32_t n) const;
|
||||
|
||||
/// otxn APIs
|
||||
uint64_t
|
||||
otxn_burden() const;
|
||||
|
||||
uint32_t
|
||||
otxn_generation() const;
|
||||
|
||||
Expected<const STBase*, HookReturnCode>
|
||||
otxn_field(uint32_t field_id) const;
|
||||
|
||||
Expected<uint256, HookReturnCode>
|
||||
otxn_id(uint32_t flags) const;
|
||||
|
||||
TxType
|
||||
otxn_type() const;
|
||||
|
||||
Expected<uint32_t, HookReturnCode>
|
||||
otxn_slot(uint32_t slot_into) const;
|
||||
|
||||
Expected<Blob, HookReturnCode>
|
||||
otxn_param(Bytes const& param_name) const;
|
||||
|
||||
/// hook APIs
|
||||
AccountID
|
||||
hook_account() const;
|
||||
|
||||
Expected<ripple::uint256, HookReturnCode>
|
||||
hook_hash(int32_t hook_no) const;
|
||||
|
||||
Expected<int64_t, HookReturnCode>
|
||||
hook_again() const;
|
||||
|
||||
Expected<Blob, HookReturnCode>
|
||||
hook_param(Bytes const& paramName) const;
|
||||
|
||||
Expected<uint64_t, HookReturnCode>
|
||||
hook_param_set(
|
||||
uint256 const& hash,
|
||||
Bytes const& paramName,
|
||||
Bytes const& paramValue) const;
|
||||
|
||||
Expected<uint64_t, HookReturnCode>
|
||||
hook_skip(uint256 const& hash, uint32_t flags) const;
|
||||
|
||||
uint8_t
|
||||
hook_pos() const;
|
||||
|
||||
/// ledger APIs
|
||||
uint64_t
|
||||
fee_base() const;
|
||||
|
||||
uint32_t
|
||||
ledger_seq() const;
|
||||
|
||||
uint256
|
||||
ledger_last_hash() const;
|
||||
|
||||
uint64_t
|
||||
ledger_last_time() const;
|
||||
|
||||
Expected<uint256, HookReturnCode>
|
||||
ledger_nonce() const;
|
||||
|
||||
Expected<Keylet, HookReturnCode>
|
||||
ledger_keylet(Keylet const& klLo, Keylet const& klHi) const;
|
||||
|
||||
/// state APIs
|
||||
|
||||
// state(): same as state_foreign with ns = 0 and account = hook_account()
|
||||
|
||||
Expected<Bytes, HookReturnCode>
|
||||
state_foreign(
|
||||
uint256 const& key,
|
||||
uint256 const& ns,
|
||||
AccountID const& account) const;
|
||||
|
||||
// state_set(): same as state_foreign_set with ns = 0 and account =
|
||||
|
||||
Expected<uint64_t, HookReturnCode>
|
||||
state_foreign_set(
|
||||
uint256 const& key,
|
||||
uint256 const& ns,
|
||||
AccountID const& account,
|
||||
Bytes& data) const;
|
||||
|
||||
/// slot APIs
|
||||
Expected<const STBase*, HookReturnCode>
|
||||
slot(uint32_t slot_no) const;
|
||||
|
||||
Expected<uint64_t, HookReturnCode>
|
||||
slot_clear(uint32_t slot_no) const;
|
||||
|
||||
Expected<uint64_t, HookReturnCode>
|
||||
slot_count(uint32_t slot_no) const;
|
||||
|
||||
Expected<uint32_t, HookReturnCode>
|
||||
slot_set(Bytes const& data, uint32_t slot_no) const;
|
||||
|
||||
Expected<uint64_t, HookReturnCode>
|
||||
slot_size(uint32_t slot_no) const;
|
||||
|
||||
Expected<uint32_t, HookReturnCode>
|
||||
slot_subarray(uint32_t parent_slot, uint32_t array_id, uint32_t new_slot)
|
||||
const;
|
||||
|
||||
Expected<uint32_t, HookReturnCode>
|
||||
slot_subfield(uint32_t parent_slot, uint32_t field_id, uint32_t new_slot)
|
||||
const;
|
||||
|
||||
Expected<std::variant<STBase, STAmount>, HookReturnCode>
|
||||
slot_type(uint32_t slot_no, uint32_t flags) const;
|
||||
|
||||
Expected<uint64_t, HookReturnCode>
|
||||
slot_float(uint32_t slot_no) const;
|
||||
|
||||
/// trace APIs
|
||||
// trace
|
||||
// trace_num
|
||||
// trace_float
|
||||
|
||||
Expected<uint32_t, HookReturnCode>
|
||||
meta_slot(uint32_t slot_into) const;
|
||||
|
||||
Expected<std::pair<uint32_t, uint32_t>, HookReturnCode>
|
||||
xpop_slot(uint32_t slot_into_tx, uint32_t slot_into_meta) const;
|
||||
|
||||
private:
|
||||
HookContext& hookCtx;
|
||||
|
||||
inline int32_t
|
||||
no_free_slots() const;
|
||||
|
||||
inline std::optional<int32_t>
|
||||
get_free_slot() const;
|
||||
|
||||
inline Expected<uint64_t, HookReturnCode>
|
||||
float_multiply_internal_parts(
|
||||
uint64_t man1,
|
||||
int32_t exp1,
|
||||
bool neg1,
|
||||
uint64_t man2,
|
||||
int32_t exp2,
|
||||
bool neg2) const;
|
||||
|
||||
inline Expected<uint64_t, HookReturnCode>
|
||||
mulratio_internal(
|
||||
int64_t& man1,
|
||||
int32_t& exp1,
|
||||
bool round_up,
|
||||
uint32_t numerator,
|
||||
uint32_t denominator) const;
|
||||
|
||||
inline Expected<uint64_t, HookReturnCode>
|
||||
float_divide_internal(uint64_t float1, uint64_t float2) const;
|
||||
|
||||
inline Expected<uint64_t, HookReturnCode>
|
||||
double_to_xfl(double x) const;
|
||||
|
||||
std::optional<ripple::Keylet>
|
||||
unserialize_keylet(Bytes const& data) const;
|
||||
|
||||
// update the state cache
|
||||
inline std::optional<
|
||||
std::reference_wrapper<std::pair<bool, ripple::Blob> const>>
|
||||
lookup_state_cache(
|
||||
AccountID const& acc,
|
||||
uint256 const& ns,
|
||||
uint256 const& key) const;
|
||||
|
||||
// check the state cache
|
||||
inline Expected<uint64_t, HookReturnCode>
|
||||
set_state_cache(
|
||||
AccountID const& acc,
|
||||
uint256 const& ns,
|
||||
uint256 const& key,
|
||||
Bytes const& data,
|
||||
bool modified) const;
|
||||
|
||||
// these are only used by get_stobject_length below
|
||||
enum parse_error {
|
||||
pe_unexpected_end = -1,
|
||||
pe_unknown_type_early = -2, // detected early
|
||||
pe_unknown_type_late = -3, // end of function
|
||||
pe_excessive_nesting = -4,
|
||||
pe_excessive_size = -5
|
||||
};
|
||||
|
||||
inline Expected<
|
||||
int32_t,
|
||||
parse_error>
|
||||
get_stobject_length(
|
||||
unsigned char* start, // in - begin iterator
|
||||
unsigned char* maxptr, // in - end iterator
|
||||
int& type, // out - populated by serialized type code
|
||||
int& field, // out - populated by serialized field code
|
||||
int& payload_start, // out - the start of actual payload data for
|
||||
// this type
|
||||
int& payload_length, // out - the length of actual payload data for
|
||||
// this type
|
||||
Rules const& rules,
|
||||
int recursion_depth = 0) // used internally
|
||||
const;
|
||||
};
|
||||
|
||||
} // namespace hook
|
||||
|
||||
#endif // HOOK_API_INCLUDED
|
||||
@@ -25,7 +25,8 @@
|
||||
_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)
|
||||
VA_NARGS_IMPL( \
|
||||
__VA_OPT__(__VA_ARGS__, ) 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
|
||||
#define FIRST(a, b) a
|
||||
#define SECOND(a, b) b
|
||||
#define STRIP_TYPES(...) FOR_VARS(SECOND, 0, __VA_ARGS__)
|
||||
@@ -88,30 +89,18 @@
|
||||
|
||||
#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; \
|
||||
#define DECLARE_HOOK_FUNCTION(R, F, ...) \
|
||||
R F(hook::HookContext& hookCtx, \
|
||||
WasmEdge_CallingFrameContext const& frameCtx __VA_OPT__( \
|
||||
COMMA __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 DEFINE_HOOK_FUNCTION(R, F, ...) \
|
||||
@@ -121,61 +110,35 @@
|
||||
const WasmEdge_Value* in, \
|
||||
WasmEdge_Value* out) \
|
||||
{ \
|
||||
int _stack = 0; \
|
||||
FOR_VARS(VAR_ASSIGN, 2, __VA_ARGS__); \
|
||||
__VA_OPT__(int _stack = 0;) \
|
||||
__VA_OPT__(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__)); \
|
||||
*const_cast<WasmEdge_CallingFrameContext*>(frameCtx) \
|
||||
__VA_OPT__(COMMA 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__)}; \
|
||||
__VA_OPT__(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__), \
|
||||
VA_NARGS(NULL __VA_OPT__(, __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)
|
||||
WasmEdge_CallingFrameContext const& frameCtx __VA_OPT__( \
|
||||
COMMA __VA_ARGS__))
|
||||
|
||||
#define HOOK_SETUP() \
|
||||
try \
|
||||
@@ -190,6 +153,7 @@
|
||||
[[maybe_unused]] const uint64_t memory_length = \
|
||||
WasmEdge_MemoryInstanceGetPageSize(memoryCtx) * \
|
||||
WasmEdge_kPageSize; \
|
||||
[[maybe_unused]] auto& api = hookCtx.api(); \
|
||||
if (!memoryCtx || !memory || !memory_length) \
|
||||
return INTERNAL_ERROR;
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#define GUARD_CHECKER_BUILD
|
||||
#include "Enum.h"
|
||||
#include "Guard.h"
|
||||
#include <fcntl.h>
|
||||
#include <iostream>
|
||||
@@ -79,7 +81,15 @@ main(int argc, char** argv)
|
||||
|
||||
close(fd);
|
||||
|
||||
auto result = validateGuards(hook, std::cout, "", 3);
|
||||
// Dummy rules for guard checker build
|
||||
hook_api::Rules rules;
|
||||
|
||||
auto result = validateGuards(
|
||||
hook,
|
||||
std::cout,
|
||||
"",
|
||||
hook_api::getImportWhitelist(rules),
|
||||
hook_api::getGuardRulesVersion(rules));
|
||||
|
||||
if (!result)
|
||||
{
|
||||
|
||||
369
include/xrpl/hook/hook_api.macro
Normal file
369
include/xrpl/hook/hook_api.macro
Normal file
@@ -0,0 +1,369 @@
|
||||
// int32_t _g(uint32_t guard_id, uint32_t maxiter);
|
||||
HOOK_API_DEFINITION(
|
||||
int32_t, _g, (uint32_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t accept(uint32_t read_ptr, uint32_t read_len, int64_t error_code);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, accept, (uint32_t, uint32_t, int64_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t rollback(uint32_t read_ptr, uint32_t read_len, int64_t error_code);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, rollback, (uint32_t, uint32_t, int64_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t util_raddr(uint32_t write_ptr, uint32_t write_len, uint32_t read_ptr, uint32_t read_len);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, util_raddr, (uint32_t, uint32_t, uint32_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t util_accid(uint32_t write_ptr, uint32_t write_len, uint32_t read_ptr, uint32_t read_len);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, util_accid, (uint32_t, uint32_t, uint32_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t util_verify(uint32_t dread_ptr, uint32_t dread_len, uint32_t sread_ptr, uint32_t sread_len, uint32_t kread_ptr, uint32_t kread_len);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, util_verify, (uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t util_sha512h(uint32_t write_ptr, uint32_t write_len, uint32_t read_ptr, uint32_t read_len);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, util_sha512h, (uint32_t, uint32_t, uint32_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t util_keylet(uint32_t write_ptr, uint32_t write_len, uint32_t keylet_type, uint32_t a, uint32_t b, uint32_t c, uint32_t d, uint32_t e, uint32_t f);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, util_keylet, (uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t sto_validate(uint32_t tread_ptr, uint32_t tread_len);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, sto_validate, (uint32_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t sto_subfield(uint32_t read_ptr, uint32_t read_len, uint32_t field_id);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, sto_subfield, (uint32_t, uint32_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t sto_subarray(uint32_t read_ptr, uint32_t read_len, uint32_t array_id);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, sto_subarray, (uint32_t, uint32_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t sto_emplace(uint32_t write_ptr, uint32_t write_len, uint32_t sread_ptr, uint32_t sread_len, uint32_t fread_ptr, uint32_t fread_len, uint32_t field_id);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, sto_emplace, (uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t sto_erase(uint32_t write_ptr, uint32_t write_len, uint32_t read_ptr, uint32_t read_len, uint32_t field_id);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, sto_erase, (uint32_t, uint32_t, uint32_t, uint32_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t etxn_burden();
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, etxn_burden, (),
|
||||
uint256{})
|
||||
|
||||
// int64_t etxn_details(uint32_t write_ptr, uint32_t write_len);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, etxn_details, (uint32_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t etxn_fee_base(uint32_t read_ptr, uint32_t read_len);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, etxn_fee_base, (uint32_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t etxn_reserve(uint32_t count);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, etxn_reserve, (uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t etxn_generation();
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, etxn_generation, (),
|
||||
uint256{})
|
||||
|
||||
// int64_t etxn_nonce(uint32_t write_ptr, uint32_t write_len);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, etxn_nonce, (uint32_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t emit(uint32_t write_ptr, uint32_t write_len, uint32_t read_ptr, uint32_t read_len);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, emit, (uint32_t, uint32_t, uint32_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t float_set(int32_t exponent, int64_t mantissa);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, float_set, (int32_t, int64_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t float_multiply(int64_t float1, int64_t float2);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, float_multiply, (int64_t, int64_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t float_mulratio(int64_t float1, uint32_t round_up, uint32_t numerator, uint32_t denominator);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, float_mulratio, (int64_t, uint32_t, uint32_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t float_negate(int64_t float1);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, float_negate, (int64_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t float_compare(int64_t float1, int64_t float2, uint32_t mode);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, float_compare, (int64_t, int64_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t float_sum(int64_t float1, int64_t float2);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, float_sum, (int64_t, int64_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t float_sto(uint32_t write_ptr, uint32_t write_len, uint32_t cread_ptr, uint32_t cread_len, uint32_t iread_ptr, uint32_t iread_len, int64_t float1, uint32_t field_code);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, float_sto, (uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, int64_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t float_sto_set(uint32_t read_ptr, uint32_t read_len);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, float_sto_set, (uint32_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t float_invert(int64_t float1);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, float_invert, (int64_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t float_divide(int64_t float1, int64_t float2);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, float_divide, (int64_t, int64_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t float_one();
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, float_one, (),
|
||||
uint256{})
|
||||
|
||||
// int64_t float_mantissa(int64_t float1);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, float_mantissa, (int64_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t float_sign(int64_t float1);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, float_sign, (int64_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t float_int(int64_t float1, uint32_t decimal_places, uint32_t abs);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, float_int, (int64_t, uint32_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t float_log(int64_t float1);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, float_log, (int64_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t float_root(int64_t float1, uint32_t n);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, float_root, (int64_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t fee_base();
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, fee_base, (),
|
||||
uint256{})
|
||||
|
||||
// int64_t ledger_seq();
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, ledger_seq, (),
|
||||
uint256{})
|
||||
|
||||
// int64_t ledger_last_time();
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, ledger_last_time, (),
|
||||
uint256{})
|
||||
|
||||
// int64_t ledger_last_hash(uint32_t write_ptr, uint32_t write_len);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, ledger_last_hash, (uint32_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t ledger_nonce(uint32_t write_ptr, uint32_t write_len);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, ledger_nonce, (uint32_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t ledger_keylet(uint32_t write_ptr, uint32_t write_len, uint32_t lread_ptr, uint32_t lread_len, uint32_t hread_ptr, uint32_t hread_len);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, ledger_keylet, (uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t hook_account(uint32_t write_ptr, uint32_t write_len);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, hook_account, (uint32_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t hook_hash(uint32_t write_ptr, uint32_t write_len, int32_t hook_no);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, hook_hash, (uint32_t, uint32_t, int32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t hook_param_set(uint32_t read_ptr, uint32_t read_len, uint32_t kread_ptr, uint32_t kread_len, uint32_t hread_ptr, uint32_t hread_len);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, hook_param_set, (uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t hook_param(uint32_t write_ptr, uint32_t write_len, uint32_t read_ptr, uint32_t read_len);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, hook_param, (uint32_t, uint32_t, uint32_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t hook_again();
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, hook_again, (),
|
||||
uint256{})
|
||||
|
||||
// int64_t hook_skip(uint32_t read_ptr, uint32_t read_len, uint32_t flags);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, hook_skip, (uint32_t, uint32_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t hook_pos();
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, hook_pos, (),
|
||||
uint256{})
|
||||
|
||||
// int64_t slot(uint32_t write_ptr, uint32_t write_len, uint32_t slot);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, slot, (uint32_t, uint32_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t slot_clear(uint32_t slot);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, slot_clear, (uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t slot_count(uint32_t slot);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, slot_count, (uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t slot_set(uint32_t read_ptr, uint32_t read_len, uint32_t slot);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, slot_set, (uint32_t, uint32_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t slot_size(uint32_t slot);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, slot_size, (uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t slot_subarray(uint32_t parent_slot, uint32_t array_id, uint32_t new_slot);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, slot_subarray, (uint32_t, uint32_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t slot_subfield(uint32_t parent_slot, uint32_t field_id, uint32_t new_slot);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, slot_subfield, (uint32_t, uint32_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t slot_type(uint32_t slot_no, uint32_t flags);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, slot_type, (uint32_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t slot_float(uint32_t slot_no);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, slot_float, (uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t state_set(uint32_t read_ptr, uint32_t read_len, uint32_t kread_ptr, uint32_t kread_len);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, state_set, (uint32_t, uint32_t, uint32_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t state_foreign_set(uint32_t read_ptr, uint32_t read_len, uint32_t kread_ptr, uint32_t kread_len, uint32_t nread_ptr, uint32_t nread_len, uint32_t aread_ptr, uint32_t aread_len);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, state_foreign_set, (uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t state(uint32_t write_ptr, uint32_t write_len, uint32_t kread_ptr, uint32_t kread_len);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, state, (uint32_t, uint32_t, uint32_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t state_foreign(uint32_t write_ptr, uint32_t write_len, uint32_t kread_ptr, uint32_t kread_len, uint32_t nread_ptr, uint32_t nread_len, uint32_t aread_ptr, uint32_t aread_len);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, state_foreign, (uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t trace(uint32_t mread_ptr, uint32_t mread_len, uint32_t dread_ptr, uint32_t dread_len, uint32_t as_hex);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, trace, (uint32_t, uint32_t, uint32_t, uint32_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t trace_num(uint32_t read_ptr, uint32_t read_len, int64_t number);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, trace_num, (uint32_t, uint32_t, int64_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t trace_float(uint32_t read_ptr, uint32_t read_len, int64_t float1);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, trace_float, (uint32_t, uint32_t, int64_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t otxn_burden();
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, otxn_burden, (),
|
||||
uint256{})
|
||||
|
||||
// int64_t otxn_field(uint32_t write_ptr, uint32_t write_len, uint32_t field_id);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, otxn_field, (uint32_t, uint32_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t otxn_generation();
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, otxn_generation, (),
|
||||
uint256{})
|
||||
|
||||
// int64_t otxn_id(uint32_t write_ptr, uint32_t write_len, uint32_t flags);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, otxn_id, (uint32_t, uint32_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t otxn_type();
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, otxn_type, (),
|
||||
uint256{})
|
||||
|
||||
// int64_t otxn_slot(uint32_t slot_no);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, otxn_slot, (uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t otxn_param(uint32_t write_ptr, uint32_t write_len, uint32_t read_ptr, uint32_t read_len);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, otxn_param, (uint32_t, uint32_t, uint32_t, uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t meta_slot(uint32_t slot_no);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, meta_slot, (uint32_t),
|
||||
uint256{})
|
||||
|
||||
// int64_t xpop_slot(uint32_t slot_no_tx, uint32_t slot_no_meta);
|
||||
HOOK_API_DEFINITION(
|
||||
int64_t, xpop_slot, (uint32_t, uint32_t),
|
||||
featureHooksUpdate1)
|
||||
@@ -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 = 110;
|
||||
static constexpr std::size_t numFeatures = 111;
|
||||
|
||||
/** Amendments that this server supports and the default voting behavior.
|
||||
Whether they are enabled depends on the Rules defined in the validated
|
||||
|
||||
@@ -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(HookAPISerializedType240, Supported::yes, VoteBehavior::DefaultNo)
|
||||
XRPL_FEATURE(PermissionedDomains, Supported::no, VoteBehavior::DefaultNo)
|
||||
XRPL_FEATURE(DynamicNFT, Supported::no, VoteBehavior::DefaultNo)
|
||||
XRPL_FEATURE(Credentials, Supported::no, VoteBehavior::DefaultNo)
|
||||
|
||||
@@ -487,7 +487,7 @@ isMemoOkay(STObject const& st, std::string& reason)
|
||||
if (!paramObj->isFieldPresent(sfHookParameterValue) ||
|
||||
paramObj->getFieldVL(sfHookParameterValue).size() > maxVal)
|
||||
{
|
||||
reason = "HookParameterValue cannot exceed 128 bytes.";
|
||||
reason = "HookParameterValue cannot exceed 256 bytes.";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
4543
src/test/app/HookAPI_test.cpp
Normal file
4543
src/test/app/HookAPI_test.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@@ -2579,6 +2579,7 @@ public:
|
||||
|
||||
auto const alice = Account{"alice"};
|
||||
auto const bob = Account{"bob"};
|
||||
|
||||
env.fund(XRP(10000), alice);
|
||||
env.fund(XRP(10000), bob);
|
||||
|
||||
@@ -3094,6 +3095,7 @@ public:
|
||||
extern int64_t rollback (uint32_t read_ptr, uint32_t read_len, int64_t error_code);
|
||||
extern int64_t etxn_details (uint32_t, uint32_t);
|
||||
extern int64_t etxn_reserve(uint32_t);
|
||||
extern int64_t hook_hash (uint32_t, uint32_t, int32_t);
|
||||
#define TOO_SMALL -4
|
||||
#define OUT_OF_BOUNDS -1
|
||||
#define PREREQUISITE_NOT_MET -9
|
||||
@@ -3116,6 +3118,45 @@ public:
|
||||
etxn_reserve(1);
|
||||
ASSERT(etxn_details((uint32_t)det, 116) == 116);
|
||||
|
||||
uint8_t expected1[49] = {
|
||||
0xEDU, 0x20U, 0x2EU, 0x00U, 0x00U, 0x00U, 0x01U, 0x3DU, 0x00U, 0x00U,
|
||||
0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x01U, 0x5BU, 0xB8U, 0x05U, 0xD6U,
|
||||
0xC3U, 0x52U, 0xDFU, 0x7AU, 0x27U, 0x76U, 0x6DU, 0xC0U, 0x20U, 0x47U,
|
||||
0xB7U, 0x64U, 0x22U, 0x5AU, 0xB7U, 0x5DU, 0xF3U, 0xFAU, 0x0DU, 0xE3U,
|
||||
0xBDU, 0xC6U, 0x40U, 0xBAU, 0xD0U, 0x0AU, 0x66U, 0xEBU, 0x68U,
|
||||
};
|
||||
// 0x5CU
|
||||
// EmitNonce 32bytes
|
||||
uint8_t expected_emit_nonce[32] = {
|
||||
0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU,
|
||||
0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU,
|
||||
0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU,
|
||||
0xFFU, 0xFFU
|
||||
};
|
||||
// 0x5DU,
|
||||
// EmitHookHash
|
||||
uint8_t expected_hook_hash[32] = {
|
||||
0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU,
|
||||
0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU,
|
||||
0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU,
|
||||
0xFFU, 0xFFU,
|
||||
};
|
||||
// 0xE1U
|
||||
|
||||
// current hook hash
|
||||
ASSERT(hook_hash((uint32_t)expected_hook_hash, 32, -1) == 32);
|
||||
|
||||
for (int i = 0; GUARD(49), i < sizeof(expected1); ++i)
|
||||
ASSERT(det[i] == expected1[i]);
|
||||
ASSERT(det[49] == 0x5CU);
|
||||
// TODO: need to test this
|
||||
// for (int i = 0; GUARD(32), i < sizeof(expected_emit_nonce); ++i)
|
||||
// ASSERT(det[50 + i] == expected_emit_nonce[i]);
|
||||
ASSERT(det[82] == 0x5DU);
|
||||
for (int i = 0; GUARD(32), i < sizeof(expected_hook_hash); ++i)
|
||||
ASSERT(det[83 + i] == expected_hook_hash[i]);
|
||||
ASSERT(det[115] == 0xE1);
|
||||
|
||||
return accept(0,0,0);
|
||||
}
|
||||
)[test.hook]"];
|
||||
@@ -3280,6 +3321,7 @@ public:
|
||||
}
|
||||
|
||||
ASSERT(etxn_nonce((uint32_t)nonce, 116) == TOO_MANY_NONCES);
|
||||
ASSERT(etxn_nonce((uint32_t)nonce, 31) == TOO_MANY_NONCES);
|
||||
|
||||
return accept(0,0,0);
|
||||
}
|
||||
@@ -6872,7 +6914,10 @@ public:
|
||||
std::vector<std::string> const keys = {
|
||||
"ED74D4036C6591A4BDF9C54CEFA39B996A5DCE5F86D11FDA1874481CE9D5A1CDC"
|
||||
"1"};
|
||||
Env env{*this, network::makeNetworkVLConfig(21337, keys)};
|
||||
Env env{
|
||||
*this,
|
||||
network::makeNetworkVLConfig(21337, keys),
|
||||
features - featureHooksUpdate1};
|
||||
|
||||
auto const master = Account("masterpassphrase");
|
||||
env(noop(master), fee(10'000'000'000), ter(tesSUCCESS));
|
||||
@@ -6950,6 +6995,16 @@ public:
|
||||
}
|
||||
)[test.hook]"];
|
||||
|
||||
// before featureHooksUpdate1
|
||||
env(ripple::test::jtx::hook(alice, {{hso(hook, overrideFlag)}}, 0),
|
||||
M("set xpop_slot (disabled)"),
|
||||
HSFEE,
|
||||
ter(temMALFORMED));
|
||||
env.close();
|
||||
|
||||
env.enableFeature(featureHooksUpdate1);
|
||||
env.close();
|
||||
|
||||
// install the hook on alice
|
||||
env(ripple::test::jtx::hook(alice, {{hso(hook, overrideFlag)}}, 0),
|
||||
M("set xpop_slot"),
|
||||
@@ -10896,6 +10951,186 @@ public:
|
||||
|
||||
// invoke the hook
|
||||
env(pay(bob, alice, XRP(1)), M("test sto_validate"), fee(XRP(1)));
|
||||
|
||||
{
|
||||
// test STIs
|
||||
TestHook hook = wasm[R"[test.hook](
|
||||
#include <stdint.h>
|
||||
extern int32_t _g (uint32_t id, uint32_t maxiter);
|
||||
#define GUARD(maxiter) _g((1ULL << 31U) + __LINE__, (maxiter)+1)
|
||||
extern int64_t accept (uint32_t read_ptr, uint32_t read_len, int64_t error_code);
|
||||
extern int64_t rollback (uint32_t read_ptr, uint32_t read_len, int64_t error_code);
|
||||
extern int64_t sto_validate(uint32_t, uint32_t);
|
||||
extern int64_t otxn_param(uint32_t, uint32_t, uint32_t, uint32_t);
|
||||
#define ASSERT(x)\
|
||||
if (!(x))\
|
||||
rollback((uint32_t)#x, sizeof(#x), __LINE__);
|
||||
#define SBUF(x) (uint32_t)(x), sizeof(x)
|
||||
|
||||
uint8_t buf[1000];
|
||||
int64_t hook(uint32_t reserved)
|
||||
{
|
||||
_g(1,1);
|
||||
|
||||
int64_t size = otxn_param(SBUF(buf), "V", 1);
|
||||
int64_t result = sto_validate(buf, size);
|
||||
|
||||
accept(0,0,result);
|
||||
}
|
||||
)[test.hook]"];
|
||||
|
||||
for (auto feature : {
|
||||
features - featureHookAPISerializedType240,
|
||||
features | featureHookAPISerializedType240,
|
||||
})
|
||||
{
|
||||
Env env{*this, feature};
|
||||
|
||||
env.fund(XRP(10000), alice, bob);
|
||||
env.close();
|
||||
|
||||
auto hasEnabled = env.current()->rules().enabled(
|
||||
featureHookAPISerializedType240);
|
||||
|
||||
// install the hook on alice
|
||||
env(ripple::test::jtx::hook(
|
||||
alice, {{hso(hook, overrideFlag)}}, 0),
|
||||
M("set sto_validate"),
|
||||
HSFEE);
|
||||
env.close();
|
||||
|
||||
// invoke the hook
|
||||
auto buildTx = [&](std::string value) {
|
||||
auto payJv = pay(bob, alice, XRP(1));
|
||||
|
||||
Json::Value params{Json::arrayValue};
|
||||
auto& param = params[0U][jss::HookParameter];
|
||||
param[jss::HookParameterName] = strHex(std::string("V"));
|
||||
param[jss::HookParameterValue] = value;
|
||||
payJv[jss::HookParameters] = params;
|
||||
return payJv;
|
||||
};
|
||||
|
||||
auto testSTI = [&](std::string value, bool expectedResult) {
|
||||
auto tx = buildTx(value);
|
||||
env(tx, M("test STI"), fee(XRP(1)));
|
||||
env.close();
|
||||
|
||||
auto const result = env.meta()
|
||||
->getFieldArray(sfHookExecutions)[0]
|
||||
.getFieldU64(sfHookReturnCode);
|
||||
if (expectedResult)
|
||||
BEAST_EXPECTS(result == 1, value);
|
||||
else
|
||||
BEAST_EXPECTS(result == 0, value);
|
||||
};
|
||||
|
||||
// STI_UINT32
|
||||
testSTI("2200000001", true);
|
||||
// STI_UINT64
|
||||
testSTI("301100000000000003E8", true);
|
||||
// STI_UINT128
|
||||
testSTI("4100000000000000000000000000000000", true);
|
||||
// STI_UINT256
|
||||
testSTI(
|
||||
"5060000000000000000000000000000000000000000000000000000000"
|
||||
"0000000000",
|
||||
true);
|
||||
// STI_AMOUNT
|
||||
testSTI("614000000000000064", true);
|
||||
testSTI(
|
||||
"61D5038D7EA4C680000000000000000000000000005553440000000000"
|
||||
"AE123A8556F3CF91154711376AFB0F894F832B3D",
|
||||
true);
|
||||
// STI_VL
|
||||
testSTI("7504DEADBEEF", true);
|
||||
// STI_ACCOUNT
|
||||
testSTI("8114AE123A8556F3CF91154711376AFB0F894F832B3D", true);
|
||||
// STI_NUMBER
|
||||
// testSTI("000400000000000000000000000000000001", true);
|
||||
// STI_OBJECT
|
||||
testSTI("E05C22000000017504DEADBEEFE1", true);
|
||||
// STI_ARRAY
|
||||
testSTI(
|
||||
"F05CE05B614000000000000064E1E05B61D5038D7EA4C6800000000000"
|
||||
"00000000000000005553440000000000AE123A8556F3CF91154711376A"
|
||||
"FB0F894F832B3DE1F1",
|
||||
true);
|
||||
// STI_UINT8
|
||||
testSTI("00101003", true);
|
||||
// STI_UINT160
|
||||
testSTI("01110000000000000000000000000000000000000000", true);
|
||||
// STI_PATHSET
|
||||
testSTI(
|
||||
"0112300000000000000000000000005553440000000000AE123A8556F3"
|
||||
"CF91154711376AFB0F894F832B3D00",
|
||||
hasEnabled);
|
||||
testSTI(
|
||||
"0112310A20B3C85F482532A9578DBB3950B85CA06594D1000000000000"
|
||||
"00000000000042544300000000000A20B3C85F482532A9578DBB3950B8"
|
||||
"5CA06594D13000000000000000000000000055534400000000000A20B3"
|
||||
"C85F482532A9578DBB3950B85CA06594D1FF3157180C769B66D942EE69"
|
||||
"E6DCC940CA48D82337AD00000000000000000000000042544300000000"
|
||||
"0057180C769B66D942EE69E6DCC940CA48D82337AD1000000000000000"
|
||||
"0000000000000000000000000030000000000000000000000000555344"
|
||||
"00000000000A20B3C85F482532A9578DBB3950B85CA06594D100",
|
||||
hasEnabled);
|
||||
// STI_VECTOR256
|
||||
testSTI(
|
||||
"0013634000000000000000000000000000000000000000000000000000"
|
||||
"0000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000",
|
||||
true);
|
||||
// STI_UINT96
|
||||
// testSTI("000400000000000000000000000000000001", true);
|
||||
// STI_UINT192
|
||||
// testSTI("000400000000000000000000000000000001", true);
|
||||
// STI_UINT384
|
||||
// testSTI("000400000000000000000000000000000001", true);
|
||||
// STI_UINT512
|
||||
// testSTI("000400000000000000000000000000000001", true);
|
||||
// STI_ISSUE
|
||||
testSTI(
|
||||
"03180000000000000000000000005553440000000000AE123A8556F3CF"
|
||||
"91154711376AFB0F894F832B3D",
|
||||
hasEnabled);
|
||||
testSTI(
|
||||
"03180000000000000000000000000000000000000000", hasEnabled);
|
||||
// STI_XCHAIN_BRIDGE
|
||||
/// Native-Native
|
||||
testSTI(
|
||||
"011914AE123A8556F3CF91154711376AFB0F894F832B3D000000000000"
|
||||
"000000000000000000000000000014AE123A8556F3CF91154711376AFB"
|
||||
"0F894F832B3D0000000000000000000000000000000000000000",
|
||||
hasEnabled);
|
||||
/// IOU-Native
|
||||
testSTI(
|
||||
"011914AE123A8556F3CF91154711376AFB0F894F832B3D000000000000"
|
||||
"0000000000005553440000000000AE123A8556F3CF91154711376AFB0F"
|
||||
"894F832B3D14AE123A8556F3CF91154711376AFB0F894F832B3D000000"
|
||||
"0000"
|
||||
"000000000000000000000000000000",
|
||||
hasEnabled);
|
||||
/// Native-IOU
|
||||
testSTI(
|
||||
"011914AE123A8556F3CF91154711376AFB0F894F832B3D000000000000"
|
||||
"0000000000005553440000000000AE123A8556F3CF91154711376AFB0F"
|
||||
"894F832B3D14AE123A8556F3CF91154711376AFB0F894F832B3D000000"
|
||||
"0000000000000000000000000000000000",
|
||||
hasEnabled);
|
||||
/// IOU-IOU
|
||||
testSTI(
|
||||
"011914AE123A8556F3CF91154711376AFB0F894F832B3D000000000000"
|
||||
"0000000000005553440000000000AE123A8556F3CF91154711376AFB0F"
|
||||
"894F832B3D14AE123A8556F3CF91154711376AFB0F894F832B3D000000"
|
||||
"0000000000000000005553440000000000AE123A8556F3CF9115471137"
|
||||
"6AFB0F894F832B3D",
|
||||
hasEnabled);
|
||||
// STI_CURRENCY
|
||||
testSTI(
|
||||
"011A0000000000000000000000005553440000000000", hasEnabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@@ -11359,7 +11594,19 @@ public:
|
||||
#define KEYLET_PAYCHAN 21
|
||||
#define KEYLET_EMITTED_TXN 22
|
||||
#define KEYLET_NFT_OFFER 23
|
||||
#define KEYLET_HOOK_DEFINITION 24
|
||||
#define KEYLET_HOOK_STATE_DIR 25
|
||||
#define KEYLET_CRON 26
|
||||
#define KEYLET_AMM 27
|
||||
#define KEYLET_BRIDGE 28
|
||||
#define KEYLET_XCHAIN_OWNED_CLAIM_ID 29
|
||||
#define KEYLET_XCHAIN_OWNED_CREATE_ACCOUNT_CLAIM_ID 30
|
||||
#define KEYLET_DID 31
|
||||
#define KEYLET_ORACLE 32
|
||||
#define KEYLET_MPTOKEN_ISSUANCE 33
|
||||
#define KEYLET_MPTOKEN 34
|
||||
#define KEYLET_CREDENTIAL 35
|
||||
#define KEYLET_PERMISSIONED_DOMAIN 36
|
||||
#define ASSERT(x)\
|
||||
if (!(x))\
|
||||
rollback((uint32_t)#x, sizeof(#x), __LINE__);
|
||||
@@ -11407,6 +11654,22 @@ public:
|
||||
0x3AU,0x51U,0x8AU,0x22U,0x53U,0x81U,0x60U,0x84U,0x1CU,0x14U,0x32U,0xFEU,
|
||||
0x6FU,0x3EU,0x6DU,0x6EU,0x76U,0x29U,0xFBU,0xBAU
|
||||
};
|
||||
|
||||
uint8_t asset1[] = // USD.rB6v18pQ765Z9DH5RQsTFevoQPFmRtBqhT
|
||||
{
|
||||
0x00U,0x00U,0x00U,0x00U,0x00U,0x00U,0x00U,0x00U,0x00U,0x00U,
|
||||
0x00U,0x00U,0x55U,0x53U,0x44U,0x00U,0x00U,0x00U,0x00U,0x00U,
|
||||
0x75U,0x6EU,0xDEU,0x88U,0xA9U,0x07U,0xD4U,0xCCU,0xF3U,0x8DU,0x6AU,0xDBU,
|
||||
0x9FU,0xC7U,0x94U,0x64U,0x19U,0xF0U,0xC4U,0x1DU
|
||||
};
|
||||
|
||||
uint8_t asset2[] = // EUR.raKM1bZkGmASBqN5v2swrf2uAPJ32Cd8GV
|
||||
{
|
||||
0x00U,0x00U,0x00U,0x00U,0x00U,0x00U,0x00U,0x00U,0x00U,0x00U,
|
||||
0x00U,0x00U,0x45U,0x48U,0x52U,0x00U,0x00U,0x00U,0x00U,0x00U,
|
||||
0x3AU,0x51U,0x8AU,0x22U,0x53U,0x81U,0x60U,0x84U,0x1CU,0x14U,0x32U,0xFEU,
|
||||
0x6FU,0x3EU,0x6DU,0x6EU,0x76U,0x29U,0xFBU,0xBAU
|
||||
};
|
||||
|
||||
int64_t hook(uint32_t reserved )
|
||||
{
|
||||
@@ -11861,11 +12124,76 @@ public:
|
||||
0,0
|
||||
)));
|
||||
|
||||
|
||||
ASSERT(34 == (e=util_keylet(buf, 34, KEYLET_NFT_OFFER,
|
||||
SBUF(a), SBUF(ns),
|
||||
0,0
|
||||
)));
|
||||
|
||||
ASSERT(34 == (e=util_keylet(buf, 34, KEYLET_HOOK_DEFINITION,
|
||||
SBUF(ns),
|
||||
0,0,
|
||||
0,0
|
||||
)));
|
||||
|
||||
ASSERT(34 == (e=util_keylet(buf, 34, KEYLET_HOOK_STATE_DIR,
|
||||
SBUF(a), SBUF(ns),
|
||||
0,0
|
||||
)));
|
||||
|
||||
ASSERT(34 == (e=util_keylet(buf, 34, KEYLET_AMM,
|
||||
SBUF(asset1), SBUF(asset2),
|
||||
0,0
|
||||
)));
|
||||
|
||||
ASSERT(INVALID_ARGUMENT == (e=util_keylet(buf, 34, KEYLET_BRIDGE,
|
||||
SBUF(a), SBUF(b),
|
||||
0,0
|
||||
)));
|
||||
|
||||
ASSERT(INVALID_ARGUMENT == (e=util_keylet(buf, 34, KEYLET_XCHAIN_OWNED_CLAIM_ID,
|
||||
SBUF(a), SBUF(b),
|
||||
0,0
|
||||
)));
|
||||
|
||||
ASSERT(INVALID_ARGUMENT == (e=util_keylet(buf, 34, KEYLET_XCHAIN_OWNED_CREATE_ACCOUNT_CLAIM_ID,
|
||||
SBUF(a), SBUF(b),
|
||||
0,0
|
||||
)));
|
||||
|
||||
ASSERT(INVALID_ARGUMENT == (e=util_keylet(buf, 34, KEYLET_DID,
|
||||
SBUF(a),
|
||||
0,0,
|
||||
0,0
|
||||
)));
|
||||
|
||||
ASSERT(34 == (e=util_keylet(buf, 34, KEYLET_ORACLE,
|
||||
SBUF(a), 3,
|
||||
0,
|
||||
0,0
|
||||
)));
|
||||
|
||||
ASSERT(INVALID_ARGUMENT == (e=util_keylet(buf, 34, KEYLET_MPTOKEN_ISSUANCE,
|
||||
SBUF(a),
|
||||
0,0,
|
||||
0,0
|
||||
)));
|
||||
|
||||
ASSERT(INVALID_ARGUMENT == (e=util_keylet(buf, 34, KEYLET_MPTOKEN,
|
||||
SBUF(a),
|
||||
0,0,
|
||||
0,0
|
||||
)));
|
||||
|
||||
ASSERT(INVALID_ARGUMENT == (e=util_keylet(buf, 34, KEYLET_CREDENTIAL,
|
||||
SBUF(a), SBUF(b),
|
||||
0,0
|
||||
)));
|
||||
|
||||
ASSERT(INVALID_ARGUMENT == (e=util_keylet(buf, 34, KEYLET_PERMISSIONED_DOMAIN,
|
||||
SBUF(a),
|
||||
0,0,
|
||||
0,0
|
||||
)));
|
||||
|
||||
ASSERT(34 == (e=util_keylet(buf, 34, KEYLET_CRON, SBUF(a), 1, 0, 0, 0)));
|
||||
{
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -21,8 +21,12 @@
|
||||
#define RIPPLE_TEST_JTX_HOOK_H_INCLUDED
|
||||
|
||||
#include <test/jtx/Account.h>
|
||||
#include <xrpld/app/hook/applyHook.h>
|
||||
#include <xrpl/json/json_value.h>
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
@@ -43,6 +47,75 @@ hso(std::string const& wasmHex, void (*f)(Json::Value& jv) = 0);
|
||||
Json::Value
|
||||
hso_delete(void (*f)(Json::Value& jv) = 0);
|
||||
|
||||
struct StubHookResult
|
||||
{
|
||||
ripple::uint256 const hookSetTxnID = ripple::uint256();
|
||||
ripple::uint256 const hookHash = ripple::uint256();
|
||||
ripple::uint256 const hookCanEmit = ripple::uint256();
|
||||
ripple::uint256 const hookNamespace = ripple::uint256();
|
||||
|
||||
std::queue<std::shared_ptr<ripple::Transaction>> emittedTxn{};
|
||||
std::optional<hook::HookStateMap> stateMap = std::nullopt;
|
||||
uint16_t changedStateCount = 0;
|
||||
std::map<
|
||||
ripple::uint256, // hook hash
|
||||
std::map<
|
||||
std::vector<uint8_t>, // hook param name
|
||||
std::vector<uint8_t> // hook param value
|
||||
>>
|
||||
hookParamOverrides = {};
|
||||
|
||||
std::optional<std::map<std::vector<uint8_t>, std::vector<uint8_t>>>
|
||||
hookParams = std::nullopt;
|
||||
std::set<ripple::uint256> hookSkips = {};
|
||||
hook_api::ExitType exitType = hook_api::ExitType::ROLLBACK;
|
||||
std::string exitReason{""};
|
||||
int64_t exitCode{-1};
|
||||
uint64_t instructionCount{0};
|
||||
bool hasCallback = false;
|
||||
bool isCallback = false;
|
||||
bool isStrong = false;
|
||||
uint32_t wasmParam = 0;
|
||||
uint32_t overrideCount = 0;
|
||||
uint8_t hookChainPosition = 0;
|
||||
bool foreignStateSetDisabled = false;
|
||||
bool executeAgainAsWeak = false;
|
||||
std::shared_ptr<STObject const> provisionalMeta = nullptr;
|
||||
};
|
||||
|
||||
struct StubHookContext
|
||||
{
|
||||
std::map<uint32_t, hook::SlotEntry> slot{};
|
||||
std::queue<uint32_t> slot_free{};
|
||||
uint32_t slot_counter{0};
|
||||
uint16_t emit_nonce_counter{0};
|
||||
uint16_t ledger_nonce_counter{0};
|
||||
int64_t expected_etxn_count{-1};
|
||||
std::map<ripple::uint256, bool> nonce_used{};
|
||||
uint32_t generation = 0;
|
||||
uint64_t burden = 0;
|
||||
std::map<uint32_t, uint32_t> guard_map{};
|
||||
StubHookResult result = {};
|
||||
std::optional<ripple::STObject> emitFailure = std::nullopt;
|
||||
const hook::HookExecutor* module = 0;
|
||||
};
|
||||
|
||||
// Overload that takes external stateMap to avoid dangling reference
|
||||
hook::HookContext
|
||||
makeStubHookContext(
|
||||
ripple::ApplyContext& applyCtx,
|
||||
ripple::AccountID const& hookAccount,
|
||||
ripple::AccountID const& otxnAccount,
|
||||
StubHookContext const& stubHookContext,
|
||||
hook::HookStateMap& stateMap);
|
||||
|
||||
hook::HookContext
|
||||
makeStubHookContext(
|
||||
ripple::ApplyContext& applyCtx,
|
||||
ripple::AccountID const& hookAccount,
|
||||
ripple::AccountID const& otxnAccount,
|
||||
StubHookContext const& stubHookContext);
|
||||
|
||||
} // namespace jtx
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -18,8 +18,10 @@
|
||||
//==============================================================================
|
||||
|
||||
#include <test/jtx/hook.h>
|
||||
#include <xrpld/app/hook/applyHook.h>
|
||||
#include <xrpl/basics/contract.h>
|
||||
#include <xrpl/hook/Enum.h>
|
||||
#include <xrpl/protocol/Keylet.h>
|
||||
#include <xrpl/protocol/jss.h>
|
||||
#include <stdexcept>
|
||||
|
||||
@@ -102,6 +104,81 @@ hso(std::string const& wasmHex, void (*f)(Json::Value& jv))
|
||||
return jv;
|
||||
}
|
||||
|
||||
// Helper function to create HookContext with external stateMap
|
||||
hook::HookContext
|
||||
makeStubHookContext(
|
||||
ripple::ApplyContext& applyCtx,
|
||||
ripple::AccountID const& hookAccount,
|
||||
ripple::AccountID const& otxnAccount,
|
||||
StubHookContext const& stubHookContext,
|
||||
hook::HookStateMap& stateMap)
|
||||
{
|
||||
auto& result = stubHookContext.result;
|
||||
auto hookParams = result.hookParams.value_or(
|
||||
std::map<std::vector<uint8_t>, std::vector<uint8_t>>{});
|
||||
return hook::HookContext{
|
||||
.applyCtx = applyCtx,
|
||||
.slot = stubHookContext.slot,
|
||||
.slot_free = stubHookContext.slot_free,
|
||||
.slot_counter = stubHookContext.slot_counter,
|
||||
.emit_nonce_counter = stubHookContext.emit_nonce_counter,
|
||||
.ledger_nonce_counter = stubHookContext.ledger_nonce_counter,
|
||||
.expected_etxn_count = stubHookContext.expected_etxn_count,
|
||||
.nonce_used = stubHookContext.nonce_used,
|
||||
.generation = stubHookContext.generation,
|
||||
.burden = stubHookContext.burden,
|
||||
.guard_map = stubHookContext.guard_map,
|
||||
.result =
|
||||
{
|
||||
.hookSetTxnID = result.hookSetTxnID,
|
||||
.hookHash = result.hookHash,
|
||||
.hookCanEmit = result.hookCanEmit,
|
||||
.accountKeylet = keylet::account(hookAccount),
|
||||
.hookKeylet = keylet::hook(hookAccount),
|
||||
.account = hookAccount,
|
||||
.otxnAccount = otxnAccount,
|
||||
.hookNamespace = result.hookNamespace,
|
||||
.emittedTxn = result.emittedTxn,
|
||||
.stateMap = stateMap,
|
||||
.changedStateCount = result.changedStateCount,
|
||||
.hookParamOverrides = result.hookParamOverrides,
|
||||
.hookParams = hookParams,
|
||||
.hookSkips = result.hookSkips,
|
||||
.exitType = result.exitType,
|
||||
.exitReason = result.exitReason,
|
||||
.exitCode = result.exitCode,
|
||||
.instructionCount = result.instructionCount,
|
||||
.hasCallback = result.hasCallback,
|
||||
.isCallback = result.isCallback,
|
||||
.isStrong = result.isStrong,
|
||||
.wasmParam = result.wasmParam,
|
||||
.overrideCount = result.overrideCount,
|
||||
.hookChainPosition = result.hookChainPosition,
|
||||
.foreignStateSetDisabled = result.foreignStateSetDisabled,
|
||||
.executeAgainAsWeak = result.executeAgainAsWeak,
|
||||
.provisionalMeta = result.provisionalMeta,
|
||||
},
|
||||
.emitFailure = stubHookContext.emitFailure,
|
||||
.module = nullptr};
|
||||
}
|
||||
|
||||
// Original function - WARNING: stateMap reference may become dangling
|
||||
// Only use when stateMap access is not needed after HookContext creation
|
||||
hook::HookContext
|
||||
makeStubHookContext(
|
||||
ripple::ApplyContext& applyCtx,
|
||||
ripple::AccountID const& hookAccount,
|
||||
ripple::AccountID const& otxnAccount,
|
||||
StubHookContext const& stubHookContext)
|
||||
{
|
||||
// Use thread_local to keep stateMap alive
|
||||
// Note: This is a workaround; each call resets the stateMap
|
||||
thread_local hook::HookStateMap stateMap;
|
||||
stateMap = stubHookContext.result.stateMap.value_or(hook::HookStateMap{});
|
||||
return makeStubHookContext(
|
||||
applyCtx, hookAccount, otxnAccount, stubHookContext, stateMap);
|
||||
}
|
||||
|
||||
} // namespace jtx
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <xrpl/basics/Blob.h>
|
||||
#include <xrpl/beast/utility/Journal.h>
|
||||
#include <xrpl/hook/Enum.h>
|
||||
#include <xrpl/hook/HookAPI.h>
|
||||
#include <xrpl/hook/Macro.h>
|
||||
#include <xrpl/hook/Misc.h>
|
||||
#include <xrpl/protocol/SField.h>
|
||||
@@ -61,365 +62,20 @@ namespace hook_api {
|
||||
if (HOOK_DBG) \
|
||||
fprintf
|
||||
|
||||
DECLARE_HOOK_FUNCTION(int32_t, _g, uint32_t guard_id, uint32_t maxiter);
|
||||
#pragma push_macro("HOOK_API_DEFINITION")
|
||||
#undef HOOK_API_DEFINITION
|
||||
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
accept,
|
||||
uint32_t read_ptr,
|
||||
uint32_t read_len,
|
||||
int64_t error_code);
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
rollback,
|
||||
uint32_t read_ptr,
|
||||
uint32_t read_len,
|
||||
int64_t error_code);
|
||||
#define HOOK_WRAP_PARAMS(...) __VA_ARGS__
|
||||
#define HOOK_API_DEFINITION(RETURN_TYPE, FUNCTION_NAME, PARAMS_TUPLE, ...) \
|
||||
DECLARE_HOOK_FUNCTION( \
|
||||
RETURN_TYPE, FUNCTION_NAME, HOOK_WRAP_PARAMS PARAMS_TUPLE);
|
||||
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
util_raddr,
|
||||
uint32_t write_ptr,
|
||||
uint32_t write_len,
|
||||
uint32_t read_ptr,
|
||||
uint32_t read_len);
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
util_accid,
|
||||
uint32_t write_ptr,
|
||||
uint32_t write_len,
|
||||
uint32_t read_ptr,
|
||||
uint32_t read_len);
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
util_verify,
|
||||
uint32_t dread_ptr,
|
||||
uint32_t dread_len,
|
||||
uint32_t sread_ptr,
|
||||
uint32_t sread_len,
|
||||
uint32_t kread_ptr,
|
||||
uint32_t kread_len);
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
util_sha512h,
|
||||
uint32_t write_ptr,
|
||||
uint32_t write_len,
|
||||
uint32_t read_ptr,
|
||||
uint32_t read_len);
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
util_keylet,
|
||||
uint32_t write_ptr,
|
||||
uint32_t write_len,
|
||||
uint32_t keylet_type,
|
||||
uint32_t a,
|
||||
uint32_t b,
|
||||
uint32_t c,
|
||||
uint32_t d,
|
||||
uint32_t e,
|
||||
uint32_t f);
|
||||
#include <xrpl/hook/hook_api.macro>
|
||||
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
sto_validate,
|
||||
uint32_t tread_ptr,
|
||||
uint32_t tread_len);
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
sto_subfield,
|
||||
uint32_t read_ptr,
|
||||
uint32_t read_len,
|
||||
uint32_t field_id);
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
sto_subarray,
|
||||
uint32_t read_ptr,
|
||||
uint32_t read_len,
|
||||
uint32_t array_id);
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
sto_emplace,
|
||||
uint32_t write_ptr,
|
||||
uint32_t write_len,
|
||||
uint32_t sread_ptr,
|
||||
uint32_t sread_len,
|
||||
uint32_t fread_ptr,
|
||||
uint32_t fread_len,
|
||||
uint32_t field_id);
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
sto_erase,
|
||||
uint32_t write_ptr,
|
||||
uint32_t write_len,
|
||||
uint32_t read_ptr,
|
||||
uint32_t read_len,
|
||||
uint32_t field_id);
|
||||
#undef HOOK_API_DEFINITION
|
||||
#undef HOOK_WRAP_PARAMS
|
||||
#pragma pop_macro("HOOK_API_DEFINITION")
|
||||
|
||||
DECLARE_HOOK_FUNCNARG(int64_t, etxn_burden);
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
etxn_details,
|
||||
uint32_t write_ptr,
|
||||
uint32_t write_len);
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
etxn_fee_base,
|
||||
uint32_t read_ptr,
|
||||
uint32_t read_len);
|
||||
DECLARE_HOOK_FUNCTION(int64_t, etxn_reserve, uint32_t count);
|
||||
DECLARE_HOOK_FUNCNARG(int64_t, etxn_generation);
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
etxn_nonce,
|
||||
uint32_t write_ptr,
|
||||
uint32_t write_len);
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
emit,
|
||||
uint32_t write_ptr,
|
||||
uint32_t write_len,
|
||||
uint32_t read_ptr,
|
||||
uint32_t read_len);
|
||||
|
||||
DECLARE_HOOK_FUNCTION(int64_t, float_set, int32_t exponent, int64_t mantissa);
|
||||
DECLARE_HOOK_FUNCTION(int64_t, float_multiply, int64_t float1, int64_t float2);
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
float_mulratio,
|
||||
int64_t float1,
|
||||
uint32_t round_up,
|
||||
uint32_t numerator,
|
||||
uint32_t denominator);
|
||||
DECLARE_HOOK_FUNCTION(int64_t, float_negate, int64_t float1);
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
float_compare,
|
||||
int64_t float1,
|
||||
int64_t float2,
|
||||
uint32_t mode);
|
||||
DECLARE_HOOK_FUNCTION(int64_t, float_sum, int64_t float1, int64_t float2);
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
float_sto,
|
||||
uint32_t write_ptr,
|
||||
uint32_t write_len,
|
||||
uint32_t cread_ptr,
|
||||
uint32_t cread_len,
|
||||
uint32_t iread_ptr,
|
||||
uint32_t iread_len,
|
||||
int64_t float1,
|
||||
uint32_t field_code);
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
float_sto_set,
|
||||
uint32_t read_ptr,
|
||||
uint32_t read_len);
|
||||
DECLARE_HOOK_FUNCTION(int64_t, float_invert, int64_t float1);
|
||||
DECLARE_HOOK_FUNCTION(int64_t, float_divide, int64_t float1, int64_t float2);
|
||||
DECLARE_HOOK_FUNCNARG(int64_t, float_one);
|
||||
DECLARE_HOOK_FUNCTION(int64_t, float_mantissa, int64_t float1);
|
||||
DECLARE_HOOK_FUNCTION(int64_t, float_sign, int64_t float1);
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
float_int,
|
||||
int64_t float1,
|
||||
uint32_t decimal_places,
|
||||
uint32_t abs);
|
||||
DECLARE_HOOK_FUNCTION(int64_t, float_log, int64_t float1);
|
||||
DECLARE_HOOK_FUNCTION(int64_t, float_root, int64_t float1, uint32_t n);
|
||||
|
||||
DECLARE_HOOK_FUNCNARG(int64_t, fee_base);
|
||||
DECLARE_HOOK_FUNCNARG(int64_t, ledger_seq);
|
||||
DECLARE_HOOK_FUNCNARG(int64_t, ledger_last_time);
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
ledger_last_hash,
|
||||
uint32_t write_ptr,
|
||||
uint32_t write_len);
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
ledger_nonce,
|
||||
uint32_t write_ptr,
|
||||
uint32_t write_len);
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
ledger_keylet,
|
||||
uint32_t write_ptr,
|
||||
uint32_t write_len,
|
||||
uint32_t lread_ptr,
|
||||
uint32_t lread_len,
|
||||
uint32_t hread_ptr,
|
||||
uint32_t hread_len);
|
||||
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
hook_account,
|
||||
uint32_t write_ptr,
|
||||
uint32_t write_len);
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
hook_hash,
|
||||
uint32_t write_ptr,
|
||||
uint32_t write_len,
|
||||
int32_t hook_no);
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
hook_param_set,
|
||||
uint32_t read_ptr,
|
||||
uint32_t read_len,
|
||||
uint32_t kread_ptr,
|
||||
uint32_t kread_len,
|
||||
uint32_t hread_ptr,
|
||||
uint32_t hread_len);
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
hook_param,
|
||||
uint32_t write_ptr,
|
||||
uint32_t write_len,
|
||||
uint32_t read_ptr,
|
||||
uint32_t read_len);
|
||||
DECLARE_HOOK_FUNCNARG(int64_t, hook_again);
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
hook_skip,
|
||||
uint32_t read_ptr,
|
||||
uint32_t read_len,
|
||||
uint32_t flags);
|
||||
DECLARE_HOOK_FUNCNARG(int64_t, hook_pos);
|
||||
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
slot,
|
||||
uint32_t write_ptr,
|
||||
uint32_t write_len,
|
||||
uint32_t slot);
|
||||
DECLARE_HOOK_FUNCTION(int64_t, slot_clear, uint32_t slot);
|
||||
DECLARE_HOOK_FUNCTION(int64_t, slot_count, uint32_t slot);
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
slot_set,
|
||||
uint32_t read_ptr,
|
||||
uint32_t read_len,
|
||||
uint32_t slot);
|
||||
DECLARE_HOOK_FUNCTION(int64_t, slot_size, uint32_t slot);
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
slot_subarray,
|
||||
uint32_t parent_slot,
|
||||
uint32_t array_id,
|
||||
uint32_t new_slot);
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
slot_subfield,
|
||||
uint32_t parent_slot,
|
||||
uint32_t field_id,
|
||||
uint32_t new_slot);
|
||||
DECLARE_HOOK_FUNCTION(int64_t, slot_type, uint32_t slot_no, uint32_t flags);
|
||||
DECLARE_HOOK_FUNCTION(int64_t, slot_float, uint32_t slot_no);
|
||||
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
state_set,
|
||||
uint32_t read_ptr,
|
||||
uint32_t read_len,
|
||||
uint32_t kread_ptr,
|
||||
uint32_t kread_len);
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
state_foreign_set,
|
||||
uint32_t read_ptr,
|
||||
uint32_t read_len,
|
||||
uint32_t kread_ptr,
|
||||
uint32_t kread_len,
|
||||
uint32_t nread_ptr,
|
||||
uint32_t nread_len,
|
||||
uint32_t aread_ptr,
|
||||
uint32_t aread_len);
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
state,
|
||||
uint32_t write_ptr,
|
||||
uint32_t write_len,
|
||||
uint32_t kread_ptr,
|
||||
uint32_t kread_len);
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
state_foreign,
|
||||
uint32_t write_ptr,
|
||||
uint32_t write_len,
|
||||
uint32_t kread_ptr,
|
||||
uint32_t kread_len,
|
||||
uint32_t nread_ptr,
|
||||
uint32_t nread_len,
|
||||
uint32_t aread_ptr,
|
||||
uint32_t aread_len);
|
||||
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
trace,
|
||||
uint32_t mread_ptr,
|
||||
uint32_t mread_len,
|
||||
uint32_t dread_ptr,
|
||||
uint32_t dread_len,
|
||||
uint32_t as_hex);
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
trace_num,
|
||||
uint32_t read_ptr,
|
||||
uint32_t read_len,
|
||||
int64_t number);
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
trace_float,
|
||||
uint32_t read_ptr,
|
||||
uint32_t read_len,
|
||||
int64_t float1);
|
||||
|
||||
DECLARE_HOOK_FUNCNARG(int64_t, otxn_burden);
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
otxn_field,
|
||||
uint32_t write_ptr,
|
||||
uint32_t write_len,
|
||||
uint32_t field_id);
|
||||
DECLARE_HOOK_FUNCNARG(int64_t, otxn_generation);
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
otxn_id,
|
||||
uint32_t write_ptr,
|
||||
uint32_t write_len,
|
||||
uint32_t flags);
|
||||
DECLARE_HOOK_FUNCNARG(int64_t, otxn_type);
|
||||
DECLARE_HOOK_FUNCTION(int64_t, otxn_slot, uint32_t slot_no);
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
otxn_param,
|
||||
uint32_t write_ptr,
|
||||
uint32_t write_len,
|
||||
uint32_t read_ptr,
|
||||
uint32_t read_len);
|
||||
|
||||
DECLARE_HOOK_FUNCTION(int64_t, meta_slot, uint32_t slot_no);
|
||||
DECLARE_HOOK_FUNCTION(
|
||||
int64_t,
|
||||
xpop_slot,
|
||||
uint32_t slot_no_tx,
|
||||
uint32_t slot_no_meta);
|
||||
|
||||
/*
|
||||
DECLARE_HOOK_FUNCTION(int64_t, str_find, uint32_t hread_ptr,
|
||||
uint32_t hread_len, uint32_t nread_ptr, uint32_t nread_len, uint32_t mode,
|
||||
uint32_t n); DECLARE_HOOK_FUNCTION(int64_t, str_replace, uint32_t
|
||||
write_ptr, uint32_t write_len, uint32_t hread_ptr, uint32_t hread_len,
|
||||
uint32_t nread_ptr,
|
||||
uint32_t nread_len, uint32_t rread_ptr, uint32_t rread_len, uint32_t mode,
|
||||
uint32_t n); DECLARE_HOOK_FUNCTION(int64_t, str_compare, uint32_t
|
||||
fread_ptr, uint32_t fread_len, uint32_t sread_ptr, uint32_t sread_len,
|
||||
uint32_t mode);
|
||||
DECLARE_HOOK_FUNCTION(int64_t, str_concat, uint32_t write_ptr,
|
||||
uint32_t write_len, uint32_t read_ptr, uint32_t read_len, uint64_t operand,
|
||||
uint32_t operand_type);
|
||||
*/
|
||||
} /* end namespace hook_api */
|
||||
|
||||
namespace hook {
|
||||
@@ -477,7 +133,6 @@ struct HookResult
|
||||
ripple::uint256 const hookHash;
|
||||
ripple::uint256 const hookCanEmit;
|
||||
ripple::Keylet const accountKeylet;
|
||||
ripple::Keylet const ownerDirKeylet;
|
||||
ripple::Keylet const hookKeylet;
|
||||
ripple::AccountID const account;
|
||||
ripple::AccountID const otxnAccount;
|
||||
@@ -554,6 +209,18 @@ struct HookContext
|
||||
// emitted txn then this optional becomes
|
||||
// populated with the SLE
|
||||
const HookExecutor* module = 0;
|
||||
|
||||
// Lazy-initialized HookAPI member
|
||||
mutable std::unique_ptr<HookAPI> api_;
|
||||
|
||||
// Access the HookAPI instance (lazy initialization)
|
||||
HookAPI&
|
||||
api() const
|
||||
{
|
||||
if (!api_)
|
||||
api_ = std::make_unique<HookAPI>(const_cast<HookContext&>(*this));
|
||||
return *api_;
|
||||
}
|
||||
};
|
||||
|
||||
bool
|
||||
@@ -794,97 +461,18 @@ public:
|
||||
|
||||
WasmEdge_LogSetDebugLevel();
|
||||
|
||||
ADD_HOOK_FUNCTION(_g, ctx);
|
||||
ADD_HOOK_FUNCTION(accept, ctx);
|
||||
ADD_HOOK_FUNCTION(rollback, ctx);
|
||||
ADD_HOOK_FUNCTION(util_raddr, ctx);
|
||||
ADD_HOOK_FUNCTION(util_accid, ctx);
|
||||
ADD_HOOK_FUNCTION(util_verify, ctx);
|
||||
ADD_HOOK_FUNCTION(util_sha512h, ctx);
|
||||
ADD_HOOK_FUNCTION(sto_validate, ctx);
|
||||
ADD_HOOK_FUNCTION(sto_subfield, ctx);
|
||||
ADD_HOOK_FUNCTION(sto_subarray, ctx);
|
||||
ADD_HOOK_FUNCTION(sto_emplace, ctx);
|
||||
ADD_HOOK_FUNCTION(sto_erase, ctx);
|
||||
ADD_HOOK_FUNCTION(util_keylet, ctx);
|
||||
#pragma push_macro("HOOK_API_DEFINITION")
|
||||
#undef HOOK_API_DEFINITION
|
||||
|
||||
ADD_HOOK_FUNCTION(emit, ctx);
|
||||
ADD_HOOK_FUNCTION(etxn_burden, ctx);
|
||||
ADD_HOOK_FUNCTION(etxn_fee_base, ctx);
|
||||
ADD_HOOK_FUNCTION(etxn_details, ctx);
|
||||
ADD_HOOK_FUNCTION(etxn_reserve, ctx);
|
||||
ADD_HOOK_FUNCTION(etxn_generation, ctx);
|
||||
ADD_HOOK_FUNCTION(etxn_nonce, ctx);
|
||||
#define HOOK_WRAP_PARAMS(...) __VA_ARGS__
|
||||
#define HOOK_API_DEFINITION(RETURN_TYPE, FUNCTION_NAME, PARAMS_TUPLE, ...) \
|
||||
ADD_HOOK_FUNCTION(FUNCTION_NAME, ctx);
|
||||
|
||||
ADD_HOOK_FUNCTION(float_set, ctx);
|
||||
ADD_HOOK_FUNCTION(float_multiply, ctx);
|
||||
ADD_HOOK_FUNCTION(float_mulratio, ctx);
|
||||
ADD_HOOK_FUNCTION(float_negate, ctx);
|
||||
ADD_HOOK_FUNCTION(float_compare, ctx);
|
||||
ADD_HOOK_FUNCTION(float_sum, ctx);
|
||||
ADD_HOOK_FUNCTION(float_sto, ctx);
|
||||
ADD_HOOK_FUNCTION(float_sto_set, ctx);
|
||||
ADD_HOOK_FUNCTION(float_invert, ctx);
|
||||
#include <xrpl/hook/hook_api.macro>
|
||||
|
||||
ADD_HOOK_FUNCTION(float_divide, ctx);
|
||||
ADD_HOOK_FUNCTION(float_one, ctx);
|
||||
ADD_HOOK_FUNCTION(float_mantissa, ctx);
|
||||
ADD_HOOK_FUNCTION(float_sign, ctx);
|
||||
ADD_HOOK_FUNCTION(float_int, ctx);
|
||||
ADD_HOOK_FUNCTION(float_log, ctx);
|
||||
ADD_HOOK_FUNCTION(float_root, ctx);
|
||||
|
||||
ADD_HOOK_FUNCTION(otxn_burden, ctx);
|
||||
ADD_HOOK_FUNCTION(otxn_generation, ctx);
|
||||
ADD_HOOK_FUNCTION(otxn_field, ctx);
|
||||
ADD_HOOK_FUNCTION(otxn_id, ctx);
|
||||
ADD_HOOK_FUNCTION(otxn_type, ctx);
|
||||
ADD_HOOK_FUNCTION(otxn_slot, ctx);
|
||||
ADD_HOOK_FUNCTION(otxn_param, ctx);
|
||||
|
||||
ADD_HOOK_FUNCTION(hook_account, ctx);
|
||||
ADD_HOOK_FUNCTION(hook_hash, ctx);
|
||||
ADD_HOOK_FUNCTION(hook_again, ctx);
|
||||
ADD_HOOK_FUNCTION(fee_base, ctx);
|
||||
ADD_HOOK_FUNCTION(ledger_seq, ctx);
|
||||
ADD_HOOK_FUNCTION(ledger_last_hash, ctx);
|
||||
ADD_HOOK_FUNCTION(ledger_last_time, ctx);
|
||||
ADD_HOOK_FUNCTION(ledger_nonce, ctx);
|
||||
ADD_HOOK_FUNCTION(ledger_keylet, ctx);
|
||||
|
||||
ADD_HOOK_FUNCTION(hook_param, ctx);
|
||||
ADD_HOOK_FUNCTION(hook_param_set, ctx);
|
||||
ADD_HOOK_FUNCTION(hook_skip, ctx);
|
||||
ADD_HOOK_FUNCTION(hook_pos, ctx);
|
||||
|
||||
ADD_HOOK_FUNCTION(state, ctx);
|
||||
ADD_HOOK_FUNCTION(state_foreign, ctx);
|
||||
ADD_HOOK_FUNCTION(state_set, ctx);
|
||||
ADD_HOOK_FUNCTION(state_foreign_set, ctx);
|
||||
|
||||
ADD_HOOK_FUNCTION(slot, ctx);
|
||||
ADD_HOOK_FUNCTION(slot_clear, ctx);
|
||||
ADD_HOOK_FUNCTION(slot_count, ctx);
|
||||
ADD_HOOK_FUNCTION(slot_set, ctx);
|
||||
ADD_HOOK_FUNCTION(slot_size, ctx);
|
||||
ADD_HOOK_FUNCTION(slot_subarray, ctx);
|
||||
ADD_HOOK_FUNCTION(slot_subfield, ctx);
|
||||
ADD_HOOK_FUNCTION(slot_type, ctx);
|
||||
ADD_HOOK_FUNCTION(slot_float, ctx);
|
||||
|
||||
ADD_HOOK_FUNCTION(trace, ctx);
|
||||
ADD_HOOK_FUNCTION(trace_num, ctx);
|
||||
ADD_HOOK_FUNCTION(trace_float, ctx);
|
||||
|
||||
ADD_HOOK_FUNCTION(meta_slot, ctx);
|
||||
ADD_HOOK_FUNCTION(xpop_slot, ctx);
|
||||
|
||||
/*
|
||||
ADD_HOOK_FUNCTION(str_find, ctx);
|
||||
ADD_HOOK_FUNCTION(str_replace, ctx);
|
||||
ADD_HOOK_FUNCTION(str_compare, ctx);
|
||||
ADD_HOOK_FUNCTION(str_concat, ctx);
|
||||
*/
|
||||
#undef HOOK_API_DEFINITION
|
||||
#undef HOOK_WRAP_PARAMS
|
||||
#pragma pop_macro("HOOK_API_DEFINITION")
|
||||
|
||||
WasmEdge_TableInstanceContext* hostTable =
|
||||
WasmEdge_TableInstanceCreate(tableType);
|
||||
|
||||
3314
src/xrpld/app/hook/detail/HookAPI.cpp
Normal file
3314
src/xrpld/app/hook/detail/HookAPI.cpp
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -27,6 +27,7 @@
|
||||
#include <xrpld/app/tx/detail/XahauGenesis.h>
|
||||
#include <xrpld/ledger/Sandbox.h>
|
||||
#include <xrpl/basics/Log.h>
|
||||
#include <xrpl/hook/Enum.h>
|
||||
#include <xrpl/hook/Guard.h>
|
||||
#include <xrpl/protocol/AccountID.h>
|
||||
#include <xrpl/protocol/Feature.h>
|
||||
@@ -607,8 +608,8 @@ Change::activateXahauGenesis()
|
||||
wasmBytes, // wasm to verify
|
||||
loggerStream,
|
||||
"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh",
|
||||
(ctx_.view().rules().enabled(featureHooksUpdate1) ? 1 : 0) +
|
||||
(ctx_.view().rules().enabled(fix20250131) ? 2 : 0));
|
||||
hook_api::getImportWhitelist(ctx_.view().rules()),
|
||||
hook_api::getGuardRulesVersion(ctx_.view().rules()));
|
||||
|
||||
if (!result)
|
||||
{
|
||||
|
||||
@@ -490,8 +490,8 @@ SetHook::validateHookSetEntry(SetHookCtx& ctx, STObject const& hookSetObj)
|
||||
hook, // wasm to verify
|
||||
logger,
|
||||
hsacc,
|
||||
(ctx.rules.enabled(featureHooksUpdate1) ? 1 : 0) +
|
||||
(ctx.rules.enabled(fix20250131) ? 2 : 0));
|
||||
hook_api::getImportWhitelist(ctx.rules),
|
||||
hook_api::getGuardRulesVersion(ctx.rules));
|
||||
|
||||
if (ctx.j.trace())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user