Q&A-2Review a production compiler configuration.
Answer
What a strong candidate says first
A compiler configuration review is a reproducibility review with a safety check bolted on. The deliverable is one sentence: given the pinned source, can I rebuild the exact deployed bytecode, and is that bytecode within limits and free of known compiler bugs? Everything else is detail.
So I start from the deployed artifact, not the repo. I pull the runtime bytecode, read the CBOR metadata appended to its tail, and reconstruct the build from what that metadata commits to: compiler version, EVM version, optimizer settings, source hashes. Then I rebuild and diff byte-for-byte. If the diff is empty, the configuration is reproducible; if it isn't, I have a source-mismatch finding before I've read a single line of Solidity.
The settings that decide the bytecode
| setting | default | what it changes |
|---|---|---|
solc version | none: must be pinned | opcodes emitted, exposure to known bugs |
evmVersion | tracks solc (0.8.20 → shanghai, 0.8.25 → cancun) | which opcodes are legal: PUSH0, MCOPY, TSTORE |
optimizer.enabled | false | gas and size |
optimizer.runs | 200 when enabled | per-call gas vs. deployed size |
viaIR | false | codegen path; different bytecode entirely |
metadata.bytecodeHash | ipfs | appends a hash; changes the CREATE2 address |
debug.revertStrings | default | revert-data size |
# foundry.toml — pinned and checked in
[profile.default]
solc = "0.8.25" # exact, not ^0.8.25
evm_version = "cancun"
optimizer = true
optimizer_runs = 200
via_ir = false
bytecode_hash = "ipfs"The trade-off I have to decide
optimizer.runs is the optimizer's guess at how often each function is called over the contract's life. High runs spend more effort on hot paths: cheaper calls, bigger bytecode. Low runs: smaller bytecode, cheaper deploy, more expensive calls. The default 200 leans toward deployment cost. The deciding criterion is call frequency against the EIP-170 ceiling of 24576 bytes of runtime code.
Hypothetical, but the shape is real: at runs = 200 a contract compiles to 22 KB and a swap costs 45k gas; at runs = 10000 it compiles to 26 KB (over the limit, deployment reverts) and the swap costs 43k. So for a contract called millions of times I raise runs and claw back size elsewhere; for a one-shot deploy near the ceiling I drop runs. viaIR is the other lever, but it changes codegen and compile time, so I only reach for it deliberately.
Failure modes and how I catch each
- Unsupported opcode.
evmVersionnewer than the target chain's hardfork. Symptom: deploy or call reverts on that chain only. Detection: compareevmVersionagainst the target's hardfork. PUSH0 on a pre-Shanghai L2 is the classic miss. - Optimizer bug. Version-specific. Detection: check the pinned version against the Solidity known-bugs list at soliditylang.org/bugs and read the compiler's own warnings.
- Source mismatch. Verified source doesn't reproduce the deployed bytecode. Detection: rebuild and diff; a metadata-hash mismatch is the tell.
- Size limit. Runtime bytecode over 24576 bytes. Detection:
forge build --sizes, or measureeth_getCodelength. - Gas regression. A settings change raises call cost. Detection: gas-snapshot diff in CI.
- Local-CI divergence. Different solc binary or version locally vs. CI. Detection: pin the exact version in both and compare bytecode hashes.
- Debug build. Optimizer off, or
revertStrings: debugshipped. Detection: metadata shows the optimizer disabled, and revert strings are present in the runtime code.
How I run it
Fetch deployed bytecode and extract metadata; rebuild from pinned source and settings; diff byte-for-byte; check size and the known-bugs list; record the settings hash alongside the release. The configuration is part of the reviewed executable artifact, so it ships with the same sign-off as the source.
Curated: · Written: · Reviewed:
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.