Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement provably extract LIMIT/OFFSET circuits (Part2) #300

Open
wants to merge 7 commits into
base: feat/provably-extract-limit-offset
Choose a base branch
from
Open
50 changes: 50 additions & 0 deletions mp2-common/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,56 @@ impl<F: RichField + Extendable<D>, const D: usize> SelectHashBuilder for Circuit
}
}

pub trait SelectCurveBuilder {
/// Select `first_curve` or `second_curve` as output depending on the Boolean `cond`
fn select_curve(
&mut self,
cond: BoolTarget,
first_curve: &CurveTarget,
second_curve: &CurveTarget,
) -> CurveTarget;
}

impl<F: RichField + Extendable<D>, const D: usize> SelectCurveBuilder for CircuitBuilder<F, D> {
fn select_curve(
&mut self,
cond: BoolTarget,
first_curve: &CurveTarget,
second_curve: &CurveTarget,
) -> CurveTarget {
let CurveTarget((first_ext, first_bool)) = first_curve;
let CurveTarget((second_ext, second_bool)) = second_curve;

let selected_ext = [
QuinticExtensionTarget::new(
first_ext[0]
.to_target_array()
.iter()
.zip(second_ext[0].to_target_array().iter())
.map(|(first, second)| self.select(cond, *first, *second))
.collect::<Vec<_>>()
.try_into()
.unwrap(),
),
QuinticExtensionTarget::new(
first_ext[1]
.to_target_array()
.iter()
.zip(second_ext[1].to_target_array().iter())
.map(|(first, second)| self.select(cond, *first, *second))
.collect::<Vec<_>>()
.try_into()
.unwrap(),
),
];

let selected_bool_target = self.select(cond, first_bool.target, second_bool.target);
let selected_bool = BoolTarget::new_unsafe(selected_bool_target);

CurveTarget((selected_ext, selected_bool))
}
}

pub trait ToFields<F: RichField> {
fn to_fields(&self) -> Vec<F>;
}
Expand Down
Loading
Loading