Compare commits

...

12 Commits

Author SHA1 Message Date
Denis Angell
c6a27e895e compile 2025-02-26 13:10:03 +01:00
Denis Angell
b56dc38c22 Merge branch 'dev' into func-hooks 2025-02-26 12:39:50 +01:00
Denis Angell
e654219ba5 dump 2025-02-26 12:39:47 +01:00
tequ
89cacb1258 Enhance shell script error handling and debugging on GHA (#447) 2025-02-24 10:33:21 +01:00
tequ
8ccff44e8c Fix Error handling on build action (#412) 2025-02-24 18:16:21 +10:00
tequ
420240a2ab Fixed not to use a large fixed range in the magic_enum. (#436) 2025-02-24 17:46:42 +10:00
Richard Holland
230873f196 debug gh builds 2025-02-06 15:21:37 +11:00
Wietse Wind
1fb1a99ea2 Update build-in-docker.yml 2025-02-05 08:23:49 +01:00
Richard Holland
e0b63ac70e Revert "debug account tx tests under release builder"
This reverts commit da8df63be3.

Revert "add strict filtering to account_tx api (#429)"

This reverts commit 317bd4bc6e.
2025-02-05 14:59:33 +11:00
Richard Holland
da8df63be3 debug account tx tests under release builder 2025-02-04 17:02:17 +11:00
RichardAH
317bd4bc6e add strict filtering to account_tx api (#429) 2025-02-03 17:56:08 +10:00
RichardAH
2fd465bb3f fix20250131 (#428)
Co-authored-by: Denis Angell <dangell@transia.co>
2025-02-03 10:33:19 +10:00
22 changed files with 382 additions and 79 deletions

View File

@@ -14,7 +14,7 @@ jobs:
checkout:
runs-on: [self-hosted, vanity]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
clean: false
checkpatterns:

View File

@@ -764,6 +764,7 @@ if (tests)
src/test/app/ValidatorSite_test.cpp
src/test/app/SetHook_test.cpp
src/test/app/SetHookTSH_test.cpp
src/test/app/SetHookV3_test.cpp
src/test/app/Wildcard_test.cpp
src/test/app/XahauGenesis_test.cpp
src/test/app/tx/apply_test.cpp

View File

@@ -1,4 +1,11 @@
#!/bin/bash
#!/bin/bash -u
# We use set -e and bash with -u to bail on first non zero exit code of any
# processes launched or upon any unbound variable.
# We use set -x to print commands before running them to help with
# debugging.
set -ex
set -e
echo "START INSIDE CONTAINER - CORE"

View File

@@ -1,4 +1,11 @@
#!/bin/bash
#!/bin/bash -u
# We use set -e and bash with -u to bail on first non zero exit code of any
# processes launched or upon any unbound variable.
# We use set -x to print commands before running them to help with
# debugging.
set -ex
set -e
echo "START INSIDE CONTAINER - FULL"
@@ -19,7 +26,7 @@ yum-config-manager --disable centos-sclo-sclo
####
cd /io;
mkdir src/certs;
mkdir -p src/certs;
curl --silent -k https://raw.githubusercontent.com/RichardAH/rippled-release-builder/main/ca-bundle/certbundle.h -o src/certs/certbundle.h;
if [ "`grep certbundle.h src/ripple/net/impl/RegisterSSLCerts.cpp | wc -l`" -eq "0" ]
then
@@ -66,8 +73,8 @@ then
#endif/g" src/ripple/net/impl/RegisterSSLCerts.cpp &&
sed -i "s/#include <ripple\/net\/RegisterSSLCerts.h>/\0\n#include <certs\/certbundle.h>/g" src/ripple/net/impl/RegisterSSLCerts.cpp
fi
mkdir .nih_c;
mkdir .nih_toolchain;
mkdir -p .nih_c;
mkdir -p .nih_toolchain;
cd .nih_toolchain &&
yum install -y wget lz4 lz4-devel git llvm13-static.x86_64 llvm13-devel.x86_64 devtoolset-10-binutils zlib-static ncurses-static -y \
devtoolset-7-gcc-c++ \
@@ -115,7 +122,7 @@ tar -xf libunwind-13.0.1.src.tar.xz &&
cp -r libunwind-13.0.1.src/include libunwind-13.0.1.src/src lld-13.0.1.src/ &&
cd lld-13.0.1.src &&
rm -rf build CMakeCache.txt &&
mkdir build &&
mkdir -p build &&
cd build &&
cmake .. -DLLVM_LIBRARY_DIR=/usr/lib64/llvm13/lib/ -DCMAKE_INSTALL_PREFIX=/usr/lib64/llvm13/ -DCMAKE_BUILD_TYPE=Release &&
make -j$3 install &&
@@ -125,7 +132,7 @@ cd ../../ &&
echo "-- Build WasmEdge --" &&
( wget -nc -q https://github.com/WasmEdge/WasmEdge/archive/refs/tags/0.11.2.zip; unzip -o 0.11.2.zip; ) &&
cd WasmEdge-0.11.2 &&
( mkdir build; echo "" ) &&
( mkdir -p build; echo "" ) &&
cd build &&
export BOOST_ROOT="/usr/local/src/boost_1_86_0" &&
export Boost_LIBRARY_DIRS="/usr/local/lib" &&

View File

@@ -1,4 +1,11 @@
#!/bin/bash
#!/bin/bash -u
# We use set -e and bash with -u to bail on first non zero exit code of any
# processes launched or upon any unbound variable.
# We use set -x to print commands before running them to help with
# debugging.
set -ex
set -e
echo "START BUILDING (HOST)"
@@ -36,7 +43,8 @@ fi
STATIC_CONTAINER=$(docker ps -a | grep $CONTAINER_NAME |wc -l)
if [[ "$STATIC_CONTAINER" -gt "0" && "$GITHUB_REPOSITORY" != "" ]]; then
#if [[ "$STATIC_CONTAINER" -gt "0" && "$GITHUB_REPOSITORY" != "" ]]; then
if false; then
echo "Static container, execute in static container to have max. cache"
docker start $CONTAINER_NAME
docker exec -i $CONTAINER_NAME /hbb_exe/activate-exec bash -x /io/build-core.sh "$GITHUB_REPOSITORY" "$GITHUB_SHA" "$BUILD_CORES" "$GITHUB_RUN_NUMBER"

View File

@@ -3,6 +3,7 @@
#include <iostream>
#include <map>
#include <memory>
#include <optional>
#include <ostream>
#include <stack>
#include <string>
@@ -13,9 +14,9 @@
using GuardLog =
std::optional<std::reference_wrapper<std::basic_ostream<char>>>;
#define DEBUG_GUARD 0
#define DEBUG_GUARD_VERBOSE 0
#define DEBUG_GUARD_VERY_VERBOSE 0
#define DEBUG_GUARD 1
#define DEBUG_GUARD_VERBOSE 1
#define DEBUG_GUARD_VERY_VERBOSE 1
#define GUARDLOG(logCode) \
if (!guardLog) \
@@ -271,7 +272,19 @@ check_guard(
int guard_func_idx,
int last_import_idx,
GuardLog guardLog,
std::string guardLogAccStr)
std::string guardLogAccStr,
/* 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
* (0b111) so the ruleVersion = 7, however if a specific rule update must be
* rolled back due to unforeseen behaviour then this may no longer be the
* case. using a bit field here leaves us flexible to rollback changes that
* might have unforeseen consequences, without also rolling back further
* changes that are fine.
*/
uint64_t rulesVersion = 0
)
{
#define MAX_GUARD_CALLS 1024
uint32_t guard_count = 0;
@@ -621,11 +634,17 @@ check_guard(
}
else if (fc_type == 10) // memory.copy
{
if (rulesVersion & 0x02U)
GUARD_ERROR("Memory.copy instruction is not allowed.");
REQUIRE(2);
ADVANCE(2);
}
else if (fc_type == 11) // memory.fill
{
if (rulesVersion & 0x02U)
GUARD_ERROR("Memory.fill instruction is not allowed.");
ADVANCE(1);
}
else if (fc_type <= 7) // numeric instructions
@@ -807,6 +826,15 @@ validateGuards(
std::vector<uint8_t> const& wasm,
GuardLog guardLog,
std::string guardLogAccStr,
/* 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
* (0b111) so the ruleVersion = 7, however if a specific rule update must be
* rolled back due to unforeseen behaviour then this may no longer be the
* case. using a bit field here leaves us flexible to rollback changes that
* might have unforeseen consequences, without also rolling back further
* changes that are fine.
*/
uint64_t rulesVersion = 0)
{
uint64_t byteCount = wasm.size();
@@ -873,23 +901,23 @@ validateGuards(
// followed by an leb128 length
int section_type = wasm[i++];
if (section_type == 0)
{
GUARDLOG(hook::log::CUSTOM_SECTION_DISALLOWED)
<< "Malformed transaction. "
<< "Hook contained a custom section, which is not allowed. Use "
"cleaner.\n";
return {};
}
// if (section_type == 0)
// {
// GUARDLOG(hook::log::CUSTOM_SECTION_DISALLOWED)
// << "Malformed transaction. "
// << "Hook contained a custom section, which is not allowed. Use "
// "cleaner.\n";
// return {};
// }
if (section_type <= last_section_type)
{
GUARDLOG(hook::log::SECTIONS_OUT_OF_SEQUENCE)
<< "Malformed transcation. "
<< "Hook contained wasm sections that were either repeated or "
"were out of sequence.\n";
return {};
}
// if (section_type <= last_section_type)
// {
// GUARDLOG(hook::log::SECTIONS_OUT_OF_SEQUENCE)
// << "Malformed transcation. "
// << "Hook contained wasm sections that were either repeated or "
// "were out of sequence.\n";
// return {};
// }
last_section_type = section_type;
@@ -1111,21 +1139,32 @@ validateGuards(
}
}
if (wasm[i] == 'm' && wasm[i + 1] == 'e' && wasm[i + 2] == 't' && wasm[i + 3] == 'h' && wasm[i + 4] == 'o' && wasm[i + 5] == 'd')
{
i += name_len;
CHECK_SHORT_HOOK();
i++;
CHECK_SHORT_HOOK();
hook_func_idx = parseLeb128(wasm, i, &i);
CHECK_SHORT_HOOK();
continue;
}
i += name_len + 1;
parseLeb128(wasm, i, &i);
CHECK_SHORT_HOOK();
}
// execution to here means export section was parsed
if (!hook_func_idx)
{
GUARDLOG(hook::log::EXPORT_MISSING)
<< "Malformed transaction. "
<< "Hook did not export: "
<< (!hook_func_idx ? "int64_t hook(uint32_t); " : "")
<< "\n";
return {};
}
// if (!hook_func_idx)
// {
// GUARDLOG(hook::log::EXPORT_MISSING)
// << "Malformed transaction. "
// << "Hook did not export: "
// << (!hook_func_idx ? "int64_t hook(uint32_t); " : "")
// << "\n";
// return {};
// }
}
else if (section_type == 3) // function section
{
@@ -1267,13 +1306,13 @@ validateGuards(
else
{
// fail
GUARDLOG(hook::log::FUNC_TYPE_INVALID)
<< "Invalid function type. Not used by any import or "
"hook/cbak func. "
<< "Codesec: " << section_type << " "
<< "Local: " << j << " "
<< "Offset: " << i << "\n";
return {};
// GUARDLOG(hook::log::FUNC_TYPE_INVALID)
// << "Invalid function type. Not used by any import or "
// "hook/cbak func. "
// << "Codesec: " << section_type << " "
// << "Local: " << j << " "
// << "Offset: " << i << "\n";
// return {};
}
int param_count = parseLeb128(wasm, i, &i);
@@ -1292,11 +1331,11 @@ validateGuards(
}
else if (param_count != (*first_signature).get().size() - 1)
{
GUARDLOG(hook::log::FUNC_TYPE_INVALID)
<< "Malformed transaction. "
<< "Hook API: " << *first_name
<< " has the wrong number of parameters.\n";
return {};
// GUARDLOG(hook::log::FUNC_TYPE_INVALID)
// << "Malformed transaction. "
// << "Hook API: " << *first_name
// << " has the wrong number of parameters.\n";
// return {};
}
for (int k = 0; k < param_count; ++k)
@@ -1360,12 +1399,12 @@ validateGuards(
// most compilers out
if (result_count != 1)
{
GUARDLOG(hook::log::FUNC_RETURN_COUNT)
<< "Malformed transaction. "
<< "Hook declares a function type that returns fewer "
"or more than one value. "
<< "\n";
return {};
// GUARDLOG(hook::log::FUNC_RETURN_COUNT)
// << "Malformed transaction. "
// << "Hook declares a function type that returns fewer "
// "or more than one value. "
// << "\n";
// return {};
}
// this can only ever be 1 in production, but in testing it may
@@ -1477,7 +1516,8 @@ validateGuards(
guard_import_number,
last_import_number,
guardLog,
guardLogAccStr);
guardLogAccStr,
rulesVersion);
if (!valid)
return {};

View File

@@ -723,6 +723,9 @@ public:
uint32_t wasmParam,
beast::Journal const& j)
{
static WasmEdge_String _hookFunctionName = WasmEdge_StringCreateByCString("methodCreate");
// HookExecutor can only execute once
assert(!spent);
@@ -761,7 +764,7 @@ public:
vm.ctx,
reinterpret_cast<const uint8_t*>(wasm),
len,
callback ? cbakFunctionName : hookFunctionName,
_hookFunctionName,
params,
1,
returns,

View File

@@ -79,7 +79,7 @@ main(int argc, char** argv)
close(fd);
auto result = validateGuards(hook, std::cout, "", 1);
auto result = validateGuards(hook, std::cout, "", 3);
if (!result)
{

View File

@@ -587,7 +587,8 @@ Change::activateXahauGenesis()
wasmBytes, // wasm to verify
loggerStream,
"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh",
ctx_.view().rules().enabled(featureHooksUpdate1) ? 1 : 0);
(ctx_.view().rules().enabled(featureHooksUpdate1) ? 1 : 0) +
(ctx_.view().rules().enabled(fix20250131) ? 2 : 0));
if (!result)
{

View File

@@ -72,6 +72,16 @@ Remit::preflight(PreflightContext const& ctx)
return temREDUNDANT;
}
if (ctx.rules.enabled(fix20250131))
{
if (!dstID || dstID == noAccount())
{
JLOG(ctx.j.warn())
<< "Malformed transaction: Remit to invalid account.";
return temMALFORMED;
}
}
if (ctx.tx.isFieldPresent(sfInform))
{
AccountID const infID = ctx.tx.getAccountID(sfInform);

View File

@@ -479,7 +479,8 @@ SetHook::validateHookSetEntry(SetHookCtx& ctx, STObject const& hookSetObj)
hook, // wasm to verify
logger,
hsacc,
ctx.rules.enabled(featureHooksUpdate1) ? 1 : 0);
(ctx.rules.enabled(featureHooksUpdate1) ? 1 : 0) +
(ctx.rules.enabled(fix20250131) ? 2 : 0));
if (ctx.j.trace())
{

View File

@@ -1776,7 +1776,7 @@ Transactor::operator()()
// write state if all chains executed successfully
if (isTesSuccess(result))
hook::finalizeHookState(stateMap, ctx_, ctx_.tx.getTransactionID());
result = hook::finalizeHookState(stateMap, ctx_, ctx_.tx.getTransactionID());
// write hook results
// this happens irrespective of whether final result was a tesSUCCESS
@@ -2031,8 +2031,9 @@ Transactor::operator()()
for (auto const& [accID, hookHashes] : aawMap)
doAgainAsWeak(accID, hookHashes, stateMap, weakResults, proMeta);
result = hook::finalizeHookState(stateMap, ctx_, ctx_.tx.getTransactionID());
// write hook results
hook::finalizeHookState(stateMap, ctx_, ctx_.tx.getTransactionID());
for (auto& weakResult : weakResults)
hook::finalizeHookResult(weakResult, ctx_, isTesSuccess(result));

View File

@@ -74,7 +74,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 = 76;
static constexpr std::size_t numFeatures = 77;
/** Amendments that this server supports and the default voting behavior.
Whether they are enabled depends on the Rules defined in the validated
@@ -364,6 +364,7 @@ extern uint256 const fix240911;
extern uint256 const fixFloatDivide;
extern uint256 const fixReduceImport;
extern uint256 const fixXahauV3;
extern uint256 const fix20250131;
} // namespace ripple

View File

@@ -469,7 +469,8 @@ REGISTER_FIX (fixPageCap, Supported::yes, VoteBehavior::De
REGISTER_FIX (fix240911, Supported::yes, VoteBehavior::DefaultYes);
REGISTER_FIX (fixFloatDivide, Supported::yes, VoteBehavior::DefaultYes);
REGISTER_FIX (fixReduceImport, Supported::yes, VoteBehavior::DefaultYes);
REGISTER_FIX (fixXahauV3, Supported::yes, VoteBehavior::DefaultNo);
REGISTER_FIX (fixXahauV3, Supported::yes, VoteBehavior::DefaultYes);
REGISTER_FIX (fix20250131, Supported::yes, VoteBehavior::DefaultYes);
// The following amendments are obsolete, but must remain supported
// because they could potentially get enabled.

View File

@@ -240,7 +240,9 @@ TxMeta::addRaw(Serializer& s, TER result, std::uint32_t index)
{
mResult = TERtoInt(result);
mIndex = index;
assert((mResult == 0) || ((mResult > 100) && (mResult <= 255)));
assert(
(mResult == 0 || mResult == 1) ||
((mResult > 100) && (mResult <= 255)));
mNodes.sort([](STObject const& o1, STObject const& o2) {
return o1.getFieldH256(sfLedgerIndex) < o2.getFieldH256(sfLedgerIndex);

View File

@@ -36,12 +36,12 @@
#include <magic/magic_enum.h>
#include <sstream>
#define MAGIC_ENUM(x) \
#define MAGIC_ENUM(x, _min, _max) \
template <> \
struct magic_enum::customize::enum_range<x> \
{ \
static constexpr int min = -20000; \
static constexpr int max = 20000; \
static constexpr int min = _min; \
static constexpr int max = _max; \
};
#define MAGIC_ENUM_16(x) \
@@ -59,14 +59,14 @@
static constexpr bool is_flags = true; \
};
MAGIC_ENUM(ripple::SerializedTypeID);
MAGIC_ENUM(ripple::LedgerEntryType);
MAGIC_ENUM(ripple::TELcodes);
MAGIC_ENUM(ripple::TEMcodes);
MAGIC_ENUM(ripple::TEFcodes);
MAGIC_ENUM(ripple::TERcodes);
MAGIC_ENUM(ripple::TEScodes);
MAGIC_ENUM(ripple::TECcodes);
MAGIC_ENUM(ripple::SerializedTypeID, -2, 10004);
MAGIC_ENUM(ripple::LedgerEntryType, 0, 255);
MAGIC_ENUM(ripple::TELcodes, -399, 300);
MAGIC_ENUM(ripple::TEMcodes, -299, -200);
MAGIC_ENUM(ripple::TEFcodes, -199, -100);
MAGIC_ENUM(ripple::TERcodes, -99, -1);
MAGIC_ENUM(ripple::TEScodes, 0, 1);
MAGIC_ENUM(ripple::TECcodes, 100, 255);
MAGIC_ENUM_16(ripple::TxType);
MAGIC_ENUM_FLAG(ripple::UniversalFlags);
MAGIC_ENUM_FLAG(ripple::AccountSetFlags);

1
src/test/app/.env Normal file
View File

@@ -0,0 +1 @@
HOOKS_COMPILE_HOST=http://localhost:9000

View File

@@ -5544,7 +5544,6 @@ public:
testTSH(sa - fixXahauV1 - fixXahauV2);
testTSH(sa - fixXahauV2);
testTSH(sa);
testEmittedTxn(sa - fixXahauV2);
testEmittedTxn(sa);
}
};

View File

@@ -0,0 +1,140 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012-2016 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include <ripple/app/hook/Enum.h>
#include <ripple/app/ledger/LedgerMaster.h>
#include <ripple/app/tx/impl/SetHook.h>
#include <ripple/protocol/TxFlags.h>
#include <ripple/protocol/jss.h>
#include <test/app/SetHook_wasm.h>
#include <test/jtx.h>
#include <test/jtx/hook.h>
#include <unordered_map>
#include <iostream>
#include <ripple/json/json_reader.h>
namespace ripple {
namespace test {
class SetHookV3_test : public beast::unit_test::suite
{
private:
// helper
void static overrideFlag(Json::Value& jv)
{
jv[jss::Flags] = hsfOVERRIDE;
}
public:
// This is a large fee, large enough that we can set most small test hooks
// without running into fee issues we only want to test fee code specifically in
// fee unit tests, the rest of the time we want to ignore it.
#define HSFEE fee(100'000'000)
#define M(m) memo(m, "", "")
std::string
loadHook()
{
std::string name = "/Users/darkmatter/projects/ledger-works/xahaud/src/test/app/wasm/custom.wasm";
if (!std::filesystem::exists(name)) {
std::cout << "File does not exist: " << name << "\n";
return "";
}
std::ifstream hookFile(name, std::ios::binary);
if (!hookFile)
{
std::cout << "Failed to open file: " << name << "\n";
return "";
}
// Read the file into a vector
std::vector<char> buffer((std::istreambuf_iterator<char>(hookFile)), std::istreambuf_iterator<char>());
// Check if the buffer is empty
if (buffer.empty()) {
std::cout << "File is empty or could not be read properly.\n";
return "";
}
return strHex(buffer);
}
void
testSimple(FeatureBitset features)
{
testcase("Test simple");
using namespace jtx;
// Env env{*this, features};
Env env{*this, envconfig(), features, nullptr,
beast::severities::kTrace
};
auto const alice = Account{"alice"};
auto const gw = Account{"gateway"};
auto const USD = gw["USD"];
env.fund(XRP(10000), alice, gw);
env.close();
env.trust(USD(100000), alice);
env.close();
env(pay(gw, alice, USD(10000)));
env.close();
std::string hook = loadHook();
std::cout << "Hook: " << hook << "\n";
// install the hook on alice
env(ripple::test::jtx::hook(alice, {{hso(hook, overrideFlag)}}, 0),
M("set simple"),
HSFEE);
env.close();
// // invoke the hook
// Json::Value jv = invoke::invoke(alice);
// Json::Value params{Json::arrayValue};
// Json::Value pv;
// Json::Value piv;
// piv[jss::HookParameterName] = "736F6D6566756E63";
// piv[jss::HookParameterValue] = "736F6D6566756E63";
// pv[jss::HookParameter] = piv;
// params[0u] = pv;
// jv[jss::HookParameters] = params;
env(invoke::invoke(alice), M("test simple"), fee(XRP(1)));
}
void
testWithFeatures(FeatureBitset features)
{
testSimple(features);
}
void
run() override
{
using namespace test::jtx;
auto const sa = supported_amendments();
testWithFeatures(sa);
}
};
BEAST_DEFINE_TESTSUITE(SetHookV3, app, ripple);
} // namespace test
} // namespace ripple
#undef M

View File

@@ -1138,6 +1138,54 @@ public:
: preHookCount + 66);
}
void
testFillCopy(FeatureBitset features)
{
testcase("Test fill/copy");
// a hook containing memory.fill instruction
std::string hookFill =
"0061736d0100000001130360027f7f017f60037f7f7e017e60017f017e02"
"170203656e76025f67000003656e76066163636570740001030201020503"
"0100020621057f01418088040b7f004180080b7f004180080b7f00418088"
"040b7f004180080b07080104686f6f6b00020aa4800001a0800001017e23"
"01412a41e400fc0b004101410110001a41004100420010011a20010b";
// a hook containing memory.copy instruction
std::string hookCopy =
"0061736d0100000001130360027f7f017f60037f7f7e017e60017f017e02"
"170203656e76025f67000003656e76066163636570740001030201020503"
"0100020621057f01418088040b7f004180080b7f004180080b7f00418088"
"040b7f004180080b07080104686f6f6b00020aa5800001a1800001017e23"
"00230141e400fc0a00004101410110001a41004100420010011a20010b";
using namespace jtx;
for (int withFix = 0; withFix < 2; ++withFix)
{
auto f = withFix ? features : features - fix20250131;
Env env{*this, f};
auto const alice = Account{"alice"};
env.fund(XRP(10000), alice);
auto const bob = Account{"bob"};
env.fund(XRP(10000), bob);
env(ripple::test::jtx::hook(alice, {{hso(hookFill)}}, 0),
M(withFix ? "hookFill - with fix" : "hookFill - zonder fix"),
HSFEE,
withFix ? ter(temMALFORMED) : ter(tesSUCCESS));
env(ripple::test::jtx::hook(bob, {{hso(hookCopy)}}, 0),
M(withFix ? "hookCopy - with fix" : "hookCopy - zonder fix"),
HSFEE,
withFix ? ter(temMALFORMED) : ter(tesSUCCESS));
env.close();
}
}
void
testCreate(FeatureBitset features)
{
@@ -11973,6 +12021,8 @@ public:
testNSDeletePartial(features);
testPageCap(features);
testFillCopy(features);
testWasm(features);
test_accept(features);
test_rollback(features);

View File

@@ -0,0 +1,10 @@
/**
*
*/
#include "hookapi.h"
int64_t hook(uint32_t reserved) {
TRACESTR("Base.c: Called.");
_g(1,1);
return accept(SBUF("base: Finished."), __LINE__);;
}

View File

@@ -0,0 +1,20 @@
/**
*
*/
#include "hookapi.h"
// #define DEBUG 1
// #define SBUF(str) (uint32_t)(str), sizeof(str)
// #define TRACESTR(v) if (DEBUG) trace((uint32_t)(#v), (uint32_t)(sizeof(#v) - 1), (uint32_t)(v), sizeof(v), 0);
// // hook developers should use this guard macro, simply GUARD(<maximum iterations>)
// #define GUARD(maxiter) _g((1ULL << 31U) + __LINE__, (maxiter)+1)
// #define GUARDM(maxiter, n) _g(( (1ULL << 31U) + (__LINE__ << 16) + n), (maxiter)+1)
// hooks-cli compile-c contracts/custom.c build
int64_t methodCreate(uint32_t reserved) {
TRACESTR("somefunc.c: Called.");
for (int i = 0; GUARD(10), i < 10; i++) {
TRACESTR("somefunc.c: Iterating.");
}
return accept(SBUF("somefunc.c: Finished."), __LINE__);
}