Skip to content

Commit

Permalink
Merge pull request #86 from namnc/integrate-boolify
Browse files Browse the repository at this point in the history
integrate boolify
  • Loading branch information
namnc authored Sep 11, 2024
2 parents d8e07ce + bf3fc6d commit bf5a35e
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 453 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ thiserror = "1.0.59"
strum_macros = "0.26.4"
strum = "0.26.2"
sim-circuit = { git = "https://github.com/brech1/sim-circuit" }
bristol-circuit = { git = "https://github.com/voltrevo/bristol-circuit", rev = "2a8b001" }
boolify = { git = "https://github.com/voltrevo/boolify", rev = "6376405" }

# DSL
circom-circom_algebra = { git = "https://github.com/iden3/circom", package = "circom_algebra", rev = "e8e125e" }
Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,22 @@ cargo build --release

- Run the compilation

```
```bash
cargo run --release
```

The compiled circuit and circuit report can be found in the `./output` directory.

### Boolean Circuits

Although this library is named after arithmetic circuits, the CLI integrates [boolify](https://github.com/voltrevo/boolify) allowing further compilation down to boolean circuits.

To achieve this, add `--boolify-width DESIRED_INT_WIDTH` to your command:

```bash
cargo run --release -- --boolify-width 16
```

## ZK/MPC/FHE backends:

- [circom-mp-spdz](https://github.com/namnc/circom-mp-spdz)
Expand Down
2 changes: 1 addition & 1 deletion input/circuit.circom
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ template ArgMax (n) {
out <== amaxs[n];
}

component main = ArgMax(1);
component main = ArgMax(2);

/* INPUT = {
"in": ["2","3","1","5","4"],
Expand Down
55 changes: 55 additions & 0 deletions src/a_gate_type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use circom_program_structure::ast::ExpressionInfixOpcode;
use serde::{Deserialize, Serialize};
use strum_macros::{Display as StrumDisplay, EnumString};

/// The supported Arithmetic gate types.
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, EnumString, StrumDisplay)]
pub enum AGateType {
AAdd,
ADiv,
AEq,
AGEq,
AGt,
ALEq,
ALt,
AMul,
ANeq,
ASub,
AXor,
APow,
AIntDiv,
AMod,
AShiftL,
AShiftR,
ABoolOr,
ABoolAnd,
ABitOr,
ABitAnd,
}

impl From<&ExpressionInfixOpcode> for AGateType {
fn from(opcode: &ExpressionInfixOpcode) -> Self {
match opcode {
ExpressionInfixOpcode::Mul => AGateType::AMul,
ExpressionInfixOpcode::Div => AGateType::ADiv,
ExpressionInfixOpcode::Add => AGateType::AAdd,
ExpressionInfixOpcode::Sub => AGateType::ASub,
ExpressionInfixOpcode::Pow => AGateType::APow,
ExpressionInfixOpcode::IntDiv => AGateType::AIntDiv,
ExpressionInfixOpcode::Mod => AGateType::AMod,
ExpressionInfixOpcode::ShiftL => AGateType::AShiftL,
ExpressionInfixOpcode::ShiftR => AGateType::AShiftR,
ExpressionInfixOpcode::LesserEq => AGateType::ALEq,
ExpressionInfixOpcode::GreaterEq => AGateType::AGEq,
ExpressionInfixOpcode::Lesser => AGateType::ALt,
ExpressionInfixOpcode::Greater => AGateType::AGt,
ExpressionInfixOpcode::Eq => AGateType::AEq,
ExpressionInfixOpcode::NotEq => AGateType::ANeq,
ExpressionInfixOpcode::BoolOr => AGateType::ABoolOr,
ExpressionInfixOpcode::BoolAnd => AGateType::ABoolAnd,
ExpressionInfixOpcode::BitOr => AGateType::ABitOr,
ExpressionInfixOpcode::BitAnd => AGateType::ABitAnd,
ExpressionInfixOpcode::BitXor => AGateType::AXor,
}
}
}
Loading

0 comments on commit bf5a35e

Please sign in to comment.