Skip to content

build: strip CBOR metadata footer for deterministic bytecode#106

Merged
Stumble merged 1 commit into
mainfrom
yxia/foundry-bytecode-hash-none
May 19, 2026
Merged

build: strip CBOR metadata footer for deterministic bytecode#106
Stumble merged 1 commit into
mainfrom
yxia/foundry-bytecode-hash-none

Conversation

@Stumble

@Stumble Stumble commented May 19, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Set bytecode_hash = "none" in foundry.toml so emitted bytecode no longer carries the appended CBOR metadata block (IPFS source hash + solc version marker).
  • The solc = "0.8.30" pin above is what actually fixes the compiler version; the in-bytecode version marker is just an artifact.

Why

The IPFS hash in the CBOR footer is computed over a metadata JSON that includes source-file paths, dependency layout, and remapping serialization. The same source produced different bytes across clones / node_modules layouts / machines, which polluted downstream consumers (most visibly: gravity_chain_core_contractsgravity-mainnet-gitops/genesis.json regenerations would diff by hundreds of lines without any runtime behavior changing — see PR #110 on the gitops side for the empirical diagnosis).

This change makes builds deterministic across clones, dependency layouts, OSes, and absolute-path differences.

What this changes

  • Each compiled contract's deployed bytecode shrinks by ~53 bytes (the stripped CBOR footer).
  • Genesis-baked contracts will be byte-identical across regenerations from the same source.
  • The compiler version pin in foundry.toml (solc = "0.8.30") is now the sole record of which solc was used.

What this trades away

  • Block-explorer source-verification flows lose the IPFS source-hash marker. For chain-genesis contracts (baked in at genesis, never redeployed at runtime) this is standard practice and matches what Uniswap, OpenZeppelin libraries, and similar deterministic-build projects do.

Test plan

  • forge clean && forge build succeeds.
  • Inspect one out/**/*.json artifact and confirm deployedBytecode.object no longer ends with the a26469706673...64736f6c63...0033 CBOR footer.
  • Re-run twice from clean clones in different paths; confirm artifacts hash identically.
  • Downstream: re-run gravity-sdk/cluster/genesis.sh against this ref twice from scratch and confirm genesis.json is byte-identical both times.

🤖 Generated with Claude Code

Set `bytecode_hash = "none"` in foundry.toml so emitted bytecode no
longer contains the appended CBOR metadata block (IPFS source hash +
solc version marker). The IPFS hash covers source paths and dependency
layout, so the same source produced different bytes across clones —
this churn polluted genesis.json regenerations without changing any
runtime behavior.

The `solc = "0.8.30"` pin above is what actually fixes the compiler
version; the in-bytecode version marker was redundant artifact.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

@Richard1048576 Richard1048576 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Stumble
Stumble merged commit ed3284e into main May 19, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants