README.md

# KzgElixir

Elixir NIF bindings for the [c-kzg-4844](https://github.com/ethereum/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-essential` or equivalent

### Submodules

This library relies on `c-kzg-4844` and `blst` as git submodules. You must initialize them:

```bash
git submodule update --init --recursive
```

## Installation

Add `kzg_elixir` to your list of dependencies in `mix.exs`:

```elixir
def deps do
  [
    {:kzg_elixir, "~> 2.1.5"}
  ]
end
```

## Usage

### 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`).

```elixir
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.

```elixir
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)}")
end
```

## Development

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.

```bash
mix deps.get
mix compile
mix test
```