Skip to content

[Yul -> Ewasm] Code generator produces infinite loops #9205

@cameel

Description

@cameel

Description

Yul->Wasm translation produces for loops that repeat the initialization code in every iteration. The effect is an infinite loop.

From Yul code like this:

for { <init> } <condition> { <increment> }
{
    <body>
}

we get wasm like this:

(loop $loop_label
    <init>
    <condition>
    <body>
    <increment>
    (br $loop_label)
)

This is wrong because jumping to loop_label repeats the <init> block in each iteration.

Environment

  • Compiler version: develop (>= 0.6.10)

Steps to Reproduce

  • Check out evmc-vms-evm-ewasm branch from Add support for ewasm evmc vm. #9143 which allows you to execute wasm tests on hera.
  • Build soltest
  • Put this example in test/libsolidity/semanticTests/tmp/test.sol
    contract test {
        function f(uint x) public pure returns(uint r) {
            for (uint i = 0; i < 5; i++)
            {
                for (uint j = 0; j < 5; j++)
                {
                    x++;
                }
            }
            return x;
        }
    }
    // ====
    // compileToEwasm: also
    // compileViaYul: true
    // ----
    // f(uint256): 0 -> 0x19
  • Run soltest:
    soltest --run_test=semanticTests/tmp/* -- --vm <path-to-evmone>/libevmone.so --vm <path-to-hera>/libhera.so —evm-version=byzantium --no-smt --show-messages
  • It hangs.

The test hangs.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions