Skip to content

Wasm build does not output panics to the JSON errors array #476

@elle-j

Description

@elle-j

Description

In --standard-json mode, when a panic occurs in resolc the native builds are consistent with solc and terminate in a success state with errors reported in the JSON output via stdout.

The Wasm build behaves similarly for errors, but not when panics occur:

Build Exit Code stdout stderr
Native 0 JSON with populated errors array empty
Wasm 101 empty panic message

Tested with:

  • resolc 1.0.0
  • resolc 0.6.0

Minimal Reproduction

1. Create a file that triggers a panic

This example uses the _ function naming collision bug to trigger a panic:

cat > trigger-ice.yul << 'EOF'
object "Test" {
    code {
        {
            let size := datasize("Test_deployed")
            codecopy(0, dataoffset("Test_deployed"), size)
            return(0, size)
        }
    }
    object "Test_deployed" {
        code {
            {
                _()
                log0(0, 32)
            }
            function _() {
                mstore(0, 0xdeadbeef)
                log0(0, 32)
            }
        }
    }
}
EOF

2. Download soljson.js

This downloads it to resolc-wasm/soljson.js:

curl -sSLo resolc-wasm/soljson.js https://github.com/ethereum/solidity/releases/download/v0.8.33/soljson.js

3. Compile the file with Wasm resolc

This assumes you have resolc.js, resolc.wasm, and soljson.js in ./resolc-wasm/:
(resolc v1.0.0 used here)

node -e "
const fs = require('fs');
const createResolc = require('./resolc-wasm/resolc.js');
const soljson = require('./resolc-wasm/soljson.js');

const input = {
  language: 'Yul',
  sources: {
    'trigger-ice.yul': {
      content: fs.readFileSync('trigger-ice.yul', 'utf8')
    }
  },
  settings: {
    optimizer: {
      enabled: false
    },
    outputSelection: {
      '*': {
        '*': ['evm.bytecode']
      }
    }
  }
};

const compiler = createResolc();
compiler.soljson = soljson;
compiler.writeToStdin(JSON.stringify(input));

const exitCode = compiler.callMain(['--standard-json']);

console.log('Exit code:', exitCode);
console.log('stdout:');
console.log(compiler.readFromStdout());
console.log('stderr:');
console.log(compiler.readFromStderr());
"

Expected Output

  • Exit code: 0
  • stdout: JSON with the error in the errors array
  • stderr: empty

Actual Output

Exit code: 101
stdout:

stderr:

thread 'main' (1) panicked at crates/resolc/src/process/worker_process.rs:91:37:
Worker error: 
thread 'main' (1) panicked at crates/llvm-context/src/polkavm/context/mod.rs:459:9:
ICE: function '_' declared subsequentally

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions