Skip to content
This repository was archived by the owner on Jan 28, 2022. It is now read-only.

Latest commit

Β 

History

History
118 lines (85 loc) Β· 3.04 KB

File metadata and controls

118 lines (85 loc) Β· 3.04 KB

THIS PROJECT HAS BEEN SUPERSEDED BY CIRC

Note: This project has been superseded by CirC, which is a Rust re-implementation of the compiler infrastructure.

It is archived here for reference purposes.

Compiler to circuit representations

Currently we have frontends for:

  • C
  • circom

We have backends for:

  • R1CS (proofs via libsnark)
  • SMT

Install

Install dependencies

Build project

Once the dependencies are installed, you should be able to build the compiler:

stack build

Test

stack test

To run an individual test (e.g., C value test), use:

stack test --ta '-p C value test'

Format

We use brittany. You can format all files (slow) with make fmt.

You can format all files changed since a git-ref REF in a directory using

./scripts/format.bash REF DIR

You can format all files in a directory using

./scripts/format.bash all DIR

The formatting script will not format files which have unstaged changes.

Run

For usage information:

stack exec compiler-exe -- -h

For example, to run function foo in file bar, use:

stack exec compiler-exe c foo bar.c -- --solve

Configuration

There is a configuration system in src/Util/Cfg.hs. You can add new configuration options there. Configuration options can be set by environmental variables, like so:

C_cfg_with_underscores_instead_of_dashes=value stack run -- ...

One particularly useful configuration options is C_streams, which enables logging streams. You can log to named streams using logIf in src/Util/Log.hs, and the output will only appear if the specified stream is enabled.

Directory structure

β”œβ”€β”€ app               -- Compiler executable
β”œβ”€β”€ src
β”‚Β Β  β”œβ”€β”€ AST           -- Circom AST and C AST helpers 
β”‚Β Β  β”œβ”€β”€ Codegen       -- Machinery for generating circuits 
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ Circify   -- Language-indended machinery (branches, fns, scopes)
β”‚Β Β  β”‚Β Β  β”‚   └── Memory-- Stack allocations and accesses
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ Circom    -- Circom
β”‚Β Β  β”‚Β Β  └── C         -- C
β”‚Β Β  β”œβ”€β”€ IR            -- The typed SMT intermediate representation
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ SMT       -- Logging
β”‚Β Β  β”‚Β Β  β”‚   β”œβ”€β”€ TySmt -- Sort-typed SMT terms
β”‚Β Β  β”‚Β Β  β”‚   β”œβ”€β”€ Assert-- Monad for accumulating SMT assertions
β”‚Β Β  β”‚Β Β  β”‚   β”œβ”€β”€ Opt   -- Optimizations over SMT
β”‚Β Β  β”‚Β Β  β”‚   └── ToPf  -- Converting SMT to R1cs
β”‚Β Β  β”‚Β Β  └── R1cs      -- R1cs
β”‚Β Β  β”‚Β Β      └── Opt   -- Optimizations over R1cs
β”‚Β Β  β”œβ”€β”€ Parser        -- Machinery for parsing source files 
β”‚Β Β  β”œβ”€β”€ Targets       -- TBD: Alex after code changes
β”‚Β Β  └── Util          -- Utilities (e.g., logging)
β”‚Β Β   Β Β  β”œβ”€β”€ Log       -- Logging
β”‚Β Β   Β Β  └── Cfg       -- Configuration
└── test              -- Tests