1use libc::FILE;
4
5pub const BYTES_PER_COMMITMENT: usize = 48;
6pub const BYTES_PER_PROOF: usize = 48;
7pub const BYTES_PER_FIELD_ELEMENT: usize = 32;
8pub const FIELD_ELEMENTS_PER_BLOB: usize = 4096;
9pub const BYTES_PER_BLOB: usize = 131072;
10pub type limb_t = u64;
11#[repr(C)]
12#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
13pub struct blst_fr {
14 l: [limb_t; 4usize],
15}
16#[repr(C)]
17#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
18pub struct blst_fp {
19 l: [limb_t; 6usize],
20}
21#[repr(C)]
22#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
23pub struct blst_fp2 {
24 fp: [blst_fp; 2usize],
25}
26#[repr(C)]
27#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
28pub struct blst_p1 {
29 x: blst_fp,
30 y: blst_fp,
31 z: blst_fp,
32}
33#[repr(C)]
34#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
35pub struct blst_p2 {
36 x: blst_fp2,
37 y: blst_fp2,
38 z: blst_fp2,
39}
40pub type g1_t = blst_p1;
41pub type g2_t = blst_p2;
42pub type fr_t = blst_fr;
43#[doc = " An array of 32 bytes. Represents an untrusted\n (potentially invalid) field element."]
44#[repr(C)]
45#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
46pub struct Bytes32 {
47 bytes: [u8; 32usize],
48}
49#[doc = " An array of 48 bytes. Represents an untrusted\n (potentially invalid) commitment/proof."]
50#[repr(C)]
51#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
52pub struct Bytes48 {
53 bytes: [u8; 48usize],
54}
55#[doc = " A basic blob data."]
56#[repr(C)]
57#[derive(Debug, Hash, PartialEq, Eq)]
58pub struct Blob {
59 bytes: [u8; 131072usize],
60}
61#[repr(C)]
62#[doc = " The common return type for all routines in which something can go wrong."]
63#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
64pub enum C_KZG_RET {
65 #[doc = "< Success!"]
66 C_KZG_OK = 0,
67 #[doc = "< The supplied data is invalid in some way."]
68 C_KZG_BADARGS = 1,
69 #[doc = "< Internal error - this should never occur."]
70 C_KZG_ERROR = 2,
71 #[doc = "< Could not allocate memory."]
72 C_KZG_MALLOC = 3,
73}
74#[doc = " Stores the setup and parameters needed for computing KZG proofs."]
75#[repr(C)]
76#[derive(Debug, Hash, PartialEq, Eq)]
77pub struct KZGSettings {
78 #[doc = " The length of `roots_of_unity`, a power of 2."]
79 max_width: u64,
80 #[doc = " Powers of the primitive root of unity determined by\n `SCALE2_ROOT_OF_UNITY` in bit-reversal permutation order,\n length `max_width`."]
81 roots_of_unity: *mut fr_t,
82 #[doc = " G1 group elements from the trusted setup,\n in Lagrange form bit-reversal permutation."]
83 g1_values: *mut g1_t,
84 #[doc = " G2 group elements from the trusted setup."]
85 g2_values: *mut g2_t,
86}
87extern "C" {
88 pub fn load_trusted_setup(
89 out: *mut KZGSettings,
90 g1_bytes: *const u8,
91 n1: usize,
92 g2_bytes: *const u8,
93 n2: usize,
94 ) -> C_KZG_RET;
95 pub fn load_trusted_setup_file(out: *mut KZGSettings, in_: *mut FILE) -> C_KZG_RET;
96 pub fn free_trusted_setup(s: *mut KZGSettings);
97 pub fn blob_to_kzg_commitment(
98 out: *mut KZGCommitment,
99 blob: *const Blob,
100 s: *const KZGSettings,
101 ) -> C_KZG_RET;
102 pub fn compute_kzg_proof(
103 proof_out: *mut KZGProof,
104 y_out: *mut Bytes32,
105 blob: *const Blob,
106 z_bytes: *const Bytes32,
107 s: *const KZGSettings,
108 ) -> C_KZG_RET;
109 pub fn compute_blob_kzg_proof(
110 out: *mut KZGProof,
111 blob: *const Blob,
112 commitment_bytes: *const Bytes48,
113 s: *const KZGSettings,
114 ) -> C_KZG_RET;
115 pub fn verify_kzg_proof(
116 ok: *mut bool,
117 commitment_bytes: *const Bytes48,
118 z_bytes: *const Bytes32,
119 y_bytes: *const Bytes32,
120 proof_bytes: *const Bytes48,
121 s: *const KZGSettings,
122 ) -> C_KZG_RET;
123 pub fn verify_blob_kzg_proof(
124 ok: *mut bool,
125 blob: *const Blob,
126 commitment_bytes: *const Bytes48,
127 proof_bytes: *const Bytes48,
128 s: *const KZGSettings,
129 ) -> C_KZG_RET;
130 pub fn verify_blob_kzg_proof_batch(
131 ok: *mut bool,
132 blobs: *const Blob,
133 commitments_bytes: *const Bytes48,
134 proofs_bytes: *const Bytes48,
135 n: usize,
136 s: *const KZGSettings,
137 ) -> C_KZG_RET;
138}