-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #258 from zkFold/pasta-curve
Add Pasta curve
- Loading branch information
Showing
5 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
{-# LANGUAGE DerivingVia #-} | ||
{-# OPTIONS_GHC -Wno-orphans #-} | ||
|
||
module ZkFold.Base.Algebra.EllipticCurve.Pasta where | ||
|
||
import Prelude | ||
|
||
import ZkFold.Base.Algebra.Basic.Class | ||
import ZkFold.Base.Algebra.Basic.Field | ||
import ZkFold.Base.Algebra.Basic.Number | ||
import ZkFold.Base.Algebra.EllipticCurve.Class | ||
import ZkFold.Base.Data.ByteString | ||
|
||
-------------------------------- Introducing Fields ---------------------------------- | ||
|
||
type FpModulus = 0x40000000000000000000000000000000224698fc094cf91b992d30ed00000001 | ||
instance Prime FpModulus | ||
|
||
type FqModulus = 0x40000000000000000000000000000000224698fc0994a8dd8c46eb2100000001 | ||
instance Prime FqModulus | ||
|
||
type Fp = Zp FpModulus | ||
type Fq = Zp FqModulus | ||
|
||
------------------------------------ Pallas ------------------------------------ | ||
|
||
data Pallas | ||
|
||
instance EllipticCurve Pallas where | ||
type ScalarField Pallas = Fq | ||
|
||
type BaseField Pallas = Fp | ||
|
||
inf = Inf | ||
|
||
gen = Point | ||
0x40000000000000000000000000000000224698fc094cf91b992d30ed00000000 | ||
0x02 | ||
|
||
add = addPoints | ||
|
||
mul = pointMul | ||
|
||
instance StandardEllipticCurve Pallas where | ||
aParameter = zero | ||
|
||
bParameter = fromConstant (5 :: Natural) | ||
|
||
------------------------------------ Vesta ------------------------------------ | ||
|
||
data Vesta | ||
|
||
instance EllipticCurve Vesta where | ||
|
||
type ScalarField Vesta = Fp | ||
|
||
type BaseField Vesta = Fq | ||
|
||
inf = Inf | ||
|
||
gen = Point | ||
0x40000000000000000000000000000000224698fc0994a8dd8c46eb2100000000 | ||
0x02 | ||
|
||
add = addPoints | ||
|
||
mul = pointMul | ||
|
||
instance StandardEllipticCurve Vesta where | ||
aParameter = zero | ||
|
||
bParameter = fromConstant (5 :: Natural) | ||
|
||
------------------------------------ Encoding ------------------------------------ | ||
|
||
instance Binary (Point Pallas) where | ||
put Inf = put (Point @Pallas zero zero) | ||
put (Point xp yp) = put xp >> put yp | ||
get = do | ||
xp <- get | ||
yp <- get | ||
return $ | ||
if xp == zero && yp == zero | ||
then Inf | ||
else Point xp yp | ||
|
||
instance Binary (Point Vesta) where | ||
put Inf = put (Point @Vesta zero zero) | ||
put (Point xp yp) = put xp >> put yp | ||
get = do | ||
xp <- get | ||
yp <- get | ||
return $ | ||
if xp == zero && yp == zero | ||
then Inf | ||
else Point xp yp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters