Skip to content
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
6 changes: 4 additions & 2 deletions include/xrpl/tx/wasm/WasmiVM.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,15 +289,17 @@ class WasmiEngine
int64_t gas,
std::string_view funcName,
std::vector<WasmParam> const& params,
ImportVec const& imports);
ImportVec const& imports,
beast::Journal j);

NotTEC
checkHlp(
Bytes const& wasmCode,
HostFunctions& hfs,
std::string_view funcName,
std::vector<WasmParam> const& params,
ImportVec const& imports);
ImportVec const& imports,
beast::Journal j);

int
addModule(Bytes const& wasmCode, bool instantiate, ImportVec const& imports, int64_t gas);
Expand Down
3 changes: 2 additions & 1 deletion src/libxrpl/tx/wasm/HostFuncWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,10 +486,11 @@ isAmendmentEnabled_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t*

if (slice->size() == uint256::bytes)
{
if (auto ret = hf->isAmendmentEnabled(uint256::fromVoid(slice->data())); *ret == 1)
if (auto ret = hf->isAmendmentEnabled(uint256::fromVoid(slice->data())); ret && *ret == 1)
{
return returnResult(runtime, params, results, ret, index);
}
// Fall through to string lookup — the 32 bytes may be an amendment name
}

if (slice->size() > 64)
Expand Down
24 changes: 12 additions & 12 deletions src/libxrpl/tx/wasm/WasmiVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -756,24 +756,22 @@ WasmiEngine::run(
ImportVec const& imports,
beast::Journal j)
{
j_ = j;

if (gas <= 0)
return Unexpected<TER>(temBAD_AMOUNT);

try
{
checkImports(imports, &hfs);
return runHlp(wasmCode, hfs, gas, funcName, params, imports);
return runHlp(wasmCode, hfs, gas, funcName, params, imports, j);
}
catch (std::exception const& e)
{
print_wasm_error(std::string("exception: ") + e.what(), nullptr, j_);
print_wasm_error(std::string("exception: ") + e.what(), nullptr, j);
}
// LCOV_EXCL_START
catch (...)
{
print_wasm_error(std::string("exception: unknown"), nullptr, j_);
print_wasm_error(std::string("exception: unknown"), nullptr, j);
}
// LCOV_EXCL_STOP
return Unexpected<TER>(tecFAILED_PROCESSING);
Expand All @@ -786,10 +784,12 @@ WasmiEngine::runHlp(
int64_t gas,
std::string_view funcName,
std::vector<WasmParam> const& params,
ImportVec const& imports)
ImportVec const& imports,
beast::Journal j)
{
// currently only 1 module support, possible parallel UT run
std::lock_guard<decltype(m_)> const lg(m_);
j_ = j;

if (wasmCode.empty())
throw std::runtime_error("empty module");
Expand Down Expand Up @@ -861,21 +861,19 @@ WasmiEngine::check(
ImportVec const& imports,
beast::Journal j)
{
j_ = j;

try
{
checkImports(imports, &hfs);
return checkHlp(wasmCode, hfs, funcName, params, imports);
return checkHlp(wasmCode, hfs, funcName, params, imports, j);
}
catch (std::exception const& e)
{
print_wasm_error(std::string("exception: ") + e.what(), nullptr, j_);
print_wasm_error(std::string("exception: ") + e.what(), nullptr, j);
}
// LCOV_EXCL_START
catch (...)
{
print_wasm_error(std::string("exception: unknown"), nullptr, j_);
print_wasm_error(std::string("exception: unknown"), nullptr, j);
}
// LCOV_EXCL_STOP

Expand All @@ -888,10 +886,12 @@ WasmiEngine::checkHlp(
HostFunctions& hfs,
std::string_view funcName,
std::vector<WasmParam> const& params,
ImportVec const& imports)
ImportVec const& imports,
beast::Journal j)
{
// currently only 1 module support, possible parallel UT run
std::lock_guard<decltype(m_)> const lg(m_);
j_ = j;

// Create and instantiate the module.
if (wasmCode.empty())
Expand Down
Loading