Skip to content

Cannot link unqualified library names via Standard JSON #12145

Open
@cameel

Description

@cameel

Description

In Standard JSON library addresses for linking require providing a source unit name and a library name as two separate components. For linking, these two parts are joined with a colon so even if the source unit name is empty, the colon is there.

This is different from the CLI where you can provide both L and :L in the --libraries option and for the former will let you match a reference without a colon.

I don't see a good way to support unqualified library names in the current Standard JSON structure so maybe we should just disallow unqualified library names in linkersymbol(). This would be a breaking change though.

Environment

  • Compiler version: 0.8.9 (develop)

Steps to Reproduce

input.json:

{
    "language": "Yul",
    "sources": {
        "contract.sol": {"content": "{ sstore(0, linkersymbol(\"L\")) }"}
    },
    "settings": {
        "outputSelection": {"*": {"*": ["evm.bytecode"]}},
        "libraries": {
            "": {
                "L": "0x1234567890123456789012345678901234567890"
            }
        }
    }
}
solc --json-indent 4 --standard-json input.json

Output:

{
    "contracts":
    {
        "contract.sol":
        {
            "object":
            {
                "evm":
                {
                    "bytecode":
                    {
                        "functionDebugData": {},
                        "generatedSources": [],
                        "linkReferences":
                        {
                            "":
                            {
                                "L":
                                [
                                    {
                                        "length": 20,
                                        "start": 1
                                    }
                                ]
                            }
                        },
                        "object": "73__$8aa64f937099b65a4febc243a5ae0f2d64$__600055",
                        "opcodes": "PUSH20 0x0 PUSH1 0x0 SSTORE ",
                        "sourceMap": "12:17:0:-:0;9:1;2:28"
                    }
                }
            }
        }
    }
}

If you change linkersymbol("L")) in the input to linkersymbol(":L")), the unlinked reference disappears.

Metadata

Metadata

Assignees

No one assigned

    Labels

    breaking change ⚠️bug 🐛low effortThere is not much implementation work to be done. The task is very easy or tiny.low impactChanges are not very noticeable or potential benefits are limited.needs designThe proposal is too vague to be implemented right awaynice to haveWe don’t see a good reason not to have it but won’t go out of our way to implement it.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions