Skip to content
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

[WIP] Add wrapper for BLS from Chia Network #72

Closed
wants to merge 8 commits into from

Conversation

mhchia
Copy link

@mhchia mhchia commented May 27, 2019

What was wrong?

Fixes #71. I will use "BLS chia" as the alias of Chia network's BLS implementation, along with its python bindings in the following paragraphs.

How was it fixed?

  • Implement functions sign, privtopub, verify, aggregate_signatures, aggregate_pubkeys, aggregate_multiple with BLS chia.
  • Copy and modify the related tests from tests/test_bls.py to tests/test_bls_chia.py and test with those functions.
  • Add a benchmark script scripts/benchmark_api.py, which is mostly inspired by Benchmark #69.

Problems

  • The private key range in BLS chia seems to be different from py_ecc. Its range is [1, 2**32 - 1]. Therefore I currently workaround it through adding all private keys with 1.
  • Sometimes signature aggregation throws RuntimeError: Caught an unknown exception! if the source signatures are initialized with blspy.Signature.from_bytes. This issue is really hard to debug since no further information is printed from the C++ side. Currently, I workaround it through adding a _sig_map: Dict[bytes, bls_chia.Signature] = {}, which memoizes all signatures generated through sign and aggregate_signatures, to avoid the issue resulting from Signature.from_bytes. Ref: Potential bug in Signature deserialization and aggregation using Python Chia-Network/bls-signatures#54

Example benchmark

Run number=100 times with timeit, with 20 keys and signatures aggregated. Need to further try the other parameters, and understand the meanings of the result.

# BLS chia
$ python py_ecc/scripts/benchmark_api.py bls_chia
Module py_ecc.bls_chia.api
privtopub: 0.012366111972369254
verify: 0.39142126898514107
aggregate_signatures: 2.8922514080186374
aggregate_pubkeys: 0.5968314119963907
verify_multiple: 4.292670964030549

# py_ecc itself
$ python py_ecc/scripts/benchmark_api.py bls
Module py_ecc.bls.api
privtopub: 1.719821373000741
verify: 121.40623104997212
aggregate_signatures: 31.77455569698941
aggregate_pubkeys: 1.140943904989399
verify_multiple: 763.4154342580005

To make use of the script with custom implementations:

  • Implement api.py with functions privtopub, verify, aggregate_signatures, aggregate_pubkeys, verify_multiple.
  • Put api.py under a package with your custom name, says "bls_another", under py_ecc, so py_ecc/bls_another/api.py.
  • Run python py_ecc/scripts/benchmark_api.py bls_another.

Cute Animal Picture

put a cute animal picture link inside the parentheses

@mhchia
Copy link
Author

mhchia commented May 27, 2019

CI fails due to the lack of CMake, but installing CMake and building result in much more time.(Though it can be mitigated with the cache in circle CI). I'm considering whether test_bls_chia.py should be added to the CI.

@ralexstokes
Copy link
Member

Worth thinking about experimenting w/ the code linked in #73

@mhchia
Copy link
Author

mhchia commented May 28, 2019

Agree! It looks pretty interesting. I think both C and pure Python worth our trying, too.

Making use of `InsecureSignature.aggregate`
Don't add 1 to the `private_key`. The range of private key should be (0,
curve_order - 1].
@mhchia
Copy link
Author

mhchia commented Jun 8, 2019

Moved to trinity in ethereum/trinity#708

@mhchia mhchia closed this Jun 8, 2019
pacrob pushed a commit to pacrob/py_ecc that referenced this pull request Oct 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrapper for BLS python bindings in Chia Network
2 participants