Skip to content

Compiler option revert-strings with value strip has different treatments in legacy and IR pipeline #16465

@matheusaaguiar

Description

@matheusaaguiar

Description

The compiler option revert-strings in CLI or revertStrings in standard JSON Input/Output when configured with the value "strip" produces different code depending on the legacy or IR pipeline.
While the IR pipeline removes strings and custom errors from the generated code for require, the legacy pipeline will only remove strings.
In both pipelines, the branch for the false condition of require generates a revert, so the behavior of the code is the same, but legacy pipeline will not suppress the custom error. This creates a "semantic" difference between the pipelines.

Steps to Reproduce

Use this Solidity code

error MyError(string emsg);
contract C {
    function f() pure external {
        require(false, MyError("abc"));
    }
}

compile with both pipelines and then check the generated code to verify that in legacy the custom error is present as argument to a revert instruction:

Legacy pipeline

solc test.sol --debug-info none --revert-strings strip --asm

generated assembly:

  mstore(0x40, 0x80)
  callvalue
  dup1
  iszero
  tag_1
  jumpi
  revert(0x00, 0x00)
tag_1:
  pop
  dataSize(sub_0)
  dup1
  dataOffset(sub_0)
  0x00
  codecopy
  0x00
  return
stop

sub_0: assembly {
      mstore(0x40, 0x80)
      callvalue
      dup1
      iszero
      tag_1
      jumpi
      revert(0x00, 0x00)
    tag_1:
      pop
      jumpi(tag_2, lt(calldatasize, 0x04))
      shr(0xe0, calldataload(0x00))
      dup1
      0x26121ff0
      eq
      tag_3
      jumpi
    tag_2:
      revert(0x00, 0x00)
    tag_3:
      tag_4
      tag_5
      jump	// in
    tag_4:
      stop
    tag_5:
      mload(0x40)
      shl(0xe0, 0x8b3d2d43)
      dup2
      mstore
      0x20
      0x04
      dup3
      add
      mstore
      0x03
      0x24
      dup3
      add
      mstore
      shl(0xe8, 0x616263)
      0x44
      dup3
      add
      mstore
      0x64
      add
      mload(0x40)
      dup1
      swap2
      sub
      swap1
      revert

    auxdata: 0xa26469706673582212201cbe11542190a594b908ff4413cc2ee54cfe3d65d7c38cf79ccf95d10fdfc24064736f6c63430008210033
}

IR pipeline

solc test.sol --debug-info none --revert-strings strip --asm --via-ir

generated assembly:

EVM assembly:
  0x80
  dup1
  0x40
  mstore
  jumpi(tag_1, callvalue)
  dataSize(sub_0)
  swap1
  dup2
  dataOffset(sub_0)
  dup3
  codecopy
  return
tag_1:
  0x00
  dup1
  revert
stop

sub_0: assembly {
      0x00
      dup1
      revert

    auxdata: 0xa2646970667358221220bd58da9e3f0aafbdbaf47ad5b1a5e02d60030b3e4811bc3e1aa83946e06b77ca64736f6c63430008210033
}

Metadata

Metadata

Labels

bug 🐛codegen errorCompiler generates invalid code. Critical.medium effortDefault level of effortmedium impactDefault level of impactmust haveSomething we consider an essential part of Solidity 1.0.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions