From 3025d3a3533bc9c145d43af4abe90306277974e9 Mon Sep 17 00:00:00 2001 From: Martin Allen <31280145+martyall@users.noreply.github.com> Date: Sun, 2 Jun 2024 10:07:49 -0500 Subject: [PATCH] Update lc (#6) * update lc * update readme * ci --- .github/workflows/cabal.yml | 72 ++++++++++++++++++++++++++++++++++++ .github/workflows/ormolu.yml | 16 ++++++++ .gitignore | 1 + README.md | 2 +- cabal.project | 4 +- factors/test/Main.hs | 10 ++--- wasm-solver/app/Main.hs | 6 +-- wasm-solver/cabal.project | 4 +- 8 files changed, 102 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/cabal.yml create mode 100644 .github/workflows/ormolu.yml diff --git a/.github/workflows/cabal.yml b/.github/workflows/cabal.yml new file mode 100644 index 0000000..4a1e3b1 --- /dev/null +++ b/.github/workflows/cabal.yml @@ -0,0 +1,72 @@ +name: Cabal CI + +on: + push: + branches: [main, master] + pull_request: + branches: [main, master] + +# INFO: The following configuration block ensures that only one build runs per branch, +# which may be desirable for projects with a costly build process. +# Remove this block from the CI workflow to let each CI job run to completion. +concurrency: + group: build-${{ github.ref }} + cancel-in-progress: true + +jobs: + build: + name: GHC ${{ matrix.ghc-version }} on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + ghc-version: ['9.8', '9.6'] + + steps: + - uses: actions/checkout@v4 + + - name: Set up GHC ${{ matrix.ghc-version }} + uses: haskell-actions/setup@v2 + id: setup + with: + ghc-version: ${{ matrix.ghc-version }} + # Defaults, added for clarity: + cabal-version: 'latest' + cabal-update: true + + - name: Configure the build + run: | + cabal configure --enable-tests --enable-benchmarks --disable-documentation + cabal build all --dry-run + # The last step generates dist-newstyle/cache/plan.json for the cache key. + + - name: Restore cached dependencies + uses: actions/cache/restore@v3 + id: cache + env: + key: ${{ runner.os }}-ghc-${{ steps.setup.outputs.ghc-version }}-cabal-${{ steps.setup.outputs.cabal-version }} + with: + path: ${{ steps.setup.outputs.cabal-store }} + key: ${{ env.key }}-plan-${{ hashFiles('**/plan.json') }} + restore-keys: ${{ env.key }}- + + - name: Install dependencies + # If we had an exact cache hit, the dependencies will be up to date. + if: steps.cache.outputs.cache-hit != 'true' + run: cabal build all --only-dependencies + + # Cache dependencies already here, so that we do not have to rebuild them should the subsequent steps fail. + - name: Save cached dependencies + uses: actions/cache/save@v3 + # If we had an exact cache hit, trying to save the cache would error because of key clash. + if: steps.cache.outputs.cache-hit != 'true' + with: + path: ${{ steps.setup.outputs.cabal-store }} + key: ${{ steps.cache.outputs.cache-primary-key }} + + - name: Build + run: cabal build all + + - name: Test + run: cabal test all \ No newline at end of file diff --git a/.github/workflows/ormolu.yml b/.github/workflows/ormolu.yml new file mode 100644 index 0000000..79a171a --- /dev/null +++ b/.github/workflows/ormolu.yml @@ -0,0 +1,16 @@ +name: Ormolu CI + +on: + push: + branches: [main, master] + pull_request: + branches: [main, master] + +jobs: + ormolu: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: haskell-actions/run-ormolu@v15 + with: + version: "0.7.2.0" \ No newline at end of file diff --git a/.gitignore b/.gitignore index 6368b42..7a4a0a7 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ trusted-setup/ !trusted-setup/pot14_final.ptau src/Contracts contracts +circuit.dot diff --git a/README.md b/README.md index a87993c..1bd206f 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ A ZK program written in a Haskell DSL that expresses a factorization of a public You can produce a circom compatible `r1cs` file for this program by running ``` -> cabal run factors-cli -- compile --output-dir trusted-setup +> cabal run factors -- compile --r1cs trusted-setup/circuit.r1cs --constraints trusted-setup/circuit.bin ``` You should see the artifacts diff --git a/cabal.project b/cabal.project index f76cdd9..84dd92a 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: 77415e01245ff6cc3cc60e9062dcf3e986b9811f - --sha256: jI3tAEGwOBqiCr6JqQfAws3X2RIp1eYbI9fXWutTMuE= + tag: 7d06e2b5df24237d8d694ca842ff1cd7e6609b34 + --sha256: ldjPgZN7M+hsD6S7kx0QsVJsK8FbCl0d7oSyPHQRoaw= index-state: 2024-05-21T06:16:08Z diff --git a/factors/test/Main.hs b/factors/test/Main.hs index 31ee241..f57b4e8 100644 --- a/factors/test/Main.hs +++ b/factors/test/Main.hs @@ -4,13 +4,13 @@ import Circom.R1CS (witnessFromCircomWitness) import Circom.Solver (CircomProgram (..), mkCircomProgram, nativeGenWitness) import Circuit import Circuit.Language +import Data.Binary (decode, encode) import qualified Data.Map as Map import Protolude import R1CS (Witness (..)) import Test.Hspec import Test.QuickCheck import ZK.Factors (Fr, factors) -import Data.Binary (encode, decode) main :: IO () main = hspec $ do @@ -21,19 +21,19 @@ main = hspec $ 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 -> (x /= 1 && y /= 1) ==> - let inputs = Map.fromList [("n", x * y), ("a", x), ("b", y)] + let inputs = Map.fromList [("n", Simple $ x * y), ("a", Simple x), ("b", Simple 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)] + let inputs = Map.fromList [("n", Simple x), ("a", Simple 1), ("b", Simple x)] Witness w = witnessFromCircomWitness $ nativeGenWitness program inputs @@ -42,7 +42,7 @@ main = hspec $ do property $ \x y z -> (x * y /= z) ==> - let inputs = Map.fromList [("n", z), ("a", x), ("b", y)] + let inputs = Map.fromList [("n", Simple z), ("a", Simple x), ("b", Simple y)] Witness w = witnessFromCircomWitness $ nativeGenWitness program inputs diff --git a/wasm-solver/app/Main.hs b/wasm-solver/app/Main.hs index 28f2aa9..db24902 100644 --- a/wasm-solver/app/Main.hs +++ b/wasm-solver/app/Main.hs @@ -1,7 +1,7 @@ module Main where -import Data.Binary (decodeFile) import Circom.Solver qualified as Circom +import Data.Binary (decodeFile) import Data.IORef (IORef, newIORef) import Protolude import System.IO.Unsafe (unsafePerformIO) @@ -70,7 +70,7 @@ getInputSize = Circom._getInputSize env foreign export ccall getInputSignalSize :: Word32 -> Word32 -> IO Int getInputSignalSize :: Word32 -> Word32 -> IO Int -getInputSignalSize = Circom._getInputSignalSize +getInputSignalSize = Circom._getInputSignalSize env foreign export ccall getWitnessSize :: Int @@ -80,4 +80,4 @@ getWitnessSize = Circom._getWitnessSize env foreign export ccall getWitness :: Int -> IO () getWitness :: Int -> IO () -getWitness = Circom._getWitness env stateRef \ No newline at end of file +getWitness = Circom._getWitness env stateRef diff --git a/wasm-solver/cabal.project b/wasm-solver/cabal.project index a8098f7..a8304bc 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: 77415e01245ff6cc3cc60e9062dcf3e986b9811f - --sha256: jI3tAEGwOBqiCr6JqQfAws3X2RIp1eYbI9fXWutTMuE= + tag: 7d06e2b5df24237d8d694ca842ff1cd7e6609b34 + --sha256: ldjPgZN7M+hsD6S7kx0QsVJsK8FbCl0d7oSyPHQRoaw=