Skip to content

Commit

Permalink
Merge pull request #14 from rymnc/implement-band
Browse files Browse the repository at this point in the history
chore(ops): implement band
  • Loading branch information
philsippl authored Feb 28, 2024
2 parents 1de8315 + cfd393d commit 900679a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,7 @@ pub unsafe fn Fr_lor(to: *mut FrElement, a: *const FrElement, b: *const FrElemen
pub unsafe fn Fr_shl(to: *mut FrElement, a: *const FrElement, b: *const FrElement) {
binop(Operation::Shl, to, a, b);
}

pub unsafe fn Fr_band(to: *mut FrElement, a: *const FrElement, b: *const FrElement) {
binop(Operation::Band, to, a, b)
}
7 changes: 5 additions & 2 deletions src/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ mod ffi {
// unsafe fn Fr_square(to: *mut FrElement, a: *const FrElement);
unsafe fn Fr_shl(to: *mut FrElement, a: *const FrElement, b: *const FrElement);
// fn Fr_shr(to: &mut FrElement, a: &FrElement, b: u32);
// fn Fr_band(to: &mut FrElement, a: &FrElement, b: &FrElement);
unsafe fn Fr_band(to: &mut FrElement, a: *const FrElement, b: *const FrElement);
// fn Fr_bor(to: &mut FrElement, a: &FrElement, b: &FrElement);
// fn Fr_bxor(to: &mut FrElement, a: &FrElement, b: &FrElement);
// fn Fr_bnot(to: &mut FrElement, a: &FrElement);
Expand Down Expand Up @@ -237,7 +237,10 @@ pub fn build_witness() -> eyre::Result<()> {
eprintln!("Calculation took: {:?}", now.elapsed());

let signal_values = get_witness_to_signal();
let mut signals = signal_values.into_iter().map(|i| ctx.signalValues[i].0).collect::<Vec<_>>();
let mut signals = signal_values
.into_iter()
.map(|i| ctx.signalValues[i].0)
.collect::<Vec<_>>();
let mut nodes = field::get_graph();
eprintln!("Graph with {} nodes", nodes.len());

Expand Down
7 changes: 6 additions & 1 deletion src/graph.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::{collections::HashMap, ops::Shl};
use std::{
collections::HashMap,
ops::{BitAnd, Shl},
};

use crate::field::M;
use ark_bn254::Fr;
Expand Down Expand Up @@ -42,6 +45,7 @@ pub enum Operation {
Geq,
Lor,
Shl,
Band,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
Expand All @@ -68,6 +72,7 @@ impl Operation {
Geq => U256::from(a >= b),
Lor => U256::from(a != U256::ZERO || b != U256::ZERO),
Shl => compute_shl_uint(a, b),
Band => a.bitand(b),
_ => unimplemented!("operator {:?} not implemented", self),
}
}
Expand Down

0 comments on commit 900679a

Please sign in to comment.