Field
Add comment to waste_bit and from_str
@@ -31,6 +31,7 @@ impl From<i128> for FieldElement {
}
impl FieldElement {
+
pub fn one() -> FieldElement {
FieldElement(Fr::one())
}
@@ -42,6 +43,10 @@ impl FieldElement {
pub fn max_num_bits() -> u32 {
Fr::NUM_BITS
}
+ /// Returns None, if the string is not a canonical
+ /// representation of a field element; less than the order
+ /// or if the hex string is invalid.
+ /// This method can be used for both hex and decimal representations.
pub fn from_str(input : &str) -> Option<FieldElement> {
let fr = match Fr::from_str(input) {
None => return None,
@@ -49,7 +54,10 @@ impl FieldElement {
};
Some(FieldElement(fr))
}
- // This is the amount of bits that are always zero, since we have enough bits to represents every element in the field without them
+ // This is the amount of bits that are always zero,
+ // In BN256, every element can be represented with 254 bits.
+ // However this representation uses 256 bits, hence 2 wasted bits
+ // Note: This has nothing to do with saturated field elements.
fn wasted_bits() -> u32 {
let vec: Vec<_> = BitIterator::new(Fr::one().into_repr()).collect();
