Bitshala / BitcoinCore-PR-Review-Club

Bitcoin Core PR Review Organising repo
10 stars 2 forks source link

Introduce secp256k1 module with field and group classes to test framework #26222 #29

Closed rajarshimaitra closed 1 year ago

rajarshimaitra commented 1 year ago

Session Details

Learning

Summary

This PR redefines the cryptographic primitives used in the Bitcoin core's functional testing framework. And adds a new module in the python framework as secp256k1.py. This module includes all the cryptographic primitives. So the way to review this PR is to understand some fun basic crypto maths.

To start with, Cover the first 3 chapters of the Programming Bitcoin Book. If you haven't done programming Bitcoin already, skim through the concepts and skip the exercises.

A free PDF is available here

Cover the below concepts from the book

Bitcoin uses secp256k1 elliptic curve for all its cryptographic operations like key/address generation, digital signatures etc. See curve specifications for the full curve details.

Mathematically:

Questions

In the questions below, GE = group element and FE = field element

  1. Did you review the PR? Concept ACK, approach ACK, tested ACK, or NACK? What was your review approach?
  2. Write a test using class FE for basic field element operations - addition, multiplication.
  3. Verify Fermat's little theorem using class FE.
  4. class GE represents infinity explicitly. what is point at infinity in an elliptic curve? Why do we need this point? Where are regions in the code where we need to handle infinity scenarios properly?
  5. What's a generator point in an elliptic curve?
  6. Are there any downsides to rewriting the elliptic curve logic using fields/groups?