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

eei return: Trap condition: unreachable #1

Closed
hugo-dc opened this issue Jul 2, 2018 · 4 comments
Closed

eei return: Trap condition: unreachable #1

hugo-dc opened this issue Jul 2, 2018 · 4 comments

Comments

@hugo-dc
Copy link
Member

hugo-dc commented Jul 2, 2018

Getting error: Trap condition: unreachable

To compare, I imported the return function manually and tried to return the same data, while calling the manually imported function the test pass without errors, I realized the only difference between the manually imported function and the ewasm-rust-api function is that ewasm-api function specifies that the function never returns (using return type -> !).

fn ethereum_return(dataOffset: *const u32, length: u32) -> !;

@hugo-dc hugo-dc changed the title revert: Trap condition: unreachable eei revert: Trap condition: unreachable Jul 2, 2018
@hugo-dc hugo-dc changed the title eei revert: Trap condition: unreachable eei return: Trap condition: unreachable Jul 2, 2018
@poemm
Copy link

poemm commented Jul 4, 2018

Maybe you already know this, but the Wasm spec requires host functions to return with the type in their signature (or never return if they are in an infinite loop). So perhaps you can return in a way which triggers a Wasm trap, which allows Wasm to handle the trap and exit cleanly. This can be optimized later.

@axic
Copy link
Member

axic commented Jul 12, 2018

-> ! is added because it was made with the assumption that ewasm/design#72 is merged

Since it is not merged, we probably should remove those atm.

@axic
Copy link
Member

axic commented Jul 16, 2018

Here's a generated code example (from sha256 precompile):

 (func $_ZN9ewasm_api6revert17h4611de01ad540c7bE (; 74 ;) (type $7)
  (call $ethereum_revert
   (i32.const 0)
   (i32.const 0)
  )
  (unreachable)
 )

-> ! means the function never returns, and it seems that Rust enforces this in the wasm output as including a trap after the function.

While this would be unnecessary since the function would never return anyway, it is a nice behaviour to ensure a non-compliant VM fails 😉

I'd really prefer to merge ewasm/design#72 and keep 😕

@axic
Copy link
Member

axic commented Aug 10, 2018

Since the design issue was decided on and ewasm/hera#249 was merged, this can be closed.

@axic axic closed this as completed Aug 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants