KzgElixir
Elixir NIF bindings for the c-kzg-4844 library, providing KZG trusted setup verification for Ethereum EIP-4844 (Proto-Danksharding).
Prerequisites
You need a C compiler (gcc or clang) and make installed on your system to build the NIF.
- macOS:
xcode-select --install - Linux:
apt-get install build-essentialor equivalent
Submodules
This library relies on c-kzg-4844 and blst as git submodules. You must initialize them:
git submodule update --init --recursiveInstallation
Add kzg_elixir to your list of dependencies in mix.exs:
def deps do
[
{:kzg_elixir, "~> 2.1.5"}
]
endUsage
1. Load Trusted Setup
Before performing any KZG operations, you must load the trusted setup configuration. This is usually provided as a file (e.g., trusted_setup_4096.txt).
path = "path/to/trusted_setup.txt"
:ok = KzgElixir.load_trusted_setup(path)2. Verify Blob KZG Proof
Verify that a blob matches a given KZG commitment and proof.
blob = <<...>> # 131072 bytes
commitment = <<...>> # 48 bytes
proof = <<...>> # 48 bytes
case KzgElixir.verify_blob_kzg_proof(blob, commitment, proof) do
{:ok, true} -> IO.puts("Valid!")
{:ok, false} -> IO.puts("Invalid!")
{:error, reason} -> IO.puts("Error: #{inspect(reason)}")
endDevelopment
The C sources for c-kzg-4844 and blst are bundled in c_src. The Makefile handles the compilation of the static libraries and links them into the NIF.
mix deps.get
mix compile
mix test