1

Will a function's returndata persist through a wrapper, even if the wrapper does not support a return value? An example would be as follows:

contract OriginalContract {
    function originalFunction() external returns (bool) {
        return true;
    }
}
interface originalContractInterface {
    function originalFunction() external;
}

contract MyContract {
    address originalContractAddress = 0x123...;

    function mainFunction() public {
        originalContractInterface(originalContractAddress).originalFunction();
        checkReturnData();
    }

    function checkReturnData() internal returns (uint256) {
        uint256 isReturnDataPresent = 0;

        assembly {

            switch returndatasize

            // No return data present
            case 0x0 {
                isReturnDataPresent := 0
            }

            // Return data present
            case 0x20 {
                isReturnDataPresent := 1
            }
        }

        return isReturnDataPresent;
    }
}

In the above example, will calling mainFunction() cause checkReturnData() to return a 0 or a 1? The OriginalContractInterface does not have a return value, so when mainFunction() calls it, will checkReturnData() be able to read the return value from the originalFunction() in the OriginalContract?

3

Yes, checkReturnData() will be able to read the return data from originalContractInterface and will return 1.


For context, returndata is the data returned from the last function call. returndatasize is the size of the return data from that call.

In the example given in the question, mainFunction() calls originalFunction(), which then sets the returndata that is used by checkReturnData(). This function now sees return data, so the switch case enters case 0x20 and sets isReturnDataPresent to 1.

Will a function's returndata persist through a wrapper, even if the wrapper does not support a return value?

The question asks whether or not the returndata will persist, even if the original function is wrapped in an interface that does not return anything. In the code block, originalContractInterface has an interface for originalFunction(), but does not include the same return value that the original function does. Even in this scenario, the returndata will persist, because it has already been written to the returndata slot in memory and has not been written over by anything.


To provide further clarity (using the same code as above for reference), the following interfaces would always store the same returndata:

interface originalContractInterfaceWithoutReturn {
    function originalFunction() external;
}

interface originalContractInterfaceWithReturn {
    function originalFunction() external returns (uint256);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.