-
Notifications
You must be signed in to change notification settings - Fork 975
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use bls.Scalar
as the base class for BLSFieldElement
#3907
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like performance improvement!
I don't like exposing the bls.Scalar
type in the specs though as it implicitly brings in a dependency on some external library when the specs should be self-contained.
One way to handle this would be to leave the spec as-is and rebind the names to more efficient implementations when testing. We do this with the BLS implementation and should be able to do something similar here without it affecting the spec itself.
Ideally I'd prefer to use an audited backend, I don't know if arkworks was cc @Pratyush |
To be fair, neither We've been using arkworks as the backend for MSMs, pairing checks, multi_exp, etc for a while too: consensus-specs/tests/core/pyspec/eth2spec/utils/bls.py Lines 87 to 92 in 2b4d94a
|
Hmm, is it possible to make this change a bit less wide? I feel like the removal of those types and functions affect both the readability of the spec (types are nice) and of the libraries who might be using those types (and now they will be dangling). Would the performance remain bad if we just typedefed Finally, just curious: what improvement does this do to the test execution time? |
Where would this typedef exist? It cannot go in the "custom types" table because it is not an SSZ type. Would we make typedefs for the other deleted types too? Would those go in the same place?
Hard to tell exactly, but locally it was 3x faster. To know for sure, we need to push a new curdleproofs release to fix CI tests. |
yeah, after looking at this some I think the better way to do this is with the it looks like we will need to extend the code to handle type substitutions (where you can swap and if the other functions are need to be updated for the performance improvements we can use the another caveat is that we will likely want a way to run both versions of the spec (as-is, and with the optimizations) so will want some way to generate both via the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love the significant performance improvement! 👍
The scope of this change looks fine to me since the polynomial-commitment docs are for crypto libs only.
I think this is a good point. We can treat |
BLSFieldElement
with bls.Scalar
bls.Scalar
as the base class for BLSFieldElement
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a plausible approach. IMO spec readability is still slightly decreased, but I think it's now at reasonable areas of the tradeoff space.
I left some comments as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks a lot!
The goal of this PR is to simplify the spec and speed up test execution. One semi-easy way to do this is to use the
arkworks_Scalar
type instead of theremerkleable:uint
type as the underlying type forBLSFieldElement
. The arkworks type is much faster and provides useful helper methods which improve spec readability. Tested locally, this PR resulted in a 300% performance improvement for KZG operations. These changes only affect internal code and not any of the public API methods; those still take bytes and convert to internal types. This PR makes the following notable changes:py_arkworks_bls12381
to get the updatedScalar
type.u128
now.BLSFieldElement
,Polynomial
,PolynomialCoeff
,Coset
,CosetEvals
.bls_modular_inverse
anddiv
.Scalar::inverse
and/
now.eip7594
to the list of executable specs and fix pylint errors.py_ecc_Scalar
class which can be used instead ofarkworks_Scalar
.