Compare commits

...

4 Commits

Author SHA1 Message Date
Oleksandr
6e410d9718 Fix clang format 2026-02-12 14:39:31 -05:00
Oleksandr
cb1bf20ab4 Check that HFS object is always new 2026-02-12 13:12:15 -05:00
Oleksandr
10864f1959 Remove ability to re-use wasm module 2026-02-12 12:55:44 -05:00
Olek
6728ab52b7 Add tests for wasm functions with many parameters (#6343)
* Add functions with many parameters

* Add 10k locals function

* Module with  5k functions

* fix typo

Co-authored-by: Mayukha Vadari <mvadari@gmail.com>

---------

Co-authored-by: Mayukha Vadari <mvadari@gmail.com>
2026-02-10 18:10:33 -05:00
22 changed files with 99922 additions and 510 deletions

View File

@@ -36,7 +36,7 @@ public:
}
Expected<std::uint32_t, HostFunctionError>
getLedgerSqn() override
getLedgerSqn() const override
{
return env_.current()->seq();
}
@@ -71,37 +71,37 @@ public:
}
Expected<std::uint32_t, HostFunctionError>
getLedgerSqn() override
getLedgerSqn() const override
{
return 12345;
}
Expected<std::uint32_t, HostFunctionError>
getParentLedgerTime() override
getParentLedgerTime() const override
{
return 67890;
}
Expected<Hash, HostFunctionError>
getParentLedgerHash() override
getParentLedgerHash() const override
{
return env_.current()->header().parentHash;
}
Expected<std::uint32_t, HostFunctionError>
getBaseFee() override
getBaseFee() const override
{
return 10;
}
Expected<int32_t, HostFunctionError>
isAmendmentEnabled(uint256 const& amendmentId) override
isAmendmentEnabled(uint256 const& amendmentId) const override
{
return 1;
}
Expected<int32_t, HostFunctionError>
isAmendmentEnabled(std::string_view const& amendmentName) override
isAmendmentEnabled(std::string_view const& amendmentName) const override
{
return 1;
}
@@ -113,7 +113,7 @@ public:
}
Expected<Bytes, HostFunctionError>
getTxField(SField const& fname) override
getTxField(SField const& fname) const override
{
if (fname == sfAccount)
return Bytes(accountID_.begin(), accountID_.end());
@@ -137,7 +137,7 @@ public:
}
Expected<Bytes, HostFunctionError>
getCurrentLedgerObjField(SField const& fname) override
getCurrentLedgerObjField(SField const& fname) const override
{
auto const& sn = fname.getName();
if (sn == "Destination" || sn == "Account")
@@ -155,7 +155,7 @@ public:
}
Expected<Bytes, HostFunctionError>
getLedgerObjField(int32_t cacheIdx, SField const& fname) override
getLedgerObjField(int32_t cacheIdx, SField const& fname) const override
{
if (fname == sfBalance)
{
@@ -171,7 +171,7 @@ public:
}
Expected<Bytes, HostFunctionError>
getTxNestedField(Slice const& locator) override
getTxNestedField(Slice const& locator) const override
{
if (locator.size() == 4)
{
@@ -189,7 +189,7 @@ public:
}
Expected<Bytes, HostFunctionError>
getCurrentLedgerObjNestedField(Slice const& locator) override
getCurrentLedgerObjNestedField(Slice const& locator) const override
{
if (locator.size() == 4)
{
@@ -207,7 +207,7 @@ public:
}
Expected<Bytes, HostFunctionError>
getLedgerObjNestedField(int32_t cacheIdx, Slice const& locator) override
getLedgerObjNestedField(int32_t cacheIdx, Slice const& locator) const override
{
if (locator.size() == 4)
{
@@ -225,37 +225,37 @@ public:
}
Expected<int32_t, HostFunctionError>
getTxArrayLen(SField const& fname) override
getTxArrayLen(SField const& fname) const override
{
return 32;
}
Expected<int32_t, HostFunctionError>
getCurrentLedgerObjArrayLen(SField const& fname) override
getCurrentLedgerObjArrayLen(SField const& fname) const override
{
return 32;
}
Expected<int32_t, HostFunctionError>
getLedgerObjArrayLen(int32_t cacheIdx, SField const& fname) override
getLedgerObjArrayLen(int32_t cacheIdx, SField const& fname) const override
{
return 32;
}
Expected<int32_t, HostFunctionError>
getTxNestedArrayLen(Slice const& locator) override
getTxNestedArrayLen(Slice const& locator) const override
{
return 32;
}
Expected<int32_t, HostFunctionError>
getCurrentLedgerObjNestedArrayLen(Slice const& locator) override
getCurrentLedgerObjNestedArrayLen(Slice const& locator) const override
{
return 32;
}
Expected<int32_t, HostFunctionError>
getLedgerObjNestedArrayLen(int32_t cacheIdx, Slice const& locator) override
getLedgerObjNestedArrayLen(int32_t cacheIdx, Slice const& locator) const override
{
return 32;
}
@@ -267,19 +267,19 @@ public:
}
Expected<int32_t, HostFunctionError>
checkSignature(Slice const& message, Slice const& signature, Slice const& pubkey) override
checkSignature(Slice const& message, Slice const& signature, Slice const& pubkey) const override
{
return 1;
}
Expected<Hash, HostFunctionError>
computeSha512HalfHash(Slice const& data) override
computeSha512HalfHash(Slice const& data) const override
{
return env_.current()->header().parentHash;
}
Expected<Bytes, HostFunctionError>
accountKeylet(AccountID const& account) override
accountKeylet(AccountID const& account) const override
{
if (!account)
return Unexpected(HostFunctionError::INVALID_ACCOUNT);
@@ -288,7 +288,7 @@ public:
}
Expected<Bytes, HostFunctionError>
ammKeylet(Asset const& issue1, Asset const& issue2) override
ammKeylet(Asset const& issue1, Asset const& issue2) const override
{
if (issue1 == issue2)
return Unexpected(HostFunctionError::INVALID_PARAMS);
@@ -299,7 +299,7 @@ public:
}
Expected<Bytes, HostFunctionError>
checkKeylet(AccountID const& account, std::uint32_t seq) override
checkKeylet(AccountID const& account, std::uint32_t seq) const override
{
if (!account)
return Unexpected(HostFunctionError::INVALID_ACCOUNT);
@@ -308,7 +308,7 @@ public:
}
Expected<Bytes, HostFunctionError>
credentialKeylet(AccountID const& subject, AccountID const& issuer, Slice const& credentialType) override
credentialKeylet(AccountID const& subject, AccountID const& issuer, Slice const& credentialType) const override
{
if (!subject || !issuer || credentialType.empty() || credentialType.size() > maxCredentialTypeLength)
return Unexpected(HostFunctionError::INVALID_ACCOUNT);
@@ -317,7 +317,7 @@ public:
}
Expected<Bytes, HostFunctionError>
escrowKeylet(AccountID const& account, std::uint32_t seq) override
escrowKeylet(AccountID const& account, std::uint32_t seq) const override
{
if (!account)
return Unexpected(HostFunctionError::INVALID_ACCOUNT);
@@ -326,7 +326,7 @@ public:
}
Expected<Bytes, HostFunctionError>
oracleKeylet(AccountID const& account, std::uint32_t documentId) override
oracleKeylet(AccountID const& account, std::uint32_t documentId) const override
{
if (!account)
return Unexpected(HostFunctionError::INVALID_ACCOUNT);
@@ -335,7 +335,7 @@ public:
}
Expected<Bytes, HostFunctionError>
getNFT(AccountID const& account, uint256 const& nftId) override
getNFT(AccountID const& account, uint256 const& nftId) const override
{
if (!account || !nftId)
{
@@ -347,38 +347,38 @@ public:
}
Expected<Bytes, HostFunctionError>
getNFTIssuer(uint256 const& nftId) override
getNFTIssuer(uint256 const& nftId) const override
{
return Bytes(accountID_.begin(), accountID_.end());
}
Expected<std::uint32_t, HostFunctionError>
getNFTTaxon(uint256 const& nftId) override
getNFTTaxon(uint256 const& nftId) const override
{
return 4;
}
Expected<int32_t, HostFunctionError>
getNFTFlags(uint256 const& nftId) override
getNFTFlags(uint256 const& nftId) const override
{
return 8;
}
Expected<int32_t, HostFunctionError>
getNFTTransferFee(uint256 const& nftId) override
getNFTTransferFee(uint256 const& nftId) const override
{
return 10;
}
Expected<std::uint32_t, HostFunctionError>
getNFTSerial(uint256 const& nftId) override
getNFTSerial(uint256 const& nftId) const override
{
return 4;
}
template <typename F>
void
log(std::string_view const& msg, F&& dataFn)
log(std::string_view const& msg, F&& dataFn) const
{
#ifdef DEBUG_OUTPUT
auto& j = std::cerr;
@@ -395,7 +395,7 @@ public:
}
Expected<int32_t, HostFunctionError>
trace(std::string_view const& msg, Slice const& data, bool asHex) override
trace(std::string_view const& msg, Slice const& data, bool asHex) const override
{
if (!asHex)
{
@@ -415,95 +415,95 @@ public:
}
Expected<int32_t, HostFunctionError>
traceNum(std::string_view const& msg, int64_t data) override
traceNum(std::string_view const& msg, int64_t data) const override
{
log(msg, [data] { return data; });
return 0;
}
Expected<int32_t, HostFunctionError>
traceAccount(std::string_view const& msg, AccountID const& account) override
traceAccount(std::string_view const& msg, AccountID const& account) const override
{
log(msg, [&account] { return toBase58(account); });
return 0;
}
Expected<int32_t, HostFunctionError>
traceFloat(std::string_view const& msg, Slice const& data) override
traceFloat(std::string_view const& msg, Slice const& data) const override
{
log(msg, [&data] { return wasm_float::floatToString(data); });
return 0;
}
Expected<int32_t, HostFunctionError>
traceAmount(std::string_view const& msg, STAmount const& amount) override
traceAmount(std::string_view const& msg, STAmount const& amount) const override
{
log(msg, [&amount] { return amount.getFullText(); });
return 0;
}
Expected<Bytes, HostFunctionError>
floatFromInt(int64_t x, int32_t mode) override
floatFromInt(int64_t x, int32_t mode) const override
{
return wasm_float::floatFromIntImpl(x, mode);
}
Expected<Bytes, HostFunctionError>
floatFromUint(uint64_t x, int32_t mode) override
floatFromUint(uint64_t x, int32_t mode) const override
{
return wasm_float::floatFromUintImpl(x, mode);
}
Expected<Bytes, HostFunctionError>
floatSet(int64_t mantissa, int32_t exponent, int32_t mode) override
floatSet(int64_t mantissa, int32_t exponent, int32_t mode) const override
{
return wasm_float::floatSetImpl(mantissa, exponent, mode);
}
Expected<int32_t, HostFunctionError>
floatCompare(Slice const& x, Slice const& y) override
floatCompare(Slice const& x, Slice const& y) const override
{
return wasm_float::floatCompareImpl(x, y);
}
Expected<Bytes, HostFunctionError>
floatAdd(Slice const& x, Slice const& y, int32_t mode) override
floatAdd(Slice const& x, Slice const& y, int32_t mode) const override
{
return wasm_float::floatAddImpl(x, y, mode);
}
Expected<Bytes, HostFunctionError>
floatSubtract(Slice const& x, Slice const& y, int32_t mode) override
floatSubtract(Slice const& x, Slice const& y, int32_t mode) const override
{
return wasm_float::floatSubtractImpl(x, y, mode);
}
Expected<Bytes, HostFunctionError>
floatMultiply(Slice const& x, Slice const& y, int32_t mode) override
floatMultiply(Slice const& x, Slice const& y, int32_t mode) const override
{
return wasm_float::floatMultiplyImpl(x, y, mode);
}
Expected<Bytes, HostFunctionError>
floatDivide(Slice const& x, Slice const& y, int32_t mode) override
floatDivide(Slice const& x, Slice const& y, int32_t mode) const override
{
return wasm_float::floatDivideImpl(x, y, mode);
}
Expected<Bytes, HostFunctionError>
floatRoot(Slice const& x, int32_t n, int32_t mode) override
floatRoot(Slice const& x, int32_t n, int32_t mode) const override
{
return wasm_float::floatRootImpl(x, n, mode);
}
Expected<Bytes, HostFunctionError>
floatPower(Slice const& x, int32_t n, int32_t mode) override
floatPower(Slice const& x, int32_t n, int32_t mode) const override
{
return wasm_float::floatPowerImpl(x, n, mode);
}
Expected<Bytes, HostFunctionError>
floatLog(Slice const& x, int32_t mode) override
floatLog(Slice const& x, int32_t mode) const override
{
return wasm_float::floatLogImpl(x, mode);
}
@@ -528,14 +528,14 @@ public:
}
};
#ifdef WASM_PERF_TESTS
struct PerfHostFunctions : public TestHostFunctions
{
Keylet leKey;
std::shared_ptr<SLE const> currentLedgerObj = nullptr;
bool isLedgerObjCached = false;
Keylet leKey_;
mutable std::optional<std::shared_ptr<SLE const>> currentLedgerObj_;
static int constexpr MAX_CACHE = 256;
std::array<std::shared_ptr<SLE const>, MAX_CACHE> cache;
mutable std::array<std::shared_ptr<SLE const>, MAX_CACHE> cache_;
// std::optional<Bytes> data_; // deferred data update, not used in
// performance
std::shared_ptr<STTx const> tx_;
@@ -543,42 +543,42 @@ struct PerfHostFunctions : public TestHostFunctions
void const* rt_ = nullptr;
PerfHostFunctions(test::jtx::Env& env, Keylet const& k, std::shared_ptr<STTx const>&& tx)
: TestHostFunctions(env), leKey(k), tx_(std::move(tx))
: TestHostFunctions(env), leKey_(k), tx_(std::move(tx))
{
}
Expected<std::uint32_t, HostFunctionError>
getLedgerSqn() override
getLedgerSqn() const override
{
return env_.current()->seq();
}
Expected<std::uint32_t, HostFunctionError>
getParentLedgerTime() override
getParentLedgerTime() const override
{
return env_.current()->parentCloseTime().time_since_epoch().count();
}
Expected<Hash, HostFunctionError>
getParentLedgerHash() override
getParentLedgerHash() const override
{
return env_.current()->header().parentHash;
}
Expected<std::uint32_t, HostFunctionError>
getBaseFee() override
getBaseFee() const override
{
return env_.current()->fees().base.drops();
}
Expected<int32_t, HostFunctionError>
isAmendmentEnabled(uint256 const& amendmentId) override
isAmendmentEnabled(uint256 const& amendmentId) const override
{
return env_.current()->rules().enabled(amendmentId);
}
Expected<int32_t, HostFunctionError>
isAmendmentEnabled(std::string_view const& amendmentName) override
isAmendmentEnabled(std::string_view const& amendmentName) const override
{
auto const& table = env_.app().getAmendmentTable();
auto const amendment = table.find(std::string(amendmentName));
@@ -586,43 +586,40 @@ struct PerfHostFunctions : public TestHostFunctions
}
Expected<std::shared_ptr<SLE const>, HostFunctionError>
getCurrentLedgerObj()
getCurrentLedgerObj() const
{
if (!isLedgerObjCached)
{
isLedgerObjCached = true;
currentLedgerObj = env_.le(leKey);
}
if (currentLedgerObj)
return currentLedgerObj;
if (!currentLedgerObj_)
currentLedgerObj_ = env_.le(leKey_);
if (*currentLedgerObj_)
return *currentLedgerObj_;
return Unexpected(HostFunctionError::LEDGER_OBJ_NOT_FOUND);
}
Expected<std::shared_ptr<SLE const>, HostFunctionError>
peekCurrentLedgerObj(int32_t cacheIdx)
peekCurrentLedgerObj(int32_t cacheIdx) const
{
--cacheIdx;
if (cacheIdx < 0 || cacheIdx >= MAX_CACHE)
return Unexpected(HostFunctionError::SLOT_OUT_RANGE);
if (!cache[cacheIdx])
if (!cache_[cacheIdx])
{ // return Unexpected(HostFunctionError::INVALID_SLOT);
auto const r = getCurrentLedgerObj();
if (!r)
return Unexpected(r.error());
cache[cacheIdx] = *r;
cache_[cacheIdx] = *r;
}
return cache[cacheIdx];
return cache_[cacheIdx];
}
Expected<int32_t, HostFunctionError>
normalizeCacheIndex(int32_t cacheIdx)
normalizeCacheIndex(int32_t cacheIdx) const
{
--cacheIdx;
if (cacheIdx < 0 || cacheIdx >= MAX_CACHE)
return Unexpected(HostFunctionError::SLOT_OUT_RANGE);
if (!cache[cacheIdx])
if (!cache_[cacheIdx])
return Unexpected(HostFunctionError::EMPTY_SLOT);
return cacheIdx;
}
@@ -640,7 +637,7 @@ struct PerfHostFunctions : public TestHostFunctions
if (!cacheIdx)
{
for (cacheIdx = 0; cacheIdx < MAX_CACHE; ++cacheIdx)
if (!cache[cacheIdx])
if (!cache_[cacheIdx])
break;
if (cacheIdx >= MAX_CACHE)
cacheIdx = intIdx++ % MAX_CACHE;
@@ -651,8 +648,8 @@ struct PerfHostFunctions : public TestHostFunctions
if (cacheIdx >= MAX_CACHE)
return Unexpected(HostFunctionError::SLOTS_FULL);
cache[cacheIdx] = env_.le(leKey);
if (!cache[cacheIdx])
cache_[cacheIdx] = env_.le(leKey_);
if (!cache_[cacheIdx])
return Unexpected(HostFunctionError::LEDGER_OBJ_NOT_FOUND);
return cacheIdx + 1;
}
@@ -732,13 +729,13 @@ struct PerfHostFunctions : public TestHostFunctions
}
Expected<Bytes, HostFunctionError>
getTxField(SField const& fname) override
getTxField(SField const& fname) const override
{
return getAnyFieldData(tx_->peekAtPField(fname));
}
Expected<Bytes, HostFunctionError>
getCurrentLedgerObjField(SField const& fname) override
getCurrentLedgerObjField(SField const& fname) const override
{
auto const sle = getCurrentLedgerObj();
if (!sle)
@@ -747,7 +744,7 @@ struct PerfHostFunctions : public TestHostFunctions
}
Expected<Bytes, HostFunctionError>
getLedgerObjField(int32_t cacheIdx, SField const& fname) override
getLedgerObjField(int32_t cacheIdx, SField const& fname) const override
{
auto const sle = peekCurrentLedgerObj(cacheIdx);
if (!sle)
@@ -819,7 +816,7 @@ struct PerfHostFunctions : public TestHostFunctions
}
Expected<Bytes, HostFunctionError>
getTxNestedField(Slice const& locator) override
getTxNestedField(Slice const& locator) const override
{
// std::cout << tx_->getJson(JsonOptions::none).toStyledString() <<
// std::endl;
@@ -830,7 +827,7 @@ struct PerfHostFunctions : public TestHostFunctions
}
Expected<Bytes, HostFunctionError>
getCurrentLedgerObjNestedField(Slice const& locator) override
getCurrentLedgerObjNestedField(Slice const& locator) const override
{
auto const sle = getCurrentLedgerObj();
if (!sle)
@@ -844,7 +841,7 @@ struct PerfHostFunctions : public TestHostFunctions
}
Expected<Bytes, HostFunctionError>
getLedgerObjNestedField(int32_t cacheIdx, Slice const& locator) override
getLedgerObjNestedField(int32_t cacheIdx, Slice const& locator) const override
{
auto const sle = peekCurrentLedgerObj(cacheIdx);
if (!sle)
@@ -858,7 +855,7 @@ struct PerfHostFunctions : public TestHostFunctions
}
Expected<int32_t, HostFunctionError>
getTxArrayLen(SField const& fname) override
getTxArrayLen(SField const& fname) const override
{
if (fname.fieldType != STI_ARRAY)
return Unexpected(HostFunctionError::NO_ARRAY);
@@ -875,7 +872,7 @@ struct PerfHostFunctions : public TestHostFunctions
}
Expected<int32_t, HostFunctionError>
getCurrentLedgerObjArrayLen(SField const& fname) override
getCurrentLedgerObjArrayLen(SField const& fname) const override
{
if (fname.fieldType != STI_ARRAY)
return Unexpected(HostFunctionError::NO_ARRAY);
@@ -896,7 +893,7 @@ struct PerfHostFunctions : public TestHostFunctions
}
Expected<int32_t, HostFunctionError>
getLedgerObjArrayLen(int32_t cacheIdx, SField const& fname) override
getLedgerObjArrayLen(int32_t cacheIdx, SField const& fname) const override
{
if (fname.fieldType != STI_ARRAY)
return Unexpected(HostFunctionError::NO_ARRAY);
@@ -917,7 +914,7 @@ struct PerfHostFunctions : public TestHostFunctions
}
Expected<int32_t, HostFunctionError>
getTxNestedArrayLen(Slice const& locator) override
getTxNestedArrayLen(Slice const& locator) const override
{
auto const r = locateField(*tx_, locator);
if (!r)
@@ -932,7 +929,7 @@ struct PerfHostFunctions : public TestHostFunctions
}
Expected<int32_t, HostFunctionError>
getCurrentLedgerObjNestedArrayLen(Slice const& locator) override
getCurrentLedgerObjNestedArrayLen(Slice const& locator) const override
{
auto const sle = getCurrentLedgerObj();
if (!sle)
@@ -951,7 +948,7 @@ struct PerfHostFunctions : public TestHostFunctions
}
Expected<int32_t, HostFunctionError>
getLedgerObjNestedArrayLen(int32_t cacheIdx, Slice const& locator) override
getLedgerObjNestedArrayLen(int32_t cacheIdx, Slice const& locator) const override
{
auto const sle = peekCurrentLedgerObj(cacheIdx);
if (!sle)
@@ -978,7 +975,7 @@ struct PerfHostFunctions : public TestHostFunctions
xrpl::detail::ApplyViewBase v(env_.app().openLedger().current().get(), tapNONE);
auto sle = v.peek(leKey);
auto sle = v.peek(leKey_);
if (!sle)
return Unexpected(HostFunctionError::LEDGER_OBJ_NOT_FOUND);
@@ -989,7 +986,7 @@ struct PerfHostFunctions : public TestHostFunctions
}
Expected<int32_t, HostFunctionError>
checkSignature(Slice const& message, Slice const& signature, Slice const& pubkey) override
checkSignature(Slice const& message, Slice const& signature, Slice const& pubkey) const override
{
if (!publicKeyType(pubkey))
return Unexpected(HostFunctionError::INVALID_PARAMS);
@@ -999,14 +996,14 @@ struct PerfHostFunctions : public TestHostFunctions
}
Expected<Hash, HostFunctionError>
computeSha512HalfHash(Slice const& data) override
computeSha512HalfHash(Slice const& data) const override
{
auto const hash = sha512Half(data);
return hash;
}
Expected<Bytes, HostFunctionError>
accountKeylet(AccountID const& account) override
accountKeylet(AccountID const& account) const override
{
if (!account)
return Unexpected(HostFunctionError::INVALID_ACCOUNT);
@@ -1015,7 +1012,7 @@ struct PerfHostFunctions : public TestHostFunctions
}
Expected<Bytes, HostFunctionError>
ammKeylet(Asset const& issue1, Asset const& issue2) override
ammKeylet(Asset const& issue1, Asset const& issue2) const override
{
if (issue1 == issue2)
return Unexpected(HostFunctionError::INVALID_PARAMS);
@@ -1029,7 +1026,7 @@ struct PerfHostFunctions : public TestHostFunctions
}
Expected<Bytes, HostFunctionError>
checkKeylet(AccountID const& account, std::uint32_t seq) override
checkKeylet(AccountID const& account, std::uint32_t seq) const override
{
if (!account)
return Unexpected(HostFunctionError::INVALID_ACCOUNT);
@@ -1038,7 +1035,7 @@ struct PerfHostFunctions : public TestHostFunctions
}
Expected<Bytes, HostFunctionError>
credentialKeylet(AccountID const& subject, AccountID const& issuer, Slice const& credentialType) override
credentialKeylet(AccountID const& subject, AccountID const& issuer, Slice const& credentialType) const override
{
if (!subject || !issuer)
return Unexpected(HostFunctionError::INVALID_ACCOUNT);
@@ -1052,7 +1049,7 @@ struct PerfHostFunctions : public TestHostFunctions
}
Expected<Bytes, HostFunctionError>
didKeylet(AccountID const& account) override
didKeylet(AccountID const& account) const override
{
if (!account)
return Unexpected(HostFunctionError::INVALID_ACCOUNT);
@@ -1061,7 +1058,7 @@ struct PerfHostFunctions : public TestHostFunctions
}
Expected<Bytes, HostFunctionError>
delegateKeylet(AccountID const& account, AccountID const& authorize) override
delegateKeylet(AccountID const& account, AccountID const& authorize) const override
{
if (!account || !authorize)
return Unexpected(HostFunctionError::INVALID_ACCOUNT);
@@ -1072,7 +1069,7 @@ struct PerfHostFunctions : public TestHostFunctions
}
Expected<Bytes, HostFunctionError>
depositPreauthKeylet(AccountID const& account, AccountID const& authorize) override
depositPreauthKeylet(AccountID const& account, AccountID const& authorize) const override
{
if (!account || !authorize)
return Unexpected(HostFunctionError::INVALID_ACCOUNT);
@@ -1083,7 +1080,7 @@ struct PerfHostFunctions : public TestHostFunctions
}
Expected<Bytes, HostFunctionError>
escrowKeylet(AccountID const& account, std::uint32_t seq) override
escrowKeylet(AccountID const& account, std::uint32_t seq) const override
{
if (!account)
return Unexpected(HostFunctionError::INVALID_ACCOUNT);
@@ -1092,7 +1089,7 @@ struct PerfHostFunctions : public TestHostFunctions
}
Expected<Bytes, HostFunctionError>
lineKeylet(AccountID const& account1, AccountID const& account2, Currency const& currency) override
lineKeylet(AccountID const& account1, AccountID const& account2, Currency const& currency) const override
{
if (!account1 || !account2)
return Unexpected(HostFunctionError::INVALID_ACCOUNT);
@@ -1106,7 +1103,7 @@ struct PerfHostFunctions : public TestHostFunctions
}
Expected<Bytes, HostFunctionError>
mptIssuanceKeylet(AccountID const& issuer, std::uint32_t seq) override
mptIssuanceKeylet(AccountID const& issuer, std::uint32_t seq) const override
{
if (!issuer)
return Unexpected(HostFunctionError::INVALID_ACCOUNT);
@@ -1116,7 +1113,7 @@ struct PerfHostFunctions : public TestHostFunctions
}
Expected<Bytes, HostFunctionError>
mptokenKeylet(MPTID const& mptid, AccountID const& holder) override
mptokenKeylet(MPTID const& mptid, AccountID const& holder) const override
{
if (!mptid)
return Unexpected(HostFunctionError::INVALID_PARAMS);
@@ -1128,7 +1125,7 @@ struct PerfHostFunctions : public TestHostFunctions
}
Expected<Bytes, HostFunctionError>
nftOfferKeylet(AccountID const& account, std::uint32_t seq) override
nftOfferKeylet(AccountID const& account, std::uint32_t seq) const override
{
if (!account)
return Unexpected(HostFunctionError::INVALID_ACCOUNT);
@@ -1137,7 +1134,7 @@ struct PerfHostFunctions : public TestHostFunctions
}
Expected<Bytes, HostFunctionError>
offerKeylet(AccountID const& account, std::uint32_t seq) override
offerKeylet(AccountID const& account, std::uint32_t seq) const override
{
if (!account)
return Unexpected(HostFunctionError::INVALID_ACCOUNT);
@@ -1146,7 +1143,7 @@ struct PerfHostFunctions : public TestHostFunctions
}
Expected<Bytes, HostFunctionError>
oracleKeylet(AccountID const& account, std::uint32_t documentId) override
oracleKeylet(AccountID const& account, std::uint32_t documentId) const override
{
if (!account)
return Unexpected(HostFunctionError::INVALID_ACCOUNT);
@@ -1155,7 +1152,7 @@ struct PerfHostFunctions : public TestHostFunctions
}
Expected<Bytes, HostFunctionError>
paychanKeylet(AccountID const& account, AccountID const& destination, std::uint32_t seq) override
paychanKeylet(AccountID const& account, AccountID const& destination, std::uint32_t seq) const override
{
if (!account || !destination)
return Unexpected(HostFunctionError::INVALID_ACCOUNT);
@@ -1166,7 +1163,7 @@ struct PerfHostFunctions : public TestHostFunctions
}
Expected<Bytes, HostFunctionError>
permissionedDomainKeylet(AccountID const& account, std::uint32_t seq) override
permissionedDomainKeylet(AccountID const& account, std::uint32_t seq) const override
{
if (!account)
return Unexpected(HostFunctionError::INVALID_ACCOUNT);
@@ -1175,7 +1172,7 @@ struct PerfHostFunctions : public TestHostFunctions
}
Expected<Bytes, HostFunctionError>
signersKeylet(AccountID const& account) override
signersKeylet(AccountID const& account) const override
{
if (!account)
return Unexpected(HostFunctionError::INVALID_ACCOUNT);
@@ -1184,7 +1181,7 @@ struct PerfHostFunctions : public TestHostFunctions
}
Expected<Bytes, HostFunctionError>
ticketKeylet(AccountID const& account, std::uint32_t seq) override
ticketKeylet(AccountID const& account, std::uint32_t seq) const override
{
if (!account)
return Unexpected(HostFunctionError::INVALID_ACCOUNT);
@@ -1193,7 +1190,7 @@ struct PerfHostFunctions : public TestHostFunctions
}
Expected<Bytes, HostFunctionError>
vaultKeylet(AccountID const& account, std::uint32_t seq) override
vaultKeylet(AccountID const& account, std::uint32_t seq) const override
{
if (!account)
return Unexpected(HostFunctionError::INVALID_ACCOUNT);
@@ -1202,7 +1199,7 @@ struct PerfHostFunctions : public TestHostFunctions
}
Expected<Bytes, HostFunctionError>
getNFT(AccountID const& account, uint256 const& nftId) override
getNFT(AccountID const& account, uint256 const& nftId) const override
{
if (!account || !nftId)
{
@@ -1226,7 +1223,7 @@ struct PerfHostFunctions : public TestHostFunctions
}
Expected<Bytes, HostFunctionError>
getNFTIssuer(uint256 const& nftId) override
getNFTIssuer(uint256 const& nftId) const override
{
auto const issuer = nft::getIssuer(nftId);
if (!issuer)
@@ -1236,29 +1233,31 @@ struct PerfHostFunctions : public TestHostFunctions
}
Expected<std::uint32_t, HostFunctionError>
getNFTTaxon(uint256 const& nftId) override
getNFTTaxon(uint256 const& nftId) const override
{
return nft::toUInt32(nft::getTaxon(nftId));
}
Expected<int32_t, HostFunctionError>
getNFTFlags(uint256 const& nftId) override
getNFTFlags(uint256 const& nftId) const override
{
return nft::getFlags(nftId);
}
Expected<int32_t, HostFunctionError>
getNFTTransferFee(uint256 const& nftId) override
getNFTTransferFee(uint256 const& nftId) const override
{
return nft::getTransferFee(nftId);
}
Expected<std::uint32_t, HostFunctionError>
getNFTSerial(uint256 const& nftId) override
getNFTSerial(uint256 const& nftId) const override
{
return nft::getSerial(nftId);
}
};
#endif
} // namespace test
} // namespace xrpl

View File

@@ -37,7 +37,8 @@ runFinishFunction(std::string const& code)
{
auto& engine = WasmEngine::instance();
auto const wasm = hexToBytes(code);
auto const re = engine.run(wasm, "finish");
HostFunctions hfs;
auto const re = engine.run(wasm, hfs, "finish");
if (re.has_value())
{
return std::optional<int32_t>(re->result);
@@ -107,10 +108,11 @@ struct Wasm_test : public beast::unit_test::suite
// clang-format on
auto& vm = WasmEngine::instance();
std::shared_ptr<ImportVec> imports(std::make_shared<ImportVec>());
WasmImpFunc<Add_proto>(*imports, "func-add", reinterpret_cast<void*>(&Add));
HostFunctions hfs;
ImportVec imports;
WasmImpFunc<Add_proto>(imports, "func-add", reinterpret_cast<void*>(&Add), &hfs);
auto re = vm.run(wasm, "addTwo", wasmParams(1234, 5678), imports);
auto re = vm.run(wasm, hfs, "addTwo", wasmParams(1234, 5678), imports);
// if (res) printf("invokeAdd get the result: %d\n", res.value());
@@ -125,7 +127,7 @@ struct Wasm_test : public beast::unit_test::suite
using namespace test::jtx;
Env env{*this};
std::shared_ptr<HostFunctions> hfs(new HostFunctions(env.journal));
HostFunctions hfs(env.journal);
{
auto wasm = hexToBytes("00000000");
@@ -175,12 +177,12 @@ struct Wasm_test : public beast::unit_test::suite
using namespace test::jtx;
Env env{*this};
std::shared_ptr<HostFunctions> hfs(new TestLedgerDataProvider(env));
auto imports = std::make_shared<ImportVec>();
WASM_IMPORT_FUNC2(*imports, getLedgerSqn, "get_ledger_sqn", hfs.get(), 33);
TestLedgerDataProvider hfs(env);
ImportVec imports;
WASM_IMPORT_FUNC2(imports, getLedgerSqn, "get_ledger_sqn", &hfs, 33);
auto& engine = WasmEngine::instance();
auto re = engine.run(ledgerSqnWasm, ESCROW_FUNCTION_NAME, {}, imports, hfs, 1'000'000, env.journal);
auto re = engine.run(ledgerSqnWasm, hfs, ESCROW_FUNCTION_NAME, {}, imports, 1'000'000, env.journal);
checkResult(re, 0, 440);
@@ -188,9 +190,13 @@ struct Wasm_test : public beast::unit_test::suite
env.close();
// empty module - run the same instance
re = engine.run({}, ESCROW_FUNCTION_NAME, {}, imports, hfs, 1'000'000, env.journal);
re = engine.run({}, hfs, ESCROW_FUNCTION_NAME, {}, imports, 1'000'000, env.journal);
#ifdef WASM_PERF_TESTS
checkResult(re, 5, 488);
#else
BEAST_EXPECT(!re);
#endif
env.close();
}
void
@@ -200,12 +206,14 @@ struct Wasm_test : public beast::unit_test::suite
auto const fibWasm = hexToBytes(fibWasmHex);
auto& engine = WasmEngine::instance();
HostFunctions hfs;
auto const re = engine.run(fibWasm, "fib", wasmParams(10));
auto const re = engine.run(fibWasm, hfs, "fib", wasmParams(10));
checkResult(re, 55, 1'137);
}
#ifdef WASM_PERF_TESTS
void
testWasmSha()
{
@@ -213,8 +221,9 @@ struct Wasm_test : public beast::unit_test::suite
auto const sha512Wasm = hexToBytes(sha512PureWasmHex);
auto& engine = WasmEngine::instance();
HostFunctions hfs;
auto const re = engine.run(sha512Wasm, "sha512_process", wasmParams(sha512PureWasmHex));
auto const re = engine.run(sha512Wasm, hfs, "sha512_process", wasmParams(sha512PureWasmHex));
checkResult(re, 34'432, 151'155);
}
@@ -225,6 +234,7 @@ struct Wasm_test : public beast::unit_test::suite
testcase("Wasm base58");
auto const b58Wasm = hexToBytes(b58WasmHex);
auto& engine = WasmEngine::instance();
HostFunctions hfs;
Bytes outb;
outb.resize(1024);
@@ -232,10 +242,11 @@ struct Wasm_test : public beast::unit_test::suite
auto const minSize = std::min(static_cast<std::uint32_t>(512), static_cast<std::uint32_t>(b58WasmHex.size()));
auto const s = std::string_view(b58WasmHex.c_str(), minSize);
auto const re = engine.run(b58Wasm, "b58enco", wasmParams(outb, s));
auto const re = engine.run(b58Wasm, hfs, "b58enco", wasmParams(outb, s));
checkResult(re, 700, 2'886'069);
}
#endif
void
testHFCost()
@@ -250,12 +261,12 @@ struct Wasm_test : public beast::unit_test::suite
auto& engine = WasmEngine::instance();
std::shared_ptr<HostFunctions> hfs(new TestHostFunctions(env, 0));
auto imp = createWasmImport(*hfs);
for (auto& i : *imp)
TestHostFunctions hfs(env, 0);
auto imp = createWasmImport(hfs);
for (auto& i : imp)
i.second.gas = 0;
auto re = engine.run(allHostFuncWasm, ESCROW_FUNCTION_NAME, {}, imp, hfs, 1'000'000, env.journal);
auto re = engine.run(allHostFuncWasm, hfs, ESCROW_FUNCTION_NAME, {}, imp, 1'000'000, env.journal);
checkResult(re, 1, 27'080);
@@ -273,10 +284,10 @@ struct Wasm_test : public beast::unit_test::suite
auto& engine = WasmEngine::instance();
std::shared_ptr<HostFunctions> hfs(new TestHostFunctions(env, 0));
auto const imp = createWasmImport(*hfs);
TestHostFunctions hfs(env, 0);
auto const imp = createWasmImport(hfs);
auto re = engine.run(allHostFuncWasm, ESCROW_FUNCTION_NAME, {}, imp, hfs, 1'000'000, env.journal);
auto re = engine.run(allHostFuncWasm, hfs, ESCROW_FUNCTION_NAME, {}, imp, 1'000'000, env.journal);
checkResult(re, 1, 66'340);
@@ -289,10 +300,10 @@ struct Wasm_test : public beast::unit_test::suite
auto& engine = WasmEngine::instance();
std::shared_ptr<HostFunctions> hfs(new TestHostFunctions(env, 0));
auto const imp = createWasmImport(*hfs);
TestHostFunctions hfs(env, 0);
auto const imp = createWasmImport(hfs);
auto re = engine.run(allHostFuncWasm, ESCROW_FUNCTION_NAME, {}, imp, hfs, 200, env.journal);
auto re = engine.run(allHostFuncWasm, hfs, ESCROW_FUNCTION_NAME, {}, imp, 200, env.journal);
if (BEAST_EXPECT(!re))
{
@@ -313,14 +324,14 @@ struct Wasm_test : public beast::unit_test::suite
using namespace test::jtx;
Env env{*this};
{
std::shared_ptr<HostFunctions> hfs(new TestHostFunctions(env, 0));
TestHostFunctions hfs(env, 0);
auto re = runEscrowWasm(allHFWasm, hfs, ESCROW_FUNCTION_NAME, {}, 100'000);
checkResult(re, 1, 66'340);
}
{
// max<int64_t>() gas
std::shared_ptr<HostFunctions> hfs(new TestHostFunctions(env, 0));
TestHostFunctions hfs(env, 0);
auto re = runEscrowWasm(allHFWasm, hfs, ESCROW_FUNCTION_NAME, {}, -1);
checkResult(re, 1, 66'340);
}
@@ -332,13 +343,13 @@ struct Wasm_test : public beast::unit_test::suite
{
}
Expected<Bytes, HostFunctionError>
getTxField(SField const& fname) override
getTxField(SField const& fname) const override
{
return Unexpected(HostFunctionError::FIELD_NOT_FOUND);
}
};
std::shared_ptr<HostFunctions> hfs(new BadTestHostFunctions(env));
BadTestHostFunctions hfs(env);
auto re = runEscrowWasm(allHFWasm, hfs, ESCROW_FUNCTION_NAME, {}, 100'000);
checkResult(re, -201, 28'965);
}
@@ -350,13 +361,13 @@ struct Wasm_test : public beast::unit_test::suite
{
}
Expected<Bytes, HostFunctionError>
getTxField(SField const& fname) override
getTxField(SField const& fname) const override
{
return Bytes((128 + 1) * 64 * 1024, 1);
}
};
std::shared_ptr<HostFunctions> hfs(new BadTestHostFunctions(env));
BadTestHostFunctions hfs(env);
auto re = runEscrowWasm(allHFWasm, hfs, ESCROW_FUNCTION_NAME, {}, 100'000);
checkResult(re, -201, 28'965);
}
@@ -365,14 +376,14 @@ struct Wasm_test : public beast::unit_test::suite
auto const deepWasm = hexToBytes(deepRecursionHex);
std::shared_ptr<TestHostFunctionsSink> hfs(new TestHostFunctionsSink(env));
TestHostFunctionsSink hfs(env);
std::string funcName("finish");
auto re = runEscrowWasm(deepWasm, hfs, funcName, {}, 1'000'000'000);
BEAST_EXPECT(!re && re.error());
// std::cout << "bad case (deep recursion) result " << re.error()
// << std::endl;
auto const& sink = hfs->getSink();
auto const& sink = hfs.getSink();
auto countSubstr = [](std::string const& str, std::string const& substr) {
std::size_t pos = 0;
int occurrences = 0;
@@ -392,7 +403,7 @@ struct Wasm_test : public beast::unit_test::suite
{ // infinite loop
auto const infiniteLoopWasm = hexToBytes(infiniteLoopWasmHex);
std::string const funcName("loop");
std::shared_ptr<HostFunctions> hfs(new TestHostFunctions(env, 0));
TestHostFunctions hfs(env, 0);
// infinite loop should be caught and fail
auto const re = runEscrowWasm(infiniteLoopWasm, hfs, funcName, {}, 1'000'000);
@@ -405,13 +416,13 @@ struct Wasm_test : public beast::unit_test::suite
{
// expected import not provided
auto const lgrSqnWasm = hexToBytes(ledgerSqnWasmHex);
std::shared_ptr<HostFunctions> hfs(new TestLedgerDataProvider(env));
std::shared_ptr<ImportVec> imports(std::make_shared<ImportVec>());
WASM_IMPORT_FUNC2(*imports, getLedgerSqn, "get_ledger_sqn2", hfs.get());
TestLedgerDataProvider hfs(env);
ImportVec imports;
WASM_IMPORT_FUNC2(imports, getLedgerSqn, "get_ledger_sqn2", &hfs);
auto& engine = WasmEngine::instance();
auto re = engine.run(lgrSqnWasm, ESCROW_FUNCTION_NAME, {}, imports, hfs, 1'000'000, env.journal);
auto re = engine.run(lgrSqnWasm, hfs, ESCROW_FUNCTION_NAME, {}, imports, 1'000'000, env.journal);
BEAST_EXPECT(!re);
}
@@ -419,14 +430,14 @@ struct Wasm_test : public beast::unit_test::suite
{
// bad import format
auto const lgrSqnWasm = hexToBytes(ledgerSqnWasmHex);
std::shared_ptr<HostFunctions> hfs(new TestLedgerDataProvider(env));
std::shared_ptr<ImportVec> imports(std::make_shared<ImportVec>());
WASM_IMPORT_FUNC2(*imports, getLedgerSqn, "get_ledger_sqn", hfs.get());
(*imports)[0].first = nullptr;
TestLedgerDataProvider hfs(env);
ImportVec imports;
WASM_IMPORT_FUNC2(imports, getLedgerSqn, "get_ledger_sqn", &hfs);
imports[0].first = nullptr;
auto& engine = WasmEngine::instance();
auto re = engine.run(lgrSqnWasm, ESCROW_FUNCTION_NAME, {}, imports, hfs, 1'000'000, env.journal);
auto re = engine.run(lgrSqnWasm, hfs, ESCROW_FUNCTION_NAME, {}, imports, 1'000'000, env.journal);
BEAST_EXPECT(!re);
}
@@ -434,12 +445,12 @@ struct Wasm_test : public beast::unit_test::suite
{
// bad function name
auto const lgrSqnWasm = hexToBytes(ledgerSqnWasmHex);
std::shared_ptr<HostFunctions> hfs(new TestLedgerDataProvider(env));
std::shared_ptr<ImportVec> imports(std::make_shared<ImportVec>());
WASM_IMPORT_FUNC2(*imports, getLedgerSqn, "get_ledger_sqn", hfs.get());
TestLedgerDataProvider hfs(env);
ImportVec imports;
WASM_IMPORT_FUNC2(imports, getLedgerSqn, "get_ledger_sqn", &hfs);
auto& engine = WasmEngine::instance();
auto re = engine.run(lgrSqnWasm, "func1", {}, imports, hfs, 1'000'000, env.journal);
auto re = engine.run(lgrSqnWasm, hfs, "func1", {}, imports, 1'000'000, env.journal);
BEAST_EXPECT(!re);
}
@@ -458,7 +469,7 @@ struct Wasm_test : public beast::unit_test::suite
{
auto const floatTestWasm = hexToBytes(floatTestsWasmHex);
std::shared_ptr<HostFunctions> hfs(new TestHostFunctions(env, 0));
TestHostFunctions hfs(env, 0);
auto re = runEscrowWasm(floatTestWasm, hfs, funcName, {}, 200'000);
checkResult(re, 1, 110'699);
env.close();
@@ -467,13 +478,14 @@ struct Wasm_test : public beast::unit_test::suite
{
auto const float0Wasm = hexToBytes(float0Hex);
std::shared_ptr<HostFunctions> hfs(new TestHostFunctions(env, 0));
TestHostFunctions hfs(env, 0);
auto re = runEscrowWasm(float0Wasm, hfs, funcName, {}, 100'000);
checkResult(re, 1, 4'259);
env.close();
}
}
#ifdef WASM_PERF_TESTS
void
perfTest()
{
@@ -544,7 +556,7 @@ struct Wasm_test : public beast::unit_test::suite
env(token::mint(alan, 0u));
env.close();
std::shared_ptr<HostFunctions> hfs(new PerfHostFunctions(env, k, env.tx()));
PerfHostFunctions hfs(env, k, env.tx());
auto re = runEscrowWasm(perfWasm, hfs, ESCROW_FUNCTION_NAME);
if (BEAST_EXPECT(re.has_value()))
@@ -561,6 +573,7 @@ struct Wasm_test : public beast::unit_test::suite
env.close();
}
}
#endif
void
testCodecovWasm()
@@ -572,7 +585,7 @@ struct Wasm_test : public beast::unit_test::suite
Env env{*this};
auto const codecovWasm = hexToBytes(codecovTestsWasmHex);
std::shared_ptr<HostFunctions> hfs(new TestHostFunctions(env, 0));
TestHostFunctions hfs(env, 0);
auto const allowance = 201'503;
auto re = runEscrowWasm(codecovWasm, hfs, ESCROW_FUNCTION_NAME, {}, allowance);
@@ -590,7 +603,7 @@ struct Wasm_test : public beast::unit_test::suite
auto disabledFloatWasm = hexToBytes(disabledFloatHex);
std::string const funcName("finish");
std::shared_ptr<HostFunctions> hfs(new TestHostFunctions(env, 0));
TestHostFunctions hfs(env, 0);
{
// f32 set constant, opcode disabled exception
@@ -703,17 +716,18 @@ struct Wasm_test : public beast::unit_test::suite
Env env(*this);
auto const startLoopWasm = hexToBytes(startLoopHex);
std::shared_ptr<HostFunctions> hfs(new TestLedgerDataProvider(env));
std::shared_ptr<ImportVec> imports(std::make_shared<ImportVec>());
TestLedgerDataProvider hfs(env);
ImportVec imports;
auto& engine = WasmEngine::instance();
auto checkRes = engine.check(startLoopWasm, "finish", {}, imports, hfs, env.journal);
auto checkRes = engine.check(startLoopWasm, hfs, "finish", {}, imports, env.journal);
BEAST_EXPECTS(checkRes == tesSUCCESS, std::to_string(TERtoInt(checkRes)));
auto re = engine.run(startLoopWasm, ESCROW_FUNCTION_NAME, {}, imports, hfs, 1'000'000, env.journal);
auto re = engine.run(startLoopWasm, hfs, ESCROW_FUNCTION_NAME, {}, imports, 1'000'000, env.journal);
BEAST_EXPECTS(re.error() == tecFAILED_PROCESSING, std::to_string(TERtoInt(re.error())));
}
#ifdef WASM_PERF_TESTS
void
testBadAlloc()
{
@@ -725,15 +739,14 @@ struct Wasm_test : public beast::unit_test::suite
using namespace test::jtx;
Env env{*this};
std::shared_ptr<HostFunctions> hfs(new TestLedgerDataProvider(env));
TestLedgerDataProvider hfs(env);
// std::shared_ptr<ImportVec> imports(std::make_shared<ImportVec>());
uint8_t buf1[8] = {7, 8, 9, 10, 11, 12, 13, 14};
{ // forged "allocate" return valid address
std::vector<WasmParam> params = {{.type = WT_U8V, .of = {.u8v = {.d = buf1, .sz = sizeof(buf1)}}}};
std::vector<WasmParam> params = {{.type = WT_U8V, .of = {.u8v = {.d = buf1, .sz = sizeof(buf1) } } }};
auto& engine = WasmEngine::instance();
auto re = engine.run(badAllocWasm, "test", params, {}, hfs, 1'000'000, env.journal);
auto re = engine.run(badAllocWasm, hfs, "test", params, {}, 1'000'000, env.journal);
if (BEAST_EXPECT(re))
{
BEAST_EXPECTS(re->result == 7, std::to_string(re->result));
@@ -742,30 +755,30 @@ struct Wasm_test : public beast::unit_test::suite
}
{ // return 0 whithout calling wasm
std::vector<WasmParam> params = {{.type = WT_U8V, .of = {.u8v = {.d = buf1, .sz = 0}}}};
std::vector<WasmParam> params = {{.type = WT_U8V, .of = {.u8v = {.d = buf1, .sz = 0 } } }};
auto& engine = WasmEngine::instance();
auto re = engine.run(badAllocWasm, "test", params, {}, hfs, 1'000'000, env.journal);
auto re = engine.run(badAllocWasm, hfs, "test", params, {}, 1'000'000, env.journal);
BEAST_EXPECT(!re) && BEAST_EXPECT(re.error() == tecFAILED_PROCESSING);
}
{ // forged "allocate" return 8Mb (which is more than memory limit)
std::vector<WasmParam> params = {{.type = WT_U8V, .of = {.u8v = {.d = buf1, .sz = 1}}}};
std::vector<WasmParam> params = {{.type = WT_U8V, .of = {.u8v = {.d = buf1, .sz = 1 } } }};
auto& engine = WasmEngine::instance();
auto re = engine.run(badAllocWasm, "test", params, {}, hfs, 1'000'000, env.journal);
auto re = engine.run(badAllocWasm, hfs, "test", params, {}, 1'000'000, env.journal);
BEAST_EXPECT(!re) && BEAST_EXPECT(re.error() == tecFAILED_PROCESSING);
}
{ // forged "allocate" return 0
std::vector<WasmParam> params = {{.type = WT_U8V, .of = {.u8v = {.d = buf1, .sz = 2}}}};
std::vector<WasmParam> params = {{.type = WT_U8V, .of = {.u8v = {.d = buf1, .sz = 2 } } }};
auto& engine = WasmEngine::instance();
auto re = engine.run(badAllocWasm, "test", params, {}, hfs, 1'000'000, env.journal);
auto re = engine.run(badAllocWasm, hfs, "test", params, {}, 1'000'000, env.journal);
BEAST_EXPECT(!re) && BEAST_EXPECT(re.error() == tecFAILED_PROCESSING);
}
{ // forged "allocate" return -1
std::vector<WasmParam> params = {{.type = WT_U8V, .of = {.u8v = {.d = buf1, .sz = 3}}}};
std::vector<WasmParam> params = {{.type = WT_U8V, .of = {.u8v = {.d = buf1, .sz = 3 } } }};
auto& engine = WasmEngine::instance();
auto re = engine.run(badAllocWasm, "test", params, {}, hfs, 1'000'000, env.journal);
auto re = engine.run(badAllocWasm, hfs, "test", params, {}, 1'000'000, env.journal);
BEAST_EXPECT(!re) && BEAST_EXPECT(re.error() == tecFAILED_PROCESSING);
}
@@ -787,6 +800,7 @@ struct Wasm_test : public beast::unit_test::suite
env.close();
}
#endif
void
testBadAlign()
@@ -799,14 +813,14 @@ struct Wasm_test : public beast::unit_test::suite
using namespace test::jtx;
Env env{*this};
std::shared_ptr<HostFunctions> hfs(new TestHostFunctions(env, 0));
auto imports = createWasmImport(*hfs);
TestHostFunctions hfs(env, 0);
auto imports = createWasmImport(hfs);
{ // Calls float_from_uint with bad alignment.
// Can be checked through codecov
auto& engine = WasmEngine::instance();
auto re = engine.run(badAlignWasm, "test", {}, imports, hfs, 1'000'000, env.journal);
auto re = engine.run(badAlignWasm, hfs, "test", {}, imports, 1'000'000, env.journal);
if (BEAST_EXPECTS(re, transToken(re.error())))
{
BEAST_EXPECTS(re->result == 0x684f7941, std::to_string(re->result));
@@ -821,7 +835,7 @@ struct Wasm_test : public beast::unit_test::suite
{
using namespace test::jtx;
Env env(*this);
std::shared_ptr<HostFunctions> hfs(new TestHostFunctions(env, 0));
TestHostFunctions hfs(env, 0);
// return int64.
{ // (module
@@ -923,6 +937,55 @@ struct Wasm_test : public beast::unit_test::suite
BEAST_EXPECT(b6 == SWAP_DATAI16);
}
void
testManyParams()
{
testcase("Wasm Many params");
auto const params1k = hexToBytes(thousandParamsHex);
auto const params1k1 = hexToBytes(thousand1ParamsHex);
using namespace test::jtx;
Env env{*this};
TestHostFunctions hfs(env, 0);
auto imports = createWasmImport(hfs);
// add 1k parameter (max that wasmi support)
std::vector<WasmParam> params;
for (int i = 0; i < 1000; ++i)
params.push_back({.type = WT_I32, .of = {.i32 = 2 * i}});
auto& engine = WasmEngine::instance();
{
auto re = engine.run(params1k, hfs, "test", params, imports, 1'000'000, env.journal);
BEAST_EXPECT(re && re->result == 999000);
}
// add 1 more parameter, module can't be created now
params.push_back({.type = WT_I32, .of = {.i32 = 2 * 1000}});
{
auto re = engine.run(params1k1, hfs, "test", params, imports, 1'000'000, env.journal);
BEAST_EXPECT(!re);
}
// function that create 10k local variables
auto const locals10k = hexToBytes(locals10kHex);
{
auto re = engine.run(locals10k, hfs, "test", wasmParams(0, 1), imports, 1'000'000, env.journal);
BEAST_EXPECT(re && re->result == 890'489'442);
}
// module has 5k functions
auto const functions5k = hexToBytes(functions5kHex);
{
auto re = engine.run(functions5k, hfs, "test0001", wasmParams(2, 3), imports, 1'000'000, env.journal);
BEAST_EXPECT(re && re->result == 5);
}
env.close();
}
void
run() override
{
@@ -934,8 +997,6 @@ struct Wasm_test : public beast::unit_test::suite
testWasmLedgerSqn();
testWasmFib();
testWasmSha();
testWasmB58();
testHFCost();
testEscrowWasmDN();
@@ -952,12 +1013,18 @@ struct Wasm_test : public beast::unit_test::suite
testWasmSectionCorruption();
testStartFunctionLoop();
testBadAlloc();
testBadAlign();
testReturnType();
testSwapBytes();
testManyParams();
#ifdef WASM_PERF_TESTS
// only performance tests can pass buffer to Wasm (and call exported "allocate" function)
testWasmSha();
testWasmB58();
testBadAlloc();
// perfTest();
#endif
}
};

File diff suppressed because it is too large Load Diff

View File

@@ -85,3 +85,8 @@ extern std::string const startLoopHex;
extern std::string const badAllocHex;
extern std::string const badAlignWasmHex;
extern std::string const thousandParamsHex;
extern std::string const thousand1ParamsHex;
extern std::string const locals10kHex;
extern std::string const functions5kHex;

View File

@@ -0,0 +1,264 @@
// clang-format off
#include <stdint.h>
int32_t test(
int32_t p0, int32_t p1, int32_t p2, int32_t p3, int32_t p4, int32_t p5, int32_t p6, int32_t p7
, int32_t p8, int32_t p9, int32_t p10, int32_t p11, int32_t p12, int32_t p13, int32_t p14, int32_t p15
, int32_t p16, int32_t p17, int32_t p18, int32_t p19, int32_t p20, int32_t p21, int32_t p22, int32_t p23
, int32_t p24, int32_t p25, int32_t p26, int32_t p27, int32_t p28, int32_t p29, int32_t p30, int32_t p31
, int32_t p32, int32_t p33, int32_t p34, int32_t p35, int32_t p36, int32_t p37, int32_t p38, int32_t p39
, int32_t p40, int32_t p41, int32_t p42, int32_t p43, int32_t p44, int32_t p45, int32_t p46, int32_t p47
, int32_t p48, int32_t p49, int32_t p50, int32_t p51, int32_t p52, int32_t p53, int32_t p54, int32_t p55
, int32_t p56, int32_t p57, int32_t p58, int32_t p59, int32_t p60, int32_t p61, int32_t p62, int32_t p63
, int32_t p64, int32_t p65, int32_t p66, int32_t p67, int32_t p68, int32_t p69, int32_t p70, int32_t p71
, int32_t p72, int32_t p73, int32_t p74, int32_t p75, int32_t p76, int32_t p77, int32_t p78, int32_t p79
, int32_t p80, int32_t p81, int32_t p82, int32_t p83, int32_t p84, int32_t p85, int32_t p86, int32_t p87
, int32_t p88, int32_t p89, int32_t p90, int32_t p91, int32_t p92, int32_t p93, int32_t p94, int32_t p95
, int32_t p96, int32_t p97, int32_t p98, int32_t p99, int32_t p100, int32_t p101, int32_t p102, int32_t p103
, int32_t p104, int32_t p105, int32_t p106, int32_t p107, int32_t p108, int32_t p109, int32_t p110, int32_t p111
, int32_t p112, int32_t p113, int32_t p114, int32_t p115, int32_t p116, int32_t p117, int32_t p118, int32_t p119
, int32_t p120, int32_t p121, int32_t p122, int32_t p123, int32_t p124, int32_t p125, int32_t p126, int32_t p127
, int32_t p128, int32_t p129, int32_t p130, int32_t p131, int32_t p132, int32_t p133, int32_t p134, int32_t p135
, int32_t p136, int32_t p137, int32_t p138, int32_t p139, int32_t p140, int32_t p141, int32_t p142, int32_t p143
, int32_t p144, int32_t p145, int32_t p146, int32_t p147, int32_t p148, int32_t p149, int32_t p150, int32_t p151
, int32_t p152, int32_t p153, int32_t p154, int32_t p155, int32_t p156, int32_t p157, int32_t p158, int32_t p159
, int32_t p160, int32_t p161, int32_t p162, int32_t p163, int32_t p164, int32_t p165, int32_t p166, int32_t p167
, int32_t p168, int32_t p169, int32_t p170, int32_t p171, int32_t p172, int32_t p173, int32_t p174, int32_t p175
, int32_t p176, int32_t p177, int32_t p178, int32_t p179, int32_t p180, int32_t p181, int32_t p182, int32_t p183
, int32_t p184, int32_t p185, int32_t p186, int32_t p187, int32_t p188, int32_t p189, int32_t p190, int32_t p191
, int32_t p192, int32_t p193, int32_t p194, int32_t p195, int32_t p196, int32_t p197, int32_t p198, int32_t p199
, int32_t p200, int32_t p201, int32_t p202, int32_t p203, int32_t p204, int32_t p205, int32_t p206, int32_t p207
, int32_t p208, int32_t p209, int32_t p210, int32_t p211, int32_t p212, int32_t p213, int32_t p214, int32_t p215
, int32_t p216, int32_t p217, int32_t p218, int32_t p219, int32_t p220, int32_t p221, int32_t p222, int32_t p223
, int32_t p224, int32_t p225, int32_t p226, int32_t p227, int32_t p228, int32_t p229, int32_t p230, int32_t p231
, int32_t p232, int32_t p233, int32_t p234, int32_t p235, int32_t p236, int32_t p237, int32_t p238, int32_t p239
, int32_t p240, int32_t p241, int32_t p242, int32_t p243, int32_t p244, int32_t p245, int32_t p246, int32_t p247
, int32_t p248, int32_t p249, int32_t p250, int32_t p251, int32_t p252, int32_t p253, int32_t p254, int32_t p255
, int32_t p256, int32_t p257, int32_t p258, int32_t p259, int32_t p260, int32_t p261, int32_t p262, int32_t p263
, int32_t p264, int32_t p265, int32_t p266, int32_t p267, int32_t p268, int32_t p269, int32_t p270, int32_t p271
, int32_t p272, int32_t p273, int32_t p274, int32_t p275, int32_t p276, int32_t p277, int32_t p278, int32_t p279
, int32_t p280, int32_t p281, int32_t p282, int32_t p283, int32_t p284, int32_t p285, int32_t p286, int32_t p287
, int32_t p288, int32_t p289, int32_t p290, int32_t p291, int32_t p292, int32_t p293, int32_t p294, int32_t p295
, int32_t p296, int32_t p297, int32_t p298, int32_t p299, int32_t p300, int32_t p301, int32_t p302, int32_t p303
, int32_t p304, int32_t p305, int32_t p306, int32_t p307, int32_t p308, int32_t p309, int32_t p310, int32_t p311
, int32_t p312, int32_t p313, int32_t p314, int32_t p315, int32_t p316, int32_t p317, int32_t p318, int32_t p319
, int32_t p320, int32_t p321, int32_t p322, int32_t p323, int32_t p324, int32_t p325, int32_t p326, int32_t p327
, int32_t p328, int32_t p329, int32_t p330, int32_t p331, int32_t p332, int32_t p333, int32_t p334, int32_t p335
, int32_t p336, int32_t p337, int32_t p338, int32_t p339, int32_t p340, int32_t p341, int32_t p342, int32_t p343
, int32_t p344, int32_t p345, int32_t p346, int32_t p347, int32_t p348, int32_t p349, int32_t p350, int32_t p351
, int32_t p352, int32_t p353, int32_t p354, int32_t p355, int32_t p356, int32_t p357, int32_t p358, int32_t p359
, int32_t p360, int32_t p361, int32_t p362, int32_t p363, int32_t p364, int32_t p365, int32_t p366, int32_t p367
, int32_t p368, int32_t p369, int32_t p370, int32_t p371, int32_t p372, int32_t p373, int32_t p374, int32_t p375
, int32_t p376, int32_t p377, int32_t p378, int32_t p379, int32_t p380, int32_t p381, int32_t p382, int32_t p383
, int32_t p384, int32_t p385, int32_t p386, int32_t p387, int32_t p388, int32_t p389, int32_t p390, int32_t p391
, int32_t p392, int32_t p393, int32_t p394, int32_t p395, int32_t p396, int32_t p397, int32_t p398, int32_t p399
, int32_t p400, int32_t p401, int32_t p402, int32_t p403, int32_t p404, int32_t p405, int32_t p406, int32_t p407
, int32_t p408, int32_t p409, int32_t p410, int32_t p411, int32_t p412, int32_t p413, int32_t p414, int32_t p415
, int32_t p416, int32_t p417, int32_t p418, int32_t p419, int32_t p420, int32_t p421, int32_t p422, int32_t p423
, int32_t p424, int32_t p425, int32_t p426, int32_t p427, int32_t p428, int32_t p429, int32_t p430, int32_t p431
, int32_t p432, int32_t p433, int32_t p434, int32_t p435, int32_t p436, int32_t p437, int32_t p438, int32_t p439
, int32_t p440, int32_t p441, int32_t p442, int32_t p443, int32_t p444, int32_t p445, int32_t p446, int32_t p447
, int32_t p448, int32_t p449, int32_t p450, int32_t p451, int32_t p452, int32_t p453, int32_t p454, int32_t p455
, int32_t p456, int32_t p457, int32_t p458, int32_t p459, int32_t p460, int32_t p461, int32_t p462, int32_t p463
, int32_t p464, int32_t p465, int32_t p466, int32_t p467, int32_t p468, int32_t p469, int32_t p470, int32_t p471
, int32_t p472, int32_t p473, int32_t p474, int32_t p475, int32_t p476, int32_t p477, int32_t p478, int32_t p479
, int32_t p480, int32_t p481, int32_t p482, int32_t p483, int32_t p484, int32_t p485, int32_t p486, int32_t p487
, int32_t p488, int32_t p489, int32_t p490, int32_t p491, int32_t p492, int32_t p493, int32_t p494, int32_t p495
, int32_t p496, int32_t p497, int32_t p498, int32_t p499, int32_t p500, int32_t p501, int32_t p502, int32_t p503
, int32_t p504, int32_t p505, int32_t p506, int32_t p507, int32_t p508, int32_t p509, int32_t p510, int32_t p511
, int32_t p512, int32_t p513, int32_t p514, int32_t p515, int32_t p516, int32_t p517, int32_t p518, int32_t p519
, int32_t p520, int32_t p521, int32_t p522, int32_t p523, int32_t p524, int32_t p525, int32_t p526, int32_t p527
, int32_t p528, int32_t p529, int32_t p530, int32_t p531, int32_t p532, int32_t p533, int32_t p534, int32_t p535
, int32_t p536, int32_t p537, int32_t p538, int32_t p539, int32_t p540, int32_t p541, int32_t p542, int32_t p543
, int32_t p544, int32_t p545, int32_t p546, int32_t p547, int32_t p548, int32_t p549, int32_t p550, int32_t p551
, int32_t p552, int32_t p553, int32_t p554, int32_t p555, int32_t p556, int32_t p557, int32_t p558, int32_t p559
, int32_t p560, int32_t p561, int32_t p562, int32_t p563, int32_t p564, int32_t p565, int32_t p566, int32_t p567
, int32_t p568, int32_t p569, int32_t p570, int32_t p571, int32_t p572, int32_t p573, int32_t p574, int32_t p575
, int32_t p576, int32_t p577, int32_t p578, int32_t p579, int32_t p580, int32_t p581, int32_t p582, int32_t p583
, int32_t p584, int32_t p585, int32_t p586, int32_t p587, int32_t p588, int32_t p589, int32_t p590, int32_t p591
, int32_t p592, int32_t p593, int32_t p594, int32_t p595, int32_t p596, int32_t p597, int32_t p598, int32_t p599
, int32_t p600, int32_t p601, int32_t p602, int32_t p603, int32_t p604, int32_t p605, int32_t p606, int32_t p607
, int32_t p608, int32_t p609, int32_t p610, int32_t p611, int32_t p612, int32_t p613, int32_t p614, int32_t p615
, int32_t p616, int32_t p617, int32_t p618, int32_t p619, int32_t p620, int32_t p621, int32_t p622, int32_t p623
, int32_t p624, int32_t p625, int32_t p626, int32_t p627, int32_t p628, int32_t p629, int32_t p630, int32_t p631
, int32_t p632, int32_t p633, int32_t p634, int32_t p635, int32_t p636, int32_t p637, int32_t p638, int32_t p639
, int32_t p640, int32_t p641, int32_t p642, int32_t p643, int32_t p644, int32_t p645, int32_t p646, int32_t p647
, int32_t p648, int32_t p649, int32_t p650, int32_t p651, int32_t p652, int32_t p653, int32_t p654, int32_t p655
, int32_t p656, int32_t p657, int32_t p658, int32_t p659, int32_t p660, int32_t p661, int32_t p662, int32_t p663
, int32_t p664, int32_t p665, int32_t p666, int32_t p667, int32_t p668, int32_t p669, int32_t p670, int32_t p671
, int32_t p672, int32_t p673, int32_t p674, int32_t p675, int32_t p676, int32_t p677, int32_t p678, int32_t p679
, int32_t p680, int32_t p681, int32_t p682, int32_t p683, int32_t p684, int32_t p685, int32_t p686, int32_t p687
, int32_t p688, int32_t p689, int32_t p690, int32_t p691, int32_t p692, int32_t p693, int32_t p694, int32_t p695
, int32_t p696, int32_t p697, int32_t p698, int32_t p699, int32_t p700, int32_t p701, int32_t p702, int32_t p703
, int32_t p704, int32_t p705, int32_t p706, int32_t p707, int32_t p708, int32_t p709, int32_t p710, int32_t p711
, int32_t p712, int32_t p713, int32_t p714, int32_t p715, int32_t p716, int32_t p717, int32_t p718, int32_t p719
, int32_t p720, int32_t p721, int32_t p722, int32_t p723, int32_t p724, int32_t p725, int32_t p726, int32_t p727
, int32_t p728, int32_t p729, int32_t p730, int32_t p731, int32_t p732, int32_t p733, int32_t p734, int32_t p735
, int32_t p736, int32_t p737, int32_t p738, int32_t p739, int32_t p740, int32_t p741, int32_t p742, int32_t p743
, int32_t p744, int32_t p745, int32_t p746, int32_t p747, int32_t p748, int32_t p749, int32_t p750, int32_t p751
, int32_t p752, int32_t p753, int32_t p754, int32_t p755, int32_t p756, int32_t p757, int32_t p758, int32_t p759
, int32_t p760, int32_t p761, int32_t p762, int32_t p763, int32_t p764, int32_t p765, int32_t p766, int32_t p767
, int32_t p768, int32_t p769, int32_t p770, int32_t p771, int32_t p772, int32_t p773, int32_t p774, int32_t p775
, int32_t p776, int32_t p777, int32_t p778, int32_t p779, int32_t p780, int32_t p781, int32_t p782, int32_t p783
, int32_t p784, int32_t p785, int32_t p786, int32_t p787, int32_t p788, int32_t p789, int32_t p790, int32_t p791
, int32_t p792, int32_t p793, int32_t p794, int32_t p795, int32_t p796, int32_t p797, int32_t p798, int32_t p799
, int32_t p800, int32_t p801, int32_t p802, int32_t p803, int32_t p804, int32_t p805, int32_t p806, int32_t p807
, int32_t p808, int32_t p809, int32_t p810, int32_t p811, int32_t p812, int32_t p813, int32_t p814, int32_t p815
, int32_t p816, int32_t p817, int32_t p818, int32_t p819, int32_t p820, int32_t p821, int32_t p822, int32_t p823
, int32_t p824, int32_t p825, int32_t p826, int32_t p827, int32_t p828, int32_t p829, int32_t p830, int32_t p831
, int32_t p832, int32_t p833, int32_t p834, int32_t p835, int32_t p836, int32_t p837, int32_t p838, int32_t p839
, int32_t p840, int32_t p841, int32_t p842, int32_t p843, int32_t p844, int32_t p845, int32_t p846, int32_t p847
, int32_t p848, int32_t p849, int32_t p850, int32_t p851, int32_t p852, int32_t p853, int32_t p854, int32_t p855
, int32_t p856, int32_t p857, int32_t p858, int32_t p859, int32_t p860, int32_t p861, int32_t p862, int32_t p863
, int32_t p864, int32_t p865, int32_t p866, int32_t p867, int32_t p868, int32_t p869, int32_t p870, int32_t p871
, int32_t p872, int32_t p873, int32_t p874, int32_t p875, int32_t p876, int32_t p877, int32_t p878, int32_t p879
, int32_t p880, int32_t p881, int32_t p882, int32_t p883, int32_t p884, int32_t p885, int32_t p886, int32_t p887
, int32_t p888, int32_t p889, int32_t p890, int32_t p891, int32_t p892, int32_t p893, int32_t p894, int32_t p895
, int32_t p896, int32_t p897, int32_t p898, int32_t p899, int32_t p900, int32_t p901, int32_t p902, int32_t p903
, int32_t p904, int32_t p905, int32_t p906, int32_t p907, int32_t p908, int32_t p909, int32_t p910, int32_t p911
, int32_t p912, int32_t p913, int32_t p914, int32_t p915, int32_t p916, int32_t p917, int32_t p918, int32_t p919
, int32_t p920, int32_t p921, int32_t p922, int32_t p923, int32_t p924, int32_t p925, int32_t p926, int32_t p927
, int32_t p928, int32_t p929, int32_t p930, int32_t p931, int32_t p932, int32_t p933, int32_t p934, int32_t p935
, int32_t p936, int32_t p937, int32_t p938, int32_t p939, int32_t p940, int32_t p941, int32_t p942, int32_t p943
, int32_t p944, int32_t p945, int32_t p946, int32_t p947, int32_t p948, int32_t p949, int32_t p950, int32_t p951
, int32_t p952, int32_t p953, int32_t p954, int32_t p955, int32_t p956, int32_t p957, int32_t p958, int32_t p959
, int32_t p960, int32_t p961, int32_t p962, int32_t p963, int32_t p964, int32_t p965, int32_t p966, int32_t p967
, int32_t p968, int32_t p969, int32_t p970, int32_t p971, int32_t p972, int32_t p973, int32_t p974, int32_t p975
, int32_t p976, int32_t p977, int32_t p978, int32_t p979, int32_t p980, int32_t p981, int32_t p982, int32_t p983
, int32_t p984, int32_t p985, int32_t p986, int32_t p987, int32_t p988, int32_t p989, int32_t p990, int32_t p991
, int32_t p992, int32_t p993, int32_t p994, int32_t p995, int32_t p996, int32_t p997, int32_t p998, int32_t p999
, int32_t p1000
)
{
int32_t x;
x = p0 + p1 + p2 + p3 + p4 + p5 + p6 + p7
+ p8 + p9 + p10 + p11 + p12 + p13 + p14 + p15
+ p16 + p17 + p18 + p19 + p20 + p21 + p22 + p23
+ p24 + p25 + p26 + p27 + p28 + p29 + p30 + p31
+ p32 + p33 + p34 + p35 + p36 + p37 + p38 + p39
+ p40 + p41 + p42 + p43 + p44 + p45 + p46 + p47
+ p48 + p49 + p50 + p51 + p52 + p53 + p54 + p55
+ p56 + p57 + p58 + p59 + p60 + p61 + p62 + p63
+ p64 + p65 + p66 + p67 + p68 + p69 + p70 + p71
+ p72 + p73 + p74 + p75 + p76 + p77 + p78 + p79
+ p80 + p81 + p82 + p83 + p84 + p85 + p86 + p87
+ p88 + p89 + p90 + p91 + p92 + p93 + p94 + p95
+ p96 + p97 + p98 + p99 + p100 + p101 + p102 + p103
+ p104 + p105 + p106 + p107 + p108 + p109 + p110 + p111
+ p112 + p113 + p114 + p115 + p116 + p117 + p118 + p119
+ p120 + p121 + p122 + p123 + p124 + p125 + p126 + p127
+ p128 + p129 + p130 + p131 + p132 + p133 + p134 + p135
+ p136 + p137 + p138 + p139 + p140 + p141 + p142 + p143
+ p144 + p145 + p146 + p147 + p148 + p149 + p150 + p151
+ p152 + p153 + p154 + p155 + p156 + p157 + p158 + p159
+ p160 + p161 + p162 + p163 + p164 + p165 + p166 + p167
+ p168 + p169 + p170 + p171 + p172 + p173 + p174 + p175
+ p176 + p177 + p178 + p179 + p180 + p181 + p182 + p183
+ p184 + p185 + p186 + p187 + p188 + p189 + p190 + p191
+ p192 + p193 + p194 + p195 + p196 + p197 + p198 + p199
+ p200 + p201 + p202 + p203 + p204 + p205 + p206 + p207
+ p208 + p209 + p210 + p211 + p212 + p213 + p214 + p215
+ p216 + p217 + p218 + p219 + p220 + p221 + p222 + p223
+ p224 + p225 + p226 + p227 + p228 + p229 + p230 + p231
+ p232 + p233 + p234 + p235 + p236 + p237 + p238 + p239
+ p240 + p241 + p242 + p243 + p244 + p245 + p246 + p247
+ p248 + p249 + p250 + p251 + p252 + p253 + p254 + p255
+ p256 + p257 + p258 + p259 + p260 + p261 + p262 + p263
+ p264 + p265 + p266 + p267 + p268 + p269 + p270 + p271
+ p272 + p273 + p274 + p275 + p276 + p277 + p278 + p279
+ p280 + p281 + p282 + p283 + p284 + p285 + p286 + p287
+ p288 + p289 + p290 + p291 + p292 + p293 + p294 + p295
+ p296 + p297 + p298 + p299 + p300 + p301 + p302 + p303
+ p304 + p305 + p306 + p307 + p308 + p309 + p310 + p311
+ p312 + p313 + p314 + p315 + p316 + p317 + p318 + p319
+ p320 + p321 + p322 + p323 + p324 + p325 + p326 + p327
+ p328 + p329 + p330 + p331 + p332 + p333 + p334 + p335
+ p336 + p337 + p338 + p339 + p340 + p341 + p342 + p343
+ p344 + p345 + p346 + p347 + p348 + p349 + p350 + p351
+ p352 + p353 + p354 + p355 + p356 + p357 + p358 + p359
+ p360 + p361 + p362 + p363 + p364 + p365 + p366 + p367
+ p368 + p369 + p370 + p371 + p372 + p373 + p374 + p375
+ p376 + p377 + p378 + p379 + p380 + p381 + p382 + p383
+ p384 + p385 + p386 + p387 + p388 + p389 + p390 + p391
+ p392 + p393 + p394 + p395 + p396 + p397 + p398 + p399
+ p400 + p401 + p402 + p403 + p404 + p405 + p406 + p407
+ p408 + p409 + p410 + p411 + p412 + p413 + p414 + p415
+ p416 + p417 + p418 + p419 + p420 + p421 + p422 + p423
+ p424 + p425 + p426 + p427 + p428 + p429 + p430 + p431
+ p432 + p433 + p434 + p435 + p436 + p437 + p438 + p439
+ p440 + p441 + p442 + p443 + p444 + p445 + p446 + p447
+ p448 + p449 + p450 + p451 + p452 + p453 + p454 + p455
+ p456 + p457 + p458 + p459 + p460 + p461 + p462 + p463
+ p464 + p465 + p466 + p467 + p468 + p469 + p470 + p471
+ p472 + p473 + p474 + p475 + p476 + p477 + p478 + p479
+ p480 + p481 + p482 + p483 + p484 + p485 + p486 + p487
+ p488 + p489 + p490 + p491 + p492 + p493 + p494 + p495
+ p496 + p497 + p498 + p499 + p500 + p501 + p502 + p503
+ p504 + p505 + p506 + p507 + p508 + p509 + p510 + p511
+ p512 + p513 + p514 + p515 + p516 + p517 + p518 + p519
+ p520 + p521 + p522 + p523 + p524 + p525 + p526 + p527
+ p528 + p529 + p530 + p531 + p532 + p533 + p534 + p535
+ p536 + p537 + p538 + p539 + p540 + p541 + p542 + p543
+ p544 + p545 + p546 + p547 + p548 + p549 + p550 + p551
+ p552 + p553 + p554 + p555 + p556 + p557 + p558 + p559
+ p560 + p561 + p562 + p563 + p564 + p565 + p566 + p567
+ p568 + p569 + p570 + p571 + p572 + p573 + p574 + p575
+ p576 + p577 + p578 + p579 + p580 + p581 + p582 + p583
+ p584 + p585 + p586 + p587 + p588 + p589 + p590 + p591
+ p592 + p593 + p594 + p595 + p596 + p597 + p598 + p599
+ p600 + p601 + p602 + p603 + p604 + p605 + p606 + p607
+ p608 + p609 + p610 + p611 + p612 + p613 + p614 + p615
+ p616 + p617 + p618 + p619 + p620 + p621 + p622 + p623
+ p624 + p625 + p626 + p627 + p628 + p629 + p630 + p631
+ p632 + p633 + p634 + p635 + p636 + p637 + p638 + p639
+ p640 + p641 + p642 + p643 + p644 + p645 + p646 + p647
+ p648 + p649 + p650 + p651 + p652 + p653 + p654 + p655
+ p656 + p657 + p658 + p659 + p660 + p661 + p662 + p663
+ p664 + p665 + p666 + p667 + p668 + p669 + p670 + p671
+ p672 + p673 + p674 + p675 + p676 + p677 + p678 + p679
+ p680 + p681 + p682 + p683 + p684 + p685 + p686 + p687
+ p688 + p689 + p690 + p691 + p692 + p693 + p694 + p695
+ p696 + p697 + p698 + p699 + p700 + p701 + p702 + p703
+ p704 + p705 + p706 + p707 + p708 + p709 + p710 + p711
+ p712 + p713 + p714 + p715 + p716 + p717 + p718 + p719
+ p720 + p721 + p722 + p723 + p724 + p725 + p726 + p727
+ p728 + p729 + p730 + p731 + p732 + p733 + p734 + p735
+ p736 + p737 + p738 + p739 + p740 + p741 + p742 + p743
+ p744 + p745 + p746 + p747 + p748 + p749 + p750 + p751
+ p752 + p753 + p754 + p755 + p756 + p757 + p758 + p759
+ p760 + p761 + p762 + p763 + p764 + p765 + p766 + p767
+ p768 + p769 + p770 + p771 + p772 + p773 + p774 + p775
+ p776 + p777 + p778 + p779 + p780 + p781 + p782 + p783
+ p784 + p785 + p786 + p787 + p788 + p789 + p790 + p791
+ p792 + p793 + p794 + p795 + p796 + p797 + p798 + p799
+ p800 + p801 + p802 + p803 + p804 + p805 + p806 + p807
+ p808 + p809 + p810 + p811 + p812 + p813 + p814 + p815
+ p816 + p817 + p818 + p819 + p820 + p821 + p822 + p823
+ p824 + p825 + p826 + p827 + p828 + p829 + p830 + p831
+ p832 + p833 + p834 + p835 + p836 + p837 + p838 + p839
+ p840 + p841 + p842 + p843 + p844 + p845 + p846 + p847
+ p848 + p849 + p850 + p851 + p852 + p853 + p854 + p855
+ p856 + p857 + p858 + p859 + p860 + p861 + p862 + p863
+ p864 + p865 + p866 + p867 + p868 + p869 + p870 + p871
+ p872 + p873 + p874 + p875 + p876 + p877 + p878 + p879
+ p880 + p881 + p882 + p883 + p884 + p885 + p886 + p887
+ p888 + p889 + p890 + p891 + p892 + p893 + p894 + p895
+ p896 + p897 + p898 + p899 + p900 + p901 + p902 + p903
+ p904 + p905 + p906 + p907 + p908 + p909 + p910 + p911
+ p912 + p913 + p914 + p915 + p916 + p917 + p918 + p919
+ p920 + p921 + p922 + p923 + p924 + p925 + p926 + p927
+ p928 + p929 + p930 + p931 + p932 + p933 + p934 + p935
+ p936 + p937 + p938 + p939 + p940 + p941 + p942 + p943
+ p944 + p945 + p946 + p947 + p948 + p949 + p950 + p951
+ p952 + p953 + p954 + p955 + p956 + p957 + p958 + p959
+ p960 + p961 + p962 + p963 + p964 + p965 + p966 + p967
+ p968 + p969 + p970 + p971 + p972 + p973 + p974 + p975
+ p976 + p977 + p978 + p979 + p980 + p981 + p982 + p983
+ p984 + p985 + p986 + p987 + p988 + p989 + p990 + p991
+ p992 + p993 + p994 + p995 + p996 + p997 + p998 + p999
+ p1000;
return x;
}
// clang-format on

View File

@@ -0,0 +1,262 @@
// clang-format off
#include <stdint.h>
int32_t test(
int32_t p0, int32_t p1, int32_t p2, int32_t p3, int32_t p4, int32_t p5, int32_t p6, int32_t p7
, int32_t p8, int32_t p9, int32_t p10, int32_t p11, int32_t p12, int32_t p13, int32_t p14, int32_t p15
, int32_t p16, int32_t p17, int32_t p18, int32_t p19, int32_t p20, int32_t p21, int32_t p22, int32_t p23
, int32_t p24, int32_t p25, int32_t p26, int32_t p27, int32_t p28, int32_t p29, int32_t p30, int32_t p31
, int32_t p32, int32_t p33, int32_t p34, int32_t p35, int32_t p36, int32_t p37, int32_t p38, int32_t p39
, int32_t p40, int32_t p41, int32_t p42, int32_t p43, int32_t p44, int32_t p45, int32_t p46, int32_t p47
, int32_t p48, int32_t p49, int32_t p50, int32_t p51, int32_t p52, int32_t p53, int32_t p54, int32_t p55
, int32_t p56, int32_t p57, int32_t p58, int32_t p59, int32_t p60, int32_t p61, int32_t p62, int32_t p63
, int32_t p64, int32_t p65, int32_t p66, int32_t p67, int32_t p68, int32_t p69, int32_t p70, int32_t p71
, int32_t p72, int32_t p73, int32_t p74, int32_t p75, int32_t p76, int32_t p77, int32_t p78, int32_t p79
, int32_t p80, int32_t p81, int32_t p82, int32_t p83, int32_t p84, int32_t p85, int32_t p86, int32_t p87
, int32_t p88, int32_t p89, int32_t p90, int32_t p91, int32_t p92, int32_t p93, int32_t p94, int32_t p95
, int32_t p96, int32_t p97, int32_t p98, int32_t p99, int32_t p100, int32_t p101, int32_t p102, int32_t p103
, int32_t p104, int32_t p105, int32_t p106, int32_t p107, int32_t p108, int32_t p109, int32_t p110, int32_t p111
, int32_t p112, int32_t p113, int32_t p114, int32_t p115, int32_t p116, int32_t p117, int32_t p118, int32_t p119
, int32_t p120, int32_t p121, int32_t p122, int32_t p123, int32_t p124, int32_t p125, int32_t p126, int32_t p127
, int32_t p128, int32_t p129, int32_t p130, int32_t p131, int32_t p132, int32_t p133, int32_t p134, int32_t p135
, int32_t p136, int32_t p137, int32_t p138, int32_t p139, int32_t p140, int32_t p141, int32_t p142, int32_t p143
, int32_t p144, int32_t p145, int32_t p146, int32_t p147, int32_t p148, int32_t p149, int32_t p150, int32_t p151
, int32_t p152, int32_t p153, int32_t p154, int32_t p155, int32_t p156, int32_t p157, int32_t p158, int32_t p159
, int32_t p160, int32_t p161, int32_t p162, int32_t p163, int32_t p164, int32_t p165, int32_t p166, int32_t p167
, int32_t p168, int32_t p169, int32_t p170, int32_t p171, int32_t p172, int32_t p173, int32_t p174, int32_t p175
, int32_t p176, int32_t p177, int32_t p178, int32_t p179, int32_t p180, int32_t p181, int32_t p182, int32_t p183
, int32_t p184, int32_t p185, int32_t p186, int32_t p187, int32_t p188, int32_t p189, int32_t p190, int32_t p191
, int32_t p192, int32_t p193, int32_t p194, int32_t p195, int32_t p196, int32_t p197, int32_t p198, int32_t p199
, int32_t p200, int32_t p201, int32_t p202, int32_t p203, int32_t p204, int32_t p205, int32_t p206, int32_t p207
, int32_t p208, int32_t p209, int32_t p210, int32_t p211, int32_t p212, int32_t p213, int32_t p214, int32_t p215
, int32_t p216, int32_t p217, int32_t p218, int32_t p219, int32_t p220, int32_t p221, int32_t p222, int32_t p223
, int32_t p224, int32_t p225, int32_t p226, int32_t p227, int32_t p228, int32_t p229, int32_t p230, int32_t p231
, int32_t p232, int32_t p233, int32_t p234, int32_t p235, int32_t p236, int32_t p237, int32_t p238, int32_t p239
, int32_t p240, int32_t p241, int32_t p242, int32_t p243, int32_t p244, int32_t p245, int32_t p246, int32_t p247
, int32_t p248, int32_t p249, int32_t p250, int32_t p251, int32_t p252, int32_t p253, int32_t p254, int32_t p255
, int32_t p256, int32_t p257, int32_t p258, int32_t p259, int32_t p260, int32_t p261, int32_t p262, int32_t p263
, int32_t p264, int32_t p265, int32_t p266, int32_t p267, int32_t p268, int32_t p269, int32_t p270, int32_t p271
, int32_t p272, int32_t p273, int32_t p274, int32_t p275, int32_t p276, int32_t p277, int32_t p278, int32_t p279
, int32_t p280, int32_t p281, int32_t p282, int32_t p283, int32_t p284, int32_t p285, int32_t p286, int32_t p287
, int32_t p288, int32_t p289, int32_t p290, int32_t p291, int32_t p292, int32_t p293, int32_t p294, int32_t p295
, int32_t p296, int32_t p297, int32_t p298, int32_t p299, int32_t p300, int32_t p301, int32_t p302, int32_t p303
, int32_t p304, int32_t p305, int32_t p306, int32_t p307, int32_t p308, int32_t p309, int32_t p310, int32_t p311
, int32_t p312, int32_t p313, int32_t p314, int32_t p315, int32_t p316, int32_t p317, int32_t p318, int32_t p319
, int32_t p320, int32_t p321, int32_t p322, int32_t p323, int32_t p324, int32_t p325, int32_t p326, int32_t p327
, int32_t p328, int32_t p329, int32_t p330, int32_t p331, int32_t p332, int32_t p333, int32_t p334, int32_t p335
, int32_t p336, int32_t p337, int32_t p338, int32_t p339, int32_t p340, int32_t p341, int32_t p342, int32_t p343
, int32_t p344, int32_t p345, int32_t p346, int32_t p347, int32_t p348, int32_t p349, int32_t p350, int32_t p351
, int32_t p352, int32_t p353, int32_t p354, int32_t p355, int32_t p356, int32_t p357, int32_t p358, int32_t p359
, int32_t p360, int32_t p361, int32_t p362, int32_t p363, int32_t p364, int32_t p365, int32_t p366, int32_t p367
, int32_t p368, int32_t p369, int32_t p370, int32_t p371, int32_t p372, int32_t p373, int32_t p374, int32_t p375
, int32_t p376, int32_t p377, int32_t p378, int32_t p379, int32_t p380, int32_t p381, int32_t p382, int32_t p383
, int32_t p384, int32_t p385, int32_t p386, int32_t p387, int32_t p388, int32_t p389, int32_t p390, int32_t p391
, int32_t p392, int32_t p393, int32_t p394, int32_t p395, int32_t p396, int32_t p397, int32_t p398, int32_t p399
, int32_t p400, int32_t p401, int32_t p402, int32_t p403, int32_t p404, int32_t p405, int32_t p406, int32_t p407
, int32_t p408, int32_t p409, int32_t p410, int32_t p411, int32_t p412, int32_t p413, int32_t p414, int32_t p415
, int32_t p416, int32_t p417, int32_t p418, int32_t p419, int32_t p420, int32_t p421, int32_t p422, int32_t p423
, int32_t p424, int32_t p425, int32_t p426, int32_t p427, int32_t p428, int32_t p429, int32_t p430, int32_t p431
, int32_t p432, int32_t p433, int32_t p434, int32_t p435, int32_t p436, int32_t p437, int32_t p438, int32_t p439
, int32_t p440, int32_t p441, int32_t p442, int32_t p443, int32_t p444, int32_t p445, int32_t p446, int32_t p447
, int32_t p448, int32_t p449, int32_t p450, int32_t p451, int32_t p452, int32_t p453, int32_t p454, int32_t p455
, int32_t p456, int32_t p457, int32_t p458, int32_t p459, int32_t p460, int32_t p461, int32_t p462, int32_t p463
, int32_t p464, int32_t p465, int32_t p466, int32_t p467, int32_t p468, int32_t p469, int32_t p470, int32_t p471
, int32_t p472, int32_t p473, int32_t p474, int32_t p475, int32_t p476, int32_t p477, int32_t p478, int32_t p479
, int32_t p480, int32_t p481, int32_t p482, int32_t p483, int32_t p484, int32_t p485, int32_t p486, int32_t p487
, int32_t p488, int32_t p489, int32_t p490, int32_t p491, int32_t p492, int32_t p493, int32_t p494, int32_t p495
, int32_t p496, int32_t p497, int32_t p498, int32_t p499, int32_t p500, int32_t p501, int32_t p502, int32_t p503
, int32_t p504, int32_t p505, int32_t p506, int32_t p507, int32_t p508, int32_t p509, int32_t p510, int32_t p511
, int32_t p512, int32_t p513, int32_t p514, int32_t p515, int32_t p516, int32_t p517, int32_t p518, int32_t p519
, int32_t p520, int32_t p521, int32_t p522, int32_t p523, int32_t p524, int32_t p525, int32_t p526, int32_t p527
, int32_t p528, int32_t p529, int32_t p530, int32_t p531, int32_t p532, int32_t p533, int32_t p534, int32_t p535
, int32_t p536, int32_t p537, int32_t p538, int32_t p539, int32_t p540, int32_t p541, int32_t p542, int32_t p543
, int32_t p544, int32_t p545, int32_t p546, int32_t p547, int32_t p548, int32_t p549, int32_t p550, int32_t p551
, int32_t p552, int32_t p553, int32_t p554, int32_t p555, int32_t p556, int32_t p557, int32_t p558, int32_t p559
, int32_t p560, int32_t p561, int32_t p562, int32_t p563, int32_t p564, int32_t p565, int32_t p566, int32_t p567
, int32_t p568, int32_t p569, int32_t p570, int32_t p571, int32_t p572, int32_t p573, int32_t p574, int32_t p575
, int32_t p576, int32_t p577, int32_t p578, int32_t p579, int32_t p580, int32_t p581, int32_t p582, int32_t p583
, int32_t p584, int32_t p585, int32_t p586, int32_t p587, int32_t p588, int32_t p589, int32_t p590, int32_t p591
, int32_t p592, int32_t p593, int32_t p594, int32_t p595, int32_t p596, int32_t p597, int32_t p598, int32_t p599
, int32_t p600, int32_t p601, int32_t p602, int32_t p603, int32_t p604, int32_t p605, int32_t p606, int32_t p607
, int32_t p608, int32_t p609, int32_t p610, int32_t p611, int32_t p612, int32_t p613, int32_t p614, int32_t p615
, int32_t p616, int32_t p617, int32_t p618, int32_t p619, int32_t p620, int32_t p621, int32_t p622, int32_t p623
, int32_t p624, int32_t p625, int32_t p626, int32_t p627, int32_t p628, int32_t p629, int32_t p630, int32_t p631
, int32_t p632, int32_t p633, int32_t p634, int32_t p635, int32_t p636, int32_t p637, int32_t p638, int32_t p639
, int32_t p640, int32_t p641, int32_t p642, int32_t p643, int32_t p644, int32_t p645, int32_t p646, int32_t p647
, int32_t p648, int32_t p649, int32_t p650, int32_t p651, int32_t p652, int32_t p653, int32_t p654, int32_t p655
, int32_t p656, int32_t p657, int32_t p658, int32_t p659, int32_t p660, int32_t p661, int32_t p662, int32_t p663
, int32_t p664, int32_t p665, int32_t p666, int32_t p667, int32_t p668, int32_t p669, int32_t p670, int32_t p671
, int32_t p672, int32_t p673, int32_t p674, int32_t p675, int32_t p676, int32_t p677, int32_t p678, int32_t p679
, int32_t p680, int32_t p681, int32_t p682, int32_t p683, int32_t p684, int32_t p685, int32_t p686, int32_t p687
, int32_t p688, int32_t p689, int32_t p690, int32_t p691, int32_t p692, int32_t p693, int32_t p694, int32_t p695
, int32_t p696, int32_t p697, int32_t p698, int32_t p699, int32_t p700, int32_t p701, int32_t p702, int32_t p703
, int32_t p704, int32_t p705, int32_t p706, int32_t p707, int32_t p708, int32_t p709, int32_t p710, int32_t p711
, int32_t p712, int32_t p713, int32_t p714, int32_t p715, int32_t p716, int32_t p717, int32_t p718, int32_t p719
, int32_t p720, int32_t p721, int32_t p722, int32_t p723, int32_t p724, int32_t p725, int32_t p726, int32_t p727
, int32_t p728, int32_t p729, int32_t p730, int32_t p731, int32_t p732, int32_t p733, int32_t p734, int32_t p735
, int32_t p736, int32_t p737, int32_t p738, int32_t p739, int32_t p740, int32_t p741, int32_t p742, int32_t p743
, int32_t p744, int32_t p745, int32_t p746, int32_t p747, int32_t p748, int32_t p749, int32_t p750, int32_t p751
, int32_t p752, int32_t p753, int32_t p754, int32_t p755, int32_t p756, int32_t p757, int32_t p758, int32_t p759
, int32_t p760, int32_t p761, int32_t p762, int32_t p763, int32_t p764, int32_t p765, int32_t p766, int32_t p767
, int32_t p768, int32_t p769, int32_t p770, int32_t p771, int32_t p772, int32_t p773, int32_t p774, int32_t p775
, int32_t p776, int32_t p777, int32_t p778, int32_t p779, int32_t p780, int32_t p781, int32_t p782, int32_t p783
, int32_t p784, int32_t p785, int32_t p786, int32_t p787, int32_t p788, int32_t p789, int32_t p790, int32_t p791
, int32_t p792, int32_t p793, int32_t p794, int32_t p795, int32_t p796, int32_t p797, int32_t p798, int32_t p799
, int32_t p800, int32_t p801, int32_t p802, int32_t p803, int32_t p804, int32_t p805, int32_t p806, int32_t p807
, int32_t p808, int32_t p809, int32_t p810, int32_t p811, int32_t p812, int32_t p813, int32_t p814, int32_t p815
, int32_t p816, int32_t p817, int32_t p818, int32_t p819, int32_t p820, int32_t p821, int32_t p822, int32_t p823
, int32_t p824, int32_t p825, int32_t p826, int32_t p827, int32_t p828, int32_t p829, int32_t p830, int32_t p831
, int32_t p832, int32_t p833, int32_t p834, int32_t p835, int32_t p836, int32_t p837, int32_t p838, int32_t p839
, int32_t p840, int32_t p841, int32_t p842, int32_t p843, int32_t p844, int32_t p845, int32_t p846, int32_t p847
, int32_t p848, int32_t p849, int32_t p850, int32_t p851, int32_t p852, int32_t p853, int32_t p854, int32_t p855
, int32_t p856, int32_t p857, int32_t p858, int32_t p859, int32_t p860, int32_t p861, int32_t p862, int32_t p863
, int32_t p864, int32_t p865, int32_t p866, int32_t p867, int32_t p868, int32_t p869, int32_t p870, int32_t p871
, int32_t p872, int32_t p873, int32_t p874, int32_t p875, int32_t p876, int32_t p877, int32_t p878, int32_t p879
, int32_t p880, int32_t p881, int32_t p882, int32_t p883, int32_t p884, int32_t p885, int32_t p886, int32_t p887
, int32_t p888, int32_t p889, int32_t p890, int32_t p891, int32_t p892, int32_t p893, int32_t p894, int32_t p895
, int32_t p896, int32_t p897, int32_t p898, int32_t p899, int32_t p900, int32_t p901, int32_t p902, int32_t p903
, int32_t p904, int32_t p905, int32_t p906, int32_t p907, int32_t p908, int32_t p909, int32_t p910, int32_t p911
, int32_t p912, int32_t p913, int32_t p914, int32_t p915, int32_t p916, int32_t p917, int32_t p918, int32_t p919
, int32_t p920, int32_t p921, int32_t p922, int32_t p923, int32_t p924, int32_t p925, int32_t p926, int32_t p927
, int32_t p928, int32_t p929, int32_t p930, int32_t p931, int32_t p932, int32_t p933, int32_t p934, int32_t p935
, int32_t p936, int32_t p937, int32_t p938, int32_t p939, int32_t p940, int32_t p941, int32_t p942, int32_t p943
, int32_t p944, int32_t p945, int32_t p946, int32_t p947, int32_t p948, int32_t p949, int32_t p950, int32_t p951
, int32_t p952, int32_t p953, int32_t p954, int32_t p955, int32_t p956, int32_t p957, int32_t p958, int32_t p959
, int32_t p960, int32_t p961, int32_t p962, int32_t p963, int32_t p964, int32_t p965, int32_t p966, int32_t p967
, int32_t p968, int32_t p969, int32_t p970, int32_t p971, int32_t p972, int32_t p973, int32_t p974, int32_t p975
, int32_t p976, int32_t p977, int32_t p978, int32_t p979, int32_t p980, int32_t p981, int32_t p982, int32_t p983
, int32_t p984, int32_t p985, int32_t p986, int32_t p987, int32_t p988, int32_t p989, int32_t p990, int32_t p991
, int32_t p992, int32_t p993, int32_t p994, int32_t p995, int32_t p996, int32_t p997, int32_t p998, int32_t p999
)
{
int32_t x;
x = p0 + p1 + p2 + p3 + p4 + p5 + p6 + p7
+ p8 + p9 + p10 + p11 + p12 + p13 + p14 + p15
+ p16 + p17 + p18 + p19 + p20 + p21 + p22 + p23
+ p24 + p25 + p26 + p27 + p28 + p29 + p30 + p31
+ p32 + p33 + p34 + p35 + p36 + p37 + p38 + p39
+ p40 + p41 + p42 + p43 + p44 + p45 + p46 + p47
+ p48 + p49 + p50 + p51 + p52 + p53 + p54 + p55
+ p56 + p57 + p58 + p59 + p60 + p61 + p62 + p63
+ p64 + p65 + p66 + p67 + p68 + p69 + p70 + p71
+ p72 + p73 + p74 + p75 + p76 + p77 + p78 + p79
+ p80 + p81 + p82 + p83 + p84 + p85 + p86 + p87
+ p88 + p89 + p90 + p91 + p92 + p93 + p94 + p95
+ p96 + p97 + p98 + p99 + p100 + p101 + p102 + p103
+ p104 + p105 + p106 + p107 + p108 + p109 + p110 + p111
+ p112 + p113 + p114 + p115 + p116 + p117 + p118 + p119
+ p120 + p121 + p122 + p123 + p124 + p125 + p126 + p127
+ p128 + p129 + p130 + p131 + p132 + p133 + p134 + p135
+ p136 + p137 + p138 + p139 + p140 + p141 + p142 + p143
+ p144 + p145 + p146 + p147 + p148 + p149 + p150 + p151
+ p152 + p153 + p154 + p155 + p156 + p157 + p158 + p159
+ p160 + p161 + p162 + p163 + p164 + p165 + p166 + p167
+ p168 + p169 + p170 + p171 + p172 + p173 + p174 + p175
+ p176 + p177 + p178 + p179 + p180 + p181 + p182 + p183
+ p184 + p185 + p186 + p187 + p188 + p189 + p190 + p191
+ p192 + p193 + p194 + p195 + p196 + p197 + p198 + p199
+ p200 + p201 + p202 + p203 + p204 + p205 + p206 + p207
+ p208 + p209 + p210 + p211 + p212 + p213 + p214 + p215
+ p216 + p217 + p218 + p219 + p220 + p221 + p222 + p223
+ p224 + p225 + p226 + p227 + p228 + p229 + p230 + p231
+ p232 + p233 + p234 + p235 + p236 + p237 + p238 + p239
+ p240 + p241 + p242 + p243 + p244 + p245 + p246 + p247
+ p248 + p249 + p250 + p251 + p252 + p253 + p254 + p255
+ p256 + p257 + p258 + p259 + p260 + p261 + p262 + p263
+ p264 + p265 + p266 + p267 + p268 + p269 + p270 + p271
+ p272 + p273 + p274 + p275 + p276 + p277 + p278 + p279
+ p280 + p281 + p282 + p283 + p284 + p285 + p286 + p287
+ p288 + p289 + p290 + p291 + p292 + p293 + p294 + p295
+ p296 + p297 + p298 + p299 + p300 + p301 + p302 + p303
+ p304 + p305 + p306 + p307 + p308 + p309 + p310 + p311
+ p312 + p313 + p314 + p315 + p316 + p317 + p318 + p319
+ p320 + p321 + p322 + p323 + p324 + p325 + p326 + p327
+ p328 + p329 + p330 + p331 + p332 + p333 + p334 + p335
+ p336 + p337 + p338 + p339 + p340 + p341 + p342 + p343
+ p344 + p345 + p346 + p347 + p348 + p349 + p350 + p351
+ p352 + p353 + p354 + p355 + p356 + p357 + p358 + p359
+ p360 + p361 + p362 + p363 + p364 + p365 + p366 + p367
+ p368 + p369 + p370 + p371 + p372 + p373 + p374 + p375
+ p376 + p377 + p378 + p379 + p380 + p381 + p382 + p383
+ p384 + p385 + p386 + p387 + p388 + p389 + p390 + p391
+ p392 + p393 + p394 + p395 + p396 + p397 + p398 + p399
+ p400 + p401 + p402 + p403 + p404 + p405 + p406 + p407
+ p408 + p409 + p410 + p411 + p412 + p413 + p414 + p415
+ p416 + p417 + p418 + p419 + p420 + p421 + p422 + p423
+ p424 + p425 + p426 + p427 + p428 + p429 + p430 + p431
+ p432 + p433 + p434 + p435 + p436 + p437 + p438 + p439
+ p440 + p441 + p442 + p443 + p444 + p445 + p446 + p447
+ p448 + p449 + p450 + p451 + p452 + p453 + p454 + p455
+ p456 + p457 + p458 + p459 + p460 + p461 + p462 + p463
+ p464 + p465 + p466 + p467 + p468 + p469 + p470 + p471
+ p472 + p473 + p474 + p475 + p476 + p477 + p478 + p479
+ p480 + p481 + p482 + p483 + p484 + p485 + p486 + p487
+ p488 + p489 + p490 + p491 + p492 + p493 + p494 + p495
+ p496 + p497 + p498 + p499 + p500 + p501 + p502 + p503
+ p504 + p505 + p506 + p507 + p508 + p509 + p510 + p511
+ p512 + p513 + p514 + p515 + p516 + p517 + p518 + p519
+ p520 + p521 + p522 + p523 + p524 + p525 + p526 + p527
+ p528 + p529 + p530 + p531 + p532 + p533 + p534 + p535
+ p536 + p537 + p538 + p539 + p540 + p541 + p542 + p543
+ p544 + p545 + p546 + p547 + p548 + p549 + p550 + p551
+ p552 + p553 + p554 + p555 + p556 + p557 + p558 + p559
+ p560 + p561 + p562 + p563 + p564 + p565 + p566 + p567
+ p568 + p569 + p570 + p571 + p572 + p573 + p574 + p575
+ p576 + p577 + p578 + p579 + p580 + p581 + p582 + p583
+ p584 + p585 + p586 + p587 + p588 + p589 + p590 + p591
+ p592 + p593 + p594 + p595 + p596 + p597 + p598 + p599
+ p600 + p601 + p602 + p603 + p604 + p605 + p606 + p607
+ p608 + p609 + p610 + p611 + p612 + p613 + p614 + p615
+ p616 + p617 + p618 + p619 + p620 + p621 + p622 + p623
+ p624 + p625 + p626 + p627 + p628 + p629 + p630 + p631
+ p632 + p633 + p634 + p635 + p636 + p637 + p638 + p639
+ p640 + p641 + p642 + p643 + p644 + p645 + p646 + p647
+ p648 + p649 + p650 + p651 + p652 + p653 + p654 + p655
+ p656 + p657 + p658 + p659 + p660 + p661 + p662 + p663
+ p664 + p665 + p666 + p667 + p668 + p669 + p670 + p671
+ p672 + p673 + p674 + p675 + p676 + p677 + p678 + p679
+ p680 + p681 + p682 + p683 + p684 + p685 + p686 + p687
+ p688 + p689 + p690 + p691 + p692 + p693 + p694 + p695
+ p696 + p697 + p698 + p699 + p700 + p701 + p702 + p703
+ p704 + p705 + p706 + p707 + p708 + p709 + p710 + p711
+ p712 + p713 + p714 + p715 + p716 + p717 + p718 + p719
+ p720 + p721 + p722 + p723 + p724 + p725 + p726 + p727
+ p728 + p729 + p730 + p731 + p732 + p733 + p734 + p735
+ p736 + p737 + p738 + p739 + p740 + p741 + p742 + p743
+ p744 + p745 + p746 + p747 + p748 + p749 + p750 + p751
+ p752 + p753 + p754 + p755 + p756 + p757 + p758 + p759
+ p760 + p761 + p762 + p763 + p764 + p765 + p766 + p767
+ p768 + p769 + p770 + p771 + p772 + p773 + p774 + p775
+ p776 + p777 + p778 + p779 + p780 + p781 + p782 + p783
+ p784 + p785 + p786 + p787 + p788 + p789 + p790 + p791
+ p792 + p793 + p794 + p795 + p796 + p797 + p798 + p799
+ p800 + p801 + p802 + p803 + p804 + p805 + p806 + p807
+ p808 + p809 + p810 + p811 + p812 + p813 + p814 + p815
+ p816 + p817 + p818 + p819 + p820 + p821 + p822 + p823
+ p824 + p825 + p826 + p827 + p828 + p829 + p830 + p831
+ p832 + p833 + p834 + p835 + p836 + p837 + p838 + p839
+ p840 + p841 + p842 + p843 + p844 + p845 + p846 + p847
+ p848 + p849 + p850 + p851 + p852 + p853 + p854 + p855
+ p856 + p857 + p858 + p859 + p860 + p861 + p862 + p863
+ p864 + p865 + p866 + p867 + p868 + p869 + p870 + p871
+ p872 + p873 + p874 + p875 + p876 + p877 + p878 + p879
+ p880 + p881 + p882 + p883 + p884 + p885 + p886 + p887
+ p888 + p889 + p890 + p891 + p892 + p893 + p894 + p895
+ p896 + p897 + p898 + p899 + p900 + p901 + p902 + p903
+ p904 + p905 + p906 + p907 + p908 + p909 + p910 + p911
+ p912 + p913 + p914 + p915 + p916 + p917 + p918 + p919
+ p920 + p921 + p922 + p923 + p924 + p925 + p926 + p927
+ p928 + p929 + p930 + p931 + p932 + p933 + p934 + p935
+ p936 + p937 + p938 + p939 + p940 + p941 + p942 + p943
+ p944 + p945 + p946 + p947 + p948 + p949 + p950 + p951
+ p952 + p953 + p954 + p955 + p956 + p957 + p958 + p959
+ p960 + p961 + p962 + p963 + p964 + p965 + p966 + p967
+ p968 + p969 + p970 + p971 + p972 + p973 + p974 + p975
+ p976 + p977 + p978 + p979 + p980 + p981 + p982 + p983
+ p984 + p985 + p986 + p987 + p988 + p989 + p990 + p991
+ p992 + p993 + p994 + p995 + p996 + p997 + p998 + p999;
return x;
}
// clang-format on

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -104,56 +104,50 @@ struct HostFunctions
return nullptr;
}
std::int64_t
getGas()
{
return -1;
}
void
setGas(std::int64_t)
{
return;
}
beast::Journal
getJournal()
getJournal() const
{
return j_;
}
virtual bool
checkSelf() const
{
return true;
}
virtual Expected<std::uint32_t, HostFunctionError>
getLedgerSqn()
getLedgerSqn() const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<std::uint32_t, HostFunctionError>
getParentLedgerTime()
getParentLedgerTime() const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<Hash, HostFunctionError>
getParentLedgerHash()
getParentLedgerHash() const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<uint32_t, HostFunctionError>
getBaseFee()
getBaseFee() const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<int32_t, HostFunctionError>
isAmendmentEnabled(uint256 const& amendmentId)
isAmendmentEnabled(uint256 const& amendmentId) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<int32_t, HostFunctionError>
isAmendmentEnabled(std::string_view const& amendmentName)
isAmendmentEnabled(std::string_view const& amendmentName) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
@@ -165,73 +159,73 @@ struct HostFunctions
}
virtual Expected<Bytes, HostFunctionError>
getTxField(SField const& fname)
getTxField(SField const& fname) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<Bytes, HostFunctionError>
getCurrentLedgerObjField(SField const& fname)
getCurrentLedgerObjField(SField const& fname) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<Bytes, HostFunctionError>
getLedgerObjField(int32_t cacheIdx, SField const& fname)
getLedgerObjField(int32_t cacheIdx, SField const& fname) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<Bytes, HostFunctionError>
getTxNestedField(Slice const& locator)
getTxNestedField(Slice const& locator) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<Bytes, HostFunctionError>
getCurrentLedgerObjNestedField(Slice const& locator)
getCurrentLedgerObjNestedField(Slice const& locator) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<Bytes, HostFunctionError>
getLedgerObjNestedField(int32_t cacheIdx, Slice const& locator)
getLedgerObjNestedField(int32_t cacheIdx, Slice const& locator) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<int32_t, HostFunctionError>
getTxArrayLen(SField const& fname)
getTxArrayLen(SField const& fname) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<int32_t, HostFunctionError>
getCurrentLedgerObjArrayLen(SField const& fname)
getCurrentLedgerObjArrayLen(SField const& fname) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<int32_t, HostFunctionError>
getLedgerObjArrayLen(int32_t cacheIdx, SField const& fname)
getLedgerObjArrayLen(int32_t cacheIdx, SField const& fname) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<int32_t, HostFunctionError>
getTxNestedArrayLen(Slice const& locator)
getTxNestedArrayLen(Slice const& locator) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<int32_t, HostFunctionError>
getCurrentLedgerObjNestedArrayLen(Slice const& locator)
getCurrentLedgerObjNestedArrayLen(Slice const& locator) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<int32_t, HostFunctionError>
getLedgerObjNestedArrayLen(int32_t cacheIdx, Slice const& locator)
getLedgerObjNestedArrayLen(int32_t cacheIdx, Slice const& locator) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
@@ -243,259 +237,259 @@ struct HostFunctions
}
virtual Expected<int32_t, HostFunctionError>
checkSignature(Slice const& message, Slice const& signature, Slice const& pubkey)
checkSignature(Slice const& message, Slice const& signature, Slice const& pubkey) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<Hash, HostFunctionError>
computeSha512HalfHash(Slice const& data)
computeSha512HalfHash(Slice const& data) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<Bytes, HostFunctionError>
accountKeylet(AccountID const& account)
accountKeylet(AccountID const& account) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<Bytes, HostFunctionError>
ammKeylet(Asset const& issue1, Asset const& issue2)
ammKeylet(Asset const& issue1, Asset const& issue2) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<Bytes, HostFunctionError>
checkKeylet(AccountID const& account, std::uint32_t seq)
checkKeylet(AccountID const& account, std::uint32_t seq) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<Bytes, HostFunctionError>
credentialKeylet(AccountID const& subject, AccountID const& issuer, Slice const& credentialType)
credentialKeylet(AccountID const& subject, AccountID const& issuer, Slice const& credentialType) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<Bytes, HostFunctionError>
didKeylet(AccountID const& account)
didKeylet(AccountID const& account) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<Bytes, HostFunctionError>
delegateKeylet(AccountID const& account, AccountID const& authorize)
delegateKeylet(AccountID const& account, AccountID const& authorize) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<Bytes, HostFunctionError>
depositPreauthKeylet(AccountID const& account, AccountID const& authorize)
depositPreauthKeylet(AccountID const& account, AccountID const& authorize) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<Bytes, HostFunctionError>
escrowKeylet(AccountID const& account, std::uint32_t seq)
escrowKeylet(AccountID const& account, std::uint32_t seq) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<Bytes, HostFunctionError>
lineKeylet(AccountID const& account1, AccountID const& account2, Currency const& currency)
lineKeylet(AccountID const& account1, AccountID const& account2, Currency const& currency) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<Bytes, HostFunctionError>
mptIssuanceKeylet(AccountID const& issuer, std::uint32_t seq)
mptIssuanceKeylet(AccountID const& issuer, std::uint32_t seq) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<Bytes, HostFunctionError>
mptokenKeylet(MPTID const& mptid, AccountID const& holder)
mptokenKeylet(MPTID const& mptid, AccountID const& holder) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<Bytes, HostFunctionError>
nftOfferKeylet(AccountID const& account, std::uint32_t seq)
nftOfferKeylet(AccountID const& account, std::uint32_t seq) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<Bytes, HostFunctionError>
offerKeylet(AccountID const& account, std::uint32_t seq)
offerKeylet(AccountID const& account, std::uint32_t seq) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<Bytes, HostFunctionError>
oracleKeylet(AccountID const& account, std::uint32_t docId)
oracleKeylet(AccountID const& account, std::uint32_t docId) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<Bytes, HostFunctionError>
paychanKeylet(AccountID const& account, AccountID const& destination, std::uint32_t seq)
paychanKeylet(AccountID const& account, AccountID const& destination, std::uint32_t seq) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<Bytes, HostFunctionError>
permissionedDomainKeylet(AccountID const& account, std::uint32_t seq)
permissionedDomainKeylet(AccountID const& account, std::uint32_t seq) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<Bytes, HostFunctionError>
signersKeylet(AccountID const& account)
signersKeylet(AccountID const& account) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<Bytes, HostFunctionError>
ticketKeylet(AccountID const& account, std::uint32_t seq)
ticketKeylet(AccountID const& account, std::uint32_t seq) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<Bytes, HostFunctionError>
vaultKeylet(AccountID const& account, std::uint32_t seq)
vaultKeylet(AccountID const& account, std::uint32_t seq) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<Bytes, HostFunctionError>
getNFT(AccountID const& account, uint256 const& nftId)
getNFT(AccountID const& account, uint256 const& nftId) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<Bytes, HostFunctionError>
getNFTIssuer(uint256 const& nftId)
getNFTIssuer(uint256 const& nftId) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<std::uint32_t, HostFunctionError>
getNFTTaxon(uint256 const& nftId)
getNFTTaxon(uint256 const& nftId) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<int32_t, HostFunctionError>
getNFTFlags(uint256 const& nftId)
getNFTFlags(uint256 const& nftId) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<int32_t, HostFunctionError>
getNFTTransferFee(uint256 const& nftId)
getNFTTransferFee(uint256 const& nftId) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<std::uint32_t, HostFunctionError>
getNFTSerial(uint256 const& nftId)
getNFTSerial(uint256 const& nftId) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<int32_t, HostFunctionError>
trace(std::string_view const& msg, Slice const& data, bool asHex)
trace(std::string_view const& msg, Slice const& data, bool asHex) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<int32_t, HostFunctionError>
traceNum(std::string_view const& msg, int64_t data)
traceNum(std::string_view const& msg, int64_t data) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<int32_t, HostFunctionError>
traceAccount(std::string_view const& msg, AccountID const& account)
traceAccount(std::string_view const& msg, AccountID const& account) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<int32_t, HostFunctionError>
traceFloat(std::string_view const& msg, Slice const& data)
traceFloat(std::string_view const& msg, Slice const& data) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<int32_t, HostFunctionError>
traceAmount(std::string_view const& msg, STAmount const& amount)
traceAmount(std::string_view const& msg, STAmount const& amount) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<Bytes, HostFunctionError>
floatFromInt(int64_t x, int32_t mode)
floatFromInt(int64_t x, int32_t mode) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<Bytes, HostFunctionError>
floatFromUint(uint64_t x, int32_t mode)
floatFromUint(uint64_t x, int32_t mode) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<Bytes, HostFunctionError>
floatSet(int64_t mantissa, int32_t exponent, int32_t mode)
floatSet(int64_t mantissa, int32_t exponent, int32_t mode) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<int32_t, HostFunctionError>
floatCompare(Slice const& x, Slice const& y)
floatCompare(Slice const& x, Slice const& y) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<Bytes, HostFunctionError>
floatAdd(Slice const& x, Slice const& y, int32_t mode)
floatAdd(Slice const& x, Slice const& y, int32_t mode) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<Bytes, HostFunctionError>
floatSubtract(Slice const& x, Slice const& y, int32_t mode)
floatSubtract(Slice const& x, Slice const& y, int32_t mode) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<Bytes, HostFunctionError>
floatMultiply(Slice const& x, Slice const& y, int32_t mode)
floatMultiply(Slice const& x, Slice const& y, int32_t mode) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<Bytes, HostFunctionError>
floatDivide(Slice const& x, Slice const& y, int32_t mode)
floatDivide(Slice const& x, Slice const& y, int32_t mode) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<Bytes, HostFunctionError>
floatRoot(Slice const& x, int32_t n, int32_t mode)
floatRoot(Slice const& x, int32_t n, int32_t mode) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<Bytes, HostFunctionError>
floatPower(Slice const& x, int32_t n, int32_t mode)
floatPower(Slice const& x, int32_t n, int32_t mode) const
{
return Unexpected(HostFunctionError::INTERNAL);
}
virtual Expected<Bytes, HostFunctionError>
floatLog(Slice const& x, int32_t mode)
floatLog(Slice const& x, int32_t mode) const
{
return Unexpected(HostFunctionError::INTERNAL);
}

View File

@@ -6,44 +6,42 @@
namespace xrpl {
class WasmHostFunctionsImpl : public HostFunctions
{
ApplyContext& ctx;
Keylet leKey;
std::shared_ptr<SLE const> currentLedgerObj = nullptr;
bool isLedgerObjCached = false;
ApplyContext& ctx_;
Keylet leKey_;
mutable std::optional<std::shared_ptr<SLE const>> currentLedgerObj_;
static int constexpr MAX_CACHE = 256;
std::array<std::shared_ptr<SLE const>, MAX_CACHE> cache;
std::array<std::shared_ptr<SLE const>, MAX_CACHE> cache_;
std::optional<Bytes> data_;
void const* rt_ = nullptr;
Expected<std::shared_ptr<SLE const>, HostFunctionError>
getCurrentLedgerObj()
getCurrentLedgerObj() const
{
if (!isLedgerObjCached)
{
isLedgerObjCached = true;
currentLedgerObj = ctx.view().read(leKey);
}
if (currentLedgerObj)
return currentLedgerObj;
if (!currentLedgerObj_)
currentLedgerObj_ = ctx_.view().read(leKey_);
if (*currentLedgerObj_)
return *currentLedgerObj_;
return Unexpected(HostFunctionError::LEDGER_OBJ_NOT_FOUND);
}
Expected<int32_t, HostFunctionError>
normalizeCacheIndex(int32_t cacheIdx)
normalizeCacheIndex(int32_t cacheIdx) const
{
--cacheIdx;
if (cacheIdx < 0 || cacheIdx >= MAX_CACHE)
return Unexpected(HostFunctionError::SLOT_OUT_RANGE);
if (!cache[cacheIdx])
if (!cache_[cacheIdx])
return Unexpected(HostFunctionError::EMPTY_SLOT);
return cacheIdx;
}
template <typename F>
void
log(std::string_view const& msg, F&& dataFn)
log(std::string_view const& msg, F&& dataFn) const
{
#ifdef DEBUG_OUTPUT
auto& j = std::cerr;
@@ -52,7 +50,7 @@ class WasmHostFunctionsImpl : public HostFunctions
return;
auto j = getJournal().trace();
#endif
j << "WasmTrace[" << to_short_string(leKey.key) << "]: " << msg << " " << dataFn();
j << "WasmTrace[" << to_short_string(leKey_.key) << "]: " << msg << " " << dataFn();
#ifdef DEBUG_OUTPUT
j << std::endl;
@@ -60,7 +58,7 @@ class WasmHostFunctionsImpl : public HostFunctions
}
public:
WasmHostFunctionsImpl(ApplyContext& ct, Keylet const& leKey) : HostFunctions(ct.journal), ctx(ct), leKey(leKey)
WasmHostFunctionsImpl(ApplyContext& ct, Keylet const& leKey) : HostFunctions(ct.journal), ctx_(ct), leKey_(leKey)
{
}
@@ -76,6 +74,13 @@ public:
return rt_;
}
virtual bool
checkSelf() const override
{
return !currentLedgerObj_ && !data_ &&
std::ranges::find_if(cache_, [](auto& p) { return !!p; }) == cache_.end();
}
std::optional<Bytes> const&
getData() const
{
@@ -83,193 +88,193 @@ public:
}
Expected<std::uint32_t, HostFunctionError>
getLedgerSqn() override;
getLedgerSqn() const override;
Expected<std::uint32_t, HostFunctionError>
getParentLedgerTime() override;
getParentLedgerTime() const override;
Expected<Hash, HostFunctionError>
getParentLedgerHash() override;
getParentLedgerHash() const override;
Expected<std::uint32_t, HostFunctionError>
getBaseFee() override;
getBaseFee() const override;
Expected<int32_t, HostFunctionError>
isAmendmentEnabled(uint256 const& amendmentId) override;
isAmendmentEnabled(uint256 const& amendmentId) const override;
Expected<int32_t, HostFunctionError>
isAmendmentEnabled(std::string_view const& amendmentName) override;
isAmendmentEnabled(std::string_view const& amendmentName) const override;
Expected<int32_t, HostFunctionError>
cacheLedgerObj(uint256 const& objId, int32_t cacheIdx) override;
Expected<Bytes, HostFunctionError>
getTxField(SField const& fname) override;
getTxField(SField const& fname) const override;
Expected<Bytes, HostFunctionError>
getCurrentLedgerObjField(SField const& fname) override;
getCurrentLedgerObjField(SField const& fname) const override;
Expected<Bytes, HostFunctionError>
getLedgerObjField(int32_t cacheIdx, SField const& fname) override;
getLedgerObjField(int32_t cacheIdx, SField const& fname) const override;
Expected<Bytes, HostFunctionError>
getTxNestedField(Slice const& locator) override;
getTxNestedField(Slice const& locator) const override;
Expected<Bytes, HostFunctionError>
getCurrentLedgerObjNestedField(Slice const& locator) override;
getCurrentLedgerObjNestedField(Slice const& locator) const override;
Expected<Bytes, HostFunctionError>
getLedgerObjNestedField(int32_t cacheIdx, Slice const& locator) override;
getLedgerObjNestedField(int32_t cacheIdx, Slice const& locator) const override;
Expected<int32_t, HostFunctionError>
getTxArrayLen(SField const& fname) override;
getTxArrayLen(SField const& fname) const override;
Expected<int32_t, HostFunctionError>
getCurrentLedgerObjArrayLen(SField const& fname) override;
getCurrentLedgerObjArrayLen(SField const& fname) const override;
Expected<int32_t, HostFunctionError>
getLedgerObjArrayLen(int32_t cacheIdx, SField const& fname) override;
getLedgerObjArrayLen(int32_t cacheIdx, SField const& fname) const override;
Expected<int32_t, HostFunctionError>
getTxNestedArrayLen(Slice const& locator) override;
getTxNestedArrayLen(Slice const& locator) const override;
Expected<int32_t, HostFunctionError>
getCurrentLedgerObjNestedArrayLen(Slice const& locator) override;
getCurrentLedgerObjNestedArrayLen(Slice const& locator) const override;
Expected<int32_t, HostFunctionError>
getLedgerObjNestedArrayLen(int32_t cacheIdx, Slice const& locator) override;
getLedgerObjNestedArrayLen(int32_t cacheIdx, Slice const& locator) const override;
Expected<int32_t, HostFunctionError>
updateData(Slice const& data) override;
Expected<int32_t, HostFunctionError>
checkSignature(Slice const& message, Slice const& signature, Slice const& pubkey) override;
checkSignature(Slice const& message, Slice const& signature, Slice const& pubkey) const override;
Expected<Hash, HostFunctionError>
computeSha512HalfHash(Slice const& data) override;
computeSha512HalfHash(Slice const& data) const override;
Expected<Bytes, HostFunctionError>
accountKeylet(AccountID const& account) override;
accountKeylet(AccountID const& account) const override;
Expected<Bytes, HostFunctionError>
ammKeylet(Asset const& issue1, Asset const& issue2) override;
ammKeylet(Asset const& issue1, Asset const& issue2) const override;
Expected<Bytes, HostFunctionError>
checkKeylet(AccountID const& account, std::uint32_t seq) override;
checkKeylet(AccountID const& account, std::uint32_t seq) const override;
Expected<Bytes, HostFunctionError>
credentialKeylet(AccountID const& subject, AccountID const& issuer, Slice const& credentialType) override;
credentialKeylet(AccountID const& subject, AccountID const& issuer, Slice const& credentialType) const override;
Expected<Bytes, HostFunctionError>
didKeylet(AccountID const& account) override;
didKeylet(AccountID const& account) const override;
Expected<Bytes, HostFunctionError>
delegateKeylet(AccountID const& account, AccountID const& authorize) override;
delegateKeylet(AccountID const& account, AccountID const& authorize) const override;
Expected<Bytes, HostFunctionError>
depositPreauthKeylet(AccountID const& account, AccountID const& authorize) override;
depositPreauthKeylet(AccountID const& account, AccountID const& authorize) const override;
Expected<Bytes, HostFunctionError>
escrowKeylet(AccountID const& account, std::uint32_t seq) override;
escrowKeylet(AccountID const& account, std::uint32_t seq) const override;
Expected<Bytes, HostFunctionError>
lineKeylet(AccountID const& account1, AccountID const& account2, Currency const& currency) override;
lineKeylet(AccountID const& account1, AccountID const& account2, Currency const& currency) const override;
Expected<Bytes, HostFunctionError>
mptIssuanceKeylet(AccountID const& issuer, std::uint32_t seq) override;
mptIssuanceKeylet(AccountID const& issuer, std::uint32_t seq) const override;
Expected<Bytes, HostFunctionError>
mptokenKeylet(MPTID const& mptid, AccountID const& holder) override;
mptokenKeylet(MPTID const& mptid, AccountID const& holder) const override;
Expected<Bytes, HostFunctionError>
nftOfferKeylet(AccountID const& account, std::uint32_t seq) override;
nftOfferKeylet(AccountID const& account, std::uint32_t seq) const override;
Expected<Bytes, HostFunctionError>
offerKeylet(AccountID const& account, std::uint32_t seq) override;
offerKeylet(AccountID const& account, std::uint32_t seq) const override;
Expected<Bytes, HostFunctionError>
oracleKeylet(AccountID const& account, std::uint32_t docId) override;
oracleKeylet(AccountID const& account, std::uint32_t docId) const override;
Expected<Bytes, HostFunctionError>
paychanKeylet(AccountID const& account, AccountID const& destination, std::uint32_t seq) override;
paychanKeylet(AccountID const& account, AccountID const& destination, std::uint32_t seq) const override;
Expected<Bytes, HostFunctionError>
permissionedDomainKeylet(AccountID const& account, std::uint32_t seq) override;
permissionedDomainKeylet(AccountID const& account, std::uint32_t seq) const override;
Expected<Bytes, HostFunctionError>
signersKeylet(AccountID const& account) override;
signersKeylet(AccountID const& account) const override;
Expected<Bytes, HostFunctionError>
ticketKeylet(AccountID const& account, std::uint32_t seq) override;
ticketKeylet(AccountID const& account, std::uint32_t seq) const override;
Expected<Bytes, HostFunctionError>
vaultKeylet(AccountID const& account, std::uint32_t seq) override;
vaultKeylet(AccountID const& account, std::uint32_t seq) const override;
Expected<Bytes, HostFunctionError>
getNFT(AccountID const& account, uint256 const& nftId) override;
getNFT(AccountID const& account, uint256 const& nftId) const override;
Expected<Bytes, HostFunctionError>
getNFTIssuer(uint256 const& nftId) override;
getNFTIssuer(uint256 const& nftId) const override;
Expected<std::uint32_t, HostFunctionError>
getNFTTaxon(uint256 const& nftId) override;
getNFTTaxon(uint256 const& nftId) const override;
Expected<int32_t, HostFunctionError>
getNFTFlags(uint256 const& nftId) override;
getNFTFlags(uint256 const& nftId) const override;
Expected<int32_t, HostFunctionError>
getNFTTransferFee(uint256 const& nftId) override;
getNFTTransferFee(uint256 const& nftId) const override;
Expected<std::uint32_t, HostFunctionError>
getNFTSerial(uint256 const& nftId) override;
getNFTSerial(uint256 const& nftId) const override;
Expected<int32_t, HostFunctionError>
trace(std::string_view const& msg, Slice const& data, bool asHex) override;
trace(std::string_view const& msg, Slice const& data, bool asHex) const override;
Expected<int32_t, HostFunctionError>
traceNum(std::string_view const& msg, int64_t data) override;
traceNum(std::string_view const& msg, int64_t data) const override;
Expected<int32_t, HostFunctionError>
traceAccount(std::string_view const& msg, AccountID const& account) override;
traceAccount(std::string_view const& msg, AccountID const& account) const override;
Expected<int32_t, HostFunctionError>
traceFloat(std::string_view const& msg, Slice const& data) override;
traceFloat(std::string_view const& msg, Slice const& data) const override;
Expected<int32_t, HostFunctionError>
traceAmount(std::string_view const& msg, STAmount const& amount) override;
traceAmount(std::string_view const& msg, STAmount const& amount) const override;
Expected<Bytes, HostFunctionError>
floatFromInt(int64_t x, int32_t mode) override;
floatFromInt(int64_t x, int32_t mode) const override;
Expected<Bytes, HostFunctionError>
floatFromUint(uint64_t x, int32_t mode) override;
floatFromUint(uint64_t x, int32_t mode) const override;
Expected<Bytes, HostFunctionError>
floatSet(int64_t mantissa, int32_t exponent, int32_t mode) override;
floatSet(int64_t mantissa, int32_t exponent, int32_t mode) const override;
Expected<int32_t, HostFunctionError>
floatCompare(Slice const& x, Slice const& y) override;
floatCompare(Slice const& x, Slice const& y) const override;
Expected<Bytes, HostFunctionError>
floatAdd(Slice const& x, Slice const& y, int32_t mode) override;
floatAdd(Slice const& x, Slice const& y, int32_t mode) const override;
Expected<Bytes, HostFunctionError>
floatSubtract(Slice const& x, Slice const& y, int32_t mode) override;
floatSubtract(Slice const& x, Slice const& y, int32_t mode) const override;
Expected<Bytes, HostFunctionError>
floatMultiply(Slice const& x, Slice const& y, int32_t mode) override;
floatMultiply(Slice const& x, Slice const& y, int32_t mode) const override;
Expected<Bytes, HostFunctionError>
floatDivide(Slice const& x, Slice const& y, int32_t mode) override;
floatDivide(Slice const& x, Slice const& y, int32_t mode) const override;
Expected<Bytes, HostFunctionError>
floatRoot(Slice const& x, int32_t n, int32_t mode) override;
floatRoot(Slice const& x, int32_t n, int32_t mode) const override;
Expected<Bytes, HostFunctionError>
floatPower(Slice const& x, int32_t n, int32_t mode) override;
floatPower(Slice const& x, int32_t n, int32_t mode) const override;
Expected<Bytes, HostFunctionError>
floatLog(Slice const& x, int32_t mode) override;
floatLog(Slice const& x, int32_t mode) const override;
};
namespace wasm_float {

View File

@@ -11,6 +11,8 @@
#include <string>
#include <vector>
// #define WASM_PERF_TESTS 1
namespace bft = boost::function_types;
namespace xrpl {
@@ -173,6 +175,8 @@ wasmParamsHlp(std::vector<WasmParam>& v, std::int64_t p, Types&&... args)
// wasmParamsHlp(v, std::forward<Types>(args)...);
// }
#ifdef WASM_PERF_TESTS
template <class... Types>
inline void
wasmParamsHlp(std::vector<WasmParam>& v, std::uint8_t const* dt, std::int32_t sz, Types&&... args)
@@ -219,6 +223,8 @@ wasmParamsHlp(std::vector<WasmParam>& v, std::string const& p, Types&&... args)
std::forward<Types>(args)...);
}
#endif
inline void
wasmParamsHlp(std::vector<WasmParam>& v)
{

View File

@@ -24,7 +24,7 @@ class WasmiEngine;
class WasmEngine
{
std::unique_ptr<WasmiEngine> const impl;
std::unique_ptr<WasmiEngine> const impl_;
WasmEngine();
@@ -43,20 +43,20 @@ public:
Expected<WasmResult<int32_t>, TER>
run(Bytes const& wasmCode,
HostFunctions& hfs,
std::string_view funcName = {},
std::vector<WasmParam> const& params = {},
std::shared_ptr<ImportVec> const& imports = {},
std::shared_ptr<HostFunctions> const& hfs = {},
ImportVec const& imports = {},
int64_t gasLimit = -1,
beast::Journal j = beast::Journal{beast::Journal::getNullSink()});
NotTEC
check(
Bytes const& wasmCode,
HostFunctions& hfs,
std::string_view funcName,
std::vector<WasmParam> const& params = {},
std::shared_ptr<ImportVec> const& imports = {},
std::shared_ptr<HostFunctions> const& hfs = {},
ImportVec const& imports = {},
beast::Journal j = beast::Journal{beast::Journal::getNullSink()});
// Host functions helper functionality
@@ -69,13 +69,13 @@ public:
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
std::shared_ptr<ImportVec>
ImportVec
createWasmImport(HostFunctions& hfs);
Expected<EscrowResult, TER>
runEscrowWasm(
Bytes const& wasmCode,
std::shared_ptr<HostFunctions> const& hfs,
HostFunctions& hfs,
std::string_view funcName = ESCROW_FUNCTION_NAME,
std::vector<WasmParam> const& params = {},
int64_t gasLimit = -1);
@@ -83,7 +83,7 @@ runEscrowWasm(
NotTEC
preflightEscrowWasm(
Bytes const& wasmCode,
std::shared_ptr<HostFunctions> const& hfs,
HostFunctions& hfs,
std::string_view funcName = ESCROW_FUNCTION_NAME,
std::vector<WasmParam> const& params = {});

View File

@@ -144,12 +144,7 @@ public:
ModuleWrapper(ModuleWrapper&& o);
ModuleWrapper&
operator=(ModuleWrapper&& o);
ModuleWrapper(
StorePtr& s,
Bytes const& wasmBin,
bool instantiate,
std::shared_ptr<ImportVec> const& imports,
beast::Journal j);
ModuleWrapper(StorePtr& s, Bytes const& wasmBin, bool instantiate, ImportVec const& imports, beast::Journal j);
~ModuleWrapper() = default;
operator bool() const;
@@ -174,7 +169,7 @@ public:
private:
WasmExternVec
buildImports(StorePtr& s, std::shared_ptr<ImportVec> const& imports);
buildImports(StorePtr& s, ImportVec const& imports);
};
class WasmiEngine
@@ -186,10 +181,6 @@ class WasmiEngine
std::mutex m_; // 1 instance mutex
// to ensure lifetime during next executions with the same module
std::shared_ptr<ImportVec> imports_;
std::shared_ptr<HostFunctions> hfs_;
public:
WasmiEngine();
~WasmiEngine() = default;
@@ -199,24 +190,24 @@ public:
Expected<WasmResult<int32_t>, TER>
run(Bytes const& wasmCode,
HostFunctions& hfs,
std::string_view funcName,
std::vector<WasmParam> const& params,
std::shared_ptr<ImportVec> const& imports,
std::shared_ptr<HostFunctions> const& hfs,
ImportVec const& imports,
int64_t gas,
beast::Journal j);
NotTEC
check(
Bytes const& wasmCode,
HostFunctions& hfs,
std::string_view funcName,
std::vector<WasmParam> const& params,
std::shared_ptr<ImportVec> const& imports,
std::shared_ptr<HostFunctions> const& hfs,
ImportVec const& imports,
beast::Journal j);
std::int64_t
getGas();
getGas() const;
// Host functions helper functionality
wasm_trap_t*
@@ -227,7 +218,7 @@ public:
private:
InstanceWrapper const&
getRT(int m = 0, int i = 0);
getRT(int m = 0, int i = 0) const;
wmem
getMem() const;
@@ -236,13 +227,24 @@ private:
allocate(int32_t size);
Expected<WasmResult<int32_t>, TER>
runHlp(Bytes const& wasmCode, std::string_view funcName, std::vector<WasmParam> const& params, int64_t gas);
runHlp(
Bytes const& wasmCode,
HostFunctions& hfs,
std::string_view funcName,
std::vector<WasmParam> const& params,
ImportVec const& imports,
int64_t gas);
NotTEC
checkHlp(Bytes const& wasmCode, std::string_view funcName, std::vector<WasmParam> const& params);
checkHlp(
Bytes const& wasmCode,
HostFunctions& hfs,
std::string_view funcName,
std::vector<WasmParam> const& params,
ImportVec const& imports);
int
addModule(Bytes const& wasmCode, bool instantiate, int64_t gas);
addModule(Bytes const& wasmCode, bool instantiate, ImportVec const& imports, int64_t gas);
void
clearModules();
@@ -255,7 +257,7 @@ private:
makeModule(Bytes const& wasmCode, WasmExternVec const& imports = {});
FuncInfo
getFunc(std::string_view funcName);
getFunc(std::string_view funcName) const;
std::vector<wasm_val_t>
convertParams(std::vector<WasmParam> const& params);

View File

@@ -25,7 +25,7 @@ WasmHostFunctionsImpl::updateData(Slice const& data)
// =========================================================
Expected<int32_t, HostFunctionError>
WasmHostFunctionsImpl::checkSignature(Slice const& message, Slice const& signature, Slice const& pubkey)
WasmHostFunctionsImpl::checkSignature(Slice const& message, Slice const& signature, Slice const& pubkey) const
{
if (!publicKeyType(pubkey))
return Unexpected(HostFunctionError::INVALID_PARAMS);
@@ -35,7 +35,7 @@ WasmHostFunctionsImpl::checkSignature(Slice const& message, Slice const& signatu
}
Expected<Hash, HostFunctionError>
WasmHostFunctionsImpl::computeSha512HalfHash(Slice const& data)
WasmHostFunctionsImpl::computeSha512HalfHash(Slice const& data) const
{
auto const hash = sha512Half(data);
return hash;

View File

@@ -480,67 +480,67 @@ floatLogImpl(Slice const& x, int32_t mode)
// =========================================================
Expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::floatFromInt(int64_t x, int32_t mode)
WasmHostFunctionsImpl::floatFromInt(int64_t x, int32_t mode) const
{
return wasm_float::floatFromIntImpl(x, mode);
}
Expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::floatFromUint(uint64_t x, int32_t mode)
WasmHostFunctionsImpl::floatFromUint(uint64_t x, int32_t mode) const
{
return wasm_float::floatFromUintImpl(x, mode);
}
Expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::floatSet(int64_t mantissa, int32_t exponent, int32_t mode)
WasmHostFunctionsImpl::floatSet(int64_t mantissa, int32_t exponent, int32_t mode) const
{
return wasm_float::floatSetImpl(mantissa, exponent, mode);
}
Expected<int32_t, HostFunctionError>
WasmHostFunctionsImpl::floatCompare(Slice const& x, Slice const& y)
WasmHostFunctionsImpl::floatCompare(Slice const& x, Slice const& y) const
{
return wasm_float::floatCompareImpl(x, y);
}
Expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::floatAdd(Slice const& x, Slice const& y, int32_t mode)
WasmHostFunctionsImpl::floatAdd(Slice const& x, Slice const& y, int32_t mode) const
{
return wasm_float::floatAddImpl(x, y, mode);
}
Expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::floatSubtract(Slice const& x, Slice const& y, int32_t mode)
WasmHostFunctionsImpl::floatSubtract(Slice const& x, Slice const& y, int32_t mode) const
{
return wasm_float::floatSubtractImpl(x, y, mode);
}
Expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::floatMultiply(Slice const& x, Slice const& y, int32_t mode)
WasmHostFunctionsImpl::floatMultiply(Slice const& x, Slice const& y, int32_t mode) const
{
return wasm_float::floatMultiplyImpl(x, y, mode);
}
Expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::floatDivide(Slice const& x, Slice const& y, int32_t mode)
WasmHostFunctionsImpl::floatDivide(Slice const& x, Slice const& y, int32_t mode) const
{
return wasm_float::floatDivideImpl(x, y, mode);
}
Expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::floatRoot(Slice const& x, int32_t n, int32_t mode)
WasmHostFunctionsImpl::floatRoot(Slice const& x, int32_t n, int32_t mode) const
{
return wasm_float::floatRootImpl(x, n, mode);
}
Expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::floatPower(Slice const& x, int32_t n, int32_t mode)
WasmHostFunctionsImpl::floatPower(Slice const& x, int32_t n, int32_t mode) const
{
return wasm_float::floatPowerImpl(x, n, mode);
}
Expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::floatLog(Slice const& x, int32_t mode)
WasmHostFunctionsImpl::floatLog(Slice const& x, int32_t mode) const
{
return wasm_float::floatLogImpl(x, mode);
}

View File

@@ -231,7 +231,7 @@ WasmHostFunctionsImpl::cacheLedgerObj(uint256 const& objId, int32_t cacheIdx)
if (cacheIdx == 0)
{
for (cacheIdx = 0; cacheIdx < MAX_CACHE; ++cacheIdx)
if (!cache[cacheIdx])
if (!cache_[cacheIdx])
break;
}
else
@@ -242,8 +242,8 @@ WasmHostFunctionsImpl::cacheLedgerObj(uint256 const& objId, int32_t cacheIdx)
if (cacheIdx >= MAX_CACHE)
return Unexpected(HostFunctionError::SLOTS_FULL);
cache[cacheIdx] = ctx.view().read(keylet);
if (!cache[cacheIdx])
cache_[cacheIdx] = ctx_.view().read(keylet);
if (!cache_[cacheIdx])
return Unexpected(HostFunctionError::LEDGER_OBJ_NOT_FOUND);
return cacheIdx + 1; // return 1-based index
}
@@ -251,13 +251,13 @@ WasmHostFunctionsImpl::cacheLedgerObj(uint256 const& objId, int32_t cacheIdx)
// Subsection: top level getters
Expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::getTxField(SField const& fname)
WasmHostFunctionsImpl::getTxField(SField const& fname) const
{
return detail::getAnyFieldData(ctx.tx.peekAtPField(fname));
return detail::getAnyFieldData(ctx_.tx.peekAtPField(fname));
}
Expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::getCurrentLedgerObjField(SField const& fname)
WasmHostFunctionsImpl::getCurrentLedgerObjField(SField const& fname) const
{
auto const sle = getCurrentLedgerObj();
if (!sle.has_value())
@@ -266,20 +266,20 @@ WasmHostFunctionsImpl::getCurrentLedgerObjField(SField const& fname)
}
Expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::getLedgerObjField(int32_t cacheIdx, SField const& fname)
WasmHostFunctionsImpl::getLedgerObjField(int32_t cacheIdx, SField const& fname) const
{
auto const normalizedIdx = normalizeCacheIndex(cacheIdx);
if (!normalizedIdx.has_value())
return Unexpected(normalizedIdx.error());
return detail::getAnyFieldData(cache[normalizedIdx.value()]->peekAtPField(fname));
return detail::getAnyFieldData(cache_[normalizedIdx.value()]->peekAtPField(fname));
}
// Subsection: nested getters
Expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::getTxNestedField(Slice const& locator)
WasmHostFunctionsImpl::getTxNestedField(Slice const& locator) const
{
auto const r = detail::locateField(ctx.tx, locator);
auto const r = detail::locateField(ctx_.tx, locator);
if (!r)
return Unexpected(r.error());
@@ -287,7 +287,7 @@ WasmHostFunctionsImpl::getTxNestedField(Slice const& locator)
}
Expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::getCurrentLedgerObjNestedField(Slice const& locator)
WasmHostFunctionsImpl::getCurrentLedgerObjNestedField(Slice const& locator) const
{
auto const sle = getCurrentLedgerObj();
if (!sle.has_value())
@@ -301,13 +301,13 @@ WasmHostFunctionsImpl::getCurrentLedgerObjNestedField(Slice const& locator)
}
Expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::getLedgerObjNestedField(int32_t cacheIdx, Slice const& locator)
WasmHostFunctionsImpl::getLedgerObjNestedField(int32_t cacheIdx, Slice const& locator) const
{
auto const normalizedIdx = normalizeCacheIndex(cacheIdx);
if (!normalizedIdx.has_value())
return Unexpected(normalizedIdx.error());
auto const r = detail::locateField(*cache[normalizedIdx.value()], locator);
auto const r = detail::locateField(*cache_[normalizedIdx.value()], locator);
if (!r)
return Unexpected(r.error());
@@ -317,12 +317,12 @@ WasmHostFunctionsImpl::getLedgerObjNestedField(int32_t cacheIdx, Slice const& lo
// Subsection: array length getters
Expected<int32_t, HostFunctionError>
WasmHostFunctionsImpl::getTxArrayLen(SField const& fname)
WasmHostFunctionsImpl::getTxArrayLen(SField const& fname) const
{
if (fname.fieldType != STI_ARRAY && fname.fieldType != STI_VECTOR256)
return Unexpected(HostFunctionError::NO_ARRAY);
auto const* field = ctx.tx.peekAtPField(fname);
auto const* field = ctx_.tx.peekAtPField(fname);
if (detail::noField(field))
return Unexpected(HostFunctionError::FIELD_NOT_FOUND);
@@ -330,7 +330,7 @@ WasmHostFunctionsImpl::getTxArrayLen(SField const& fname)
}
Expected<int32_t, HostFunctionError>
WasmHostFunctionsImpl::getCurrentLedgerObjArrayLen(SField const& fname)
WasmHostFunctionsImpl::getCurrentLedgerObjArrayLen(SField const& fname) const
{
if (fname.fieldType != STI_ARRAY && fname.fieldType != STI_VECTOR256)
return Unexpected(HostFunctionError::NO_ARRAY);
@@ -347,7 +347,7 @@ WasmHostFunctionsImpl::getCurrentLedgerObjArrayLen(SField const& fname)
}
Expected<int32_t, HostFunctionError>
WasmHostFunctionsImpl::getLedgerObjArrayLen(int32_t cacheIdx, SField const& fname)
WasmHostFunctionsImpl::getLedgerObjArrayLen(int32_t cacheIdx, SField const& fname) const
{
if (fname.fieldType != STI_ARRAY && fname.fieldType != STI_VECTOR256)
return Unexpected(HostFunctionError::NO_ARRAY);
@@ -356,7 +356,7 @@ WasmHostFunctionsImpl::getLedgerObjArrayLen(int32_t cacheIdx, SField const& fnam
if (!normalizedIdx.has_value())
return Unexpected(normalizedIdx.error());
auto const* field = cache[normalizedIdx.value()]->peekAtPField(fname);
auto const* field = cache_[normalizedIdx.value()]->peekAtPField(fname);
if (detail::noField(field))
return Unexpected(HostFunctionError::FIELD_NOT_FOUND);
@@ -366,9 +366,9 @@ WasmHostFunctionsImpl::getLedgerObjArrayLen(int32_t cacheIdx, SField const& fnam
// Subsection: nested array length getters
Expected<int32_t, HostFunctionError>
WasmHostFunctionsImpl::getTxNestedArrayLen(Slice const& locator)
WasmHostFunctionsImpl::getTxNestedArrayLen(Slice const& locator) const
{
auto const r = detail::locateField(ctx.tx, locator);
auto const r = detail::locateField(ctx_.tx, locator);
if (!r)
return Unexpected(r.error());
@@ -377,7 +377,7 @@ WasmHostFunctionsImpl::getTxNestedArrayLen(Slice const& locator)
}
Expected<int32_t, HostFunctionError>
WasmHostFunctionsImpl::getCurrentLedgerObjNestedArrayLen(Slice const& locator)
WasmHostFunctionsImpl::getCurrentLedgerObjNestedArrayLen(Slice const& locator) const
{
auto const sle = getCurrentLedgerObj();
if (!sle.has_value())
@@ -391,13 +391,13 @@ WasmHostFunctionsImpl::getCurrentLedgerObjNestedArrayLen(Slice const& locator)
}
Expected<int32_t, HostFunctionError>
WasmHostFunctionsImpl::getLedgerObjNestedArrayLen(int32_t cacheIdx, Slice const& locator)
WasmHostFunctionsImpl::getLedgerObjNestedArrayLen(int32_t cacheIdx, Slice const& locator) const
{
auto const normalizedIdx = normalizeCacheIndex(cacheIdx);
if (!normalizedIdx.has_value())
return Unexpected(normalizedIdx.error());
auto const r = detail::locateField(*cache[normalizedIdx.value()], locator);
auto const r = detail::locateField(*cache_[normalizedIdx.value()], locator);
if (!r)
return Unexpected(r.error());

View File

@@ -6,7 +6,7 @@
namespace xrpl {
Expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::accountKeylet(AccountID const& account)
WasmHostFunctionsImpl::accountKeylet(AccountID const& account) const
{
if (!account)
return Unexpected(HostFunctionError::INVALID_ACCOUNT);
@@ -15,7 +15,7 @@ WasmHostFunctionsImpl::accountKeylet(AccountID const& account)
}
Expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::ammKeylet(Asset const& issue1, Asset const& issue2)
WasmHostFunctionsImpl::ammKeylet(Asset const& issue1, Asset const& issue2) const
{
if (issue1 == issue2)
return Unexpected(HostFunctionError::INVALID_PARAMS);
@@ -29,7 +29,7 @@ WasmHostFunctionsImpl::ammKeylet(Asset const& issue1, Asset const& issue2)
}
Expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::checkKeylet(AccountID const& account, std::uint32_t seq)
WasmHostFunctionsImpl::checkKeylet(AccountID const& account, std::uint32_t seq) const
{
if (!account)
return Unexpected(HostFunctionError::INVALID_ACCOUNT);
@@ -39,6 +39,7 @@ WasmHostFunctionsImpl::checkKeylet(AccountID const& account, std::uint32_t seq)
Expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::credentialKeylet(AccountID const& subject, AccountID const& issuer, Slice const& credentialType)
const
{
if (!subject || !issuer)
return Unexpected(HostFunctionError::INVALID_ACCOUNT);
@@ -52,7 +53,7 @@ WasmHostFunctionsImpl::credentialKeylet(AccountID const& subject, AccountID cons
}
Expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::didKeylet(AccountID const& account)
WasmHostFunctionsImpl::didKeylet(AccountID const& account) const
{
if (!account)
return Unexpected(HostFunctionError::INVALID_ACCOUNT);
@@ -61,7 +62,7 @@ WasmHostFunctionsImpl::didKeylet(AccountID const& account)
}
Expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::delegateKeylet(AccountID const& account, AccountID const& authorize)
WasmHostFunctionsImpl::delegateKeylet(AccountID const& account, AccountID const& authorize) const
{
if (!account || !authorize)
return Unexpected(HostFunctionError::INVALID_ACCOUNT);
@@ -72,7 +73,7 @@ WasmHostFunctionsImpl::delegateKeylet(AccountID const& account, AccountID const&
}
Expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::depositPreauthKeylet(AccountID const& account, AccountID const& authorize)
WasmHostFunctionsImpl::depositPreauthKeylet(AccountID const& account, AccountID const& authorize) const
{
if (!account || !authorize)
return Unexpected(HostFunctionError::INVALID_ACCOUNT);
@@ -83,7 +84,7 @@ WasmHostFunctionsImpl::depositPreauthKeylet(AccountID const& account, AccountID
}
Expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::escrowKeylet(AccountID const& account, std::uint32_t seq)
WasmHostFunctionsImpl::escrowKeylet(AccountID const& account, std::uint32_t seq) const
{
if (!account)
return Unexpected(HostFunctionError::INVALID_ACCOUNT);
@@ -92,7 +93,7 @@ WasmHostFunctionsImpl::escrowKeylet(AccountID const& account, std::uint32_t seq)
}
Expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::lineKeylet(AccountID const& account1, AccountID const& account2, Currency const& currency)
WasmHostFunctionsImpl::lineKeylet(AccountID const& account1, AccountID const& account2, Currency const& currency) const
{
if (!account1 || !account2)
return Unexpected(HostFunctionError::INVALID_ACCOUNT);
@@ -106,7 +107,7 @@ WasmHostFunctionsImpl::lineKeylet(AccountID const& account1, AccountID const& ac
}
Expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::mptIssuanceKeylet(AccountID const& issuer, std::uint32_t seq)
WasmHostFunctionsImpl::mptIssuanceKeylet(AccountID const& issuer, std::uint32_t seq) const
{
if (!issuer)
return Unexpected(HostFunctionError::INVALID_ACCOUNT);
@@ -116,7 +117,7 @@ WasmHostFunctionsImpl::mptIssuanceKeylet(AccountID const& issuer, std::uint32_t
}
Expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::mptokenKeylet(MPTID const& mptid, AccountID const& holder)
WasmHostFunctionsImpl::mptokenKeylet(MPTID const& mptid, AccountID const& holder) const
{
if (!mptid)
return Unexpected(HostFunctionError::INVALID_PARAMS);
@@ -128,7 +129,7 @@ WasmHostFunctionsImpl::mptokenKeylet(MPTID const& mptid, AccountID const& holder
}
Expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::nftOfferKeylet(AccountID const& account, std::uint32_t seq)
WasmHostFunctionsImpl::nftOfferKeylet(AccountID const& account, std::uint32_t seq) const
{
if (!account)
return Unexpected(HostFunctionError::INVALID_ACCOUNT);
@@ -137,7 +138,7 @@ WasmHostFunctionsImpl::nftOfferKeylet(AccountID const& account, std::uint32_t se
}
Expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::offerKeylet(AccountID const& account, std::uint32_t seq)
WasmHostFunctionsImpl::offerKeylet(AccountID const& account, std::uint32_t seq) const
{
if (!account)
return Unexpected(HostFunctionError::INVALID_ACCOUNT);
@@ -146,7 +147,7 @@ WasmHostFunctionsImpl::offerKeylet(AccountID const& account, std::uint32_t seq)
}
Expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::oracleKeylet(AccountID const& account, std::uint32_t documentId)
WasmHostFunctionsImpl::oracleKeylet(AccountID const& account, std::uint32_t documentId) const
{
if (!account)
return Unexpected(HostFunctionError::INVALID_ACCOUNT);
@@ -155,7 +156,7 @@ WasmHostFunctionsImpl::oracleKeylet(AccountID const& account, std::uint32_t docu
}
Expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::paychanKeylet(AccountID const& account, AccountID const& destination, std::uint32_t seq)
WasmHostFunctionsImpl::paychanKeylet(AccountID const& account, AccountID const& destination, std::uint32_t seq) const
{
if (!account || !destination)
return Unexpected(HostFunctionError::INVALID_ACCOUNT);
@@ -166,7 +167,7 @@ WasmHostFunctionsImpl::paychanKeylet(AccountID const& account, AccountID const&
}
Expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::permissionedDomainKeylet(AccountID const& account, std::uint32_t seq)
WasmHostFunctionsImpl::permissionedDomainKeylet(AccountID const& account, std::uint32_t seq) const
{
if (!account)
return Unexpected(HostFunctionError::INVALID_ACCOUNT);
@@ -175,7 +176,7 @@ WasmHostFunctionsImpl::permissionedDomainKeylet(AccountID const& account, std::u
}
Expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::signersKeylet(AccountID const& account)
WasmHostFunctionsImpl::signersKeylet(AccountID const& account) const
{
if (!account)
return Unexpected(HostFunctionError::INVALID_ACCOUNT);
@@ -184,7 +185,7 @@ WasmHostFunctionsImpl::signersKeylet(AccountID const& account)
}
Expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::ticketKeylet(AccountID const& account, std::uint32_t seq)
WasmHostFunctionsImpl::ticketKeylet(AccountID const& account, std::uint32_t seq) const
{
if (!account)
return Unexpected(HostFunctionError::INVALID_ACCOUNT);
@@ -193,7 +194,7 @@ WasmHostFunctionsImpl::ticketKeylet(AccountID const& account, std::uint32_t seq)
}
Expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::vaultKeylet(AccountID const& account, std::uint32_t seq)
WasmHostFunctionsImpl::vaultKeylet(AccountID const& account, std::uint32_t seq) const
{
if (!account)
return Unexpected(HostFunctionError::INVALID_ACCOUNT);

View File

@@ -10,41 +10,41 @@ namespace xrpl {
// =========================================================
Expected<std::uint32_t, HostFunctionError>
WasmHostFunctionsImpl::getLedgerSqn()
WasmHostFunctionsImpl::getLedgerSqn() const
{
return ctx.view().seq();
return ctx_.view().seq();
}
Expected<std::uint32_t, HostFunctionError>
WasmHostFunctionsImpl::getParentLedgerTime()
WasmHostFunctionsImpl::getParentLedgerTime() const
{
return ctx.view().parentCloseTime().time_since_epoch().count();
return ctx_.view().parentCloseTime().time_since_epoch().count();
}
Expected<Hash, HostFunctionError>
WasmHostFunctionsImpl::getParentLedgerHash()
WasmHostFunctionsImpl::getParentLedgerHash() const
{
return ctx.view().header().parentHash;
return ctx_.view().header().parentHash;
}
Expected<std::uint32_t, HostFunctionError>
WasmHostFunctionsImpl::getBaseFee()
WasmHostFunctionsImpl::getBaseFee() const
{
return ctx.view().fees().base.drops();
return ctx_.view().fees().base.drops();
}
Expected<int32_t, HostFunctionError>
WasmHostFunctionsImpl::isAmendmentEnabled(uint256 const& amendmentId)
WasmHostFunctionsImpl::isAmendmentEnabled(uint256 const& amendmentId) const
{
return ctx.view().rules().enabled(amendmentId);
return ctx_.view().rules().enabled(amendmentId);
}
Expected<int32_t, HostFunctionError>
WasmHostFunctionsImpl::isAmendmentEnabled(std::string_view const& amendmentName)
WasmHostFunctionsImpl::isAmendmentEnabled(std::string_view const& amendmentName) const
{
auto const& table = ctx.app.getAmendmentTable();
auto const& table = ctx_.app.getAmendmentTable();
auto const amendment = table.find(std::string(amendmentName));
return ctx.view().rules().enabled(amendment);
return ctx_.view().rules().enabled(amendment);
}
} // namespace xrpl

View File

@@ -11,7 +11,7 @@ namespace xrpl {
// =========================================================
Expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::getNFT(AccountID const& account, uint256 const& nftId)
WasmHostFunctionsImpl::getNFT(AccountID const& account, uint256 const& nftId) const
{
if (!account)
return Unexpected(HostFunctionError::INVALID_ACCOUNT);
@@ -19,7 +19,7 @@ WasmHostFunctionsImpl::getNFT(AccountID const& account, uint256 const& nftId)
if (!nftId)
return Unexpected(HostFunctionError::INVALID_PARAMS);
auto obj = nft::findToken(ctx.view(), account, nftId);
auto obj = nft::findToken(ctx_.view(), account, nftId);
if (!obj)
return Unexpected(HostFunctionError::LEDGER_OBJ_NOT_FOUND);
@@ -32,7 +32,7 @@ WasmHostFunctionsImpl::getNFT(AccountID const& account, uint256 const& nftId)
}
Expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::getNFTIssuer(uint256 const& nftId)
WasmHostFunctionsImpl::getNFTIssuer(uint256 const& nftId) const
{
auto const issuer = nft::getIssuer(nftId);
if (!issuer)
@@ -42,25 +42,25 @@ WasmHostFunctionsImpl::getNFTIssuer(uint256 const& nftId)
}
Expected<std::uint32_t, HostFunctionError>
WasmHostFunctionsImpl::getNFTTaxon(uint256 const& nftId)
WasmHostFunctionsImpl::getNFTTaxon(uint256 const& nftId) const
{
return nft::toUInt32(nft::getTaxon(nftId));
}
Expected<int32_t, HostFunctionError>
WasmHostFunctionsImpl::getNFTFlags(uint256 const& nftId)
WasmHostFunctionsImpl::getNFTFlags(uint256 const& nftId) const
{
return nft::getFlags(nftId);
}
Expected<int32_t, HostFunctionError>
WasmHostFunctionsImpl::getNFTTransferFee(uint256 const& nftId)
WasmHostFunctionsImpl::getNFTTransferFee(uint256 const& nftId) const
{
return nft::getTransferFee(nftId);
}
Expected<std::uint32_t, HostFunctionError>
WasmHostFunctionsImpl::getNFTSerial(uint256 const& nftId)
WasmHostFunctionsImpl::getNFTSerial(uint256 const& nftId) const
{
return nft::getSerial(nftId);
}

View File

@@ -10,7 +10,7 @@
namespace xrpl {
Expected<int32_t, HostFunctionError>
WasmHostFunctionsImpl::trace(std::string_view const& msg, Slice const& data, bool asHex)
WasmHostFunctionsImpl::trace(std::string_view const& msg, Slice const& data, bool asHex) const
{
if (!asHex)
{
@@ -30,28 +30,28 @@ WasmHostFunctionsImpl::trace(std::string_view const& msg, Slice const& data, boo
}
Expected<int32_t, HostFunctionError>
WasmHostFunctionsImpl::traceNum(std::string_view const& msg, int64_t data)
WasmHostFunctionsImpl::traceNum(std::string_view const& msg, int64_t data) const
{
log(msg, [data] { return data; });
return 0;
}
Expected<int32_t, HostFunctionError>
WasmHostFunctionsImpl::traceAccount(std::string_view const& msg, AccountID const& account)
WasmHostFunctionsImpl::traceAccount(std::string_view const& msg, AccountID const& account) const
{
log(msg, [&account] { return toBase58(account); });
return 0;
}
Expected<int32_t, HostFunctionError>
WasmHostFunctionsImpl::traceFloat(std::string_view const& msg, Slice const& data)
WasmHostFunctionsImpl::traceFloat(std::string_view const& msg, Slice const& data) const
{
log(msg, [&data] { return wasm_float::floatToString(data); });
return 0;
}
Expected<int32_t, HostFunctionError>
WasmHostFunctionsImpl::traceAmount(std::string_view const& msg, STAmount const& amount)
WasmHostFunctionsImpl::traceAmount(std::string_view const& msg, STAmount const& amount) const
{
log(msg, [&amount] { return amount.getFullText(); });
return 0;

View File

@@ -89,21 +89,21 @@ setCommonHostFunctions(HostFunctions* hfs, ImportVec& i)
// clang-format on
}
std::shared_ptr<ImportVec>
ImportVec
createWasmImport(HostFunctions& hfs)
{
std::shared_ptr<ImportVec> i(std::make_shared<ImportVec>());
ImportVec import;
setCommonHostFunctions(&hfs, *i);
WASM_IMPORT_FUNC2(*i, updateData, "update_data", &hfs, 1000);
setCommonHostFunctions(&hfs, import);
WASM_IMPORT_FUNC2(import, updateData, "update_data", &hfs, 1000);
return i;
return import;
}
Expected<EscrowResult, TER>
runEscrowWasm(
Bytes const& wasmCode,
std::shared_ptr<HostFunctions> const& hfs,
HostFunctions& hfs,
std::string_view funcName,
std::vector<WasmParam> const& params,
int64_t gasLimit)
@@ -112,7 +112,7 @@ runEscrowWasm(
auto& vm = WasmEngine::instance();
// vm.initMaxPages(MAX_PAGES);
auto const ret = vm.run(wasmCode, funcName, params, createWasmImport(*hfs), hfs, gasLimit, hfs->getJournal());
auto const ret = vm.run(wasmCode, hfs, funcName, params, createWasmImport(hfs), gasLimit, hfs.getJournal());
// std::cout << "runEscrowWasm, mod size: " << wasmCode.size()
// << ", gasLimit: " << gasLimit << ", funcName: " << funcName;
@@ -134,7 +134,7 @@ runEscrowWasm(
NotTEC
preflightEscrowWasm(
Bytes const& wasmCode,
std::shared_ptr<HostFunctions> const& hfs,
HostFunctions& hfs,
std::string_view funcName,
std::vector<WasmParam> const& params)
{
@@ -142,14 +142,14 @@ preflightEscrowWasm(
auto& vm = WasmEngine::instance();
// vm.initMaxPages(MAX_PAGES);
auto const ret = vm.check(wasmCode, funcName, params, createWasmImport(*hfs), hfs, hfs->getJournal());
auto const ret = vm.check(wasmCode, hfs, funcName, params, createWasmImport(hfs), hfs.getJournal());
return ret;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
WasmEngine::WasmEngine() : impl(std::make_unique<WasmiEngine>())
WasmEngine::WasmEngine() : impl_(std::make_unique<WasmiEngine>())
{
}
@@ -163,39 +163,39 @@ WasmEngine::instance()
Expected<WasmResult<int32_t>, TER>
WasmEngine::run(
Bytes const& wasmCode,
HostFunctions& hfs,
std::string_view funcName,
std::vector<WasmParam> const& params,
std::shared_ptr<ImportVec> const& imports,
std::shared_ptr<HostFunctions> const& hfs,
ImportVec const& imports,
int64_t gasLimit,
beast::Journal j)
{
return impl->run(wasmCode, funcName, params, imports, hfs, gasLimit, j);
return impl_->run(wasmCode, hfs, funcName, params, imports, gasLimit, j);
}
NotTEC
WasmEngine::check(
Bytes const& wasmCode,
HostFunctions& hfs,
std::string_view funcName,
std::vector<WasmParam> const& params,
std::shared_ptr<ImportVec> const& imports,
std::shared_ptr<HostFunctions> const& hfs,
ImportVec const& imports,
beast::Journal j)
{
return impl->check(wasmCode, funcName, params, imports, hfs, j);
return impl_->check(wasmCode, hfs, funcName, params, imports, j);
}
void*
WasmEngine::newTrap(std::string const& msg)
{
return impl->newTrap(msg);
return impl_->newTrap(msg);
}
// LCOV_EXCL_START
beast::Journal
WasmEngine::getJournal() const
{
return impl->getJournal();
return impl_->getJournal();
}
// LCOV_EXCL_STOP

View File

@@ -232,7 +232,7 @@ ModuleWrapper::ModuleWrapper(
StorePtr& s,
Bytes const& wasmBin,
bool instantiate,
std::shared_ptr<ImportVec> const& imports,
ImportVec const& imports,
beast::Journal j)
: module_(init(s, wasmBin, j)), j_(j)
{
@@ -319,14 +319,14 @@ makeImpReturn(WasmImportFunc const& imp)
}
WasmExternVec
ModuleWrapper::buildImports(StorePtr& s, std::shared_ptr<ImportVec> const& imports)
ModuleWrapper::buildImports(StorePtr& s, ImportVec const& imports)
{
WasmImporttypeVec importTypes;
wasm_module_imports(module_.get(), &importTypes.vec_);
if (!importTypes.vec_.size)
return {};
if (!imports)
if (imports.empty())
throw std::runtime_error("Missing imports");
WasmExternVec wimports(importTypes.vec_.size);
@@ -350,7 +350,7 @@ ModuleWrapper::buildImports(StorePtr& s, std::shared_ptr<ImportVec> const& impor
// continue;
bool impSet = false;
for (auto const& obj : *imports)
for (auto const& obj : imports)
{
auto const& imp = obj.second;
if (imp.name != fieldName)
@@ -500,7 +500,7 @@ WasmiEngine::WasmiEngine() : engine_(init()), store_(nullptr, &wasm_store_delete
}
int
WasmiEngine::addModule(Bytes const& wasmCode, bool instantiate, int64_t gas)
WasmiEngine::addModule(Bytes const& wasmCode, bool instantiate, ImportVec const& imports, int64_t gas)
{
moduleWrap_.reset();
store_.reset(); // to free the memory before creating new store
@@ -518,7 +518,7 @@ WasmiEngine::addModule(Bytes const& wasmCode, bool instantiate, int64_t gas)
// LCOV_EXCL_STOP
}
moduleWrap_ = std::make_unique<ModuleWrapper>(store_, wasmCode, instantiate, imports_, j_);
moduleWrap_ = std::make_unique<ModuleWrapper>(store_, wasmCode, instantiate, imports, j_);
if (!moduleWrap_)
throw std::runtime_error("can't create module wrapper"); // LCOV_EXCL_LINE
@@ -533,7 +533,7 @@ WasmiEngine::addModule(Bytes const& wasmCode, bool instantiate, int64_t gas)
// }
FuncInfo
WasmiEngine::getFunc(std::string_view funcName)
WasmiEngine::getFunc(std::string_view funcName) const
{
return moduleWrap_->getFunc(funcName);
}
@@ -554,7 +554,10 @@ WasmiEngine::convertParams(std::vector<WasmParam> const& params)
case WT_I64:
v.push_back(WASM_I64_VAL(p.of.i64));
break;
// LCOV_EXCL_STOP
// LCOV_EXCL_STOP
#ifdef WASM_PERF_TESTS
case WT_U8V: {
auto mem = getMem();
if (!mem.s)
@@ -566,6 +569,9 @@ WasmiEngine::convertParams(std::vector<WasmParam> const& params)
v.push_back(WASM_I32_VAL(sz));
}
break;
#endif
// LCOV_EXCL_START
default:
throw std::runtime_error("unknown parameter type: " + std::to_string(p.type));
@@ -693,6 +699,9 @@ WasmiEngine::call(FuncInfo const& f, std::vector<wasm_val_t>& in, std::int64_t p
return call<NR>(f, in, std::forward<Types>(args)...);
}
#ifdef WASM_PERF_TESTS
// passing vector only for tests
template <int NR, class... Types>
WasmiResult
WasmiEngine::call(FuncInfo const& f, std::vector<wasm_val_t>& in, uint8_t const* d, int32_t sz, Types&&... args)
@@ -709,6 +718,8 @@ WasmiEngine::call(FuncInfo const& f, std::vector<wasm_val_t>& in, uint8_t const*
return call<NR>(f, in, std::forward<Types>(args)...);
}
#endif
template <int NR, class... Types>
WasmiResult
WasmiEngine::call(FuncInfo const& f, std::vector<wasm_val_t>& in, Bytes const& p, Types&&... args)
@@ -729,26 +740,19 @@ checkImports(ImportVec const& imports, HostFunctions* hfs)
Expected<WasmResult<int32_t>, TER>
WasmiEngine::run(
Bytes const& wasmCode,
HostFunctions& hfs,
std::string_view funcName,
std::vector<WasmParam> const& params,
std::shared_ptr<ImportVec> const& imports,
std::shared_ptr<HostFunctions> const& hfs,
ImportVec const& imports,
int64_t gas,
beast::Journal j)
{
j_ = j;
if (!wasmCode.empty())
{ // save values for reuse
imports_ = imports;
hfs_ = hfs;
}
try
{
if (imports_)
checkImports(*imports_, hfs.get());
return runHlp(wasmCode, funcName, params, gas);
checkImports(imports, &hfs);
return runHlp(wasmCode, hfs, funcName, params, imports, gas);
}
catch (std::exception const& e)
{
@@ -764,22 +768,35 @@ WasmiEngine::run(
}
Expected<WasmResult<int32_t>, TER>
WasmiEngine::runHlp(Bytes const& wasmCode, std::string_view funcName, std::vector<WasmParam> const& params, int64_t gas)
WasmiEngine::runHlp(
Bytes const& wasmCode,
HostFunctions& hfs,
std::string_view funcName,
std::vector<WasmParam> const& params,
ImportVec const& imports,
int64_t gas)
{
// currently only 1 module support, possible parallel UT run
std::lock_guard<decltype(m_)> lg(m_);
// Create and instantiate the module.
#ifndef WASM_PERF_TESTS
if (wasmCode.empty())
throw std::runtime_error("empty module");
if (!hfs.checkSelf())
throw std::runtime_error("hfs isn't clean");
#else
// re-using module only for perf tests
if (!wasmCode.empty())
#endif
{
[[maybe_unused]] int const m = addModule(wasmCode, true, gas);
// Create and instantiate the module.
[[maybe_unused]] int const m = addModule(wasmCode, true, imports, gas);
}
if (!moduleWrap_ || !moduleWrap_->instanceWrap_)
throw std::runtime_error("no instance"); // LCOV_EXCL_LINE
if (hfs_)
hfs_->setRT(&getRT());
hfs.setRT(&getRT());
// Call main
auto const f = getFunc(!funcName.empty() ? funcName : "_start");
@@ -820,25 +837,18 @@ WasmiEngine::runHlp(Bytes const& wasmCode, std::string_view funcName, std::vecto
NotTEC
WasmiEngine::check(
Bytes const& wasmCode,
HostFunctions& hfs,
std::string_view funcName,
std::vector<WasmParam> const& params,
std::shared_ptr<ImportVec> const& imports,
std::shared_ptr<HostFunctions> const& hfs,
ImportVec const& imports,
beast::Journal j)
{
j_ = j;
if (!wasmCode.empty())
{
imports_ = imports;
hfs_ = hfs;
}
try
{
if (imports_)
checkImports(*imports_, hfs_.get());
return checkHlp(wasmCode, funcName, params);
checkImports(imports, &hfs);
return checkHlp(wasmCode, hfs, funcName, params, imports);
}
catch (std::exception const& e)
{
@@ -855,7 +865,12 @@ WasmiEngine::check(
}
NotTEC
WasmiEngine::checkHlp(Bytes const& wasmCode, std::string_view funcName, std::vector<WasmParam> const& params)
WasmiEngine::checkHlp(
Bytes const& wasmCode,
HostFunctions& hfs,
std::string_view funcName,
std::vector<WasmParam> const& params,
ImportVec const& imports)
{
// currently only 1 module support, possible parallel UT run
std::lock_guard<decltype(m_)> lg(m_);
@@ -864,7 +879,7 @@ WasmiEngine::checkHlp(Bytes const& wasmCode, std::string_view funcName, std::vec
if (wasmCode.empty())
throw std::runtime_error("empty nodule");
int const m = addModule(wasmCode, false, -1);
int const m = addModule(wasmCode, false, imports, -1);
if ((m < 0) || !moduleWrap_)
throw std::runtime_error("no module"); // LCOV_EXCL_LINE
@@ -881,7 +896,7 @@ WasmiEngine::checkHlp(Bytes const& wasmCode, std::string_view funcName, std::vec
// LCOV_EXCL_START
std::int64_t
WasmiEngine::getGas()
WasmiEngine::getGas() const
{
return moduleWrap_ ? moduleWrap_->getGas() : -1;
}
@@ -894,7 +909,7 @@ WasmiEngine::getMem() const
}
InstanceWrapper const&
WasmiEngine::getRT(int m, int i)
WasmiEngine::getRT(int m, int i) const
{
if (!moduleWrap_)
throw std::runtime_error("no module");
@@ -904,6 +919,9 @@ WasmiEngine::getRT(int m, int i)
int32_t
WasmiEngine::allocate(int32_t sz)
{
#ifndef WASM_PERF_TESTS
throw std::runtime_error("allocate not implemented"); // LCOV_EXCL_LINE
#else
if (sz <= 0)
throw std::runtime_error("can't allocate memory, " + std::to_string(sz) + " bytes");
@@ -918,6 +936,7 @@ WasmiEngine::allocate(int32_t sz)
throw std::runtime_error("invalid memory allocation, " + std::to_string(sz) + " bytes");
return p;
#endif
}
wasm_trap_t*