Skip to content
New issue

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

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

Already on GitHub? # to your account

EEI: implement getReturnDataSize and returnDataCopy #80

Merged
merged 2 commits into from
Jan 17, 2018
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
36 changes: 32 additions & 4 deletions src/eei.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ namespace HeraVM {

if (import->base == Name("getCallDataSize")) {
HERA_DEBUG << "callDataSize\n";
return Literal((uint32_t)msg.input_size);
return Literal(static_cast<uint32_t>(msg.input_size));
}

if (import->base == Name("callDataCopy")) {
Expand Down Expand Up @@ -212,7 +212,7 @@ namespace HeraVM {
if (import->base == Name("getCodeSize")) {
HERA_DEBUG << "getCodeSize\n";

return Literal((uint32_t)code.size());
return Literal(static_cast<uint32_t>(code.size()));
}

if (import->base == Name("externalCodeCopy")) {
Expand Down Expand Up @@ -243,7 +243,7 @@ namespace HeraVM {
evm_address address = loadUint160(addressOffset);
size_t code_size = context->fn_table->get_code(NULL, context, &address);

return Literal((uint32_t)code_size);
return Literal(static_cast<uint32_t>(code_size));
}

if (import->base == Name("getBlockCoinbase")) {
Expand Down Expand Up @@ -405,6 +405,23 @@ namespace HeraVM {
return Literal();
}

if (import->base == Name("getReturnDataSize")) {
HERA_DEBUG << "getReturnDataSize\n";
return Literal(static_cast<uint32_t>(lastReturnData.size()));
}

if (import->base == Name("returnDataCopy")) {
uint32_t dataOffset = arguments[0].geti32();
uint32_t offset = arguments[1].geti32();
uint32_t size = arguments[2].geti32();

HERA_DEBUG << "returnDataCopy " << hex << offset << " " << size << dec << "\n";

storeMemory(lastReturnData, dataOffset, offset, size);

return Literal();
}

if (
import->base == Name("call") ||
import->base == Name("callCode") ||
Expand Down Expand Up @@ -489,6 +506,10 @@ namespace HeraVM {
vector<uint8_t> result(call_result.output_data, call_result.output_data + call_result.output_size);
result.resize(resultLength);
storeMemory(result, 0, resultOffset, resultLength);

lastReturnData.assign(call_result.output_data, call_result.output_data + call_result.output_size);
Copy link
Collaborator

Choose a reason for hiding this comment

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

The same goes for CREATE.

} else {
lastReturnData.clear();
}

if (call_result.release)
Expand Down Expand Up @@ -533,7 +554,14 @@ namespace HeraVM {

evm_result create_result;
context->fn_table->call(&create_result, context, &create_message);
storeUint160(create_result.create_address, resultOffset);
if (create_result.status_code == EVM_SUCCESS)
storeUint160(create_result.create_address, resultOffset);

if (create_result.output_data) {
lastReturnData.assign(create_result.output_data, create_result.output_data + create_result.output_size);
} else {
lastReturnData.clear();
}

if (create_result.release)
create_result.release(&create_result);
Expand Down
1 change: 1 addition & 0 deletions src/eei.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ struct EthereumInterface : ShellExternalInterface {
struct evm_context* context = nullptr;
std::vector<uint8_t> const& code;
struct evm_message const& msg;
std::vector<uint8_t> lastReturnData;
ExecutionResult & result;
};

Expand Down