Skip to content

Improve metadata handling #59

Description

@montyly

Following the trailofbits/manticore#909 discussion:

We need to improve

def _remove_metadata(self):
"""
Init bytecode contains metadata that needs to be removed
see http://solidity.readthedocs.io/en/v0.4.24/metadata.html#encoding-of-the-metadata-hash-in-the-bytecode
"""
self._init_bytecodes = {
key: re.sub(r"a165627a7a72305820.{64}0029", r"", bytecode)
for (key, bytecode) in self._init_bytecodes.items()
}
self._runtime_bytecodes = {
key: re.sub(r"a165627a7a72305820.{64}0029", r"", bytecode)
for (key, bytecode) in self._runtime_bytecodes.items()
}

To handle newer versions of the metadata encoding, including:

0xa2
0x65 'b' 'z' 'z' 'r' '1' 0x58 0x20 <32 bytes swarm hash>
0x64 's' 'o' 'l' 'c' 0x43 <3 byte version encoding>
0x00 0x32
0xa2
0x64 'i' 'p' 'f' 's' 0x58 0x22 <34 bytes IPFS hash>
0x64 's' 'o' 'l' 'c' 0x43 <3 byte version encoding>
0x00 0x32

We could also handle the parsing of the metatadata, like doing the key-values extraction.

Additionally, we should add a public function allowing external tools to access these functionalities. This would be useful for, at least, Manticore and evm-cfg-builder.

Activity

  1. 0xalpharush commented on Oct 27, 2022

    @0xalpharush
    Contributor

    Fwiw in solc 0.8.18, there will be an option to remove the metadata with "appendCBOR": false https://docs.soliditylang.org/en/develop/using-the-compiler.html#input-description

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions