ethereum / solidity

Solidity, the Smart Contract Programming Language
https://soliditylang.org
GNU General Public License v3.0
23.32k stars 5.77k forks source link

ICE on calling externally a function that returns calldata pointers #9134

Closed haltman-at closed 4 years ago

haltman-at commented 4 years ago

Description

As of Solidity 0.6.9, it is possible for functions to return calldata pointers. If such a function is called externally, an InternalCompilerError results.

Suggested fix: Since I don't think there's really any sensible way to handle calling such a function externally, only internal and private functions should be allowed to return calldata pointers.

Environment

Steps to Reproduce

//SPDX-License-Identifier: MIT
pragma solidity ^0.6.9;

contract CalldataTest {
  function test(bytes calldata x) public returns (bytes calldata) {
    return x;
  }
  function tester(bytes calldata x) public {
    this.test(x);
  }
}

Attempting to compile this yields an ICE.

chriseth commented 4 years ago

Right before the release, I thought "did we actually test this"? We did, and it worked, but I only tested the test function via remix, not the tester :)

I think the bug is that FunctionType::asExternallyCallableFunction does not properly change the location of the return variables, only the parameters.