Skip to content
This repository has been archived by the owner on Jan 21, 2022. It is now read-only.

Extra bytes returned on revert("") #800

Closed
ZumZoom opened this issue Nov 1, 2020 · 2 comments
Closed

Extra bytes returned on revert("") #800

ZumZoom opened this issue Nov 1, 2020 · 2 comments

Comments

@ZumZoom
Copy link

ZumZoom commented Nov 1, 2020

Calling revert(string) in Solidity should return abi-encoded string as if it were a call to Error(string) function (docs).

Therefore when calling revert with empty string revert("") I expect to receive correct abi-encoded Error(""):

0x08c379a0                                                          <- Error(string) selector
0000000000000000000000000000000000000000000000000000000000000020    <- string offset = 32
0000000000000000000000000000000000000000000000000000000000000000    <- string length = 0

However ganache-cli appends extra 32 bytes of zeroes in that case and returned bytes are

0x08c379a0                                                          <- Error(string) selector
0000000000000000000000000000000000000000000000000000000000000020    <- string offset = 32
0000000000000000000000000000000000000000000000000000000000000000    <- string length = 0
0000000000000000000000000000000000000000000000000000000000000000    <- unexpected extra 32 bytes

Those extra zeroes break the code that relies on the size of abi-encoded string.

Expected Behavior

Error("") should be abi-encoded as 68 bytes.

Current Behavior

Error("") is abi-encoded as 100 bytes.

Steps to Reproduce

contract RevertReasonParserTest {
    function emptyStringRevert() external pure  {
        revert("");
    }

    function test() external view {
        try this.emptyStringRevert() {
        } catch (bytes memory reason) {
            require(reason.length == 68, "Incorrect reason length");
        }
    }
}

Your Environment

  • Version used: 6.12.1
@axic
Copy link
Contributor

axic commented Nov 1, 2020

Can you open the same issue on https://github.com/ethereum/solidity? It seems to be belonging there and not here. (Also confirming this is happening.)

@ZumZoom
Copy link
Author

ZumZoom commented Nov 1, 2020

Sure. Thanks for suggestion.
ethereum/solidity#10170
I also checked that the behaviour is consistent with mainnet, ropsten and ethereumjs-vm.
It is likely a Solidity bug so I'm closing the issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants