Skip to content

Commit

Permalink
Validate the function signature of main in binaryen
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Oct 25, 2018
1 parent 69fa573 commit 15b9dc2
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/binaryen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,23 @@ void BinaryenEngine::verifyContract(wasm::Module & module)
"Contract exports more than (\"main\") and (\"memory\")."
);

// The existence of this is ensured above.
wasm::Export* main_export = module.getExport(wasm::Name("main"));

wasm::Function* main_function = module.getFunctionOrNull(main_export->value);
ensureCondition(
main_function,
ContractValidationFailure,
"Contract is invalid. \"main\" export doesn't point to a function."
);

ensureCondition(
(main_function->getNumParams() == 0) &&
(main_function->result == wasm::Type::none),
ContractValidationFailure,
"Contract is invalid. \"main\" has an invalid signature."
);

for (auto const& import: module.imports) {
ensureCondition(
import->module == wasm::Name("ethereum")
Expand Down

0 comments on commit 15b9dc2

Please sign in to comment.