Skip to content

Commit

Permalink
Update lc (#6)
Browse files Browse the repository at this point in the history
* update lc

* update readme

* ci
  • Loading branch information
martyall authored Jun 2, 2024
1 parent dc8fced commit 3025d3a
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 13 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/cabal.yml
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions .github/workflows/ormolu.yml
Original file line number Diff line number Diff line change
@@ -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"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ trusted-setup/
!trusted-setup/pot14_final.ptau
src/Contracts
contracts
circuit.dot
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions factors/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions wasm-solver/app/Main.hs
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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

Expand All @@ -80,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
4 changes: 2 additions & 2 deletions wasm-solver/cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -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=

0 comments on commit 3025d3a

Please sign in to comment.