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

[WIP] Add isAccountEmpty to EEI #539

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
11 changes: 10 additions & 1 deletion src/binaryen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,14 @@ class BinaryenEthereumInterface : public wasm::ShellExternalInterface, EthereumI
eeiSelfDestruct(addressOffset);
}

if (import->base == wasm::Name("isAccountEmpty")) {
heraAssert(arguments.size() == 1, string("Argument count mismatch in: ") + import->base.str);

uint32_t addressOffset = static_cast<uint32_t>(arguments[0].geti32());

return wasm::Literal(eeiIsAccountEmpty(addressOffset));
}

heraAssert(false, string("Unsupported import called: ") + import->module.str + "::" + import->base.str + " (" + to_string(arguments.size()) + "arguments)");
}

Expand Down Expand Up @@ -628,7 +636,8 @@ void BinaryenEngine::verifyContract(wasm::Module & module)
{ wasm::Name("callDelegate"), createFunctionType({ wasm::Type::i64, wasm::Type::i32, wasm::Type::i32, wasm::Type::i32 }, wasm::Type::i32) },
{ wasm::Name("callStatic"), createFunctionType({ wasm::Type::i64, wasm::Type::i32, wasm::Type::i32, wasm::Type::i32 }, wasm::Type::i32) },
{ wasm::Name("create"), createFunctionType({ wasm::Type::i32, wasm::Type::i32, wasm::Type::i32, wasm::Type::i32 }, wasm::Type::i32) },
{ wasm::Name("selfDestruct"), createFunctionType({ wasm::Type::i32 }, wasm::Type::none) }
{ wasm::Name("selfDestruct"), createFunctionType({ wasm::Type::i32 }, wasm::Type::none) },
{ wasm::Name("isAccountEmpty"), createFunctionType({ wasm::Type::i32 }, wasm::Type::i32) }
};

for (auto const& import: module.imports) {
Expand Down
9 changes: 9 additions & 0 deletions src/eei.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,15 @@ void WasmEngine::collectBenchmarkingData()
throw EndExecution{};
}

uint32_t EthereumInterface::eeiIsAccountEmpty(uint32_t addressOffset)
{
HERA_DEBUG << depthToString() << " isAccountEmpty " << hex << addressOffset << dec << "\n";

evmc_address address = loadAddress(addressOffset);

return m_host.account_exists(address) ? 0 : 1;
}

void EthereumInterface::takeGas(int64_t gas)
{
// NOTE: gas >= 0 is validated by the callers of this method
Expand Down
1 change: 1 addition & 0 deletions src/eei.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ class EthereumInterface {
uint32_t eeiCall(EEICallKind kind, int64_t gas, uint32_t addressOffset, uint32_t valueOffset, uint32_t dataOffset, uint32_t dataLength);
uint32_t eeiCreate(uint32_t valueOffset, uint32_t dataOffset, uint32_t length, uint32_t resultOffset);
void eeiSelfDestruct(uint32_t addressOffset);
uint32_t eeiIsAccountEmpty(uint32_t addressOffset);

private:
void eeiRevertOrFinish(bool revert, uint32_t offset, uint32_t size);
Expand Down