Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP use two copies of c-kzg #4276

Closed

Conversation

michaelsproul
Copy link
Member

@michaelsproul michaelsproul commented May 9, 2023

Proposed Changes

This uses some nasty hacks on my fork of c-kzg to enable two copies of the library to be linked: one with the mainnet spec, and one with the minimal spec. We can then select between them at runtime.

The main complication is that the C library wants to use the same symbol names for both libraries, which is worked around by:

  • Using a different name for the resulting library (ckzgmin vs ckzg).
  • Using objcopy to rename the public symbols when the minimal spec is enabled. A ckzgmin_ prefix is added.
  • Using some regexes to modify the c_kzg_4844.h header so that the function stub names match the renamed symbols in the object file.
  • Using some Rust import directives to rename the ckzgmin_ prefixed names back to the names without prefixes, so that the hand-written code that references them remains correct regardless of minimal/mainnet spec usage.

See the trusted_setup_minimal.rs for a basic test that shows the two libraries working independently (deserializing the minimal JSON into the mainnet JSON or vice versa will fail).

TODO

If we decide to take this approach:

  • The crypto/kzg library has to be thoroughly refactored to use type-level selection between minimal and mainnet specs. Like EthSpec, but probably not EthSpec due to the circular dependency.
  • We would need a version of objcopy that works cross-platform. Maybe cargo-binutils.
  • There might be some other stuff that's broken. I wasn't quite sure if I needed to rename the internal symbols or remove them with something like --discard-all.

@michaelsproul
Copy link
Member Author

Closing in favour of ethereum/c-kzg-4844#312

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant