-
Notifications
You must be signed in to change notification settings - Fork 1
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
refac: upstream latest plonky2 #7
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,27 +107,64 @@ impl<F: RichField + Extendable<D>, const D: usize> FqTarget<F, D> { | |
pub fn is_equal(&self, builder: &mut CircuitBuilder<F, D>, rhs: &Self) -> BoolTarget { | ||
let a_limbs = self.target.value.limbs.iter().map(|x| x.0).collect_vec(); | ||
let b_limbs = rhs.target.value.limbs.iter().map(|x| x.0).collect_vec(); | ||
assert_eq!(a_limbs.len(), b_limbs.len()); | ||
|
||
let terms = a_limbs | ||
if a_limbs.len() == b_limbs.len() { | ||
self.compare_same_length(builder, &a_limbs, &b_limbs) | ||
} else { | ||
self.compare_different_length(builder, &a_limbs, &b_limbs) | ||
} | ||
} | ||
|
||
fn compare_same_length( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry I fail to see why the two functions are different - if you give same length inputs to the TLDR do we really need this new function ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense, it could be simplified as you said. Fixed in commit 698cc66, thanks! |
||
&self, | ||
builder: &mut CircuitBuilder<F, D>, | ||
lhs: &Vec<Target>, | ||
rhs: &Vec<Target>, | ||
) -> BoolTarget { | ||
let terms = lhs | ||
.iter() | ||
.zip(b_limbs) | ||
.map(|(&a, b)| builder.is_equal(a, b).target) | ||
.zip(rhs) | ||
.map(|(&a, b)| builder.is_equal(a, *b).target) | ||
.collect_vec(); | ||
let is_equal = builder.mul_many(terms); | ||
|
||
// is_equal is ensured to be 0 or 1, so we can safely convert it to bool. | ||
BoolTarget::new_unsafe(is_equal) | ||
} | ||
|
||
pub fn is_zero(&self, builder: &mut CircuitBuilder<F, D>) -> BoolTarget { | ||
fn compare_different_length( | ||
&self, | ||
builder: &mut CircuitBuilder<F, D>, | ||
lhs: &Vec<Target>, | ||
rhs: &Vec<Target>, | ||
) -> BoolTarget { | ||
let (shorter, longer) = if lhs.len() < rhs.len() { | ||
(&lhs, &rhs) | ||
} else { | ||
(&rhs, &lhs) | ||
}; | ||
let mut terms = Vec::with_capacity(longer.len()); | ||
|
||
// Compare common limbs | ||
for (a, b) in shorter.iter().zip(longer.iter()) { | ||
terms.push(builder.is_equal(*a, *b).target); | ||
} | ||
|
||
let zero = builder.zero(); | ||
let mut t = builder._true(); | ||
for l in self.target.value.limbs.iter() { | ||
let eq = builder.is_equal(zero, l.0); | ||
t = builder.and(eq, t); | ||
// Check if the remaining limbs in the longer one are all zeros | ||
for &limb in longer.iter().skip(shorter.len()) { | ||
terms.push(builder.is_equal(limb, zero).target); | ||
} | ||
t | ||
|
||
let is_equal = builder.mul_many(terms); | ||
|
||
// is_equal is ensured to be 0 or 1, so we can safely convert it to bool. | ||
BoolTarget::new_unsafe(is_equal) | ||
} | ||
|
||
pub fn is_zero(&self, builder: &mut CircuitBuilder<F, D>) -> BoolTarget { | ||
let zero = Self::zero(builder); | ||
self.is_equal(builder, &zero) | ||
} | ||
|
||
pub fn constant(builder: &mut CircuitBuilder<F, D>, c: Fq) -> Self { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May need to update after merging PR Lagrange-Labs/plonky2-ecdsa#3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in commit c37edcd. Thanks!