Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add bool flag to validation for EVM context #2201

Merged
merged 3 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/masternodes/mn_checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,7 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor {
uint64_t time;
uint32_t txn;
uint64_t evmContext;
bool useEvmContext;

public:
CCustomTxApplyVisitor(const CTransaction &tx,
Expand All @@ -778,12 +779,14 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor {
const Consensus::Params &consensus,
uint64_t time,
uint32_t txn,
const uint64_t evmContext)
const uint64_t evmContext,
const bool useEvmContext)

: CCustomTxVisitor(tx, height, coins, mnview, consensus),
time(time),
txn(txn),
evmContext(evmContext) {}
evmContext(evmContext),
useEvmContext(useEvmContext) {}

Res operator()(const CCreateMasterNodeMessage &obj) const {
Require(CheckMasternodeCreationTx());
Expand Down Expand Up @@ -3927,7 +3930,7 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor {
return Res::Err("evm tx size too large");

CrossBoundaryResult result;
const auto prevalidateResults = evm_try_prevalidate_raw_tx(result, HexStr(obj.evmTx), true, evmContext);
const auto prevalidateResults = evm_try_prevalidate_raw_tx(result, HexStr(obj.evmTx), useEvmContext, evmContext);

// Completely remove this fork guard on mainnet upgrade to restore nonce check from EVM activation
if (height >= static_cast<uint32_t>(consensus.ChangiIntermediateHeight)) {
Expand Down Expand Up @@ -4174,10 +4177,16 @@ Res CustomTxVisit(CCustomCSView &mnview,
if (IsDisabledTx(height, tx, consensus)) {
return Res::ErrCode(CustomTxErrCodes::Fatal, "Disabled custom transaction");
}

auto context = evmContext;
if (context == 0) context = evm_get_context();
bool useEvmContext = true;
if (context == 0) {
useEvmContext = false;
context = evm_get_context();
}

try {
return std::visit(CCustomTxApplyVisitor(tx, height, coins, mnview, consensus, time, txn, context), txMessage);
return std::visit(CCustomTxApplyVisitor(tx, height, coins, mnview, consensus, time, txn, context, useEvmContext), txMessage);
} catch (const std::bad_variant_access &e) {
return Res::Err(e.what());
} catch (...) {
Expand Down
3 changes: 1 addition & 2 deletions src/masternodes/mn_rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,7 @@ void execTestTx(const CTransaction& tx, uint32_t height, CTransactionRef optAuth
if (optAuthTx)
AddCoins(coins, *optAuthTx, height);
CCustomCSView view(*pcustomcsview);
uint64_t gasUsed{};
res = CustomTxVisit(view, coins, tx, height, Params().GetConsensus(), txMessage, ::ChainActive().Tip()->nTime, gasUsed);
res = CustomTxVisit(view, coins, tx, height, Params().GetConsensus(), txMessage, ::ChainActive().Tip()->nTime);
}
if (!res) {
if (res.code == CustomTxErrCodes::NotEnoughBalance) {
Expand Down