-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from namnc/issue-31-PrefixOp
Support `PrefixOp`
- Loading branch information
Showing
9 changed files
with
214 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use circom_2_arithc::{circom::input::Input, program::build_circuit}; | ||
|
||
const TEST_FILE_PATH: &str = "./tests/circuits/addZero.circom"; | ||
|
||
#[test] | ||
fn test_add_zero() { | ||
let input = Input::new(TEST_FILE_PATH.into(), "./".into()).unwrap(); | ||
let circuit = build_circuit(&input).unwrap(); | ||
let sim_circuit = circuit.build_sim_circuit().unwrap(); | ||
|
||
let circuit_input = vec![ | ||
42, // actual input | ||
0, // constant - FIXME: should not need to provide this | ||
]; | ||
|
||
let res = sim_circuit.execute(&circuit_input).unwrap(); | ||
|
||
assert_eq!(res, vec![42]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
pragma circom 2.0.0; | ||
|
||
template addZero() { | ||
signal input in; | ||
signal output out; | ||
|
||
out <== in + 0; | ||
} | ||
|
||
component main = addZero(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
pragma circom 2.0.0; | ||
|
||
template constantSum() { | ||
signal output out; | ||
|
||
out <== 3 + 5; | ||
} | ||
|
||
component main = constantSum(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
pragma circom 2.0.0; | ||
|
||
template prefixOps() { | ||
signal input a; | ||
signal input b; | ||
signal input c; | ||
|
||
signal output negateA; | ||
|
||
signal output notA; | ||
signal output notB; | ||
signal output notC; | ||
|
||
signal output complementA; | ||
signal output complementB; | ||
signal output complementC; | ||
|
||
negateA <== -a; | ||
|
||
notA <== !a; | ||
notB <== !b; | ||
notC <== !c; | ||
|
||
complementA <== ~a; | ||
complementB <== ~b; | ||
complementC <== ~c; | ||
} | ||
|
||
component main = prefixOps(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use circom_2_arithc::{circom::input::Input, program::build_circuit}; | ||
|
||
const TEST_FILE_PATH: &str = "./tests/circuits/constantSum.circom"; | ||
|
||
#[test] | ||
fn test_constant_sum() { | ||
let input = Input::new(TEST_FILE_PATH.into(), "./".into()).unwrap(); | ||
let circuit = build_circuit(&input).unwrap(); | ||
let sim_circuit = circuit.build_sim_circuit().unwrap(); | ||
|
||
let circuit_input = vec![]; | ||
let res = sim_circuit.execute(&circuit_input).unwrap(); | ||
|
||
assert_eq!( | ||
res, | ||
Vec::<u32>::new(), // FIXME: Should be vec![8] | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use circom_2_arithc::{circom::input::Input, program::build_circuit}; | ||
|
||
const TEST_FILE_PATH: &str = "./tests/circuits/prefixOps.circom"; | ||
|
||
#[test] | ||
fn test_prefix_ops() { | ||
let input = Input::new(TEST_FILE_PATH.into(), "./".into()).unwrap(); | ||
let circuit = build_circuit(&input).unwrap(); | ||
let sim_circuit = circuit.build_sim_circuit().unwrap(); | ||
|
||
let circuit_input = vec![ | ||
0, 1, 2, // actual inputs | ||
0, u32::MAX // constants - FIXME: should not need to provide these | ||
]; | ||
|
||
let res = sim_circuit.execute(&circuit_input).unwrap(); | ||
|
||
assert_eq!(res, vec![ | ||
0, // -0 | ||
|
||
1, // !0 | ||
0, // !1 | ||
0, // !2 | ||
|
||
0b_11111111_11111111_11111111_11111111, // ~0 | ||
0b_11111111_11111111_11111111_11111110, // ~1 | ||
0b_11111111_11111111_11111111_11111101, // ~2 | ||
]); | ||
} |