perlin-network / life

A secure WebAssembly VM catered for decentralized applications.
MIT License
1.7k stars 122 forks source link

Execute never returns #66

Closed singpolyma-shopify closed 5 years ago

singpolyma-shopify commented 5 years ago
// Execute starts the virtual machines main instruction processing loop.
// This function may return at any point and is guaranteed to return
// at least once every 10000 instructions. Caller is responsible for
// detecting VM status in a loop.

As far as I can tell, this is just not true. It only returns on exit/error or gas limit exceeded. And a trivial infinite loop (jmp over and over) never triggers the gas limit check. This means there is no way to prevent a VM from being tied up forever by an infinite loop.

losfair commented 5 years ago

Should be fixed in a35232cc.

singpolyma-shopify commented 5 years ago

Testing latest master from here does not resolve the issue for me. For now I am using this: https://github.com/singpolyma-shopify/life/commit/fbda4000ae9d2e31666cfd1363ee6898105b17f2

losfair commented 5 years ago

The VM no longer returns every 10000 instructions, but only when gas limit exceeded or an import is called. The commit a35232cc should have fixed the gas limit check issue.

It's suggested that you use gas limit for limiting execution cycles.

Let me know whether the gas limit check in latest master works for you.

singpolyma-shopify commented 5 years ago

I tried master and set GasLimit to 1 and a trivial infinite loop still ran forever.

losfair commented 5 years ago

I tried with the following code:

(module
    (func $app_main (export "app_main") (result i32)
        (loop
            br 0
        )
        (unreachable)
    )
)

with GasLimit set to 1 and gas policy compiler.SimpleGasPolicy{GasPerInstruction:1}. It terminates correctly. Could you post your code here?

singpolyma-shopify commented 5 years ago

I forgot to set gas policy on this time trying. My bad, working now. Thanks!