Skip to content

Commit 07c126c

Browse files
committed
update the rust accumulator dep and remove check on empty lists
1 parent aeadc4b commit 07c126c

File tree

3 files changed

+21
-30
lines changed

3 files changed

+21
-30
lines changed

flake.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

haskell-accumulator/lib/Bindings/Internal.hs

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
6060
getPolyCommitmentG1 :: [Fr] -> [Point1] -> IO (Either String Point1)
6161
getPolyCommitmentG1 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.
7370
getPolyCommitmentG2 :: [Fr] -> [Point2] -> IO (Either String Point2)
7471
getPolyCommitmentG2 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

haskell-accumulator/test/Main.hs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ runE2EExample = do
129129
accCommit <- getPolyCommitOverG2 [] myAcc crsG2
130130

131131
-- Say we want to proof the subset of the set
132-
let mySubset = ["element3", "element9"] :: [Element]
132+
let mySubset = mySet -- ["element3", "element9"] :: [Element]
133133

134134
-- then the proof can be calculated via
135135
proof <- getPolyCommitOverG2 mySubset myAcc crsG2
@@ -155,10 +155,8 @@ runE2EExample = do
155155
print $ "With proof: " ++ show (byteStringAsHex proofBS)
156156
print $ "Set: " ++ show mySet
157157
print $ "With accumulator commitment: " ++ show (byteStringAsHex accBS)
158-
print $ "The proof is: " ++ show pairingCheck
159-
160-
-- Verify the proof onchain (but doing it with offchain code)
161-
print "E2E run complete"
158+
print $ "The proof is evaluated as: " ++ show pairingCheck
159+
print "E2E run complete"
162160

163161
-- Main function with benchmarking and an E2E example
164162
main :: IO ()

0 commit comments

Comments
 (0)