Rust API for BLS signatures and EVM precompiles #387
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
And here we are finally for the first part of the Rust API, namely BLS signatures.
This is still a draft, because there's again a few questions about how this should ideally be wrapped. Currently the code simply uses type aliases similar to the Go API. This is "fine", but leads to the user having to write code like:
which imo is rather ugly.
2 alternatives come to mind:
deserialize_*_compressed
(and friends) return the deserialized type directly. That way we can hide theunsafe
code in the fake constructor.deserialize
) and we shouldn't suffer from copies, because we can of course just pass the pointers of the underlying object to C.Another point:
Funnily (or ironically), while we can nicely turn the nested messages in
batch_verify
etc. into a bunch ofCttSpan
s, we still have to make a copy of the data due to Rusts extreme stance on pointer mutability. Given that themessages
argument is just a reference (wouldn't make sense to force it to be&mut
), we are not allowed to turn them into aCttSpan
(orctt_span
to be exact), because it is defined as having abyte*
field and not aconst byte*
field. I'm a bit perplexed that we cannot even cast an immutable to a mutable pointer inside of anunsafe
block. At least that's my understanding so far.I'm not sure if we want to restrict us so far as to have the
ctt_span
have aconst byte*
field, because there should be valid reasons to use the type for mutation as well? We could of course have actt_span_const
, but that's also a bit ridiculous.Anyway, while the tests are not pretty due to so much error checking and
MaybeUninit
work, at least they all pass.