ewasm / hera

Hera: Ewasm virtual machine conforming to the EVMC API
Apache License 2.0
179 stars 50 forks source link

(Regression) EVMC fails to validate contract via Sentinel #551

Open jwasinger opened 5 years ago

jwasinger commented 5 years ago

Using the genesis provided here (which is the same as the ewasm testnet genesis for milestone 1), a transaction containing this wast fails to deploy:

(module
  (import "ethereum" "storageStore" (func $storageStore (param i32 i32)))
  (memory 1)
  (data (i32.const 0)  "\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00") ;; Path                                                                                  
  (data (i32.const 32) "\cd\ab\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00") ;; Value                                                                                 
  (export "memory" (memory 0))
  (export "main" (func $main))
  (func $main

  )
)

The only output I get from Hera is: "Sentinel has failed on contract. It is invalid."

Maybe this is intended (and the contract is in some way malformed according to wasm-chisel's validation specs), however it is completely opaque what the underlying reason for the failure is.

chfast commented 5 years ago

Can this be reproduces with testeth or any other tool? Can you add this as a JSON test to ewasm/tests?

jwasinger commented 5 years ago

I'm not sure. I don't think it can be tested for unless we want to write unit test cases for hard-coded sentinel contract bytecodes....

If we had more detailed output from the sentinel contract, it would make solving issues like this a lot easier.

jwasinger commented 5 years ago

I built a new version of the sentinel contract from source and tried to test a simple contract deployment. This bug persists.

My rustc version:

nightly-x86_64-unknown-linux-gnu (default)
rustc 1.38.0-nightly (4bb6b4a5e 2019-07-11)

How to reproduce locally (note: the wasm in this example is different than in the issue description. but they are both bare-bones simple and trigger the same bug): https://github.com/jwasinger/ewasm-dev-env/tree/post-milestone-1

jwasinger commented 5 years ago
Executing message in Hera
Metering (input 120 bytes)...
Executing message in Hera
Executing with wabt...
Module failed to load.
Metering done (output 0 bytes, used 9223372036854775807 gas) with code=1
Sentinel has failed on contract. It is invalid.

It looks like the sentinel itself fails to load with whatever version of wabt is shipped with hera at current master branch.

axic commented 5 years ago

It seems that an old version of llvm always included a linker custom section and the milestone1 version of sentinel was probably compiled like that. Source: https://github.com/WebAssembly/wabt/issues/842

Manually dropping all custom sections with chisel's repack feature makes it to work with wabt – at least confirmed with wasm2wat, which decodes without issues.

jwasinger commented 5 years ago
Executing message in Hera
Metering (input 120 bytes)...
Executing message in Hera
Executing with wabt...
wabt (execute): invalid section size: extends past end
Module failed to load.
Metering done (output 0 bytes, used 9223372036854775807 gas) with code=1
Sentinel has failed on contract. It is invalid.

^ I get this after updating all components, using a freshly built and chiseled sentinel contract.