Skip to content

Commit

Permalink
feat: add NIF to use KZG functions (#780)
Browse files Browse the repository at this point in the history
Co-authored-by: Tomás Grüner <[email protected]>
  • Loading branch information
Godspower-Eze and MegaRedHand authored Mar 6, 2024
1 parent f3d6067 commit dccee9d
Show file tree
Hide file tree
Showing 8 changed files with 4,800 additions and 0 deletions.
50 changes: 50 additions & 0 deletions lib/kzg.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
defmodule Kzg do
@moduledoc """
KZG functions
"""
use Rustler, otp_app: :lambda_ethereum_consensus, crate: "kzg_nif"

@spec blob_to_kzg_commitment(Types.blob()) :: {:ok, Types.kzg_commitment()} | {:error, binary()}
def blob_to_kzg_commitment(_blob) do
:erlang.nif_error(:nif_not_loaded)
end

@spec compute_kzg_proof(Types.blob(), Types.bytes32()) ::
{:ok, {Types.kzg_proof(), Types.bytes32()}} | {:error, binary()}
def compute_kzg_proof(_blob, _z) do
:erlang.nif_error(:nif_not_loaded)
end

@spec verify_kzg_proof(
Types.kzg_commitment(),
Types.bytes32(),
Types.bytes32(),
Types.kzg_proof()
) ::
{:ok, boolean} | {:error, binary()}
def verify_kzg_proof(_kzg_commitment, _z, _y, _kzg_proof) do
:erlang.nif_error(:nif_not_loaded)
end

@spec compute_blob_kzg_proof(Types.blob(), Types.kzg_commitment()) ::
{:ok, Types.kzg_proof()} | {:error, binary()}
def compute_blob_kzg_proof(_blob, _kzg_commitment) do
:erlang.nif_error(:nif_not_loaded)
end

@spec verify_blob_kzg_proof(Types.blob(), Types.kzg_commitment(), Types.kzg_proof()) ::
{:ok, boolean} | {:error, binary()}
def verify_blob_kzg_proof(_blob, _kzg_commitment, _kzg_proof) do
:erlang.nif_error(:nif_not_loaded)
end

@spec verify_blob_kzg_proof_batch(
list(Types.blob()),
list(Types.kzg_commitment()),
list(Types.kzg_proof())
) ::
{:ok, boolean} | {:error, binary()}
def verify_blob_kzg_proof_batch(_blobs, _kzg_commitments, _kzg_proofs) do
:erlang.nif_error(:nif_not_loaded)
end
end
5 changes: 5 additions & 0 deletions native/kzg_nif/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[target.'cfg(target_os = "macos")']
rustflags = [
"-C", "link-arg=-undefined",
"-C", "link-arg=dynamic_lookup",
]
1 change: 1 addition & 0 deletions native/kzg_nif/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
268 changes: 268 additions & 0 deletions native/kzg_nif/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions native/kzg_nif/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "kzg_nif"
version = "0.1.0"
edition = "2021"

[lib]
name = "kzg_nif"
path = "src/lib.rs"
crate-type = ["cdylib"]

[dependencies]
rustler = "0.31.0"
c-kzg = "0.4.2"
Loading

0 comments on commit dccee9d

Please sign in to comment.