mirror of
https://github.com/logos-storage/logos-storage-proofs-circuits.git
synced 2026-01-03 22:13:08 +00:00
fix the JSON does not handle large numbers problem
This commit is contained in:
parent
1f4ae5874d
commit
5581ba56f5
@ -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);
|
||||
|
||||
@ -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 =
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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"
|
||||
let slotCfg = mySlotCfg
|
||||
circomMainComponentV1 slotCfg "slot_main.circom"
|
||||
samplingTest slotCfg "input_example.json"
|
||||
Loading…
x
Reference in New Issue
Block a user