Solidity: Failed stack assertion related calldata arrays

Created on 25 May 2019  路  6Comments  路  Source: ethereum/solidity

Description

Hi, I was working on a small project and I got an error with my code:

Internal compiler error during compilation:
/home/user/Documents/Scripts/solidity/libsolidity/codegen/ContractCompiler.cpp(57): Throw in function void {anonymous}::StackHeightChecker::check()
Dynamic exception type: boost::exception_detail::clone_impl<langutil::InternalCompilerError>
std::exception::what: I sense a disturbance in the stack: 1 vs 2
[dev::tag_comment*] = I sense a disturbance in the stack: 1 vs 2

I can reproduce it from 5.2 to 6.0 (throw not implemented before that).
I also use ABIEncoderV2 to build bytes[].

Environment

  • Compiler version: 5.9
  • Target EVM version (as per compiler settings): IDK
  • Framework/IDE (e.g. Truffle or Remix): Remix and linux 5.9 builded by my self solc binary
  • Operating system: Firefox/Ubuntu

Steps to Reproduce

Just try to compile :

./solc test.sol

test.sol:

pragma solidity >=0.5.2 <0.6.0;
pragma experimental ABIEncoderV2;

contract Test {
    struct shouldBug {
        bytes[2] deadly;
    }
    mapping(uint256 => shouldBug) graveyard;

    function killer(bytes[2] calldata weapon) external {
      graveyard[1] = shouldBug(weapon);
    }
}

Also die in the same way using remix.

bug

Most helpful comment

Ok I think I found the bug (when accessIndex, forgot to put calldata dynamic length array's size on stack). I can try to fix when I get time (this Thursday). (I haven't investigate possible fixes)

All 6 comments

Probably the same cause:

pragma experimental ABIEncoderV2;

contract Test {
    function f(bytes[2] calldata w) external {
      bytes[2] memory x = w;
    }
}
Internal compiler error during compilation:
/build/source/libsolidity/codegen/CompilerUtils.cpp(1195): Throw in function void dev::solidity::CompilerUtils::moveToStackVariable(const dev::solidity::VariableDeclaration&)
Dynamic exception type: boost::exception_detail::clone_impl<langutil::InternalCompilerError>
std::exception::what: Variable size and position mismatch.
[dev::tag_comment*] = Variable size and position mismatch.

@sifmelcara you are probably right because that exactly the same error with:

pragma solidity >=0.5.2 <0.6.0;
pragma experimental ABIEncoderV2;

contract Test {
    struct shouldBug {
        bytes[2] deadly;
    }

    function killer(bytes[2] calldata weapon) external {
      shouldBug memory corpse = shouldBug(weapon);
    }
}
InternalCompilerError: Variable size and position mismatch.

(Here done with remix)

Ok I think I found the bug (when accessIndex, forgot to put calldata dynamic length array's size on stack). I can try to fix when I get time (this Thursday). (I haven't investigate possible fixes)

@sifmelcara great!

I assigned you to mark this issue as "taken" so we can spot unassigned issues easier. Feel free to unassign yourself again if you no longer work on this issue :)

I'm (unfortunately) closing this as "won't fix" in favour of #7635. As a workaround it should always be possible to use public functions with arguments in memory - calldata arrays will only be implemented in a feature-complete way with ABIEncoderV2.

Was this page helpful?
0 / 5 - 0 ratings