ethereum / c-kzg-4844

A minimal implementation of the Polynomial Commitments API for EIP-4844 and EIP-7594, written in C.
Apache License 2.0
118 stars 109 forks source link

Rust runtime bindings take 2 #376

Closed pawanjay176 closed 1 year ago

pawanjay176 commented 1 year ago

This is a version of what Sean described in https://github.com/ethereum/c-kzg-4844/pull/363#issuecomment-1749509149

The changes are the following:

  1. Make all kzg interface functions methods on the KzgSettings struct
  2. In the public interface, the Blob argument is just a byte slice
  3. Make Blob a private type which contains a byte slice. The Blob constructor does the length check and returns an error if it doesn't equal self.bytes_per_blob()
  4. Have internal functions which accept a length validatedBlob call the underlying FFI functions.

Some advantages to this approach:

  1. No generics
  2. Blob being just a byte slice in the public interface means that users of the library can store the Blobs in whatever container they want and don't have to do conversions before passing it to the library
  3. All kzg functions being methods on KzgSettings is advantageous because we do the blob length validations w.r.t a given trusted setup
  4. A Blob passed to the internal functions would be valid w.r.t the passed KzgSettings so there's less scope of shooting ourselves in the foot for any future changes.

Curious to see what you guys think @Rjected @asn-d6 @jtraglia cc @realbigsean