Skip to content

Commit

Permalink
Merge pull request #446 from ewasm/validate-main-sig
Browse files Browse the repository at this point in the history
Validate the function signature of main in binaryen
  • Loading branch information
axic authored Oct 25, 2018
2 parents 69fa573 + ab24465 commit b8640fe
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\" is not 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 b8640fe

Please sign in to comment.