@@ -16,7 +16,7 @@ import Foreign.Ptr (Ptr, plusPtr)
1616
1717-- [General notes on this file]
1818-- This file contains the FFI bindings to the Rust library 'rust-accumulator' with
19- -- source location https://github.com/input-output-hk /rust-accumulator
19+ -- source location https://github.com/cardano-scaling /rust-accumulator
2020-- This rust lib is compiled to C and then linked using haskell.nix to Haskell.
2121-- This FFI below uses two functions from the Rust library:
2222--
@@ -56,33 +56,26 @@ getPolyCommitmentG2_ frs pts = do
5656 withForeignPtr ptPtr $ \ pt ->
5757 get_poly_commitment_g2 out fr (fromIntegral $ length frs) pt (fromIntegral $ length pts)
5858
59- -- | Safe version of getPolyCommitmentG1 that performs bounds checking.
59+ -- | Safe version of getPolyCommitmentG1_ that performs bounds checking.
6060getPolyCommitmentG1 :: [Fr ] -> [Point1 ] -> IO (Either String Point1 )
6161getPolyCommitmentG1 frs pts = do
62- if null frs
63- then return $ Left " The scalar list cannot be empty."
62+ let ptsExpectedSize = length frs + 1
63+ if length pts < ptsExpectedSize
64+ then return $ Left " The G1 points list must be at least one element larger than the scalar list."
6465 else do
65- let ptsExpectedSize = length frs + 1
66- if length pts < ptsExpectedSize
67- then return $ Left " The G1 points list must be at least one element larger than the scalar list."
68- else do
69- result <- getPolyCommitmentG1_ frs (take ptsExpectedSize pts)
70- return $ Right result
71-
72- -- | Safe version of getPolyCommitmentG2 that performs bounds checking.
66+ result <- getPolyCommitmentG1_ frs (take ptsExpectedSize pts)
67+ return $ Right result
68+
69+ -- | Safe version of getPolyCommitmentG2_ that performs bounds checking.
7370getPolyCommitmentG2 :: [Fr ] -> [Point2 ] -> IO (Either String Point2 )
7471getPolyCommitmentG2 frs pts = do
75- -- Check if the list of Fr elements is empty
76- if null frs
77- then return $ Left " The scalar list cannot be empty."
72+ -- Check if the list of Point2 is at least one element larger than Fr
73+ let ptsExpectedSize = length frs + 1
74+ if length pts < ptsExpectedSize
75+ then return $ Left " The G2 points list must be at least one element larger than the scalar list."
7876 else do
79- -- Check if the list of Point2 is at least one element larger than Fr
80- let ptsExpectedSize = length frs + 1
81- if length pts < ptsExpectedSize
82- then return $ Left " The G2 points list must be at least one element larger than the scalar list."
83- else do
84- result <- getPolyCommitmentG2_ frs (take ptsExpectedSize pts)
85- return $ Right result
77+ result <- getPolyCommitmentG2_ frs (take ptsExpectedSize pts)
78+ return $ Right result
8679
8780-- [Helper functions]
8881
0 commit comments