-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add NIF to use KZG functions (#780)
Co-authored-by: Tomás Grüner <[email protected]>
- Loading branch information
1 parent
f3d6067
commit dccee9d
Showing
8 changed files
with
4,800 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/target |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
Oops, something went wrong.