-
Notifications
You must be signed in to change notification settings - Fork 983
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
Test generators for kzg-4844 libraries #3274
Conversation
Great work! Some installation errors: Linux (CircleCI)Operating System: Ubuntu 20.04.5 LTS
macOSCPU: M1 pro
IIUC, milagro_bls_binding also uses @kevaundray could you make |
@kevaundray do you have some py-ecc v.s. arkworks benchmarks of the pairing? Once we make CircleCI pass, we can try to see if this PR also makes #3255 CircleCI pass. |
@hwwhww I will prepare benchmark numbers + a script to verify and make the modifications that you mentioned above :) |
Ran benchmarks on my laptop MacBook Pro M1. ReproduceTo reproduce from source, you can do the following:
To reproduce from pypi:
Py-ecc benchmarks
Arkworks benchmarks
Notespairings vs pairingsGen I store the points in Projective coordinates, but arkworks requires pairing input to be in Affine coordinates. This will incur a cost. pairingsGen is just the generators being used to which arkworks can optimise as the conversion from Projective to Affine since z=1. pairingsGen will replace one of the pairings with two points which don't have z=1, to see if there is a noticeable cost. MultiExp Having a multi-exponentation algorithm is quite common for ECC libraries so py-arkworks also exposes this. It uses pippenger so would be alot faster than g1_lincomb. We won't be able to use it in the specs but it may be useful for test generation in the future |
@kevaundray Thank you! CircleCI (Linux) installation succeeds now. But for macOS, I only see Python 3.10 and Python 3.11 distributions:
Any chance you could also upload CPython 3.8 and 3.9 support? Python3.8 is the minimum requirement of eth2spec. I guess it's still early for PyPy+macOS+arm64 distribution so you can skip it for now. (Also, PyPy only provides 3.8 and 3.9 support and started to support M1 last year. 🥲) I managed to install it with a CPython 3.10 env on the same machine. The test case that used to take me |
@hwwhww I've pushed a 0.3.3 which now uses 3.8 :) |
@hwwhww if tests are generated using py-arkworks specifically and not via the bls interface, we can probably reduce the six seconds further via py-arkworks specific functions! |
@kevaundray Great! FYI, just to record my troubleshooting for PyPy, I did something like what I needed for milagro binding:
The same test case I mentioned (~30s with py-ecc) is now only |
@@ -0,0 +1,288 @@ | |||
""" |
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.
Should this file be split into many files, like one file per one kzg-4844 function? I think doing it similarly to the one in https://github.com/ethereum/consensus-specs/tree/dev/tests/generators/ssz_generic is more organized.
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.
No strong opinion on this one. @hwwhww what would you prefer? I copied from the bls generators which seem to have this structure
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 slightly prefer separate files, but I can see there are some shared helpers/constants. ~500 lines look acceptable so far, but if you expect to extend the test cases, refactoring them early seems better.
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.
Decided on the call today to leave for now and split when the file becomes too large.
Co-authored-by: Hsiao-Wei Wang <hsiaowei.eth@gmail.com>
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.
There are two minor typos that need to be fixed here:
|
||
## Condition | ||
|
||
The `verify_blob_kzg_proof` handler should verify that `commitment` is a correct KZG commitment to `blob` by using the blob KZG proof `proof`, and the result should match the expected `output`. If the commitment or proof are invalid (e.g. not on the curve or not in the G1 subgroup of the BLS curve) or `blob` is invalid (e.g. incorrect length or one of the 32 byte blocks does not represent a BLS field element), it should error, i.e. the output should be `None`. |
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.
If the commitment or proof is invalid (e.g. not on the curve or not in the G1 subgroup of the BLS curve) or
blob
is invalid (e.g. incorrect length or one of the 32-byte blocks does not represent a BLS field element), it should error, i.e. the output should benull
.
Note that it's not as same as the pyspec BLS signature verify_*
methods: in BLS signature API implementation, we catch the exception and return False
.
I'm not suggesting adding error handling in polynomial-commitments.md
, I think that's too Pythonic. Just note that the clients have to deal with the error handling themselves.
btw, does c-kzg
also throw exceptions in these cases? /cc @jtraglia
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'm not entirely sure what cases you're referring to, but the C library in c-kzg-4844
will return C_KZG_BADARGS
if given invalid inputs. Generally, the bindings will throw an exception if the library doesn't return C_KZG_OK
(success).
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.
For example, the case that the input is in the correct length but doesn't pass the subgroup check. I suppose it's not C_KZG_OK
there so will throw an exception?
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.
Yes, the bindings will throw an exception. For example:
So either there's something wrong with the tests or something wrong with ckzg. When tested against ckzg, there are failures in
All of the test cases for the other functions pass. |
Co-authored-by: Hsiao-Wei Wang <hsiaowei.eth@gmail.com>
Co-authored-by: Hsiao-Wei Wang <hsiaowei.eth@gmail.com>
Co-authored-by: Hsiao-Wei Wang <hsiaowei.eth@gmail.com>
Co-authored-by: Hsiao-Wei Wang <hsiaowei.eth@gmail.com>
Co-authored-by: Hsiao-Wei Wang <hsiaowei.eth@gmail.com>
Co-authored-by: Hsiao-Wei Wang <hsiaowei.eth@gmail.com>
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 it's fine to merge it now and then @kevaundray can add more bls.py
fixes later. Please use squash and merge for the 45 commits. 🙏
But also see @jtraglia pointed out that the new test vector found inconsistency between pyspec or c-kzg, should we address that in this PR? (or the issue may be in c-kzg?)
Seems like a bug was found -- ckzg was not following the spec! See ethereum/c-kzg-4844#168 for a fix! With that PR I'm not getting the errors above anymore (using the python bindings). |
That was a c
that was a c-kzg bug after all! |
Based on #3272.
Tests to be written for
compute_kzg_proof
verify_blob_kzg_proof
verify_blob_kzg_proof_batch
blob_to_kzg_commitment
verify_kzg_proof
compute_blob_kzg_proof