Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
40 changes: 24 additions & 16 deletions src/compiler/evm_frontend/evm_imported.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -885,14 +885,28 @@ static uint64_t evmHandleCallInternal(zen::runtime::EVMInstance *Instance,
}

uint64_t CallGas = Gas;
bool HasEnoughBalance = true;
if (HasValueArgs && HasValue) {
const auto CallerBalance = Module->Host->get_balance(CurrentMsg->recipient);
const intx::uint256 CallerValue =
intx::be::load<intx::uint256>(CallerBalance);
HasEnoughBalance = CallerValue >= intx::uint256(Value);
}

if (HasValueArgs) {
std::optional<bool> AccountState;
uint64_t GasCost = HasValue ? zen::evm::CALL_VALUE_COST : 0;
if (HasValue && !HasEnoughBalance) {
GasCost -= zen::evm::CALL_GAS_STIPEND;
}
if (CallKind == EVMC_CALL) {
if (HasValue || Instance->getRevision() < EVMC_SPURIOUS_DRAGON) {
AccountState = Module->Host->account_exists(TargetAddr);
if (!AccountState.value()) {
GasCost += zen::evm::ACCOUNT_CREATION_COST;
if (HasValue && HasEnoughBalance) {
GasCost -= zen::evm::CALL_GAS_STIPEND;
}
}
}
}
Expand All @@ -909,23 +923,12 @@ static uint64_t evmHandleCallInternal(zen::runtime::EVMInstance *Instance,
Instance, zen::common::ErrorCode::GasLimitExceeded);
}

if (HasValueArgs) {
bool HasEnoughBalance = true;
if (HasValue) {
Instance->addGas(zen::evm::CALL_GAS_STIPEND);
CallGas += zen::evm::CALL_GAS_STIPEND;

const auto CallerBalance =
Module->Host->get_balance(CurrentMsg->recipient);
const intx::uint256 CallerValue =
intx::be::load<intx::uint256>(CallerBalance);
HasEnoughBalance = CallerValue >= intx::uint256(Value);

if (!HasEnoughBalance) {
Instance->setReturnData({});
return 0;
}
if (HasValueArgs && HasValue) {
if (!HasEnoughBalance) {
Instance->setReturnData({});
return 0;
}
CallGas += zen::evm::CALL_GAS_STIPEND;
}

uint8_t *MemoryBase = Instance->getMemoryBase();
Expand Down Expand Up @@ -969,6 +972,11 @@ static uint64_t evmHandleCallInternal(zen::runtime::EVMInstance *Instance,
GasLeft = 0;
}
uint64_t GasUsed = CallGas > GasLeft ? CallGas - GasLeft : 0;
if (HasValue) {
GasUsed = GasUsed > zen::evm::CALL_GAS_STIPEND
? GasUsed - zen::evm::CALL_GAS_STIPEND
: 0;
}
if (GasUsed > 0) {
Instance->chargeGas(GasUsed);
}
Expand Down
2 changes: 1 addition & 1 deletion src/tests/evm_state_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace {
constexpr bool DEBUG = true;
constexpr bool PRINT_FAILURE_DETAILS = true;
// TODO: RunMode selection logic will be refactored in the future.
constexpr auto STATE_TEST_RUN_MODE = common::RunMode::MultipassMode;
constexpr auto STATE_TEST_RUN_MODE = common::RunMode::InterpMode;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why change to InterpMode by default

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest #334 defaults to InterpMode.


struct TxIntrinsicCost {
int64_t Intrinsic = 0;
Expand Down
Loading