Skip to content

Commit ced530a

Browse files
MegaRedHandkariy
authored andcommitted
chore: use LambdaWorks' implementation of bit operations (lambdaclass#1291)
* Use lambdaworks' implementation of bit operations * Update changelog
1 parent 0614d45 commit ced530a

File tree

3 files changed

+9
-19
lines changed

3 files changed

+9
-19
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
#### Upcoming Changes
44

5+
* chore: use LambdaWorks' implementation of bit operations for `Felt252` [#1291](https://github.com/lambdaclass/cairo-rs/pull/1291)
6+
57
#### [0.8.0] - 2023-6-26
68

7-
* feat: Add feature `lambdaworks-felt` to `felt` & `cairo-vm` crates [#1218](https://github.com/lambdaclass/cairo-rs/pull/1281)
9+
* feat: Add feature `lambdaworks-felt` to `felt` & `cairo-vm` crates [#1281](https://github.com/lambdaclass/cairo-rs/pull/1281)
810

911
Changes under this feature:
1012
* `Felt252` now uses _lambdaworks_' `FieldElement` internally

felt/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ lazy_static = { version = "1.4.0", default-features = false, features = [
1919
"spin_no_std",
2020
] }
2121
serde = { version = "1.0", features = ["derive"], default-features = false }
22-
lambdaworks-math = { version = "0.1.1", default-features = false, optional=true }
22+
lambdaworks-math = { version = "0.1.1", default-features = false, optional = true }
2323

2424
[dev-dependencies]
2525
proptest = "1.1.0"

felt/src/lib_lambdaworks.rs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -853,15 +853,13 @@ impl ShrAssign<usize> for Felt252 {
853853
}
854854
}
855855

856-
// TODO: move to upstream
857856
impl<'a> BitAnd for &'a Felt252 {
858857
type Output = Felt252;
859858
fn bitand(self, rhs: Self) -> Self::Output {
860859
self.clone() & rhs
861860
}
862861
}
863862

864-
// TODO: move to upstream
865863
impl<'a> BitAnd<&'a Felt252> for Felt252 {
866864
type Output = Self;
867865
fn bitand(self, rhs: &Self) -> Self {
@@ -872,9 +870,9 @@ impl<'a> BitAnd<&'a Felt252> for Felt252 {
872870
impl<'a> BitAnd<Felt252> for &'a Felt252 {
873871
type Output = Felt252;
874872
fn bitand(self, rhs: Self::Output) -> Self::Output {
875-
// TODO: move to upstream
876873
let a = self.value.representative();
877874
let b = rhs.value.representative();
875+
878876
let value = FieldElement::new(a & b);
879877
Self::Output { value }
880878
}
@@ -883,31 +881,21 @@ impl<'a> BitAnd<Felt252> for &'a Felt252 {
883881
impl<'a> BitOr for &'a Felt252 {
884882
type Output = Felt252;
885883
fn bitor(self, rhs: Self) -> Self::Output {
886-
// TODO: move to upstream
887-
let mut a = self.value.representative();
884+
let a = self.value.representative();
888885
let b = rhs.value.representative();
889886

890-
for i in 0..a.limbs.len() {
891-
a.limbs[i] |= b.limbs[i];
892-
}
893-
let value = FieldElement::new(a);
894-
// let value = FieldElement::new(a | b);
887+
let value = FieldElement::new(a | b);
895888
Self::Output { value }
896889
}
897890
}
898891

899892
impl<'a> BitXor for &'a Felt252 {
900893
type Output = Felt252;
901894
fn bitxor(self, rhs: Self) -> Self::Output {
902-
// TODO: move to upstream
903-
let mut a = self.value.representative();
895+
let a = self.value.representative();
904896
let b = rhs.value.representative();
905897

906-
for i in 0..a.limbs.len() {
907-
a.limbs[i] ^= b.limbs[i];
908-
}
909-
let value = FieldElement::new(a);
910-
// let value = FieldElement::new(a ^ b);
898+
let value = FieldElement::new(a ^ b);
911899
Self::Output { value }
912900
}
913901
}

0 commit comments

Comments
 (0)