-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f90d00
commit 35cfa83
Showing
8 changed files
with
193 additions
and
83 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,17 @@ | ||
[package] | ||
name = "circuit-std-rs" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
|
||
[dependencies] | ||
expander_compiler = { path = "../expander_compiler"} | ||
|
||
ark-std.workspace = true | ||
rand.workspace = true | ||
expander_config.workspace = true | ||
expander_circuit.workspace = true | ||
gkr.workspace = true | ||
arith.workspace = true | ||
gf2.workspace = true | ||
mersenne31.workspace = true |
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,5 @@ | ||
pub mod traits; | ||
pub use traits::StdCircuit; | ||
|
||
pub mod logup; | ||
pub use logup::{LogUpCircuit, LogUpParams}; |
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,14 @@ | ||
use std::fmt::Debug; | ||
|
||
use expander_compiler::frontend::{internal::DumpLoadTwoVariables, Config, Define, Variable}; | ||
use rand::RngCore; | ||
|
||
// All std circuits must implement the following trait | ||
pub trait StdCircuit<C: Config>: Clone + Define<C> + DumpLoadTwoVariables<Variable> { | ||
type Params: Clone + Debug; | ||
type Assignment: Clone + DumpLoadTwoVariables<C::CircuitField>; | ||
|
||
fn new_circuit(params: &Self::Params) -> Self; | ||
|
||
fn new_assignment(params: &Self::Params, rng: impl RngCore) -> Self::Assignment; | ||
} |
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,38 @@ | ||
use circuit_std_rs::StdCircuit; | ||
use expander_compiler::frontend::*; | ||
use extra::Serde; | ||
use rand::thread_rng; | ||
|
||
pub fn circuit_test_helper<Cfg, Cir>(params: &Cir::Params) | ||
where | ||
Cfg: Config, | ||
Cir: StdCircuit<Cfg>, | ||
{ | ||
let mut rng = thread_rng(); | ||
let compile_result: CompileResult<Cfg> = compile(&Cir::new_circuit(¶ms)).unwrap(); | ||
let assignment = Cir::new_assignment(¶ms, &mut rng); | ||
let witness = compile_result | ||
.witness_solver | ||
.solve_witness(&assignment) | ||
.unwrap(); | ||
let output = compile_result.layered_circuit.run(&witness); | ||
assert_eq!(output, vec![true]); | ||
|
||
let file = std::fs::File::create("circuit.txt").unwrap(); | ||
let writer = std::io::BufWriter::new(file); | ||
compile_result | ||
.layered_circuit | ||
.serialize_into(writer) | ||
.unwrap(); | ||
|
||
let file = std::fs::File::create("witness.txt").unwrap(); | ||
let writer = std::io::BufWriter::new(file); | ||
witness.serialize_into(writer).unwrap(); | ||
|
||
let file = std::fs::File::create("witness_solver.txt").unwrap(); | ||
let writer = std::io::BufWriter::new(file); | ||
compile_result | ||
.witness_solver | ||
.serialize_into(writer) | ||
.unwrap(); | ||
} |
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 @@ | ||
mod common; | ||
|
||
use circuit_std_rs::{LogUpCircuit, LogUpParams}; | ||
use expander_compiler::frontend::*; | ||
|
||
#[test] | ||
fn logup_test() { | ||
let logup_params = LogUpParams { | ||
key_len: 7, | ||
value_len: 7, | ||
n_table_rows: 123, | ||
n_queries: 456, | ||
}; | ||
|
||
common::circuit_test_helper::<BN254Config, LogUpCircuit>(&logup_params); | ||
common::circuit_test_helper::<M31Config, LogUpCircuit>(&logup_params); | ||
common::circuit_test_helper::<GF2Config, LogUpCircuit>(&logup_params); | ||
} |