Implementing Elliptic Curves

close button

Part II

Elliptic Curve Operations

With field arithmetic abstracted away, we can now implement our elliptic curve. For efficiency purposes, we want to implement the elliptic curve in the Jacobian space, where points are represented as (x,y,z)(x, y, z).In contracts/EllipticCurve.sol, we have defined a new struct JacPoint to represent points on the curve.

struct JacPoint { Felt x; Felt y; Felt z; }

We want to implement functions to support point manipulation. Specifically, we wish to implement the following functions.



jacAdd(JacPoint, JacPoint) → JacPoint

Adds 2 Jacobian points and returns the result. If the points are equivalent, then double the point instead.

jacMul(JacPoint, uint256) → JacPoint

Multiplies a Jacobian point with a scalar value and returns the result.

generatePoint(uint256) → JacPoint

Multiplies the generator point GG with a scalar value and returns the result.

In our implementation, we define the point at infinity to be any point with z-coordinate of value 00. For example, (4,8,0)(4, 8, 0) and (1,1,0)(1, 1, 0) are both the point at infinity.

Your Task

In contracts/EllipticCurve.sol, implement the logic for jacAdd, jacMul, and generatePoint. These functions must be implemented efficiently.

Run tests in Questplay

Having grasped the runic lexicon, you can now begin to enchant fresh power atop that with had begun to fade...