Skip to content
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
5 changes: 5 additions & 0 deletions src/cli/dtvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ int main(int argc, char *argv[]) {
#ifdef ZEN_ENABLE_EVM
if (Config.Format == InputFormat::EVM) {
auto MockedEVMHost = std::make_unique<zen::evm::ZenMockedEVMHost>();
// Set tx_origin from sender address before loading state,
// so loadState() can override it if tx_origin is present in state.json
MockedEVMHost->tx_context.tx_origin =
zen::utils::parseAddress(SenderAddress);
// Load state if specified
if (!LoadStateFile.empty() &&
!zen::utils::loadState(*MockedEVMHost, LoadStateFile)) {
Expand Down Expand Up @@ -379,6 +383,7 @@ int main(int argc, char *argv[]) {
.SenderAddress = SenderAddress,
.ContractAddress = ContractAddress};
evmc_message Msg = createEvmMessage(MockedHost, MsgConfig, Bytecode);

RT->callEVMMain(*Inst, Msg, ExeResult);

if (EVMC_CREATE == MsgKind && ExeResult.status_code == EVMC_SUCCESS) {
Expand Down
2 changes: 2 additions & 0 deletions src/tests/evm_interp_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ EVMExecutionResult executeEvmBytecodeFile(const std::string &FilePath,
Config.Mode = Mode;

auto MockedHost = std::make_unique<zen::evm::ZenMockedEVMHost>();
MockedHost->tx_context.tx_origin = zen::evm::DEFAULT_DEPLOYER_ADDRESS;
auto RT = Runtime::newEVMRuntime(Config, MockedHost.get());
EXPECT_TRUE(RT != nullptr) << "Failed to create runtime";
if (!RT) {
Expand Down Expand Up @@ -268,6 +269,7 @@ TEST_P(EVMSampleTest, ExecuteSample) {
Config.Mode = common::RunMode::InterpMode;

auto MockedHost = std::make_unique<zen::evm::ZenMockedEVMHost>();
MockedHost->tx_context.tx_origin = zen::evm::DEFAULT_DEPLOYER_ADDRESS;

auto RT = Runtime::newEVMRuntime(Config, MockedHost.get());
ASSERT_TRUE(RT != nullptr) << "Failed to create runtime";
Expand Down
9 changes: 9 additions & 0 deletions src/utils/evm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@ bool saveState(const evmc::MockedHost &Host, const std::string &FilePath) {
File << " \"block_base_fee\": ";
writeJsonString(File, toHex(Host.tx_context.block_base_fee.bytes,
sizeof(Host.tx_context.block_base_fee.bytes)));
File << ",\n";
File << " \"tx_origin\": ";
writeJsonString(File, toHex(Host.tx_context.tx_origin.bytes,
sizeof(Host.tx_context.tx_origin.bytes)));
File << "\n";
File << " }\n";

Expand Down Expand Up @@ -418,6 +422,11 @@ bool loadState(evmc::MockedHost &Host, const std::string &FilePath) {
Host.tx_context.block_base_fee =
zen::utils::parseUint256(TxContext["block_base_fee"].GetString());
}

if (TxContext.HasMember("tx_origin") && TxContext["tx_origin"].IsString()) {
Host.tx_context.tx_origin =
zen::utils::parseAddress(TxContext["tx_origin"].GetString());
}
Comment thread
cmgCr marked this conversation as resolved.
}

return true;
Expand Down
4 changes: 2 additions & 2 deletions tests/evm_asm/origin.expected
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
status: success
error_code: 0
stack: []
memory: '0000000000000000000000000000000000000000000000000000000000000000'
memory: '0000000000000000000000001000000000000000000000000000000000000000'
storage: {}
transient_storage: {}
return: '0000000000000000000000000000000000000000000000000000000000000000'
return: '0000000000000000000000001000000000000000000000000000000000000000'
events: []
Loading