diff --git a/circuit/slot_main.circom b/circuit/slot_main.circom index 6dd9d1d..a2357bb 100644 --- a/circuit/slot_main.circom +++ b/circuit/slot_main.circom @@ -1,3 +1,3 @@ pragma circom 2.0.0; include "sample_cells.circom"; -component main {public [entropy,slotRoot]} = SampleAndProveV1(1024, 9, 20); +component main {public [entropy,slotRoot]} = SampleAndProveV1(1024, 5, 10); diff --git a/reference/haskell/Sampling.hs b/reference/haskell/Sampling.hs index f0c3ef3..4395490 100644 --- a/reference/haskell/Sampling.hs +++ b/reference/haskell/Sampling.hs @@ -13,10 +13,10 @@ import qualified ZK.Algebra.Curves.BN128.Fr.Mont as Fr -------------------------------------------------------------------------------- -samplingTest :: FilePath -> IO () -samplingTest fpath = do +samplingTest :: SlotConfig -> FilePath -> IO () +samplingTest slotCfg fpath = do let entropy = 123456789 :: Fr - input <- calculateCircuitInput exSlotCfg entropy + input <- calculateCircuitInput slotCfg entropy exportCircuitInput fpath input -------------------------------------------------------------------------------- @@ -59,15 +59,18 @@ calculateCircuitInput slotCfg entropy = do -- | Export the inputs of the storage proof circuits in JSON format, -- which @circom@ can consume. -- +-- NOTE: large numbers (field elements) must be encoded as JSON strings, +-- not numbers, as Javascript cannot handle large numbers! +-- exportCircuitInput :: FilePath -> CircuitInput -> IO () exportCircuitInput fpath input = do h <- openFile fpath WriteMode - hPutStrLn h $ "{ \"entropy\": " ++ show (_entropy input) - hPutStrLn h $ ", \"slotRoot\": " ++ show (_slotRoot input) + hPutStrLn h $ "{ \"entropy\": " ++ show (show (_entropy input)) + hPutStrLn h $ ", \"slotRoot\": " ++ show (show (_slotRoot input)) hPutStrLn h $ ", \"cellData\": " - hPrintListOfLists h (_cellData input) + hPrintListOfLists h ((map.map) show $ _cellData input) hPutStrLn h $ ", \"merklePaths\": " - hPrintListOfLists h (_merklePaths input) + hPrintListOfLists h ((map.map) show $ _merklePaths input) hPutStrLn h $ "}" hClose h @@ -86,7 +89,7 @@ hPrintList' h indentation xs = do hPutStrLn h (indentation False ++ "]") hPrintList :: Show a => Handle -> Int -> [a] -> IO () -hPrintList h indentBy xs = hPrintList' h (\_ -> indent indentBy) xs +hPrintList h indentBy xs = hPrintList' h (\_ -> indent indentBy) $ xs hPrintListOfLists :: Show a => Handle -> [[a]] -> IO () hPrintListOfLists h xss = diff --git a/reference/haskell/Slot.hs b/reference/haskell/Slot.hs index 89be6d8..dfcaf64 100644 --- a/reference/haskell/Slot.hs +++ b/reference/haskell/Slot.hs @@ -52,8 +52,8 @@ fieldElemsPerCell cfg = (_cellSize cfg + 30) `div` 31 -- -- > template SampleAndProveV1( nCells, nFieldElemsPerCell, nSamples ) { ... } -- -circomMainComponentV1 :: FilePath -> SlotConfig -> IO () -circomMainComponentV1 circomFile slotCfg = do +circomMainComponentV1 :: SlotConfig -> FilePath -> IO () +circomMainComponentV1 slotCfg circomFile = do let params = show (_nCells slotCfg) ++ ", " ++ show (fieldElemsPerCell slotCfg) diff --git a/reference/haskell/testMain.hs b/reference/haskell/testMain.hs index 36b8718..a82e3ef 100644 --- a/reference/haskell/testMain.hs +++ b/reference/haskell/testMain.hs @@ -4,8 +4,16 @@ module Main where import Slot import Sampling +mySlotCfg :: SlotConfig +mySlotCfg = MkSlotCfg + { _cellSize = 128 + , _nCells = 1024 + , _nSamples = 10 + , _dataSrc = FakeData 12345 + } + main :: IO () main = do - let slotCfg = exSlotCfg - circomMainComponentV1 "slot_main.circom" slotCfg - samplingTest "input_example.json" \ No newline at end of file + let slotCfg = mySlotCfg + circomMainComponentV1 slotCfg "slot_main.circom" + samplingTest slotCfg "input_example.json" \ No newline at end of file