Skip to content

Commit

Permalink
pointGen
Browse files Browse the repository at this point in the history
  • Loading branch information
echatav committed Dec 18, 2024
1 parent c9d3899 commit 21692e3
Show file tree
Hide file tree
Showing 15 changed files with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ instance EllipticCurve BLS12_381_G1 where

type BaseField BLS12_381_G1 = Fq

gen = pointXY
pointGen = pointXY
0x17f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb
0x8b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1

Expand All @@ -91,7 +91,7 @@ instance EllipticCurve BLS12_381_G2 where

type BaseField BLS12_381_G2 = Fq2

gen = pointXY
pointGen = pointXY
(Ext2
0x24aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8
0x13e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e)
Expand Down
4 changes: 2 additions & 2 deletions symbolic-base/src/ZkFold/Base/Algebra/EllipticCurve/BN254.hs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ data BN254_G1
instance EllipticCurve BN254_G1 where
type ScalarField BN254_G1 = Fr
type BaseField BN254_G1 = Fp
gen = pointXY 1 2
pointGen = pointXY 1 2
add = addPoints
mul = pointMul

Expand All @@ -85,7 +85,7 @@ data BN254_G2
instance EllipticCurve BN254_G2 where
type ScalarField BN254_G2 = Fr
type BaseField BN254_G2 = Fp2
gen = pointXY
pointGen = pointXY
(Ext2 0x1800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed
0x198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c2)
(Ext2 0x12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa
Expand Down
4 changes: 2 additions & 2 deletions symbolic-base/src/ZkFold/Base/Algebra/EllipticCurve/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class
type BooleanOf curve :: Type
type BooleanOf curve = P.Bool

gen :: Point curve
pointGen :: Point curve

add :: Point curve -> Point curve -> Point curve

Expand Down Expand Up @@ -136,7 +136,7 @@ instance (EllipticCurve curve, AdditiveGroup (BaseField curve)) => AdditiveGroup
negate = pointNegate

instance (EllipticCurve curve, Arbitrary (ScalarField curve)) => Arbitrary (Point curve) where
arbitrary = arbitrary <&> (`mul` gen)
arbitrary = arbitrary <&> (`mul` pointGen)

class (EllipticCurve curve1, EllipticCurve curve2, ScalarField curve1 ~ ScalarField curve2,
P.Eq (TargetGroup curve1 curve2), MultiplicativeGroup (TargetGroup curve1 curve2),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ instance EllipticCurve Ed25519 where
type BaseField Ed25519 = Zp Ed25519_Base
type ScalarField Ed25519 = Zp Ed25519_Scalar

gen = pointXY
pointGen = pointXY
(toZp @Ed25519_Base $ 15112221349535400772501151409588531511454012693041857206046113283949847762202)
(toZp @Ed25519_Base $ 46316835694926478169428394003475163141307993866256225615783033603165251855960)

Expand Down
4 changes: 2 additions & 2 deletions symbolic-base/src/ZkFold/Base/Algebra/EllipticCurve/Pasta.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ instance EllipticCurve Pallas where

type BaseField Pallas = Fp

gen = pointXY
pointGen = pointXY
0x40000000000000000000000000000000224698fc094cf91b992d30ed00000000
0x02

Expand All @@ -54,7 +54,7 @@ instance EllipticCurve Vesta where

type BaseField Vesta = Fq

gen = pointXY
pointGen = pointXY
0x40000000000000000000000000000000224698fc0994a8dd8c46eb2100000000
0x02

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ data Secp256k1
instance EllipticCurve Secp256k1 where
type ScalarField Secp256k1 = Fn
type BaseField Secp256k1 = Fp
gen = pointXY
pointGen = pointXY
0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798
0x483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8
add = addPoints
Expand Down
6 changes: 3 additions & 3 deletions symbolic-base/src/ZkFold/Base/Protocol/KZG.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ instance forall (c1 :: Type) (c2 :: Type) d kzg f g1 core.
setupProve (KZG x) =
let d = value @d
xs = V.fromList $ map (x^) [0..d-!1]
gs = fmap (`mul` gen) xs
gs = fmap (`mul` pointGen) xs
in gs

setupVerify :: kzg -> SetupVerify kzg
setupVerify (KZG x) =
let d = value @d
xs = V.fromList $ map (x^) [0..d-!1]
gs = fmap (`mul` gen) xs
in (gs, gen, x `mul` gen)
gs = fmap (`mul` pointGen) xs
in (gs, pointGen, x `mul` pointGen)

prove :: SetupProve kzg
-> Witness kzg
Expand Down
4 changes: 2 additions & 2 deletions symbolic-base/src/ZkFold/Base/Protocol/Plonk/Verifier.hs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ plonkVerify
-- Step 12: Compute E
e = (
negate r0 + v * a_xi + vn 2 * b_xi + vn 3 * c_xi + vn 4 * s1_xi + vn 5 * s2_xi + eta * z1_xi'
) `mul` gen
) `mul` pointGen

-- Step 13: Compute the pairing
p1 = pairing (proof1 + eta `mul` proof2) h1
p2 = pairing (xi `mul` proof1 + (eta * xi * omega) `mul` proof2 + f - e) (gen @c2)
p2 = pairing (xi `mul` proof1 + (eta * xi * omega) `mul` proof2 + f - e) (pointGen @c2)
6 changes: 3 additions & 3 deletions symbolic-base/src/ZkFold/Base/Protocol/Plonkup/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ plonkupSetup :: forall i p n l c1 c2 ts core.
, CoreFunction c1 core) => Plonkup p i n l c1 c2 ts -> PlonkupSetup p i n l c1 c2
plonkupSetup Plonkup {..} =
let xs = fromList $ map (x^) [0 .. (value @n + 5)]
gs = fmap (`mul` gen) xs
h0 = gen
h1 = x `mul` gen
gs = fmap (`mul` pointGen) xs
h0 = pointGen
h1 = x `mul` pointGen

relation@PlonkupRelation{..} = fromJust $ toPlonkupRelation ac :: PlonkupRelation p i n l (ScalarField c1)

Expand Down
4 changes: 2 additions & 2 deletions symbolic-base/src/ZkFold/Base/Protocol/Plonkup/Verifier.hs
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ plonkupVerify
e = (
negate r0 + v * a_xi + vn 2 * b_xi + vn 3 * c_xi + vn 4 * s1_xi + vn 5 * s2_xi + vn 6 * f_xi
+ vn 7 * t_xi + vn 8 * h2_xi + eta * z1_xi' + eta * v * t_xi' + eta * vn 2 * z2_xi' + eta * vn 3 * h1_xi'
) `mul` gen
) `mul` pointGen

-- Step 13: Compute the pairing
p1 = pairing (proof1 + eta `mul` proof2) h1
p2 = pairing (xi `mul` proof1 + (eta * xi * omega) `mul` proof2 + f - e) (gen @c2)
p2 = pairing (xi `mul` proof1 + (eta * xi * omega) `mul` proof2 + f - e) (pointGen @c2)
4 changes: 2 additions & 2 deletions symbolic-base/src/ZkFold/Base/Protocol/Protostar/Commit.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ instance KnownNat n => PedersonSetup n (Point BLS12_381_G1) where
groupElements =
-- TODO: This is just for testing purposes! Not to be used in production
let x = fst $ random $ mkStdGen 0 :: Zp BLS12_381_Scalar
in fromList $ take (value @n) $ iterate (scale x) gen
in fromList $ take (value @n) $ iterate (scale x) pointGen

instance KnownNat n => PedersonSetup n (Point Ed25519) where
groupElements =
-- TODO: This is just for testing purposes! Not to be used in production
let x = fst $ random $ mkStdGen 0 :: ScalarField Ed25519
in fromList $ take (value @n) $ iterate (scale x) gen
in fromList $ take (value @n) $ iterate (scale x) pointGen

instance (PedersonSetup n c, Scale f c, AdditiveGroup c) => HomomorphicCommit (Vector n f) c where
hcommit v = sum $ zipWith scale v groupElements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ ecdsaVerify publicKey message (r, s) =
where
n = fromConstant $ value @n

g = gen
g = pointGen

(sInv, _, _) = eea s n

Expand Down
2 changes: 1 addition & 1 deletion symbolic-base/src/ZkFold/Symbolic/Data/Ed25519.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ instance
type ScalarField (AcEd25519 c) = FieldElement c
type BooleanOf (AcEd25519 c) = Bool c

gen = pointXY
pointGen = pointXY
(fromConstant (15112221349535400772501151409588531511454012693041857206046113283949847762202 :: Natural))
(fromConstant (46316835694926478169428394003475163141307993866256225615783033603165251855960 :: Natural))

Expand Down
2 changes: 1 addition & 1 deletion symbolic-base/test/Tests/EllipticCurve.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ specEllipticCurve = hspec $ do
it "should match test vector" $ do
let p, q :: Point Secp256k1
p = pointXY (fromConstant x) (fromConstant y)
q = scale k gen
q = scale k pointGen
p `shouldBe` q

data TestVector = TestVector
Expand Down
4 changes: 2 additions & 2 deletions symbolic-base/test/Tests/Pairing.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ propVerificationKZG x p z =
let n = deg $ vec2poly p

-- G1
gs = V.fromList $ map ((`mul` gen) . (x^)) [0 .. n]
gs = V.fromList $ map ((`mul` pointGen) . (x^)) [0 .. n]
g0 = V.head gs :: Point c1

-- G2
h0 = gen :: Point c2
h0 = pointGen :: Point c2
h1 = x `mul` h0

com = msm @c1 @core
Expand Down

0 comments on commit 21692e3

Please sign in to comment.