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

from_bytes_unchecked() #321

Merged
merged 2 commits into from
Dec 4, 2023
Merged

from_bytes_unchecked() #321

merged 2 commits into from
Dec 4, 2023

Conversation

arvidn
Copy link
Contributor

@arvidn arvidn commented Nov 25, 2023

This extends the Streamable trait to support unchecked parsing. This is especially useful for parsing trusted BLS public keys and signatures. In unchecked mode the points are not verified to be on the G1 and G2 curves (because they are trusted to be).

change

The main change is adding a new parameter to the Streamable trait's parse() function, indicating whether we want checked or unchecked parsing.

Additionally, a new convenience function is added from_bytes_unchecked(), as short-hand for just converting a buffer. This follows the naming convention we already use in chia-blockchain, and supersedes some existing python bindings for from_bytes_unchecked() on the BLS types.

profile

The first commit adds a benchmark, highlighting how much time is saved when not checking the validity of points:

parse Signature         time:   [70.305 µs 70.518 µs 70.770 µs]
parse PublicKey         time:   [52.534 µs 52.647 µs 52.770 µs]
parse Signature (unchecked)
                        time:   [25.412 µs 25.458 µs 25.503 µs]
parse PublicKey (unchecked)
                        time:   [12.471 µs 12.491 µs 12.514 µs]
type checked unchecked unchecked / checked
Signature 70.518 µs 25.458 µs 36.1%
PublicKey 52.647 µs 12.491 µs 23.7%

This can make a significant different when parsing trusted keys. We do this quite a lot, when reading from our database, or just when serializing/deserializing between processes in a python ProcessPool

Copy link

coveralls-official bot commented Nov 25, 2023

Pull Request Test Coverage Report for Build 7086843569

  • 81 of 91 (89.01%) changed or added relevant lines in 11 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.06%) to 86.381%

Changes Missing Coverage Covered Lines Changed/Added Lines %
chia-bls/src/signature.rs 6 7 85.71%
chia-tools/src/visit_spends.rs 0 4 0.0%
chia-traits/src/streamable.rs 30 35 85.71%
Files with Coverage Reduction New Missed Lines %
chia-traits/src/streamable.rs 1 94.89%
Totals Coverage Status
Change from base Build 7086759231: 0.06%
Covered Lines: 10878
Relevant Lines: 12593

💛 - Coveralls

@arvidn arvidn force-pushed the from_bytes_unchecked branch from 664d202 to 127507b Compare November 25, 2023 17:00
@arvidn arvidn marked this pull request as ready for review November 25, 2023 17:03
@arvidn arvidn requested a review from richardkiss November 27, 2023 12:36
@arvidn arvidn force-pushed the from_bytes_unchecked branch 3 times, most recently from 2b39798 to 83dbeb6 Compare November 30, 2023 23:24
@arvidn arvidn requested a review from richardkiss December 2, 2023 11:12
@arvidn arvidn force-pushed the from_bytes_unchecked branch from 83dbeb6 to a8ee9af Compare December 4, 2023 12:49
@arvidn arvidn force-pushed the from_bytes_unchecked branch from a8ee9af to d6a4fd1 Compare December 4, 2023 12:51
@arvidn arvidn merged commit 713d75c into main Dec 4, 2023
53 checks passed
@arvidn arvidn deleted the from_bytes_unchecked branch December 4, 2023 22:41
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.

2 participants