From 05c89ca8a433c32402e109f2a41b279f7f51cfe9 Mon Sep 17 00:00:00 2001 From: martyall Date: Mon, 20 May 2024 18:44:55 -0700 Subject: [PATCH 1/6] use circom program types --- cabal.project | 4 ++-- factors-solver/app/Main.hs | 7 +++---- factors-solver/cabal.project | 4 ++-- factors/app/Main.hs | 6 +++--- factors/src/ZK/Factors.hs | 22 ++++++---------------- factors/test/Main.hs | 20 ++++++++++++-------- 6 files changed, 28 insertions(+), 35 deletions(-) diff --git a/cabal.project b/cabal.project index fedec56..0000715 100644 --- a/cabal.project +++ b/cabal.project @@ -19,13 +19,13 @@ source-repository-package source-repository-package type: git location: https://github.com/l-adic/galois-fields.git - tag: b0867ffdebda5043c80315a51b15e82ed25acba6 + tag: 525521de7b985364f7e0c32222fc3b21fea8e530 --sha256: pYe2FTNHPTzZeTnOMe6S9eh3EOY6Hi6PjdfsNjPSOZQ= source-repository-package type: git location: https://github.com/l-adic/arithmetic-circuits.git - tag: d243f4cd91fb0adae11c18c726ef884cf7ea7d0d + tag: b0fc0e4d9e1fdcf7591298487284206688bcb8e1 --sha256: cmgHbYgMfPCjtZiLqqKMrvL+D8kIPGN9sE07iVqBS5Q= index-state: 2023-10-15T12:29:38Z diff --git a/factors-solver/app/Main.hs b/factors-solver/app/Main.hs index 68af0b0..296c5f4 100644 --- a/factors-solver/app/Main.hs +++ b/factors-solver/app/Main.hs @@ -4,7 +4,7 @@ import Circuit.Solver.Circom qualified as Circom import Data.IORef (IORef, newIORef) import Protolude import System.IO.Unsafe (unsafePerformIO) -import ZK.Factors +import ZK.Factors (factors, Fr) main :: IO () main = mempty @@ -16,13 +16,12 @@ stateRef = unsafePerformIO $ do {-# NOINLINE stateRef #-} env :: Circom.ProgramEnv Fr -env = - Circom.mkProgramEnv (factorsVars @Fr factors) (factorsCircuit factors) +env = Circom.mkProgramEnv factors foreign export ccall init :: Int -> IO () init :: Int -> IO () -init = Circom._init +init = Circom._init env stateRef foreign export ccall getNVars :: Int diff --git a/factors-solver/cabal.project b/factors-solver/cabal.project index 4b9e962..8bd2034 100644 --- a/factors-solver/cabal.project +++ b/factors-solver/cabal.project @@ -29,11 +29,11 @@ source-repository-package source-repository-package type: git location: https://github.com/l-adic/galois-fields.git - tag: b0867ffdebda5043c80315a51b15e82ed25acba6 + tag: 525521de7b985364f7e0c32222fc3b21fea8e530 --sha256: pYe2FTNHPTzZeTnOMe6S9eh3EOY6Hi6PjdfsNjPSOZQ= source-repository-package type: git location: https://github.com/l-adic/arithmetic-circuits.git - tag: d243f4cd91fb0adae11c18c726ef884cf7ea7d0d + tag: b0fc0e4d9e1fdcf7591298487284206688bcb8e1 --sha256: cmgHbYgMfPCjtZiLqqKMrvL+D8kIPGN9sE07iVqBS5Q= diff --git a/factors/app/Main.hs b/factors/app/Main.hs index 360f6c2..84f30c1 100644 --- a/factors/app/Main.hs +++ b/factors/app/Main.hs @@ -4,10 +4,10 @@ import Data.Binary (encodeFile) import Protolude import R1CS (toR1CS) import R1CS.Circom (r1csToCircomR1CS) +import Circuit.Solver.Circom (CircomProgram(..)) import ZK.Factors main :: IO () main = do - let Factors {..} = factors @Fr - r1cs = toR1CS factorsVars factorsCircuit - encodeFile "trusted-setup/circuit.r1cs" $ r1csToCircomR1CS r1cs + let r1cs = r1csToCircomR1CS $ toR1CS (cpVars factors) (cpCircuit factors) + encodeFile "trusted-setup/circuit.r1cs" r1cs \ No newline at end of file diff --git a/factors/src/ZK/Factors.hs b/factors/src/ZK/Factors.hs index 146f067..622dcbc 100644 --- a/factors/src/ZK/Factors.hs +++ b/factors/src/ZK/Factors.hs @@ -2,37 +2,27 @@ {-# OPTIONS_GHC -fno-warn-orphans #-} module ZK.Factors - ( Factors (..), - factors, + ( factors, Fr, ) where import Circuit import Circuit.Language -import R1CS.Circom (circomReindexMap) +import Circuit.Solver.Circom (CircomProgram, mkCircomProgram) import Data.Field.Galois (GaloisField, Prime) import Protolude type Fr = Prime 21888242871839275222246405745257275088548364400416034343698204186575808495617 -factorsE :: (GaloisField f, Hashable f) => ExprM f (Var Wire f Bool) +factorsE :: (GaloisField f, Hashable f) => ExprM f (Var Wire f 'TBool) factorsE = do n <- var_ <$> fieldInput Public "n" a <- var_ <$> fieldInput Private "a" b <- var_ <$> fieldInput Private "b" boolOutput "out" $ eq_ n (a * b) -data Factors f = Factors - { factorsCircuit :: ArithCircuit f, - factorsVars :: CircuitVars Text - } - -factors :: forall f. (GaloisField f, Hashable f) => Factors f +factors :: CircomProgram Fr factors = - let BuilderState {..} = snd $ runCircuitBuilder (factorsE @f) - f = circomReindexMap bsVars - in Factors - { factorsCircuit = reindex f bsCircuit, - factorsVars = reindex f bsVars - } + let BuilderState {..} = snd $ runCircuitBuilder factorsE + in mkCircomProgram bsVars bsCircuit \ No newline at end of file diff --git a/factors/test/Main.hs b/factors/test/Main.hs index 7eff9cd..df65cc5 100644 --- a/factors/test/Main.hs +++ b/factors/test/Main.hs @@ -1,27 +1,31 @@ module Main (main) where -import Circuit (solve, lookupVar, assignInputs) +import Circuit (lookupVar) +import R1CS (Witness(..)) +import R1CS.Circom (witnessFromCircomWitness) +import Circuit.Solver.Circom (CircomProgram(..), nativeGenWitness) import qualified Data.Map as Map import Protolude import Test.Hspec import Test.QuickCheck -import ZK.Factors (Factors (..), Fr, factors) +import ZK.Factors (factors) main :: IO () main = hspec $ do - let circuit = factorsCircuit $ factors @Fr - vars = factorsVars $ factors @Fr + let vars = cpVars factors describe "Factors" $ do it "should accept valid factors" $ do property $ \x y -> - let inputs = assignInputs vars $ Map.fromList [("n", x * y), ("a", x), ("b", y)] - w = solve vars circuit inputs + let inputs = Map.fromList [("n", x * y), ("a", x), ("b", y)] + Witness w = witnessFromCircomWitness $ + nativeGenWitness factors inputs in lookupVar vars "out" w === Just 1 it "shouldn't accept invalid factors" $ do property $ \x y z -> (x * y /= z) ==> - let inputs = assignInputs vars $ Map.fromList [("n", z), ("a", x), ("b", y)] - w = solve vars circuit inputs + let inputs = Map.fromList [("n", z), ("a", x), ("b", y)] + Witness w = witnessFromCircomWitness $ + nativeGenWitness factors inputs in lookupVar vars "out" w == Just 0 From bcf5599a80ea2f12f84e3a17bdcc529a76a13d01 Mon Sep 17 00:00:00 2001 From: martyall Date: Mon, 20 May 2024 23:48:17 -0700 Subject: [PATCH 2/6] correct filenames --- README.md | 2 +- cabal.project | 4 ++-- factors-solver/.envrc | 1 - factors/app/Main.hs | 3 ++- flake.nix | 6 +++--- wasm-solver/.envrc | 1 + {factors-solver => wasm-solver}/.gitignore | 0 {factors-solver => wasm-solver}/app/Main.hs | 0 {factors-solver => wasm-solver}/build-wasm.sh | 6 +++--- {factors-solver => wasm-solver}/cabal.project | 4 ++-- {factors-solver => wasm-solver}/cbits/init.c | 0 {factors-solver => wasm-solver}/default.nix | 0 {factors-solver => wasm-solver}/factors-solver.cabal | 4 ++-- {factors-solver => wasm-solver}/flake.lock | 0 14 files changed, 16 insertions(+), 15 deletions(-) delete mode 100644 factors-solver/.envrc create mode 100644 wasm-solver/.envrc rename {factors-solver => wasm-solver}/.gitignore (100%) rename {factors-solver => wasm-solver}/app/Main.hs (100%) rename {factors-solver => wasm-solver}/build-wasm.sh (71%) rename {factors-solver => wasm-solver}/cabal.project (90%) rename {factors-solver => wasm-solver}/cbits/init.c (100%) rename {factors-solver => wasm-solver}/default.nix (100%) rename {factors-solver => wasm-solver}/factors-solver.cabal (93%) rename {factors-solver => wasm-solver}/flake.lock (100%) diff --git a/README.md b/README.md index a444f40..0228788 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ You should see an artifact `trusted-setup/circuit.r1cs`. A constraint solver applied to the `factors` program. You can produce a circom compatible WASM binary for this solver by running ``` -> cd factors-solver +> cd wasm-solver > ./build-wasm ``` diff --git a/cabal.project b/cabal.project index 0000715..ac59bdc 100644 --- a/cabal.project +++ b/cabal.project @@ -20,13 +20,13 @@ source-repository-package type: git location: https://github.com/l-adic/galois-fields.git tag: 525521de7b985364f7e0c32222fc3b21fea8e530 - --sha256: pYe2FTNHPTzZeTnOMe6S9eh3EOY6Hi6PjdfsNjPSOZQ= + --sha256: hPbO7PElCJ3X6+WibL0EmdPlZqLq6stjn2r5auhsv08= source-repository-package type: git location: https://github.com/l-adic/arithmetic-circuits.git tag: b0fc0e4d9e1fdcf7591298487284206688bcb8e1 - --sha256: cmgHbYgMfPCjtZiLqqKMrvL+D8kIPGN9sE07iVqBS5Q= + --sha256: jI3tAEGwOBqiCr6JqQfAws3X2RIp1eYbI9fXWutTMuE= index-state: 2023-10-15T12:29:38Z diff --git a/factors-solver/.envrc b/factors-solver/.envrc deleted file mode 100644 index d79705e..0000000 --- a/factors-solver/.envrc +++ /dev/null @@ -1 +0,0 @@ -use flake ..#ormoluLive diff --git a/factors/app/Main.hs b/factors/app/Main.hs index 84f30c1..7bb7351 100644 --- a/factors/app/Main.hs +++ b/factors/app/Main.hs @@ -10,4 +10,5 @@ import ZK.Factors main :: IO () main = do let r1cs = r1csToCircomR1CS $ toR1CS (cpVars factors) (cpCircuit factors) - encodeFile "trusted-setup/circuit.r1cs" r1cs \ No newline at end of file + encodeFile "trusted-setup/circuit.r1cs" r1cs + encodeFile "trusted-setup/circuit.bin" factors \ No newline at end of file diff --git a/flake.nix b/flake.nix index 574eca1..afb4fe7 100644 --- a/flake.nix +++ b/flake.nix @@ -41,7 +41,7 @@ ); defaultGHC = perGHC.${defaultGHCVersion}; - ormoluLive = import factors-solver/default.nix { + wasmSolver = import wasm-solver/default.nix { inherit pkgs inputs defaultGHC; }; in @@ -63,8 +63,8 @@ withHoogle = false; exactDeps = false; }; - ormoluLive = ormoluLive.shell; - ghcWasm = ormoluLive.ghcWasmShell; + wasmSolver = wasmSolver.shell; + ghcWasm = wasmSolver.ghcWasmShell; }; legacyPackages = defaultGHC // perGHC; }); diff --git a/wasm-solver/.envrc b/wasm-solver/.envrc new file mode 100644 index 0000000..383fb6b --- /dev/null +++ b/wasm-solver/.envrc @@ -0,0 +1 @@ +use flake ..#wasmSolver diff --git a/factors-solver/.gitignore b/wasm-solver/.gitignore similarity index 100% rename from factors-solver/.gitignore rename to wasm-solver/.gitignore diff --git a/factors-solver/app/Main.hs b/wasm-solver/app/Main.hs similarity index 100% rename from factors-solver/app/Main.hs rename to wasm-solver/app/Main.hs diff --git a/factors-solver/build-wasm.sh b/wasm-solver/build-wasm.sh similarity index 71% rename from factors-solver/build-wasm.sh rename to wasm-solver/build-wasm.sh index 9165581..2835379 100755 --- a/factors-solver/build-wasm.sh +++ b/wasm-solver/build-wasm.sh @@ -3,9 +3,9 @@ set -e WDIR="$(mktemp -d)" trap 'rm -rf -- "$WDIR"' EXIT -wasm32-wasi-cabal build exe:factors-solver --minimize-conflict-set -wasm32-wasi-cabal list-bin exe:factors-solver -FACTORS_WASM="$(wasm32-wasi-cabal list-bin exe:factors-solver)" +wasm32-wasi-cabal build exe:wasm-solver --minimize-conflict-set +wasm32-wasi-cabal list-bin exe:wasm-solver +FACTORS_WASM="$(wasm32-wasi-cabal list-bin exe:wasm-solver)" wizer \ --allow-wasi --wasm-bulk-memory true \ "$FACTORS_WASM" -o "$WDIR/factors-init.wasm" \ diff --git a/factors-solver/cabal.project b/wasm-solver/cabal.project similarity index 90% rename from factors-solver/cabal.project rename to wasm-solver/cabal.project index 8bd2034..839fbad 100644 --- a/factors-solver/cabal.project +++ b/wasm-solver/cabal.project @@ -30,10 +30,10 @@ source-repository-package type: git location: https://github.com/l-adic/galois-fields.git tag: 525521de7b985364f7e0c32222fc3b21fea8e530 - --sha256: pYe2FTNHPTzZeTnOMe6S9eh3EOY6Hi6PjdfsNjPSOZQ= + --sha256: hPbO7PElCJ3X6+WibL0EmdPlZqLq6stjn2r5auhsv08= source-repository-package type: git location: https://github.com/l-adic/arithmetic-circuits.git tag: b0fc0e4d9e1fdcf7591298487284206688bcb8e1 - --sha256: cmgHbYgMfPCjtZiLqqKMrvL+D8kIPGN9sE07iVqBS5Q= + --sha256: jI3tAEGwOBqiCr6JqQfAws3X2RIp1eYbI9fXWutTMuE= diff --git a/factors-solver/cbits/init.c b/wasm-solver/cbits/init.c similarity index 100% rename from factors-solver/cbits/init.c rename to wasm-solver/cbits/init.c diff --git a/factors-solver/default.nix b/wasm-solver/default.nix similarity index 100% rename from factors-solver/default.nix rename to wasm-solver/default.nix diff --git a/factors-solver/factors-solver.cabal b/wasm-solver/factors-solver.cabal similarity index 93% rename from factors-solver/factors-solver.cabal rename to wasm-solver/factors-solver.cabal index 93f3af2..a27a2ca 100644 --- a/factors-solver/factors-solver.cabal +++ b/wasm-solver/factors-solver.cabal @@ -1,8 +1,8 @@ cabal-version: 3.0 -name: factors-solver +name: wasm-solver version: 0.0.0.0 -executable factors-solver +executable wasm-solver main-is: Main.hs c-sources: cbits/init.c hs-source-dirs: app diff --git a/factors-solver/flake.lock b/wasm-solver/flake.lock similarity index 100% rename from factors-solver/flake.lock rename to wasm-solver/flake.lock From f7e9627f7c386f7a3a83388fa9cdfb312f74bc7e Mon Sep 17 00:00:00 2001 From: martyall Date: Tue, 21 May 2024 00:18:29 -0700 Subject: [PATCH 3/6] rename things away from repo template, add native solver that reads compiled circuit from bin file --- README.md | 2 +- cabal.project | 4 +--- factors/{app => compile}/Main.hs | 4 ++-- factors/factors.cabal | 19 +++++++++++++++---- factors/native-solver/Main.hs | 25 +++++++++++++++++++++++++ factors/src/ZK/Factors.hs | 2 +- factors/test/Main.hs | 20 +++++++++++--------- wasm-solver/app/Main.hs | 2 +- 8 files changed, 57 insertions(+), 21 deletions(-) rename factors/{app => compile}/Main.hs (74%) create mode 100644 factors/native-solver/Main.hs diff --git a/README.md b/README.md index 0228788..94e84d9 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ You should have a local ethereum node with an unlocked default account and the w A ZK program written in a Haskell DSL that expresses a factorization of a public input `n` into a product of secret inputs `a` and `b`. You can produce a circom compatible `r1cs` file for this program by running ``` -> cabal run factors +> cabal run compile ``` You should see an artifact `trusted-setup/circuit.r1cs`. diff --git a/cabal.project b/cabal.project index ac59bdc..db9c353 100644 --- a/cabal.project +++ b/cabal.project @@ -28,6 +28,4 @@ source-repository-package tag: b0fc0e4d9e1fdcf7591298487284206688bcb8e1 --sha256: jI3tAEGwOBqiCr6JqQfAws3X2RIp1eYbI9fXWutTMuE= -index-state: 2023-10-15T12:29:38Z - - +index-state: 2024-05-21T06:16:08Z diff --git a/factors/app/Main.hs b/factors/compile/Main.hs similarity index 74% rename from factors/app/Main.hs rename to factors/compile/Main.hs index 7bb7351..5e20ad7 100644 --- a/factors/app/Main.hs +++ b/factors/compile/Main.hs @@ -1,14 +1,14 @@ module Main where +import Circuit.Solver.Circom (CircomProgram (..)) import Data.Binary (encodeFile) import Protolude import R1CS (toR1CS) import R1CS.Circom (r1csToCircomR1CS) -import Circuit.Solver.Circom (CircomProgram(..)) import ZK.Factors main :: IO () main = do let r1cs = r1csToCircomR1CS $ toR1CS (cpVars factors) (cpCircuit factors) encodeFile "trusted-setup/circuit.r1cs" r1cs - encodeFile "trusted-setup/circuit.bin" factors \ No newline at end of file + encodeFile "trusted-setup/circuit.bin" factors diff --git a/factors/factors.cabal b/factors/factors.cabal index 665f163..83665ee 100644 --- a/factors/factors.cabal +++ b/factors/factors.cabal @@ -34,16 +34,27 @@ library hs-source-dirs: src default-language: GHC2021 -executable factors +executable compile import: warnings, extensions, deps main-is: Main.hs build-depends: binary , factors - , aeson - , wl-pprint-text >=1.2.0 - hs-source-dirs: app + hs-source-dirs: compile + default-language: GHC2021 + +executable native-solver + import: warnings, extensions, deps + main-is: Main.hs + build-depends: + aeson + , binary + , factors + , file-embed >= 0.0.16.0 + , string-conversions + + hs-source-dirs: native-solver default-language: GHC2021 test-suite factors-test diff --git a/factors/native-solver/Main.hs b/factors/native-solver/Main.hs new file mode 100644 index 0000000..e9384a9 --- /dev/null +++ b/factors/native-solver/Main.hs @@ -0,0 +1,25 @@ +{-# LANGUAGE TemplateHaskell #-} + +module Main where + +import Circuit.Solver.Circom (CircomProgram, nativeGenWitness) +import Data.Aeson (decodeFileStrict) +import Data.Binary (decode, encodeFile) +import Data.FileEmbed (embedFileRelative) +import Data.String.Conversions (cs) +import Protolude +import ZK.Factors (Fr) + +main :: IO () +main = do + mInputs <- decodeFileStrict "trusted-setup/inputs.json" + inputs <- maybe (panic "Failed to decode inputs") (pure . map fromInteger) mInputs + let circuit :: CircomProgram Fr + circuit = decode $ cs circuitBin + wtns = nativeGenWitness circuit inputs + encodeFile "trusted-setup/circuit.wtns" wtns + +-- We do this to avoid compiling the program twice. It's easier to read it +-- from a file after initial compilation. +circuitBin :: ByteString +circuitBin = $(embedFileRelative "../trusted-setup/circuit.bin") diff --git a/factors/src/ZK/Factors.hs b/factors/src/ZK/Factors.hs index 622dcbc..2213428 100644 --- a/factors/src/ZK/Factors.hs +++ b/factors/src/ZK/Factors.hs @@ -25,4 +25,4 @@ factorsE = do factors :: CircomProgram Fr factors = let BuilderState {..} = snd $ runCircuitBuilder factorsE - in mkCircomProgram bsVars bsCircuit \ No newline at end of file + in mkCircomProgram bsVars bsCircuit diff --git a/factors/test/Main.hs b/factors/test/Main.hs index df65cc5..1e3dd28 100644 --- a/factors/test/Main.hs +++ b/factors/test/Main.hs @@ -1,11 +1,11 @@ module Main (main) where import Circuit (lookupVar) -import R1CS (Witness(..)) -import R1CS.Circom (witnessFromCircomWitness) -import Circuit.Solver.Circom (CircomProgram(..), nativeGenWitness) +import Circuit.Solver.Circom (CircomProgram (..), nativeGenWitness) import qualified Data.Map as Map import Protolude +import R1CS (Witness (..)) +import R1CS.Circom (witnessFromCircomWitness) import Test.Hspec import Test.QuickCheck import ZK.Factors (factors) @@ -18,14 +18,16 @@ main = hspec $ do property $ \x y -> let inputs = Map.fromList [("n", x * y), ("a", x), ("b", y)] - Witness w = witnessFromCircomWitness $ - nativeGenWitness factors inputs - in lookupVar vars "out" w === Just 1 + Witness w = + witnessFromCircomWitness $ + nativeGenWitness factors inputs + in lookupVar vars "out" w === Just 1 it "shouldn't accept invalid factors" $ do property $ \x y z -> (x * y /= z) ==> let inputs = Map.fromList [("n", z), ("a", x), ("b", y)] - Witness w = witnessFromCircomWitness $ - nativeGenWitness factors inputs - in lookupVar vars "out" w == Just 0 + Witness w = + witnessFromCircomWitness $ + nativeGenWitness factors inputs + in lookupVar vars "out" w == Just 0 diff --git a/wasm-solver/app/Main.hs b/wasm-solver/app/Main.hs index 296c5f4..6378300 100644 --- a/wasm-solver/app/Main.hs +++ b/wasm-solver/app/Main.hs @@ -4,7 +4,7 @@ import Circuit.Solver.Circom qualified as Circom import Data.IORef (IORef, newIORef) import Protolude import System.IO.Unsafe (unsafePerformIO) -import ZK.Factors (factors, Fr) +import ZK.Factors (Fr, factors) main :: IO () main = mempty From 090ca2082b598a44674b4e2fa96db2f1c31003ea Mon Sep 17 00:00:00 2001 From: martyall Date: Wed, 22 May 2024 13:50:08 -0700 Subject: [PATCH 4/6] wip --- .gitignore | 1 + .parcelrc | 3 +++ app/Prover/Prove.js | 34 +++++++++++++++++++++++++---- cabal.project | 2 +- factors/cli/Main.hs | 10 +++++++++ factors/compile/Main.hs | 14 ------------ factors/factors.cabal | 21 ++++-------------- factors/native-solver/Main.hs | 25 --------------------- factors/src/ZK/Factors.hs | 19 ++++++++-------- factors/test/Main.hs | 37 +++++++++++++++++++++----------- package-lock.json | 3 ++- package.json | 5 +++-- wasm-solver/app/Main.hs | 12 ++++++++--- wasm-solver/cabal.project | 2 +- wasm-solver/factors-solver.cabal | 4 +++- 15 files changed, 100 insertions(+), 92 deletions(-) create mode 100644 factors/cli/Main.hs delete mode 100644 factors/compile/Main.hs delete mode 100644 factors/native-solver/Main.hs diff --git a/.gitignore b/.gitignore index b2b6ab3..6368b42 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ dist-newstyle www/circuit_final.zkey www/circuit.wasm +www/circuit.bin output .spago .purs-repl diff --git a/.parcelrc b/.parcelrc index 89a3cde..a2e1d78 100644 --- a/.parcelrc +++ b/.parcelrc @@ -7,6 +7,9 @@ "*.wasm": [ "@parcel/transformer-raw" ], + "*.bin": [ + "@parcel/transformer-raw" + ], "*.zkey": [ "@parcel/transformer-raw" ] diff --git a/app/Prover/Prove.js b/app/Prover/Prove.js index 6ba186a..3b1f944 100644 --- a/app/Prover/Prove.js +++ b/app/Prover/Prove.js @@ -1,16 +1,42 @@ -import { WASI } from "@bjorn3/browser_wasi_shim/dist"; +import { WASI, PreopenDirectory, File, strace } from "@bjorn3/browser_wasi_shim/dist"; import { groth16, wtns } from "snarkjs"; +async function load_external_file(path) { + const response = await fetch(path); + const buffer = await response.arrayBuffer(); + console.log(buffer); + return new File(buffer); +} async function _fullProve(input) { const wasmFile = "circuit.wasm"; const zkeyFile = "circuit_final.zkey"; - const wasi = new WASI([], [], []); - let options = { additionalImports: { wasi_snapshot_preview1: wasi.wasiImport }}; - const w= { + let fds = [ + new PreopenDirectory("/", [ + ["circuit.bin", await load_external_file("circuit.bin")] + ]) + ]; + console.log(fds); + const wasi = new WASI([], [], fds, { debug: true }); + console.log("wasi pre-initialized"); + console.log(wasi); + let options = { + initializeWasi: (instance) => { + wasi.initialize(instance); + console.log("wasi post-initialized"); + console.log(wasi); + }, + additionalWASMImports: { + wasi_snapshot_preview1: strace(wasi.wasiImport, ["proc_exit"]) + } + }; + + const w = { type: "mem" }; await wtns.calculate(input, wasmFile, w, options); + console.log("fds"); + console.log(fds); const {proof, publicSignals} = await groth16.prove(zkeyFile, w); return {proof, inputs: publicSignals}; } diff --git a/cabal.project b/cabal.project index db9c353..5b40b5e 100644 --- a/cabal.project +++ b/cabal.project @@ -25,7 +25,7 @@ source-repository-package source-repository-package type: git location: https://github.com/l-adic/arithmetic-circuits.git - tag: b0fc0e4d9e1fdcf7591298487284206688bcb8e1 + tag: 5652076dd29189c1362c9e3d938d03feeff6eb21 --sha256: jI3tAEGwOBqiCr6JqQfAws3X2RIp1eYbI9fXWutTMuE= index-state: 2024-05-21T06:16:08Z diff --git a/factors/cli/Main.hs b/factors/cli/Main.hs new file mode 100644 index 0000000..3ae9ff9 --- /dev/null +++ b/factors/cli/Main.hs @@ -0,0 +1,10 @@ +{-# LANGUAGE TemplateHaskell #-} + +module Main where + +import Circom.CLI (defaultMain) +import Protolude +import ZK.Factors (Fr, factors) + +main :: IO () +main = defaultMain "circuit" $ factors @Fr diff --git a/factors/compile/Main.hs b/factors/compile/Main.hs deleted file mode 100644 index 5e20ad7..0000000 --- a/factors/compile/Main.hs +++ /dev/null @@ -1,14 +0,0 @@ -module Main where - -import Circuit.Solver.Circom (CircomProgram (..)) -import Data.Binary (encodeFile) -import Protolude -import R1CS (toR1CS) -import R1CS.Circom (r1csToCircomR1CS) -import ZK.Factors - -main :: IO () -main = do - let r1cs = r1csToCircomR1CS $ toR1CS (cpVars factors) (cpCircuit factors) - encodeFile "trusted-setup/circuit.r1cs" r1cs - encodeFile "trusted-setup/circuit.bin" factors diff --git a/factors/factors.cabal b/factors/factors.cabal index 83665ee..356fc24 100644 --- a/factors/factors.cabal +++ b/factors/factors.cabal @@ -13,6 +13,7 @@ common extensions DataKinds TypeApplications NoImplicitPrelude + NamedFieldPuns RecordWildCards OverloadedStrings @@ -34,27 +35,13 @@ library hs-source-dirs: src default-language: GHC2021 -executable compile +executable cli import: warnings, extensions, deps main-is: Main.hs build-depends: - binary - , factors - - hs-source-dirs: compile - default-language: GHC2021 - -executable native-solver - import: warnings, extensions, deps - main-is: Main.hs - build-depends: - aeson - , binary - , factors - , file-embed >= 0.0.16.0 - , string-conversions + factors - hs-source-dirs: native-solver + hs-source-dirs: cli default-language: GHC2021 test-suite factors-test diff --git a/factors/native-solver/Main.hs b/factors/native-solver/Main.hs deleted file mode 100644 index e9384a9..0000000 --- a/factors/native-solver/Main.hs +++ /dev/null @@ -1,25 +0,0 @@ -{-# LANGUAGE TemplateHaskell #-} - -module Main where - -import Circuit.Solver.Circom (CircomProgram, nativeGenWitness) -import Data.Aeson (decodeFileStrict) -import Data.Binary (decode, encodeFile) -import Data.FileEmbed (embedFileRelative) -import Data.String.Conversions (cs) -import Protolude -import ZK.Factors (Fr) - -main :: IO () -main = do - mInputs <- decodeFileStrict "trusted-setup/inputs.json" - inputs <- maybe (panic "Failed to decode inputs") (pure . map fromInteger) mInputs - let circuit :: CircomProgram Fr - circuit = decode $ cs circuitBin - wtns = nativeGenWitness circuit inputs - encodeFile "trusted-setup/circuit.wtns" wtns - --- We do this to avoid compiling the program twice. It's easier to read it --- from a file after initial compilation. -circuitBin :: ByteString -circuitBin = $(embedFileRelative "../trusted-setup/circuit.bin") diff --git a/factors/src/ZK/Factors.hs b/factors/src/ZK/Factors.hs index 2213428..d3a53ff 100644 --- a/factors/src/ZK/Factors.hs +++ b/factors/src/ZK/Factors.hs @@ -9,20 +9,19 @@ where import Circuit import Circuit.Language -import Circuit.Solver.Circom (CircomProgram, mkCircomProgram) import Data.Field.Galois (GaloisField, Prime) import Protolude type Fr = Prime 21888242871839275222246405745257275088548364400416034343698204186575808495617 -factorsE :: (GaloisField f, Hashable f) => ExprM f (Var Wire f 'TBool) -factorsE = do - n <- var_ <$> fieldInput Public "n" +factors :: (GaloisField f, Hashable f) => ExprM f (Var Wire f 'TBool) +factors = do a <- var_ <$> fieldInput Private "a" b <- var_ <$> fieldInput Private "b" - boolOutput "out" $ eq_ n (a * b) - -factors :: CircomProgram Fr -factors = - let BuilderState {..} = snd $ runCircuitBuilder factorsE - in mkCircomProgram bsVars bsCircuit + n <- var_ <$> fieldInput Public "n" + let cs = + [ neq_ n a, + neq_ n b, + eq_ n (a * b) + ] + boolOutput "out" $ unAnd_ $ foldMap And_ cs diff --git a/factors/test/Main.hs b/factors/test/Main.hs index 1e3dd28..5fdb435 100644 --- a/factors/test/Main.hs +++ b/factors/test/Main.hs @@ -1,33 +1,44 @@ module Main (main) where -import Circuit (lookupVar) -import Circuit.Solver.Circom (CircomProgram (..), nativeGenWitness) +import Circom.R1CS (witnessFromCircomWitness) +import Circom.Solver (CircomProgram (..), mkCircomProgram, nativeGenWitness) +import Circuit +import Circuit.Language import qualified Data.Map as Map import Protolude import R1CS (Witness (..)) -import R1CS.Circom (witnessFromCircomWitness) import Test.Hspec import Test.QuickCheck -import ZK.Factors (factors) +import ZK.Factors (Fr, factors) main :: IO () main = hspec $ do - let vars = cpVars factors + let BuilderState {bsVars, bsCircuit} = snd $ runCircuitBuilder (factors @Fr) + program = mkCircomProgram bsVars bsCircuit + vars = cpVars program describe "Factors" $ do - it "should accept valid factors" $ do + it "should accept valid factorizations" $ property $ \x y -> - let inputs = Map.fromList [("n", x * y), ("a", x), ("b", y)] - Witness w = - witnessFromCircomWitness $ - nativeGenWitness factors inputs - in lookupVar vars "out" w === Just 1 - it "shouldn't accept invalid factors" $ do + (x /= 1 && y /= 1) ==> + let inputs = Map.fromList [("n", x * y), ("a", x), ("b", y)] + Witness w = + witnessFromCircomWitness $ + nativeGenWitness program inputs + in lookupVar vars "out" w === Just 1 + it "shouldn't accept trivial factorizations" $ + property $ \x -> + let inputs = Map.fromList [("n", x), ("a", 1), ("b", x)] + Witness w = + witnessFromCircomWitness $ + nativeGenWitness program inputs + in lookupVar vars "out" w == Just 0 + it "shouldn't accept invalid factorizations" $ property $ \x y z -> (x * y /= z) ==> let inputs = Map.fromList [("n", z), ("a", x), ("b", y)] Witness w = witnessFromCircomWitness $ - nativeGenWitness factors inputs + nativeGenWitness program inputs in lookupVar vars "out" w == Just 0 diff --git a/package-lock.json b/package-lock.json index c56a311..aa7547b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "license": "ISC", "dependencies": { "@bjorn3/browser_wasi_shim": "^0.3.0", + "circom_runtime": "github:l-adic/circom_runtime#920bcb1", "ethjs-provider-http": "^0.1.6", "keccak": "^3.0.0", "secp256k1": "^5.0.0", @@ -2980,7 +2981,7 @@ }, "node_modules/circom_runtime": { "version": "0.1.25", - "resolved": "git+ssh://git@github.com/l-adic/circom_runtime.git#1957dbe25714ab21b78cea88e2093ee00acebbee", + "resolved": "git+ssh://git@github.com/l-adic/circom_runtime.git#920bcb1b9e37b90e283e3d987301e192801604d7", "license": "Apache-2.0", "dependencies": { "ffjavascript": "0.3.0" diff --git a/package.json b/package.json index e704440..a43f5e1 100644 --- a/package.json +++ b/package.json @@ -36,10 +36,11 @@ "ethjs-provider-http": "^0.1.6", "keccak": "^3.0.0", "secp256k1": "^5.0.0", - "snarkjs": "github:l-adic/snarkjs#actually-use-wasm-options" + "snarkjs": "github:l-adic/snarkjs#actually-use-wasm-options", + "circom_runtime": "github:l-adic/circom_runtime#920bcb1" }, "overrides": { - "circom_runtime": "github:l-adic/circom_runtime#wasi-import-options" + "circom_runtime": "github:l-adic/circom_runtime#920bcb1" }, "parcel": { "aliases": { diff --git a/wasm-solver/app/Main.hs b/wasm-solver/app/Main.hs index 6378300..8bd2a47 100644 --- a/wasm-solver/app/Main.hs +++ b/wasm-solver/app/Main.hs @@ -1,10 +1,12 @@ module Main where -import Circuit.Solver.Circom qualified as Circom +import Data.Binary (encodeFile) +import Circom.Solver qualified as Circom import Data.IORef (IORef, newIORef) import Protolude import System.IO.Unsafe (unsafePerformIO) import ZK.Factors (Fr, factors) +import Circuit.Language main :: IO () main = mempty @@ -16,7 +18,9 @@ stateRef = unsafePerformIO $ do {-# NOINLINE stateRef #-} env :: Circom.ProgramEnv Fr -env = Circom.mkProgramEnv factors +env = Circom.mkProgramEnv $ + let BuilderState {bsVars, bsCircuit} = snd $ runCircuitBuilder factors + in Circom.mkCircomProgram bsVars bsCircuit foreign export ccall init :: Int -> IO () @@ -36,7 +40,9 @@ getVersion = Circom._getVersion env foreign export ccall getRawPrime :: IO () getRawPrime :: IO () -getRawPrime = Circom._getRawPrime env stateRef +getRawPrime = do + encodeFile "/foo.bin" (1234 :: Int) + Circom._getRawPrime env stateRef foreign export ccall writeSharedRWMemory :: Int -> Word32 -> IO () diff --git a/wasm-solver/cabal.project b/wasm-solver/cabal.project index 839fbad..562edbe 100644 --- a/wasm-solver/cabal.project +++ b/wasm-solver/cabal.project @@ -35,5 +35,5 @@ source-repository-package source-repository-package type: git location: https://github.com/l-adic/arithmetic-circuits.git - tag: b0fc0e4d9e1fdcf7591298487284206688bcb8e1 + tag: 5652076dd29189c1362c9e3d938d03feeff6eb21 --sha256: jI3tAEGwOBqiCr6JqQfAws3X2RIp1eYbI9fXWutTMuE= diff --git a/wasm-solver/factors-solver.cabal b/wasm-solver/factors-solver.cabal index a27a2ca..11c68c5 100644 --- a/wasm-solver/factors-solver.cabal +++ b/wasm-solver/factors-solver.cabal @@ -14,10 +14,12 @@ executable wasm-solver RecordWildCards ghc-options: -Wall -Wunused-packages -no-hs-main -optl-mexec-model=reactor - "-optl-Wl,--export=init,--export=getNVars,--export=getVersion,--export=getRawPrime,--export=writeSharedRWMemory,--export=readSharedRWMemory,--export=getFieldNumLen32,--export=setInputSignal,--export=getInputSignalSize,--export=getWitnessSize,--export=getWitness,--export=getInputSize" + "-optl-Wl, --export=hs_init, --export=init,--export=getNVars,--export=getVersion,--export=getRawPrime,--export=writeSharedRWMemory,--export=readSharedRWMemory,--export=getFieldNumLen32,--export=setInputSignal,--export=getInputSignalSize,--export=getWitnessSize,--export=getWitness,--export=getInputSize" build-depends: arithmetic-circuits:circom-compat + , arithmetic-circuits:language , base >=4.10 && <5 + , binary , factors , protolude From ed28095b5c2e7798a2e05a50ec9ca7048d82b605 Mon Sep 17 00:00:00 2001 From: martyall Date: Wed, 22 May 2024 21:56:24 -0700 Subject: [PATCH 5/6] works with loading circuit.bin file, updated readme --- README.md | 21 +- app/Prover/Prove.js | 18 +- cabal.project | 2 +- factors/factors.cabal | 3 +- factors/test/Main.hs | 5 + package-lock.json | 602 +------------------------------ package.json | 4 +- wasm-solver/app/Main.hs | 18 +- wasm-solver/cabal.project | 2 +- wasm-solver/factors-solver.cabal | 3 +- 10 files changed, 44 insertions(+), 634 deletions(-) diff --git a/README.md b/README.md index 94e84d9..a87993c 100644 --- a/README.md +++ b/README.md @@ -26,13 +26,24 @@ You should have a local ethereum node with an unlocked default account and the w ## Contents ### The factors zk program -A ZK program written in a Haskell DSL that expresses a factorization of a public input `n` into a product of secret inputs `a` and `b`. You can produce a circom compatible `r1cs` file for this program by running +A ZK program written in a Haskell DSL that expresses a factorization of a public input `n` into a product of secret inputs `a` and `b`. The factorization must be non-trivial, i.e. `a /= 1 && b /= 1`. + +You can produce a circom compatible `r1cs` file for this program by running + +``` +> cabal run factors-cli -- compile --output-dir trusted-setup +``` + +You should see the artifacts ``` -> cabal run compile +trusted-setup +├── circuit.bin +├── circuit.r1cs +└ ... ``` -You should see an artifact `trusted-setup/circuit.r1cs`. +The `circuit.r1cs` file is the R1CS that is expected by snarkjs for proving/verification key generation. The `circuit.bin` is the binary serialization of the constraints represented by the compiled circuit. This file is required in order to evaluate the circuit, i.e. generate a witness. ### A factors program constraint solver A constraint solver applied to the `factors` program. You can produce a circom compatible WASM binary for this solver by running @@ -68,10 +79,10 @@ You can comple the contracts, build the purescript ffi, and deploy this smart co ``` ### A frontend application -Assuming you have done the previous steps, copy the proving key to the `www` folder +Assuming you have done the previous steps, copy the proving key and the compiled circuit to the `www` folder ``` -> cp trusted-setup/circuit_final.zkey www +> cp trusted-setup/circuit_final.zkey trusted-setup/circuit.bin www ``` You should see the `circuit.wasm` solver binary is already there. Assuming you have deployed the verifying contract, you can start the frontend: diff --git a/app/Prover/Prove.js b/app/Prover/Prove.js index 3b1f944..38c3fb5 100644 --- a/app/Prover/Prove.js +++ b/app/Prover/Prove.js @@ -1,10 +1,9 @@ -import { WASI, PreopenDirectory, File, strace } from "@bjorn3/browser_wasi_shim/dist"; +import { WASI, PreopenDirectory, File, OpenFile, ConsoleStdout } from "@bjorn3/browser_wasi_shim/dist"; import { groth16, wtns } from "snarkjs"; async function load_external_file(path) { const response = await fetch(path); const buffer = await response.arrayBuffer(); - console.log(buffer); return new File(buffer); } @@ -12,31 +11,26 @@ async function _fullProve(input) { const wasmFile = "circuit.wasm"; const zkeyFile = "circuit_final.zkey"; let fds = [ + new OpenFile(new File([])), // stdin + ConsoleStdout.lineBuffered(msg => console.log(`[WASI stdout] ${msg}`)), + ConsoleStdout.lineBuffered(msg => console.warn(`[WASI stderr] ${msg}`)), new PreopenDirectory("/", [ ["circuit.bin", await load_external_file("circuit.bin")] ]) ]; - console.log(fds); const wasi = new WASI([], [], fds, { debug: true }); - console.log("wasi pre-initialized"); - console.log(wasi); let options = { - initializeWasi: (instance) => { + initializeWasiReactorModuleInstance: (instance) => { wasi.initialize(instance); - console.log("wasi post-initialized"); - console.log(wasi); }, additionalWASMImports: { - wasi_snapshot_preview1: strace(wasi.wasiImport, ["proc_exit"]) + wasi_snapshot_preview1: wasi.wasiImport } }; - const w = { type: "mem" }; await wtns.calculate(input, wasmFile, w, options); - console.log("fds"); - console.log(fds); const {proof, publicSignals} = await groth16.prove(zkeyFile, w); return {proof, inputs: publicSignals}; } diff --git a/cabal.project b/cabal.project index 5b40b5e..0b61b1d 100644 --- a/cabal.project +++ b/cabal.project @@ -25,7 +25,7 @@ source-repository-package source-repository-package type: git location: https://github.com/l-adic/arithmetic-circuits.git - tag: 5652076dd29189c1362c9e3d938d03feeff6eb21 + tag: cb35efaceafa2caebb3de3473ac4dffe7f2f47ab --sha256: jI3tAEGwOBqiCr6JqQfAws3X2RIp1eYbI9fXWutTMuE= index-state: 2024-05-21T06:16:08Z diff --git a/factors/factors.cabal b/factors/factors.cabal index 356fc24..b6491a1 100644 --- a/factors/factors.cabal +++ b/factors/factors.cabal @@ -35,7 +35,7 @@ library hs-source-dirs: src default-language: GHC2021 -executable cli +executable factors-cli import: warnings, extensions, deps main-is: Main.hs build-depends: @@ -51,6 +51,7 @@ test-suite factors-test hs-source-dirs: test main-is: Main.hs build-depends: + binary , factors , hspec , QuickCheck diff --git a/factors/test/Main.hs b/factors/test/Main.hs index 5fdb435..31ee241 100644 --- a/factors/test/Main.hs +++ b/factors/test/Main.hs @@ -10,6 +10,7 @@ import R1CS (Witness (..)) import Test.Hspec import Test.QuickCheck import ZK.Factors (Fr, factors) +import Data.Binary (encode, decode) main :: IO () main = hspec $ do @@ -17,6 +18,10 @@ main = hspec $ do program = mkCircomProgram bsVars bsCircuit vars = cpVars program describe "Factors" $ do + it "can serialize/deserialize the program" $ do + let a = decode (encode program) + cpCircuit a `shouldBe` cpCircuit program + it "should accept valid factorizations" $ property $ \x y -> diff --git a/package-lock.json b/package-lock.json index aa7547b..c9c586f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "license": "ISC", "dependencies": { "@bjorn3/browser_wasi_shim": "^0.3.0", - "circom_runtime": "github:l-adic/circom_runtime#920bcb1", + "circom_runtime": "github:l-adic/circom_runtime#bbfe3eeb68e18dfcb4d5e24668e536b030741e31", "ethjs-provider-http": "^0.1.6", "keccak": "^3.0.0", "secp256k1": "^5.0.0", @@ -209,58 +209,6 @@ "@lezer/common": "^1.0.0" } }, - "node_modules/@lmdb/lmdb-darwin-arm64": { - "version": "2.8.5", - "resolved": "https://registry.npmjs.org/@lmdb/lmdb-darwin-arm64/-/lmdb-darwin-arm64-2.8.5.tgz", - "integrity": "sha512-KPDeVScZgA1oq0CiPBcOa3kHIqU+pTOwRFDIhxvmf8CTNvqdZQYp5cCKW0bUk69VygB2PuTiINFWbY78aR2pQw==", - "cpu": [ - "arm64" - ], - "dev": true, - "optional": true, - "os": [ - "darwin" - ] - }, - "node_modules/@lmdb/lmdb-darwin-x64": { - "version": "2.8.5", - "resolved": "https://registry.npmjs.org/@lmdb/lmdb-darwin-x64/-/lmdb-darwin-x64-2.8.5.tgz", - "integrity": "sha512-w/sLhN4T7MW1nB3R/U8WK5BgQLz904wh+/SmA2jD8NnF7BLLoUgflCNxOeSPOWp8geP6nP/+VjWzZVip7rZ1ug==", - "cpu": [ - "x64" - ], - "dev": true, - "optional": true, - "os": [ - "darwin" - ] - }, - "node_modules/@lmdb/lmdb-linux-arm": { - "version": "2.8.5", - "resolved": "https://registry.npmjs.org/@lmdb/lmdb-linux-arm/-/lmdb-linux-arm-2.8.5.tgz", - "integrity": "sha512-c0TGMbm2M55pwTDIfkDLB6BpIsgxV4PjYck2HiOX+cy/JWiBXz32lYbarPqejKs9Flm7YVAKSILUducU9g2RVg==", - "cpu": [ - "arm" - ], - "dev": true, - "optional": true, - "os": [ - "linux" - ] - }, - "node_modules/@lmdb/lmdb-linux-arm64": { - "version": "2.8.5", - "resolved": "https://registry.npmjs.org/@lmdb/lmdb-linux-arm64/-/lmdb-linux-arm64-2.8.5.tgz", - "integrity": "sha512-vtbZRHH5UDlL01TT5jB576Zox3+hdyogvpcbvVJlmU5PdL3c5V7cj1EODdh1CHPksRl+cws/58ugEHi8bcj4Ww==", - "cpu": [ - "arm64" - ], - "dev": true, - "optional": true, - "os": [ - "linux" - ] - }, "node_modules/@lmdb/lmdb-linux-x64": { "version": "2.8.5", "resolved": "https://registry.npmjs.org/@lmdb/lmdb-linux-x64/-/lmdb-linux-x64-2.8.5.tgz", @@ -274,19 +222,6 @@ "linux" ] }, - "node_modules/@lmdb/lmdb-win32-x64": { - "version": "2.8.5", - "resolved": "https://registry.npmjs.org/@lmdb/lmdb-win32-x64/-/lmdb-win32-x64-2.8.5.tgz", - "integrity": "sha512-4wvrf5BgnR8RpogHhtpCPJMKBmvyZPhhUtEwMJbXh0ni2BucpfF07jlmyM11zRqQ2XIq6PbC2j7W7UCCcm1rRQ==", - "cpu": [ - "x64" - ], - "dev": true, - "optional": true, - "os": [ - "win32" - ] - }, "node_modules/@mischnic/json-sourcemap": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/@mischnic/json-sourcemap/-/json-sourcemap-0.1.1.tgz", @@ -301,58 +236,6 @@ "node": ">=12.0.0" } }, - "node_modules/@msgpackr-extract/msgpackr-extract-darwin-arm64": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/@msgpackr-extract/msgpackr-extract-darwin-arm64/-/msgpackr-extract-darwin-arm64-3.0.2.tgz", - "integrity": "sha512-9bfjwDxIDWmmOKusUcqdS4Rw+SETlp9Dy39Xui9BEGEk19dDwH0jhipwFzEff/pFg95NKymc6TOTbRKcWeRqyQ==", - "cpu": [ - "arm64" - ], - "dev": true, - "optional": true, - "os": [ - "darwin" - ] - }, - "node_modules/@msgpackr-extract/msgpackr-extract-darwin-x64": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/@msgpackr-extract/msgpackr-extract-darwin-x64/-/msgpackr-extract-darwin-x64-3.0.2.tgz", - "integrity": "sha512-lwriRAHm1Yg4iDf23Oxm9n/t5Zpw1lVnxYU3HnJPTi2lJRkKTrps1KVgvL6m7WvmhYVt/FIsssWay+k45QHeuw==", - "cpu": [ - "x64" - ], - "dev": true, - "optional": true, - "os": [ - "darwin" - ] - }, - "node_modules/@msgpackr-extract/msgpackr-extract-linux-arm": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/@msgpackr-extract/msgpackr-extract-linux-arm/-/msgpackr-extract-linux-arm-3.0.2.tgz", - "integrity": "sha512-MOI9Dlfrpi2Cuc7i5dXdxPbFIgbDBGgKR5F2yWEa6FVEtSWncfVNKW5AKjImAQ6CZlBK9tympdsZJ2xThBiWWA==", - "cpu": [ - "arm" - ], - "dev": true, - "optional": true, - "os": [ - "linux" - ] - }, - "node_modules/@msgpackr-extract/msgpackr-extract-linux-arm64": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/@msgpackr-extract/msgpackr-extract-linux-arm64/-/msgpackr-extract-linux-arm64-3.0.2.tgz", - "integrity": "sha512-FU20Bo66/f7He9Fp9sP2zaJ1Q8L9uLPZQDub/WlUip78JlPeMbVL8546HbZfcW9LNciEXc8d+tThSJjSC+tmsg==", - "cpu": [ - "arm64" - ], - "dev": true, - "optional": true, - "os": [ - "linux" - ] - }, "node_modules/@msgpackr-extract/msgpackr-extract-linux-x64": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/@msgpackr-extract/msgpackr-extract-linux-x64/-/msgpackr-extract-linux-x64-3.0.2.tgz", @@ -366,19 +249,6 @@ "linux" ] }, - "node_modules/@msgpackr-extract/msgpackr-extract-win32-x64": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/@msgpackr-extract/msgpackr-extract-win32-x64/-/msgpackr-extract-win32-x64-3.0.2.tgz", - "integrity": "sha512-O+6Gs8UeDbyFpbSh2CPEz/UOrrdWPTBYNblZK5CxxLisYt4kGX3Sc+czffFonyjiGSq3jWLwJS/CCJc7tBr4sQ==", - "cpu": [ - "x64" - ], - "dev": true, - "optional": true, - "os": [ - "win32" - ] - }, "node_modules/@npmcli/fs": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/@npmcli/fs/-/fs-2.1.2.tgz", @@ -1943,146 +1813,6 @@ "@parcel/watcher-win32-x64": "2.4.1" } }, - "node_modules/@parcel/watcher-android-arm64": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/@parcel/watcher-android-arm64/-/watcher-android-arm64-2.4.1.tgz", - "integrity": "sha512-LOi/WTbbh3aTn2RYddrO8pnapixAziFl6SMxHM69r3tvdSm94JtCenaKgk1GRg5FJ5wpMCpHeW+7yqPlvZv7kg==", - "cpu": [ - "arm64" - ], - "dev": true, - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">= 10.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" - } - }, - "node_modules/@parcel/watcher-darwin-arm64": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/@parcel/watcher-darwin-arm64/-/watcher-darwin-arm64-2.4.1.tgz", - "integrity": "sha512-ln41eihm5YXIY043vBrrHfn94SIBlqOWmoROhsMVTSXGh0QahKGy77tfEywQ7v3NywyxBBkGIfrWRHm0hsKtzA==", - "cpu": [ - "arm64" - ], - "dev": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">= 10.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" - } - }, - "node_modules/@parcel/watcher-darwin-x64": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/@parcel/watcher-darwin-x64/-/watcher-darwin-x64-2.4.1.tgz", - "integrity": "sha512-yrw81BRLjjtHyDu7J61oPuSoeYWR3lDElcPGJyOvIXmor6DEo7/G2u1o7I38cwlcoBHQFULqF6nesIX3tsEXMg==", - "cpu": [ - "x64" - ], - "dev": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">= 10.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" - } - }, - "node_modules/@parcel/watcher-freebsd-x64": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/@parcel/watcher-freebsd-x64/-/watcher-freebsd-x64-2.4.1.tgz", - "integrity": "sha512-TJa3Pex/gX3CWIx/Co8k+ykNdDCLx+TuZj3f3h7eOjgpdKM+Mnix37RYsYU4LHhiYJz3DK5nFCCra81p6g050w==", - "cpu": [ - "x64" - ], - "dev": true, - "optional": true, - "os": [ - "freebsd" - ], - "engines": { - "node": ">= 10.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" - } - }, - "node_modules/@parcel/watcher-linux-arm-glibc": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/@parcel/watcher-linux-arm-glibc/-/watcher-linux-arm-glibc-2.4.1.tgz", - "integrity": "sha512-4rVYDlsMEYfa537BRXxJ5UF4ddNwnr2/1O4MHM5PjI9cvV2qymvhwZSFgXqbS8YoTk5i/JR0L0JDs69BUn45YA==", - "cpu": [ - "arm" - ], - "dev": true, - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" - } - }, - "node_modules/@parcel/watcher-linux-arm64-glibc": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/@parcel/watcher-linux-arm64-glibc/-/watcher-linux-arm64-glibc-2.4.1.tgz", - "integrity": "sha512-BJ7mH985OADVLpbrzCLgrJ3TOpiZggE9FMblfO65PlOCdG++xJpKUJ0Aol74ZUIYfb8WsRlUdgrZxKkz3zXWYA==", - "cpu": [ - "arm64" - ], - "dev": true, - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" - } - }, - "node_modules/@parcel/watcher-linux-arm64-musl": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/@parcel/watcher-linux-arm64-musl/-/watcher-linux-arm64-musl-2.4.1.tgz", - "integrity": "sha512-p4Xb7JGq3MLgAfYhslU2SjoV9G0kI0Xry0kuxeG/41UfpjHGOhv7UoUDAz/jb1u2elbhazy4rRBL8PegPJFBhA==", - "cpu": [ - "arm64" - ], - "dev": true, - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" - } - }, "node_modules/@parcel/watcher-linux-x64-glibc": { "version": "2.4.1", "resolved": "https://registry.npmjs.org/@parcel/watcher-linux-x64-glibc/-/watcher-linux-x64-glibc-2.4.1.tgz", @@ -2123,66 +1853,6 @@ "url": "https://opencollective.com/parcel" } }, - "node_modules/@parcel/watcher-win32-arm64": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/@parcel/watcher-win32-arm64/-/watcher-win32-arm64-2.4.1.tgz", - "integrity": "sha512-Uq2BPp5GWhrq/lcuItCHoqxjULU1QYEcyjSO5jqqOK8RNFDBQnenMMx4gAl3v8GiWa59E9+uDM7yZ6LxwUIfRg==", - "cpu": [ - "arm64" - ], - "dev": true, - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">= 10.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" - } - }, - "node_modules/@parcel/watcher-win32-ia32": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/@parcel/watcher-win32-ia32/-/watcher-win32-ia32-2.4.1.tgz", - "integrity": "sha512-maNRit5QQV2kgHFSYwftmPBxiuK5u4DXjbXx7q6eKjq5dsLXZ4FJiVvlcw35QXzk0KrUecJmuVFbj4uV9oYrcw==", - "cpu": [ - "ia32" - ], - "dev": true, - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">= 10.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" - } - }, - "node_modules/@parcel/watcher-win32-x64": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/@parcel/watcher-win32-x64/-/watcher-win32-x64-2.4.1.tgz", - "integrity": "sha512-+DvS92F9ezicfswqrvIRM2njcYJbd5mb9CUgtrHCHmvn7pPPa+nMDRu1o1bYYz/l5IB2NVGNJWiH7h1E58IF2A==", - "cpu": [ - "x64" - ], - "dev": true, - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">= 10.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" - } - }, "node_modules/@parcel/workers": { "version": "2.12.0", "resolved": "https://registry.npmjs.org/@parcel/workers/-/workers-2.12.0.tgz", @@ -2255,86 +1925,6 @@ } } }, - "node_modules/@swc/core-darwin-arm64": { - "version": "1.4.15", - "resolved": "https://registry.npmjs.org/@swc/core-darwin-arm64/-/core-darwin-arm64-1.4.15.tgz", - "integrity": "sha512-m1D89yN82QTp8AcSm3p9YgcfbdOqc9WmhvnMwoS0lUs6RIIFekI2tEboc9Rp9gre/1lkgzPYI+KGge1BaQzScA==", - "cpu": [ - "arm64" - ], - "dev": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-darwin-x64": { - "version": "1.4.15", - "resolved": "https://registry.npmjs.org/@swc/core-darwin-x64/-/core-darwin-x64-1.4.15.tgz", - "integrity": "sha512-aQBTfKrXIKiBrZY5MtqMRtbXTYCnMxUir4qy0me0+sIWTVxQ7znBxrwQsXsbPHIIZ+pohcLCg0HKfybev0NqXA==", - "cpu": [ - "x64" - ], - "dev": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-linux-arm-gnueabihf": { - "version": "1.4.15", - "resolved": "https://registry.npmjs.org/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.4.15.tgz", - "integrity": "sha512-EZhdJBjzct/0UiF3sPD1w+LbLFJOsvym4b3njyl7jnP+py5rz2WlIJDxVKcS+b1RKEebLU7OsnYXzuXFjq0dwA==", - "cpu": [ - "arm" - ], - "dev": true, - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-linux-arm64-gnu": { - "version": "1.4.15", - "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.4.15.tgz", - "integrity": "sha512-plKc41q8PgOm5rm3gEmPs+0skuddW0CrXPsERFzyaJ8gKTEwOVtg3sa3folXzsIgw0ODr61xzqYnh7zgJllMGg==", - "cpu": [ - "arm64" - ], - "dev": true, - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-linux-arm64-musl": { - "version": "1.4.15", - "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.4.15.tgz", - "integrity": "sha512-4Gj0z1bo1rI3pKanqv5grH4EZ/pJRGZXG9LnkZ9FBrg4LUgptEumomca1UYFgBifHi3hirJsOQacuKFpw2NCEg==", - "cpu": [ - "arm64" - ], - "dev": true, - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=10" - } - }, "node_modules/@swc/core-linux-x64-gnu": { "version": "1.4.15", "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.4.15.tgz", @@ -2367,54 +1957,6 @@ "node": ">=10" } }, - "node_modules/@swc/core-win32-arm64-msvc": { - "version": "1.4.15", - "resolved": "https://registry.npmjs.org/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.4.15.tgz", - "integrity": "sha512-q+u2toNPU9OQonSUI0pB6BIGkNsIrvok6AbUJYpmvZqawmNrngSs9quS2WDe58vfIe9r0lVenweY6WIRlGMFTg==", - "cpu": [ - "arm64" - ], - "dev": true, - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-win32-ia32-msvc": { - "version": "1.4.15", - "resolved": "https://registry.npmjs.org/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.4.15.tgz", - "integrity": "sha512-eEtU3yQXuBJO5tiokLz0sf0lABVNqR/l6p071v1ltDJGUD4vSer5kHOmm0Hn1zWB43EGda6b17Bb2DEHZ1DpKA==", - "cpu": [ - "ia32" - ], - "dev": true, - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-win32-x64-msvc": { - "version": "1.4.15", - "resolved": "https://registry.npmjs.org/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.4.15.tgz", - "integrity": "sha512-9CWhKyrDgrotsciAYFSsDIYgi/4LRbvJusyAtA3RBeXar1eNouFPwdlwj8zTqtJsOteZAUpbZSret0Z59cTqCQ==", - "cpu": [ - "x64" - ], - "dev": true, - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=10" - } - }, "node_modules/@swc/counter": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/@swc/counter/-/counter-0.1.3.tgz", @@ -2981,7 +2523,7 @@ }, "node_modules/circom_runtime": { "version": "0.1.25", - "resolved": "git+ssh://git@github.com/l-adic/circom_runtime.git#920bcb1b9e37b90e283e3d987301e192801604d7", + "resolved": "git+ssh://git@github.com/l-adic/circom_runtime.git#bbfe3eeb68e18dfcb4d5e24668e536b030741e31", "license": "Apache-2.0", "dependencies": { "ffjavascript": "0.3.0" @@ -4812,126 +4354,6 @@ "lightningcss-win32-x64-msvc": "1.24.1" } }, - "node_modules/lightningcss-darwin-arm64": { - "version": "1.24.1", - "resolved": "https://registry.npmjs.org/lightningcss-darwin-arm64/-/lightningcss-darwin-arm64-1.24.1.tgz", - "integrity": "sha512-1jQ12jBy+AE/73uGQWGSafK5GoWgmSiIQOGhSEXiFJSZxzV+OXIx+a9h2EYHxdJfX864M+2TAxWPWb0Vv+8y4w==", - "cpu": [ - "arm64" - ], - "dev": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">= 12.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" - } - }, - "node_modules/lightningcss-darwin-x64": { - "version": "1.24.1", - "resolved": "https://registry.npmjs.org/lightningcss-darwin-x64/-/lightningcss-darwin-x64-1.24.1.tgz", - "integrity": "sha512-R4R1d7VVdq2mG4igMU+Di8GPf0b64ZLnYVkubYnGG0Qxq1KaXQtAzcLI43EkpnoWvB/kUg8JKCWH4S13NfiLcQ==", - "cpu": [ - "x64" - ], - "dev": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">= 12.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" - } - }, - "node_modules/lightningcss-freebsd-x64": { - "version": "1.24.1", - "resolved": "https://registry.npmjs.org/lightningcss-freebsd-x64/-/lightningcss-freebsd-x64-1.24.1.tgz", - "integrity": "sha512-z6NberUUw5ALES6Ixn2shmjRRrM1cmEn1ZQPiM5IrZ6xHHL5a1lPin9pRv+w6eWfcrEo+qGG6R9XfJrpuY3e4g==", - "cpu": [ - "x64" - ], - "dev": true, - "optional": true, - "os": [ - "freebsd" - ], - "engines": { - "node": ">= 12.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" - } - }, - "node_modules/lightningcss-linux-arm-gnueabihf": { - "version": "1.24.1", - "resolved": "https://registry.npmjs.org/lightningcss-linux-arm-gnueabihf/-/lightningcss-linux-arm-gnueabihf-1.24.1.tgz", - "integrity": "sha512-NLQLnBQW/0sSg74qLNI8F8QKQXkNg4/ukSTa+XhtkO7v3BnK19TS1MfCbDHt+TTdSgNEBv0tubRuapcKho2EWw==", - "cpu": [ - "arm" - ], - "dev": true, - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 12.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" - } - }, - "node_modules/lightningcss-linux-arm64-gnu": { - "version": "1.24.1", - "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-gnu/-/lightningcss-linux-arm64-gnu-1.24.1.tgz", - "integrity": "sha512-AQxWU8c9E9JAjAi4Qw9CvX2tDIPjgzCTrZCSXKELfs4mCwzxRkHh2RCxX8sFK19RyJoJAjA/Kw8+LMNRHS5qEg==", - "cpu": [ - "arm64" - ], - "dev": true, - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 12.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" - } - }, - "node_modules/lightningcss-linux-arm64-musl": { - "version": "1.24.1", - "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-musl/-/lightningcss-linux-arm64-musl-1.24.1.tgz", - "integrity": "sha512-JCgH/SrNrhqsguUA0uJUM1PvN5+dVuzPIlXcoWDHSv2OU/BWlj2dUYr3XNzEw748SmNZPfl2NjQrAdzaPOn1lA==", - "cpu": [ - "arm64" - ], - "dev": true, - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 12.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" - } - }, "node_modules/lightningcss-linux-x64-gnu": { "version": "1.24.1", "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-gnu/-/lightningcss-linux-x64-gnu-1.24.1.tgz", @@ -4972,26 +4394,6 @@ "url": "https://opencollective.com/parcel" } }, - "node_modules/lightningcss-win32-x64-msvc": { - "version": "1.24.1", - "resolved": "https://registry.npmjs.org/lightningcss-win32-x64-msvc/-/lightningcss-win32-x64-msvc-1.24.1.tgz", - "integrity": "sha512-joEupPjYJ7PjZtDsS5lzALtlAudAbgIBMGJPNeFe5HfdmJXFd13ECmEM+5rXNxYVMRHua2w8132R6ab5Z6K9Ow==", - "cpu": [ - "x64" - ], - "dev": true, - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">= 12.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" - } - }, "node_modules/lines-and-columns": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.2.4.tgz", diff --git a/package.json b/package.json index a43f5e1..2db6b9a 100644 --- a/package.json +++ b/package.json @@ -37,10 +37,10 @@ "keccak": "^3.0.0", "secp256k1": "^5.0.0", "snarkjs": "github:l-adic/snarkjs#actually-use-wasm-options", - "circom_runtime": "github:l-adic/circom_runtime#920bcb1" + "circom_runtime": "github:l-adic/circom_runtime#bbfe3eeb68e18dfcb4d5e24668e536b030741e31" }, "overrides": { - "circom_runtime": "github:l-adic/circom_runtime#920bcb1" + "circom_runtime": "github:l-adic/circom_runtime#bbfe3eeb68e18dfcb4d5e24668e536b030741e31" }, "parcel": { "aliases": { diff --git a/wasm-solver/app/Main.hs b/wasm-solver/app/Main.hs index 8bd2a47..28f2aa9 100644 --- a/wasm-solver/app/Main.hs +++ b/wasm-solver/app/Main.hs @@ -1,12 +1,11 @@ module Main where -import Data.Binary (encodeFile) +import Data.Binary (decodeFile) import Circom.Solver qualified as Circom import Data.IORef (IORef, newIORef) import Protolude import System.IO.Unsafe (unsafePerformIO) -import ZK.Factors (Fr, factors) -import Circuit.Language +import ZK.Factors (Fr) main :: IO () main = mempty @@ -18,9 +17,10 @@ stateRef = unsafePerformIO $ do {-# NOINLINE stateRef #-} env :: Circom.ProgramEnv Fr -env = Circom.mkProgramEnv $ - let BuilderState {bsVars, bsCircuit} = snd $ runCircuitBuilder factors - in Circom.mkCircomProgram bsVars bsCircuit +env = unsafePerformIO $ do + p <- decodeFile "/circuit.bin" + pure $ Circom.mkProgramEnv p +{-# NOINLINE env #-} foreign export ccall init :: Int -> IO () @@ -40,9 +40,7 @@ getVersion = Circom._getVersion env foreign export ccall getRawPrime :: IO () getRawPrime :: IO () -getRawPrime = do - encodeFile "/foo.bin" (1234 :: Int) - Circom._getRawPrime env stateRef +getRawPrime = Circom._getRawPrime env stateRef foreign export ccall writeSharedRWMemory :: Int -> Word32 -> IO () @@ -82,4 +80,4 @@ getWitnessSize = Circom._getWitnessSize env foreign export ccall getWitness :: Int -> IO () getWitness :: Int -> IO () -getWitness = Circom._getWitness env stateRef +getWitness = Circom._getWitness env stateRef \ No newline at end of file diff --git a/wasm-solver/cabal.project b/wasm-solver/cabal.project index 562edbe..a3828bb 100644 --- a/wasm-solver/cabal.project +++ b/wasm-solver/cabal.project @@ -35,5 +35,5 @@ source-repository-package source-repository-package type: git location: https://github.com/l-adic/arithmetic-circuits.git - tag: 5652076dd29189c1362c9e3d938d03feeff6eb21 + tag: cb35efaceafa2caebb3de3473ac4dffe7f2f47ab --sha256: jI3tAEGwOBqiCr6JqQfAws3X2RIp1eYbI9fXWutTMuE= diff --git a/wasm-solver/factors-solver.cabal b/wasm-solver/factors-solver.cabal index 11c68c5..6a8f5db 100644 --- a/wasm-solver/factors-solver.cabal +++ b/wasm-solver/factors-solver.cabal @@ -14,11 +14,10 @@ executable wasm-solver RecordWildCards ghc-options: -Wall -Wunused-packages -no-hs-main -optl-mexec-model=reactor - "-optl-Wl, --export=hs_init, --export=init,--export=getNVars,--export=getVersion,--export=getRawPrime,--export=writeSharedRWMemory,--export=readSharedRWMemory,--export=getFieldNumLen32,--export=setInputSignal,--export=getInputSignalSize,--export=getWitnessSize,--export=getWitness,--export=getInputSize" + "-optl-Wl,--export=init,--export=getNVars,--export=getVersion,--export=getRawPrime,--export=writeSharedRWMemory,--export=readSharedRWMemory,--export=getFieldNumLen32,--export=setInputSignal,--export=getInputSignalSize,--export=getWitnessSize,--export=getWitness,--export=getInputSize" build-depends: arithmetic-circuits:circom-compat - , arithmetic-circuits:language , base >=4.10 && <5 , binary , factors From 6acb31c0d9d12b72007dab38008512864e4ac625 Mon Sep 17 00:00:00 2001 From: martyall Date: Wed, 22 May 2024 22:13:50 -0700 Subject: [PATCH 6/6] updated circuits dep --- cabal.project | 2 +- wasm-solver/cabal.project | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cabal.project b/cabal.project index 0b61b1d..f76cdd9 100644 --- a/cabal.project +++ b/cabal.project @@ -25,7 +25,7 @@ source-repository-package source-repository-package type: git location: https://github.com/l-adic/arithmetic-circuits.git - tag: cb35efaceafa2caebb3de3473ac4dffe7f2f47ab + tag: 77415e01245ff6cc3cc60e9062dcf3e986b9811f --sha256: jI3tAEGwOBqiCr6JqQfAws3X2RIp1eYbI9fXWutTMuE= index-state: 2024-05-21T06:16:08Z diff --git a/wasm-solver/cabal.project b/wasm-solver/cabal.project index a3828bb..a8098f7 100644 --- a/wasm-solver/cabal.project +++ b/wasm-solver/cabal.project @@ -35,5 +35,5 @@ source-repository-package source-repository-package type: git location: https://github.com/l-adic/arithmetic-circuits.git - tag: cb35efaceafa2caebb3de3473ac4dffe7f2f47ab + tag: 77415e01245ff6cc3cc60e9062dcf3e986b9811f --sha256: jI3tAEGwOBqiCr6JqQfAws3X2RIp1eYbI9fXWutTMuE=