Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prepare Hook API #413

Open
wants to merge 10 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/ripple/app/hook/Enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -434,5 +434,9 @@ static const std::map<std::string, std::vector<uint8_t>> import_whitelist{
// featureHooks1
static const std::map<std::string, std::vector<uint8_t>> import_whitelist_1{
{"xpop_slot", {0x7EU, 0x7FU, 0x7FU}}};
// featureHooks2
static const std::map<std::string, std::vector<uint8_t>> import_whitelist_2{
{"prepare", {0x7EU, 0x7FU, 0x7FU, 0x7FU, 0x7FU}}};
}; // namespace hook_api

#endif
31 changes: 23 additions & 8 deletions src/ripple/app/hook/Guard.h
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ validateGuards(
* might have unforeseen consequences, without also rolling back further
* changes that are fine.
*/
uint64_t rulesVersion = 0)
uint64_t rulesVersion = 0x00U)
{
uint64_t byteCount = wasm.size();

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

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

auto const& api_signature = *sig;

if (!first_signature)
{
Expand Down
8 changes: 8 additions & 0 deletions src/ripple/app/hook/applyHook.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ DECLARE_HOOK_FUNCTION(
etxn_nonce,
uint32_t write_ptr,
uint32_t write_len);
DECLARE_HOOK_FUNCTION(
int64_t,
prepare,
uint32_t write_ptr,
uint32_t write_len,
uint32_t read_ptr,
uint32_t read_len);
DECLARE_HOOK_FUNCTION(
int64_t,
emit,
Expand Down Expand Up @@ -802,6 +809,7 @@ class HookExecutor
ADD_HOOK_FUNCTION(sto_erase, ctx);
ADD_HOOK_FUNCTION(util_keylet, ctx);

ADD_HOOK_FUNCTION(prepare, ctx);
ADD_HOOK_FUNCTION(emit, ctx);
ADD_HOOK_FUNCTION(etxn_burden, ctx);
ADD_HOOK_FUNCTION(etxn_fee_base, ctx);
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/app/hook/guard_checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ main(int argc, char** argv)

close(fd);

auto result = validateGuards(hook, std::cout, "", 3);
auto result = validateGuards(hook, std::cout, "", 0x0001 + 0x0002 + 0x0004);

if (!result)
{
Expand Down
Loading
Loading