initial code for HooksUpdate1, unfinished, compiling

This commit is contained in:
Richard Holland
2023-07-04 14:05:45 +00:00
parent d6ce1add8b
commit fc6f8dde94
9 changed files with 72 additions and 14 deletions

View File

@@ -169,7 +169,9 @@ namespace hook_api
EMITTED_TXN = 22, EMITTED_TXN = 22,
NFT_OFFER = 23, NFT_OFFER = 23,
HOOK_DEFINITION = 24, HOOK_DEFINITION = 24,
LAST_KLTYPE = HOOK_DEFINITION HOOK_STATE_DIR = 25,
LAST_KLTYPE_V0 = HOOK_DEFINITION,
LAST_KLTYPE_V1 = HOOK_STATE_DIR,
}; };
} }
@@ -324,5 +326,11 @@ namespace hook_api
{"otxn_param",{0x7EU,0x7FU,0x7FU,0x7FU,0x7FU}}, {"otxn_param",{0x7EU,0x7FU,0x7FU,0x7FU,0x7FU}},
{"meta_slot",{0x7EU,0x7FU}} {"meta_slot",{0x7EU,0x7FU}}
}; };
// featureHooks1
static const std::map<std::string, std::vector<uint8_t>> import_whitelist_1
{
};
}; };
#endif #endif

View File

@@ -759,7 +759,8 @@ std::pair<
validateGuards( validateGuards(
std::vector<uint8_t> const& wasm, std::vector<uint8_t> const& wasm,
GuardLog guardLog, GuardLog guardLog,
std::string guardLogAccStr) std::string guardLogAccStr,
uint64_t rulesVersion = 0)
{ {
uint64_t byteCount = wasm.size(); uint64_t byteCount = wasm.size();
@@ -914,6 +915,13 @@ validateGuards(
guard_import_number = func_upto; guard_import_number = func_upto;
} }
else if (hook_api::import_whitelist.find(import_name) == hook_api::import_whitelist.end()) else if (hook_api::import_whitelist.find(import_name) == hook_api::import_whitelist.end())
{
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) GUARDLOG(hook::log::IMPORT_ILLEGAL)
<< "Malformed transaction. " << "Malformed transaction. "
@@ -921,6 +929,7 @@ validateGuards(
<< "appear in the hook_api function set: `" << import_name << "`" << "\n"; << "appear in the hook_api function set: `" << import_name << "`" << "\n";
return {}; return {};
} }
}
// add to import map // add to import map
if (import_type_map.find(type_idx) == import_type_map.end()) if (import_type_map.find(type_idx) == import_type_map.end())

View File

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

View File

@@ -2605,7 +2605,14 @@ DEFINE_HOOK_FUNCTION(
if (write_len < 34) if (write_len < 34)
return TOO_SMALL; return TOO_SMALL;
if (keylet_type < 1 || keylet_type > keylet_code::LAST_KLTYPE) bool const v1 = applyCtx.view().rules().enabled(featureHooksUpdate1);
if (keylet_type == 0)
return INVALID_ARGUMENT;
auto const last = v1 ? keylet_code::LAST_KLTYPE_V1 : keylet_code::LAST_KLTYPE_V0;
if (keylet_type > last)
return INVALID_ARGUMENT; return INVALID_ARGUMENT;
try try
@@ -2799,6 +2806,31 @@ DEFINE_HOOK_FUNCTION(
return serialize_keylet(kl, memory, write_ptr, write_len); return serialize_keylet(kl, memory, write_ptr, write_len);
} }
case keylet_code::HOOK_STATE_DIR:
{
if (a == 0 || b == 0 || c == 0 || d == 0)
return INVALID_ARGUMENT;
if (e != 0 || f != 0)
return INVALID_ARGUMENT;
uint32_t aread_ptr = a, aread_len = b, nread_ptr = c, nread_len = d;
if (NOT_IN_BOUNDS(aread_ptr, aread_len, memory_length) ||
NOT_IN_BOUNDS(nread_ptr, nread_len, memory_length))
return OUT_OF_BOUNDS;
if (aread_len != 20 || nread_len != 32)
return INVALID_ARGUMENT;
ripple::Keylet kl =
ripple::keylet::hookStateDir(
AccountID::fromVoid(memory + aread_ptr),
ripple::base_uint<256>::fromVoid(memory + nread_ptr));
return serialize_keylet(kl, memory, write_ptr, write_len);
}
// skip is overloaded, has a single, optional 4 byte argument // skip is overloaded, has a single, optional 4 byte argument
case keylet_code::SKIP: case keylet_code::SKIP:

View File

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

View File

@@ -450,7 +450,8 @@ SetHook::validateHookSetEntry(SetHookCtx& ctx, STObject const& hookSetObj)
validateGuards( validateGuards(
hook, // wasm to verify hook, // wasm to verify
logger, logger,
hsacc hsacc,
ctx.rules.enabled(featureHooksUpdate1) ? 1 : 0
); );
if (ctx.j.trace()) if (ctx.j.trace())
@@ -627,7 +628,8 @@ SetHook::preflight(PreflightContext const& ctx)
{ {
.j = ctx.j, .j = ctx.j,
.tx = ctx.tx, .tx = ctx.tx,
.app = ctx.app .app = ctx.app,
.rules = ctx.rules
}; };
bool allBlank = true; bool allBlank = true;
@@ -1092,7 +1094,8 @@ SetHook::setHook()
{ {
.j = ctx_.app.journal("View"), .j = ctx_.app.journal("View"),
.tx = ctx_.tx, .tx = ctx_.tx,
.app = ctx_.app .app = ctx_.app,
.rules = ctx_.view().rules()
}; };
const int blobMax = hook::maxHookWasmSize(); const int blobMax = hook::maxHookWasmSize();

View File

@@ -35,6 +35,7 @@
#include <vector> #include <vector>
#include <ripple/app/hook/Enum.h> #include <ripple/app/hook/Enum.h>
#include <ripple/app/hook/applyHook.h> #include <ripple/app/hook/applyHook.h>
#include <ripple/protocol/Rules.h>
namespace ripple { namespace ripple {
@@ -52,6 +53,7 @@ struct SetHookCtx
beast::Journal j; beast::Journal j;
STTx const& tx; STTx const& tx;
Application& app; Application& app;
Rules const& rules;
}; };
class SetHook : public Transactor class SetHook : public Transactor

View File

@@ -74,7 +74,7 @@ namespace detail {
// Feature.cpp. Because it's only used to reserve storage, and determine how // 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 // 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. // the actual number of amendments. A LogicError on startup will verify this.
static constexpr std::size_t numFeatures = 64; static constexpr std::size_t numFeatures = 65;
/** Amendments that this server supports and the default voting behavior. /** Amendments that this server supports and the default voting behavior.
Whether they are enabled depends on the Rules defined in the validated Whether they are enabled depends on the Rules defined in the validated
@@ -352,6 +352,7 @@ extern uint256 const fixNonFungibleTokensV1_2;
extern uint256 const fixNFTokenRemint; extern uint256 const fixNFTokenRemint;
extern uint256 const featureImport; extern uint256 const featureImport;
extern uint256 const featureXahauGenesis; extern uint256 const featureXahauGenesis;
extern uint256 const featureHooksUpdate1;
} // namespace ripple } // namespace ripple

View File

@@ -458,6 +458,8 @@ REGISTER_FEATURE(PaychanAndEscrowForTokens, Supported::yes, VoteBehavior::De
REGISTER_FEATURE(URIToken, Supported::yes, VoteBehavior::DefaultYes); REGISTER_FEATURE(URIToken, Supported::yes, VoteBehavior::DefaultYes);
REGISTER_FEATURE(Import, Supported::yes, VoteBehavior::DefaultNo); REGISTER_FEATURE(Import, Supported::yes, VoteBehavior::DefaultNo);
REGISTER_FEATURE(XahauGenesis, Supported::yes, VoteBehavior::DefaultNo); REGISTER_FEATURE(XahauGenesis, Supported::yes, VoteBehavior::DefaultNo);
REGISTER_FEATURE(HooksUpdate1, Supported::yes, VoteBehavior::DefaultNo);
// The following amendments are obsolete, but must remain supported // The following amendments are obsolete, but must remain supported
// because they could potentially get enabled. // because they could potentially get enabled.