Skip to content

Commit

Permalink
Update ~-operator to use 254 bits instead of 256
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelis committed Jul 3, 2024
1 parent 2eaaa6d commit 9f3da35
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions circom_algebra/src/algebra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,13 +554,13 @@ impl<C: Default + Clone + Display + Hash + Eq> ArithmeticExpression<C> {
}

// Bit operations
pub fn complement_256(
pub fn complement_254(
elem: &ArithmeticExpression<C>,
field: &BigInt,
) -> ArithmeticExpression<C> {
use ArithmeticExpression::*;
if let Number { value } = elem {
Number { value: modular_arithmetic::complement_256(value, field) }
Number { value: modular_arithmetic::complement_254(value, field) }
} else {
NonQuadratic
}
Expand Down
12 changes: 6 additions & 6 deletions circom_algebra/src/modular_arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ pub fn multi_inv(values: &Vec<BigInt>, field: &BigInt) -> Vec<BigInt>{

//Bit operations

// 256 bit complement
pub fn complement_256(elem: &BigInt, field: &BigInt) -> BigInt {
// 254 bit complement
pub fn complement_254(elem: &BigInt, field: &BigInt) -> BigInt {
let (sign, mut bit_repr) = bit_representation(elem);
while bit_repr.len() > 256 {
while bit_repr.len() > 254 {
bit_repr.pop();
}
for _i in bit_repr.len()..256 {
for _i in bit_repr.len()..254 {
bit_repr.push(0);
}
for bit in &mut bit_repr {
Expand Down Expand Up @@ -252,8 +252,8 @@ mod tests {
.expect("generating the big int was not possible");
let big_num = BigInt::parse_bytes("1234".as_bytes(), 10)
.expect("generating the big int was not possible");
let big_num_complement = complement_256(&big_num, &field);
let big_num_complement_complement = complement_256(&big_num_complement, &field);
let big_num_complement = complement_254(&big_num, &field);
let big_num_complement_complement = complement_254(&big_num_complement, &field);
let big_num_modulus = modulus(&big_num, &field);
assert_eq!(big_num_complement_complement, big_num_modulus);
}
Expand Down
2 changes: 1 addition & 1 deletion constraint_generation/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2079,7 +2079,7 @@ fn execute_prefix_op(
let result = match prefix_op {
BoolNot => AExpr::not(value, field),
Sub => AExpr::prefix_sub(value, field),
Complement => AExpr::complement_256(value, field),
Complement => AExpr::complement_254(value, field),
};
Result::Ok(result)
}
Expand Down

0 comments on commit 9f3da35

Please sign in to comment.