mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Document version field in CBOR metadata.
This commit is contained in:
parent
a6a28ac475
commit
aa4ee3a155
@ -124,30 +124,35 @@ Encoding of the Metadata Hash in the Bytecode
|
|||||||
=============================================
|
=============================================
|
||||||
|
|
||||||
Because we might support other ways to retrieve the metadata file in the future,
|
Because we might support other ways to retrieve the metadata file in the future,
|
||||||
the mapping ``{"bzzr0": <Swarm hash>}`` is stored
|
the mapping ``{"bzzr0": <Swarm hash>, "solc": <compiler version>}`` is stored
|
||||||
`CBOR <https://tools.ietf.org/html/rfc7049>`_-encoded. Since the mapping might
|
`CBOR <https://tools.ietf.org/html/rfc7049>`_-encoded. Since the mapping might
|
||||||
contain more keys (see below) and the beginning of that
|
contain more keys (see below) and the beginning of that
|
||||||
encoding is not easy to find, its length is added in a two-byte big-endian
|
encoding is not easy to find, its length is added in a two-byte big-endian
|
||||||
encoding. The current version of the Solidity compiler usually adds the following
|
encoding. The current version of the Solidity compiler usually adds the following
|
||||||
to the end of the deployed bytecode::
|
to the end of the deployed bytecode::
|
||||||
|
|
||||||
0xa1 0x65 'b' 'z' 'z' 'r' '0' 0x58 0x20 <32 bytes swarm hash> 0x00 0x29
|
0xa2
|
||||||
|
0x65 'b' 'z' 'z' 'r' '0' 0x58 0x20 <32 bytes swarm hash>
|
||||||
|
0x64 's' 'o' 'l' 'c' 0x43 <3 byte version encoding>
|
||||||
|
0x00 0x32
|
||||||
|
|
||||||
So in order to retrieve the data, the end of the deployed bytecode can be checked
|
So in order to retrieve the data, the end of the deployed bytecode can be checked
|
||||||
to match that pattern and use the Swarm hash to retrieve the file.
|
to match that pattern and use the Swarm hash to retrieve the file.
|
||||||
|
|
||||||
|
Whereas release builds of solc use a 3 byte encoding of the version as shown
|
||||||
|
above (one byte each for major, minor and patch version number), prerelease builds
|
||||||
|
will instead use a complete version string including commit hash and build date.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
The CBOR mapping can also contain other keys, so it is better to fully
|
The CBOR mapping can also contain other keys, so it is better to fully
|
||||||
decode the data instead of relying on it starting with ``0xa165``.
|
decode the data instead of relying on it starting with ``0xa265``.
|
||||||
For example, if any experimental features that affect code generation
|
For example, if any experimental features that affect code generation
|
||||||
are used, the mapping will also contain ``"experimental": true``.
|
are used, the mapping will also contain ``"experimental": true``.
|
||||||
Furthermore, we are planning to add the compiler version to the mapping
|
|
||||||
to ease source-verification and scanning for bugs.
|
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
The compiler currently uses the "swarm version 0" hash of the metadata,
|
The compiler currently uses the "swarm version 0" hash of the metadata,
|
||||||
but this might change in the future, so do not rely on this sequence
|
but this might change in the future, so do not rely on this sequence
|
||||||
to start with ``0xa1 0x65 'b' 'z' 'z' 'r' '0'``. We might also
|
to start with ``0xa2 0x65 'b' 'z' 'z' 'r' '0'``. We might also
|
||||||
add additional data to this CBOR structure, so the
|
add additional data to this CBOR structure, so the
|
||||||
best option is to use a proper CBOR parser.
|
best option is to use a proper CBOR parser.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user