Skip to content

Commit

Permalink
Merge branch 'dev' into gnark_expr
Browse files Browse the repository at this point in the history
  • Loading branch information
siq1 committed Oct 12, 2024
2 parents 0603d57 + f45a448 commit bcb8982
Show file tree
Hide file tree
Showing 9 changed files with 347 additions and 17 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
- uses: Swatinem/rust-cache@v2
with:
workspaces: "expander_compiler -> expander_compiler/target"
# The prefix cache key, this can be changed to start a new cache manually.
prefix-key: "mpi-v5.0.5" # update me if brew formula changes to a new version
- if: matrix.os == 'macos-latest'
run: brew install openmpi
- if: matrix.os == 'ubuntu-latest'
Expand Down Expand Up @@ -66,6 +68,10 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
workspaces: "expander_compiler -> expander_compiler/target"
# The prefix cache key, this can be changed to start a new cache manually.
prefix-key: "mpi-v5.0.5" # update me if brew formula changes to a new version
- if: matrix.os == 'macos-latest'
run: brew install openmpi
- if: matrix.os == 'ubuntu-latest'
Expand All @@ -79,6 +85,10 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
workspaces: "expander_compiler -> expander_compiler/target"
# The prefix cache key, this can be changed to start a new cache manually.
prefix-key: "mpi-v5.0.5" # update me if brew formula changes to a new version
- run: RUSTFLAGS="-C target-cpu=native -C target-feature=+avx512f" cargo test

test-go:
Expand Down
5 changes: 1 addition & 4 deletions ecgo/builder/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ func (r *Root) PublicVariable(f schema.LeafInfo) frontend.Variable {
ExtraId: 2 + uint64(r.nbPublicInputs),
})
r.nbPublicInputs++
// Currently, new version of public input is not support by Expander
// So we use a hint to isolate it in witness solver
x, _ := r.NewHint(IdentityHint, 1, r.addVar())
return x[0]
return r.addVar()
}

// SecretVariable creates a new secret variable for the circuit.
Expand Down
4 changes: 2 additions & 2 deletions ecgo/examples/poseidon_m31/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func M31CircuitBuild() {

layered_circuit := circuit.GetLayeredCircuit()
// circuit.GetCircuitIr().Print()
err = os.WriteFile("circuit.txt", layered_circuit.Serialize(), 0o644)
err = os.WriteFile("poseidon_120_circuit_m31.txt", layered_circuit.Serialize(), 0o644)
if err != nil {
panic(err)
}
Expand All @@ -81,7 +81,7 @@ func M31CircuitBuild() {
if err != nil {
panic(err)
}
err = os.WriteFile("witness.txt", witness.Serialize(), 0o644)
err = os.WriteFile("poseidon_120_witness_m31.txt", witness.Serialize(), 0o644)
if err != nil {
panic(err)
}
Expand Down
22 changes: 22 additions & 0 deletions expander_compiler/src/frontend/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ macro_rules! declare_circuit_field_type {
[$crate::frontend::internal::declare_circuit_field_type!(@type $elem); $n]
};

(@type [$elem:tt]) => {
Vec<$crate::frontend::internal::declare_circuit_field_type!(@type $elem)>
};

(@type $other:ty) => {
$other
};
Expand All @@ -33,6 +37,12 @@ macro_rules! declare_circuit_dump_into {
}
};

($field_value:expr, @type [$elem:tt], $vars:expr, $public_vars:expr) => {
for _x in $field_value.iter() {
$crate::frontend::internal::declare_circuit_dump_into!(_x, @type $elem, $vars, $public_vars);
}
};

($field_value:expr, @type $other:ty, $vars:expr, $public_vars:expr) => {
};
}
Expand All @@ -53,6 +63,12 @@ macro_rules! declare_circuit_load_from {
}
};

($field_value:expr, @type [$elem:tt], $vars:expr, $public_vars:expr) => {
for _x in $field_value.iter_mut() {
$crate::frontend::internal::declare_circuit_load_from!(_x, @type $elem, $vars, $public_vars);
}
};

($field_value:expr, @type $other:ty, $vars:expr, $public_vars:expr) => {
};
}
Expand All @@ -71,6 +87,12 @@ macro_rules! declare_circuit_num_vars {
$crate::frontend::internal::declare_circuit_num_vars!($field_value[0], @type $elem, $cnt_sec, $cnt_pub, $array_cnt * $n);
};

($field_value:expr, @type [$elem:tt], $cnt_sec:expr, $cnt_pub:expr, $array_cnt:expr) => {
for _x in $field_value.iter() {
$crate::frontend::internal::declare_circuit_num_vars!(_x, @type $elem, $cnt_sec, $cnt_pub, $array_cnt);
}
};

($field_value:expr, @type $other:ty, $cnt_sec:expr, $cnt_pub:expr, $array_cnt:expr) => {
};
}
Expand Down
2 changes: 1 addition & 1 deletion expander_compiler/src/layering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{

mod compile;
mod input;
pub mod ir_split; // TODO
pub mod ir_split;
mod layer_layout;
mod wire;

Expand Down
6 changes: 3 additions & 3 deletions expander_compiler/tests/keccak_gf2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,15 +288,15 @@ fn keccak_gf2_main() {
.solve_witnesses(&assignments_correct)
.unwrap();

let file = std::fs::File::create("circuit.txt").unwrap();
let file = std::fs::File::create("circuit_gf2.txt").unwrap();
let writer = std::io::BufWriter::new(file);
layered_circuit.serialize_into(writer).unwrap();

let file = std::fs::File::create("witness.txt").unwrap();
let file = std::fs::File::create("witness_gf2.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 file = std::fs::File::create("witness_gf2_solver.txt").unwrap();
let writer = std::io::BufWriter::new(file);
witness_solver.serialize_into(writer).unwrap();

Expand Down
3 changes: 2 additions & 1 deletion expander_compiler/tests/keccak_gf2_full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ fn copy_out_unaligned(s: Vec<Vec<Variable>>, rate: usize, output_len: usize) ->

declare_circuit!(Keccak256Circuit {
p: [[Variable; 64 * 8]; N_HASHES],
out: [[Variable; 256]; N_HASHES], // TODO: use public inputs
out: [[PublicVariable; 256]; N_HASHES],
});

fn compute_keccak<C: Config>(api: &mut API<C>, p: &Vec<Variable>) -> Vec<Variable> {
Expand Down Expand Up @@ -290,6 +290,7 @@ fn keccak_gf2_full() {
);

let (simd_input, simd_public_input) = witness.to_simd::<gf2::GF2x8>();
println!("{} {}", simd_input.len(), simd_public_input.len());
expander_circuit.layers[0].input_vals = simd_input;
expander_circuit.public_input = simd_public_input.clone();

Expand Down
Loading

0 comments on commit bcb8982

Please sign in to comment.