Skip to content

Commit 106bece

Browse files
authored
Merge pull request #443 from ewasm/evmc-v6
Upgrade EVMC to version 6.0.0
2 parents c85c962 + ba658df commit 106bece

File tree

5 files changed

+50
-52
lines changed

5 files changed

+50
-52
lines changed

circle.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ defaults:
6969

7070
save-aleth-cache: &save-aleth-cache
7171
save_cache:
72-
key: &aleth-cache-key aleth-prebuilt-cache-{{arch}}-{{checksum "toolchain"}}-v1.4.0rc7
72+
key: &aleth-cache-key aleth-prebuilt-cache-{{arch}}-{{checksum "toolchain"}}-v1.5.0-alpha.5
7373
paths:
7474
- ~/build
7575
- ~/.hunter
@@ -83,7 +83,7 @@ defaults:
8383
name: "Checkout aleth repo"
8484
working_directory: ~/
8585
command: |
86-
git clone https://github.com/ethereum/aleth --branch v1.4.0rc7 --single-branch --recurse-submodules --depth 1
86+
git clone https://github.com/ethereum/aleth --branch v1.5.0-alpha.5 --single-branch --recurse-submodules --depth 1
8787
8888
link-hera: &link-hera
8989
run:
@@ -118,7 +118,7 @@ defaults:
118118
run:
119119
name: "Install aleth"
120120
command: |
121-
URL=https://github.com/ethereum/aleth/releases/download/v1.4.0rc7/aleth-1.4.0rc7-linux-x86_64.tar.gz
121+
URL=https://github.com/ethereum/aleth/releases/download/v1.5.0-alpha.5/aleth-1.5.0-alpha.5-linux-x86_64.tar.gz
122122
curl -L $URL | sudo tar xz -C /usr/local
123123
124124
fetch-tests: &fetch-tests

evmc

Submodule evmc updated from 224080e to 354ba6f

src/eei.cpp

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ namespace hera {
6666

6767
HERA_DEBUG << "): " << dec;
6868

69-
evmc_uint256be result;
70-
m_context->fn_table->get_storage(&result, m_context, &m_msg.destination, &path);
69+
evmc_bytes32 result = m_context->host->get_storage(m_context, &m_msg.destination, &path);
7170

7271
if (useHex)
7372
{
@@ -150,9 +149,8 @@ namespace hera {
150149
takeInterfaceGas(GasSchedule::balance);
151150

152151
evmc_address address = loadAddress(addressOffset);
153-
evmc_uint256be result;
154-
m_context->fn_table->get_balance(&result, m_context, &address);
155-
storeUint128(result, resultOffset);
152+
evmc_uint256be balance = m_context->host->get_balance(m_context, &address);
153+
storeUint128(balance, resultOffset);
156154
}
157155

158156
uint32_t EthereumInterface::eeiGetBlockHash(uint64_t number, uint32_t resultOffset)
@@ -161,8 +159,7 @@ namespace hera {
161159

162160
takeInterfaceGas(GasSchedule::blockhash);
163161

164-
evmc_uint256be blockhash;
165-
m_context->fn_table->get_block_hash(&blockhash, m_context, static_cast<int64_t>(number));
162+
evmc_bytes32 blockhash = m_context->host->get_block_hash(m_context, static_cast<int64_t>(number));
166163

167164
if (isZeroUint256(blockhash))
168165
return 1;
@@ -236,7 +233,7 @@ namespace hera {
236233
evmc_address address = loadAddress(addressOffset);
237234
// FIXME: optimise this so no vector needs to be created
238235
vector<uint8_t> codeBuffer(length);
239-
size_t numCopied = m_context->fn_table->copy_code(m_context, &address, codeOffset, codeBuffer.data(), codeBuffer.size());
236+
size_t numCopied = m_context->host->copy_code(m_context, &address, codeOffset, codeBuffer.data(), codeBuffer.size());
240237
ensureCondition(numCopied == length, InvalidMemoryAccess, "Out of bounds (source) memory copy");
241238

242239
storeMemory(codeBuffer, 0, resultOffset, length);
@@ -249,7 +246,7 @@ namespace hera {
249246
takeInterfaceGas(GasSchedule::extcode);
250247

251248
evmc_address address = loadAddress(addressOffset);
252-
size_t code_size = m_context->fn_table->get_code_size(m_context, &address);
249+
size_t code_size = m_context->host->get_code_size(m_context, &address);
253250

254251
return static_cast<uint32_t>(code_size);
255252
}
@@ -317,7 +314,7 @@ namespace hera {
317314
vector<uint8_t> data(length);
318315
loadMemory(dataOffset, data, length);
319316

320-
m_context->fn_table->emit_log(m_context, &m_msg.destination, data.data(), length, topics.data(), numberOfTopics);
317+
m_context->host->emit_log(m_context, &m_msg.destination, data.data(), length, topics.data(), numberOfTopics);
321318
}
322319

323320
int64_t EthereumInterface::eeiGetBlockNumber()
@@ -365,19 +362,17 @@ namespace hera {
365362

366363
ensureCondition(!(m_msg.flags & EVMC_STATIC), StaticModeViolation, "storageStore");
367364

368-
evmc_uint256be path = loadBytes32(pathOffset);
369-
evmc_uint256be value = loadBytes32(valueOffset);
370-
evmc_uint256be current;
371-
372-
m_context->fn_table->get_storage(&current, m_context, &m_msg.destination, &path);
365+
evmc_bytes32 path = loadBytes32(pathOffset);
366+
evmc_bytes32 value = loadBytes32(valueOffset);
367+
evmc_bytes32 current = m_context->host->get_storage(m_context, &m_msg.destination, &path);
373368

374369
// Charge the right amount in case of the create case.
375370
if (isZeroUint256(current) && !isZeroUint256(value))
376371
takeInterfaceGas(GasSchedule::storageStoreCreate - GasSchedule::storageStoreChange);
377372

378373
// We do not need to take care about the delete case (gas refund), the client does it.
379374

380-
m_context->fn_table->set_storage(m_context, &m_msg.destination, &path, &value);
375+
m_context->host->set_storage(m_context, &m_msg.destination, &path, &value);
381376
}
382377

383378
void EthereumInterface::eeiStorageLoad(uint32_t pathOffset, uint32_t resultOffset)
@@ -386,9 +381,8 @@ namespace hera {
386381

387382
takeInterfaceGas(GasSchedule::storageLoad);
388383

389-
evmc_uint256be path = loadBytes32(pathOffset);
390-
evmc_uint256be result;
391-
m_context->fn_table->get_storage(&result, m_context, &m_msg.destination, &path);
384+
evmc_bytes32 path = loadBytes32(pathOffset);
385+
evmc_bytes32 result = m_context->host->get_storage(m_context, &m_msg.destination, &path);
392386

393387
storeBytes32(result, resultOffset);
394388
}
@@ -431,7 +425,6 @@ namespace hera {
431425
evmc_message call_message;
432426
call_message.destination = loadAddress(addressOffset);
433427
call_message.flags = m_msg.flags & EVMC_STATIC;
434-
call_message.code_hash = {};
435428
call_message.depth = m_msg.depth + 1;
436429

437430
switch (kind) {
@@ -489,8 +482,6 @@ namespace hera {
489482
call_message.input_size = 0;
490483
}
491484

492-
evmc_result call_result;
493-
494485
// Start with base call gas
495486
takeInterfaceGas(GasSchedule::call);
496487

@@ -506,7 +497,7 @@ namespace hera {
506497
return 1;
507498

508499
// Only charge callNewAccount gas if the account is new and non-zero value is being transferred per EIP161.
509-
if ((kind == EEICallKind::Call) && !m_context->fn_table->account_exists(m_context, &call_message.destination))
500+
if ((kind == EEICallKind::Call) && !m_context->host->account_exists(m_context, &call_message.destination))
510501
takeInterfaceGas(GasSchedule::callNewAccount);
511502
}
512503

@@ -522,7 +513,7 @@ namespace hera {
522513

523514
call_message.gas = gas;
524515

525-
m_context->fn_table->call(&call_result, m_context, &call_message);
516+
evmc_result call_result = m_context->host->call(m_context, &call_message);
526517

527518
if (call_result.output_data) {
528519
m_lastReturnData.assign(call_result.output_data, call_result.output_data + call_result.output_size);
@@ -579,18 +570,15 @@ namespace hera {
579570
create_message.input_size = 0;
580571
}
581572

582-
create_message.code_hash = {};
583573
create_message.depth = m_msg.depth + 1;
584574
create_message.kind = EVMC_CREATE;
585575
create_message.flags = 0;
586576

587-
evmc_result create_result;
588-
589577
int64_t gas = maxCallGas(m_result.gasLeft);
590578
create_message.gas = gas;
591579
takeInterfaceGas(gas);
592580

593-
m_context->fn_table->call(&create_result, m_context, &create_message);
581+
evmc_result create_result = m_context->host->call(m_context, &create_message);
594582

595583
/* Return unspent gas */
596584
heraAssert(create_result.gas_left >= 0, "EVMC returned negative gas left");
@@ -628,9 +616,10 @@ namespace hera {
628616

629617
evmc_address address = loadAddress(addressOffset);
630618

631-
if (!m_context->fn_table->account_exists(m_context, &address))
619+
if (!m_context->host->account_exists(m_context, &address))
632620
takeInterfaceGas(GasSchedule::callNewAccount);
633-
m_context->fn_table->selfdestruct(m_context, &m_msg.destination, &address);
621+
622+
m_context->host->selfdestruct(m_context, &m_msg.destination, &address);
634623

635624
throw EndExecution{};
636625
}
@@ -815,8 +804,7 @@ namespace hera {
815804

816805
bool EthereumInterface::enoughSenderBalanceFor(evmc_uint256be const& value) const
817806
{
818-
evmc_uint256be balance;
819-
m_context->fn_table->get_balance(&balance, m_context, &m_msg.destination);
807+
evmc_uint256be balance = m_context->host->get_balance(m_context, &m_msg.destination);
820808
return safeLoadUint128(balance) >= safeLoadUint128(value);
821809
}
822810

src/eei.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class EthereumInterface {
7373
m_result.isRevert = false;
7474

7575
// cache the transaction context here
76-
m_context->fn_table->get_tx_context(&m_tx_context, m_context);
76+
m_tx_context = m_context->host->get_tx_context(m_context);
7777
}
7878

7979
// WAVM host functions access this interface through an instance,

src/hera.cpp

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ struct hera_instance : evmc_instance {
9494
bool metering = false;
9595
map<evmc_address, vector<uint8_t>> contract_preload_list;
9696

97-
hera_instance() noexcept : evmc_instance({EVMC_ABI_VERSION, "hera", hera_get_buildinfo()->project_version, nullptr, nullptr, nullptr, nullptr}) {}
97+
hera_instance() noexcept : evmc_instance({EVMC_ABI_VERSION, "hera", hera_get_buildinfo()->project_version, nullptr, nullptr, nullptr, nullptr, nullptr}) {}
9898
};
9999

100100
const evmc_address sentinelAddress = { .bytes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xa } };
@@ -110,21 +110,19 @@ pair<evmc_status_code, vector<uint8_t>> callSystemContract(
110110
vector<uint8_t> const& input
111111
) {
112112
evmc_message message = {
113+
.kind = EVMC_CALL,
114+
.flags = EVMC_STATIC,
115+
.depth = 0,
116+
.gas = gas,
113117
.destination = address,
114118
.sender = {},
115-
.value = {},
116119
.input_data = input.data(),
117120
.input_size = input.size(),
118-
.code_hash = {},
121+
.value = {},
119122
.create2_salt = {},
120-
.gas = gas,
121-
.depth = 0,
122-
.kind = EVMC_CALL,
123-
.flags = EVMC_STATIC
124123
};
125124

126-
evmc_result result;
127-
context->fn_table->call(&result, context, &message);
125+
evmc_result result = context->host->call(context, &message);
128126

129127
vector<uint8_t> ret;
130128
if (result.status_code == EVMC_SUCCESS && result.output_data)
@@ -471,7 +469,7 @@ bool hera_parse_sys_option(hera_instance *hera, string const& _name, string cons
471469
return true;
472470
}
473471

474-
int hera_set_option(
472+
evmc_set_option_result hera_set_option(
475473
evmc_instance *instance,
476474
char const *name,
477475
char const *value
@@ -481,29 +479,32 @@ int hera_set_option(
481479
if (strcmp(name, "evm1mode") == 0) {
482480
if (evm1mode_options.count(value)) {
483481
hera->evm1mode = evm1mode_options.at(value);
484-
return 1;
482+
return EVMC_SET_OPTION_SUCCESS;
485483
}
484+
return EVMC_SET_OPTION_INVALID_VALUE;
486485
}
487486

488487
if (strcmp(name, "metering") == 0) {
489488
hera->metering = strcmp(value, "true") == 0;
490-
return 1;
489+
return EVMC_SET_OPTION_SUCCESS;
491490
}
492491

493492
if (strcmp(name, "engine") == 0) {
494493
auto it = wasm_engine_map.find(value);
495494
if (it != wasm_engine_map.end()) {
496495
hera->engine = it->second();
497-
return 1;
496+
return EVMC_SET_OPTION_SUCCESS;
498497
}
498+
return EVMC_SET_OPTION_INVALID_VALUE;
499499
}
500500

501501
if (strncmp(name, "sys:", 4) == 0) {
502502
if (hera_parse_sys_option(hera, string(name), string(value)))
503-
return 1;
503+
return EVMC_SET_OPTION_SUCCESS;
504+
return EVMC_SET_OPTION_INVALID_VALUE;
504505
}
505506

506-
return 0;
507+
return EVMC_SET_OPTION_INVALID_NAME;
507508
}
508509

509510
void hera_destroy(evmc_instance* instance) noexcept
@@ -512,6 +513,14 @@ void hera_destroy(evmc_instance* instance) noexcept
512513
delete hera;
513514
}
514515

516+
evmc_capabilities_flagset hera_get_capabilities(evmc_instance* instance)
517+
{
518+
evmc_capabilities_flagset caps = EVMC_CAPABILITY_EWASM;
519+
if (static_cast<hera_instance*>(instance)->evm1mode != hera_evm1mode::reject)
520+
caps |= EVMC_CAPABILITY_EVM1;
521+
return caps;
522+
}
523+
515524
} // anonymous namespace
516525

517526
extern "C" {
@@ -521,6 +530,7 @@ evmc_instance* evmc_create_hera() noexcept
521530
hera_instance* instance = new hera_instance;
522531
instance->destroy = hera_destroy;
523532
instance->execute = hera_execute;
533+
instance->get_capabilities = hera_get_capabilities;
524534
instance->set_option = hera_set_option;
525535
return instance;
526536
}

0 commit comments

Comments
 (0)