Skip to content

feat(contracts): deploy each Honk library once per distinct bytecode - #42

Merged
xgreenx merged 3 commits into
mainfrom
feat/shared-honk-libraries
Sep 14, 2026
Merged

xgreenx merged 3 commits into
mainfrom
feat/shared-honk-libraries

Conversation

@xgreenx

@xgreenx xgreenx commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

RelationsLib and ZKTranscriptLib compile to identical bytecode in both verifier files, yet each circuit deployed its own copy: ~15.8 KB paid twice.

Changes

  • deploy::Libraries groups link references by the hash of the library's creation code and deploys each distinct hash once; every file whose copy has that hash links the one address. No version, no list.
  • Libraries land through the CREATE2 deployer under an empty salt, so the address is library_address(creation_code); a re-run finds code there and sends nothing.
  • circuits::deploy_honk_verifiers(provider, artifacts, &Circuit::ALL, sender) deploys a set and returns HonkVerifiers { verifiers, libraries }. deploy_honk_verifier still works alone.
  • Libraries::link returns linked creation code without deploying (factory deploys).
  • The circuits.rs doc no longer claims the libraries are unshared.
  • Anvil: both circuits in 4 transactions (was 6), 2 library deployments, each verifier's code carries the shared addresses, Initializer hash equals keccak256(code), logN differs.
  • LinkFixture.sol links same-named libraries compiled from other code; read from forge out/, its pair deploys beside the circuits' pair.

Verified

  • forge test 482 passed; lint and fmt clean.
  • nightly fmt, clippy, cargo test --all with anvil: 14 unit + 7 anvil pass; cargo doc clean.

Not verified / known issues

  • Keyed by creation code, not runtime code: it is the CREATE2 preimage, and equal creation code is equal runtime code.
  • chain-configurations builds on a pin bump; to share it must replace link_creation_code with Libraries::deploy + link.
  • A chain without the CREATE2 deployer gets it installed.

bb writes RelationsLib and ZKTranscriptLib into every verifier it generates
and forge links each verifier only against its own file's copy, so the two
circuits paid for two identical deployments. Libraries groups link
references by the hash of the library's creation code and deploys each
distinct hash once, through the CREATE2 deployer at an address derived from
that hash, so a library already on the chain is found and linked rather
than deployed again. deploy_honk_verifiers takes a set; deploy_honk_verifier
still works alone. Both circuits: four transactions, was six.

Assisted-by: Claude Fable 5.1
Signed-off-by: xgreenx <xgreenx9999@gmail.com>
The vendored verifiers' libraries are identical today, so they can only show
the sharing half of the rule. LinkFixture.sol links libraries under the same
two names compiled from other code; the anvil test reads it from forge's
out/ and shows its pair deployed beside the circuits' pair, not shared.

Assisted-by: Claude Fable 5.1
Signed-off-by: xgreenx <xgreenx9999@gmail.com>
Assisted-by: Claude Fable 5.1
Signed-off-by: xgreenx <xgreenx9999@gmail.com>
@xgreenx
xgreenx merged commit ce15d3d into main Sep 14, 2026
11 checks passed
@xgreenx xgreenx mentioned this pull request Sep 14, 2026
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.

1 participant