Expose sub-structure of bytecode
- Dominant language
- C++
- Stars
- 25.7k
- Forks
- 6.2k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 21
Description
### Current specification
[Bytecode Structure Output](https://notes.argot.org/@solidity-bytecode-structure-output)
Read the spec for full detail. Here I'll include only the example which well illustrates the end state of the `--bin-structure` output that we want to achieve:
```json
{
"contract": "C.sol:C",
"object": "A",
"creation": true,
"start": 0,
"length": 281,
"code": {
"start": 0,
"length": 72
},
"assemblies": [
{
"object": "AA",
"creation": false,
"start": 72,
"length": 165,
"code": {
"start": 72,
"length": 112,
"immutableReferences": {
"x": [
{
"name": "some_immutable",
"start": 94,
"length": 32
},
{
"name": "some_immutable",
"start": 128,
"length": 32
}
]
},
"linkReferences": {
"L.sol": {
"L": [
{
"start": 73,
"length": 20
},
{
"start": 161,
"length": 20
}
]
}
}
},
"metadata": {
"start": 184,
"length": 53
}
},
{
"contract": "D.sol:D",
"object": "AB",
"creation": false,
"start": 237,
"length": 8,
"code": {
"start": 237,
"length": 8
}
},
{
"object": "AAA",
"creation": false,
"start": 245,
"length": 8,
"code": {
"start": 245,
"length": 8
}
}
],
"data": [
{
"name": "number",
"id": "01aec967ba5d2a807edd3fd8942c6f72c0c62961bfeb10c1f79c756f7294b0e3",
"start": 253,
"length": 16
},
{
"name": "text",
"id": "ba89b09a32fea8c9d831e7d39b3ab27821c445fc505e8e0e7dd4a68b1b8b6b00",
"start": 269,
"length": 12
}
]
}
```
---
### Old description
@alcuadrado and others proposed to expose the boundary between code and data in the emitted bytecode ( https://www.notion.so/Miscellaneous-debugging-symbols-Initial-proposal-2948f1a1f74742c0901ad54af05fa1ff ). I think this is a good idea, but we should not stop at only that number.
In essence, we have code, sub-objects (runtime code of the current contract or creation code of created contracts), data and metadata. This structure also matches what we have when we compile Yul objects, so I think a common data format can be found here.
Proposal:
Export an array of sections, each section is a json object of the following form:
```
{
start: x, // bytes
length: n, // bytes
kind: 'code' / 'data' / 'object' / 'deployObject' / 'metadata',
name: 'factory.sol:Factory'
]
```
Contributor guide
Research direction
Start by reading the linked Bytecode Structure Output specification and reviewing the existing --bin-structure behavior described in the issue. No source file or test is identified in the payload; done means exposing the specified nested bytecode structure, including objects, code, data, metadata, immutable references, and link references, in the output format shown.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, solidity
- Domain
- blockchain, compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100