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

Add local asn1 encoding tools #60

Merged
merged 1 commit into from
Jun 3, 2019
Merged

Add local asn1 encoding tools #60

merged 1 commit into from
Jun 3, 2019

Conversation

carver
Copy link
Collaborator

@carver carver commented May 31, 2019

What was wrong?

In order to use coincurve for creating/verifying non-recoverable signatures, we want (or need?) ASN1-encoded signatures. See #58

How was it fixed?

ASN1 in general is a pretty expansive standard. It takes pretty significant libraries to support it in general. We would prefer not to add external dependencies to this very sensitive library. Luckily, we are only using one small corner of ASN1 (a sequence of two integers that are guaranteed positive and can be contained in 32 bytes). So it's relatively straightforward to implement a custom encoded/decoder for this case, which saves us a library.

Out of an abundance of caution, I added hypothesis tests against two different asn1 libraries. (encoding to/from the cross-product of all three implementations)

Cute Animal Picture

Cute animal picture

@pipermerriam
Copy link
Member

@carver did you do any initial stress testing like running the tests in a loop for an hour and boosting the total examples up a but for that time?

Copy link
Member

@pipermerriam pipermerriam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 this looks pleasantly easy to reason about. Of course, there was that broadly used implementation of a binary search that had a bug in it for like 30 years that nobody noticed so there's that...

Copy link
Contributor

@jannikluhn jannikluhn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍

# We locally implement serialization and deserialization for this specific spec
# with constrained inputs.
# This is done locally to avoid importing a 3rd-party library, in this very sensitive project.
# asn1tools and pyasn1 were used as reference APIs, see how in tests/core/test_utils_asn1.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a comment here that this module is for internal use only as it doesn't fully validate inputs (which is fine for us as we only use it to bridge to coincurve, but if someone uses it with unvalidated external inputs they might end up accepting invalid signatures).

@@ -0,0 +1,112 @@
# Non-recoverable signatures are encoded using an asn1 sequence of two integers
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick regarding the module name: ASN1 seems to be just the language to describe the schema, the encoding is called DER.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks for pointing that out. Will rename.

@carver
Copy link
Collaborator Author

carver commented Jun 3, 2019

@carver did you do any initial stress testing like running the tests in a loop for an hour and boosting the total examples up a but for that time?

Yup, I ran it for a bit! I only ran it for about a half an hour though, and some of them were testing pyasn1 vs asn1tools. I'll focus on just the ones that test local against reference (that change should actually get merged). I'll do a local run that should take about... 2 hours, and then merge.

@carver carver merged commit 6dbe04a into ethereum:master Jun 3, 2019
@carver carver deleted the asn1 branch June 3, 2019 23:17
@carver carver mentioned this pull request Jun 3, 2019
pacrob pushed a commit to pacrob/eth-keys that referenced this pull request Dec 20, 2023
Exclude huge and unnecessary venv*/ from dist
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.

3 participants