Skip to content

Commit

Permalink
remove comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcardon committed Dec 10, 2023
1 parent 49eaf63 commit 948076f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 141 deletions.
141 changes: 0 additions & 141 deletions crypto/Pact/Core/Crypto/Pairing.hs
Original file line number Diff line number Diff line change
Expand Up @@ -600,144 +600,3 @@ pairingCheck = go 1
| p1 == CurveInf || p2 == CurveInf = go acc rest
| otherwise = go (acc * millerLoop p1 p2) rest
go acc [] = finalExponentiate parameterHex acc == 1

-- zkDefs :: NativeModule
-- zkDefs = ("Zk",
-- [ pointAdditionDef
-- , scalarMultDef
-- , pairingCheckDef
-- ])

-- | Pointwise addition on two points on the curve BN254,
-- either from G1 or G2.
-- pointAdditionDef :: NativeDef
-- pointAdditionDef =
-- defRNative "point-add" pactPointAdd (funType a [("type", tTyString), ("point1", a), ("point2", a)])
-- [ "(point-add 'g1 {'x: 1, 'y: 2} {'x: 1, 'y: 2})"
-- ] "Add two points together that lie on the curve BN254. Point addition either in Fq or in Fq2"
-- where
-- a = mkTyVar "a" []
-- pactPointAdd :: RNativeFun e
-- pactPointAdd i as@[TLiteral (LString ptTy) _ , TObject p1 _, (TObject p2 _) :: Term Name] =
-- case T.toLower ptTy of
-- "g1" -> do
-- p1' <- toG1 i p1
-- p2' <- toG1 i p2
-- unless (isOnCurve p1' b1 && isOnCurve p2' b1) $ evalError' i "Point not on curve"
-- _ <- computeGas (Right i) (GZKArgs (PointAdd ZKG1))
-- let p3' = add p1' p2'
-- pure $ TObject (fromG1 p3') def
-- "g2" -> do
-- p1' <- toG2 i p1
-- p2' <- toG2 i p2
-- unless (isOnCurve p1' b2 && isOnCurve p2' b2) $ evalError' i "Point not on curve"
-- _ <- computeGas (Right i) (GZKArgs (PointAdd ZKG2))
-- let p3' = add p1' p2'
-- pure $ TObject (fromG2 p3') def
-- _ -> argsError i as
-- pactPointAdd i as = argsError i as

-- -- | Scalar multiplication of two points.
-- scalarMultDef :: NativeDef
-- scalarMultDef =
-- defRNative "scalar-mult" scalarMul (funType a [("type", tTyString), ("point1", a), ("scalar", tTyInteger)])
-- [ "(scalar-mult 'g1 {'x: 1, 'y: 2} 2)" ]
-- "Multiply a point that lies on the curve BN254 by an integer value"
-- where
-- a = mkTyVar "a" []
-- curveOrder :: Integer
-- curveOrder = 21888242871839275222246405745257275088548364400416034343698204186575808495617
-- scalarMul :: RNativeFun e
-- scalarMul i as@[TLiteral (LString ptTy) _ , TObject p1 _, (TLiteral (LInteger scalar) _) :: Term Name] = do
-- let scalar' = scalar `mod` curveOrder
-- case T.toLower ptTy of
-- "g1" -> do
-- p1' <- toG1 i p1
-- unless (isOnCurve p1' b1) $ evalError' i "Point not on curve"
-- _ <- computeGas (Right i) (GZKArgs (ScalarMult ZKG1))
-- let p2' = multiply p1' scalar'
-- pure $ TObject (fromG1 p2') def
-- "g2" -> do
-- p1' <- toG2 i p1
-- unless (isOnCurve p1' b2) $ evalError' i "Point not on curve"
-- _ <- computeGas (Right i) (GZKArgs (ScalarMult ZKG2))
-- let p2' = multiply p1' scalar'
-- pure $ TObject (fromG2 p2') def
-- _ -> argsError i as
-- scalarMul i as = argsError i as

-- pairingCheckDef :: NativeDef
-- pairingCheckDef =
-- defRNative "pairing-check" pairingCheck' (funType tTyBool [("points-g1", TyList a), ("points-g2", TyList b)])
-- []
-- "Perform pairing and final exponentiation points in G1 and G2 in BN254, check if the result is 1"
-- where
-- a = mkTyVar "a" []
-- b = mkTyVar "b" []
-- pairingCheck':: RNativeFun e
-- pairingCheck' i [TList p1s _ _, TList p2s _ _] = do
-- g1s <- traverse termToG1 $ G.toList p1s
-- g2s <- traverse termToG2 $ G.toList p2s
-- traverse_ (`ensureOnCurve` b1) g1s
-- traverse_ (`ensureOnCurve` b2) g2s
-- let pairs = zip g1s g2s
-- _ <- computeGas (Right i) (GZKArgs (Pairing (length pairs)))
-- pure $ toTerm $ pairingCheck pairs
-- where
-- ensureOnCurve :: (Num p, Eq p) => CurvePoint p -> p -> Eval e ()
-- ensureOnCurve p bp = unless (isOnCurve p bp) $ evalError' i "Point not on curve"
-- termToG1 (TObject o _) = toG1 i o
-- termToG1 _ = evalError' i "not a point"
-- termToG2 (TObject o _) = toG2 i o
-- termToG2 _ = evalError' i "not a point"
-- pairingCheck' i as = argsError i as

-- toG1 :: ObjectData PactValue -> Maybe G1
-- toG1 (ObjectData obj) = do
-- px <- fromIntegral <$> preview (ix (Name.Field "x") . _PLiteral . _LInteger) obj
-- py <- fromIntegral <$> preview (ix (Name.Field "y") . _PLiteral . _LInteger) obj
-- if px == 0 && py == 0 then pure CurveInf
-- else pure (Point px py)

-- fromG1 :: G1 -> ObjectData PactValue
-- fromG1 CurveInf = ObjectData pts
-- where
-- pts = M.fromList
-- [ (Name.Field "x", PLiteral (LInteger 0))
-- , (Name.Field "y", PLiteral (LInteger 0))]
-- fromG1 (Point x y) = ObjectData pts
-- where
-- pts =
-- M.fromList
-- [ (Name.Field "x", PLiteral (LInteger (fromIntegral x)))
-- , (Name.Field "y", PLiteral (LInteger (fromIntegral y)))]

-- toG2 :: ObjectData PactValue -> Maybe G2
-- toG2 (ObjectData om) = do
-- pxl <- preview (ix (Name.Field "x") . _PList) om
-- px <- traverse (preview (_PLiteral . _LInteger . to fromIntegral)) pxl
-- pyl <- preview (ix (Name.Field "y") . _PList) om
-- py <- traverse (preview (_PLiteral . _LInteger . to fromIntegral)) pyl
-- let px' = fromList (G.toList px)
-- py' = fromList (G.toList py)
-- if px' == 0 && py' == 0 then pure CurveInf
-- else pure (Point px' py')

-- fromG2 :: G2 -> ObjectData PactValue
-- fromG2 CurveInf = ObjectData pts
-- where
-- pts =
-- M.fromList
-- [ (Name.Field "x", PList (G.fromList [PLiteral (LInteger 0)]))
-- , (Name.Field "y", PList (G.fromList [PLiteral (LInteger 0)]))]
-- fromG2 (Point x y) = ObjectData pts
-- where
-- toPactPt (Extension e) = let
-- elems' = fmap (PInteger . fromIntegral) (unPoly e)
-- in PList elems'
-- x' = toPactPt x
-- y' = toPactPt y
-- pts =
-- M.fromList
-- [ (Name.Field "x", x')
-- , (Name.Field "y", y')]
5 changes: 5 additions & 0 deletions pact-core/Pact/Core/Environment/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ checkSigCaps
checkSigCaps sigs = do
granted <- getAllStackCaps
autos <- useEvalState (esCaps . csAutonomous)
-- Pretty much, what this means is:
-- if you installed a capability from code (using `install-capability`)
-- then we disable unscoped sigs. Why?
-- Because we do not want to allow the installation of managed caps with
-- resources when a user explicitly did not sign for it.
pure $ M.filter (match (S.null autos) granted) sigs
where
match allowEmpty granted sigCaps =
Expand Down

0 comments on commit 948076f

Please sign in to comment.