Skip to content

Commit

Permalink
Merge pull request #2138 from AleoHQ/fix/varname-and-comments
Browse files Browse the repository at this point in the history
Fix variable name and comments.
  • Loading branch information
howardwu authored Oct 30, 2023
2 parents 1872869 + dc2f4ba commit 1583ecb
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions console/types/scalar/src/from_bits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,16 @@ impl<E: Environment> FromBits for Scalar<E> {

// If `num_bits` is greater than `size_in_data_bits`, check it is less than `Scalar::MODULUS`.
if num_bits > size_in_data_bits {
// Retrieve the modulus & subtract by 1 as we'll check `bits_le` is less than or *equal* to this value.
// (For advanced users) Scalar::MODULUS - 1 is equivalent to -1 in the field.
let modulus_minus_one = E::Scalar::modulus();
// Retrieve the modulus as we'll check `bits_le` is less than this value.
let modulus = E::Scalar::modulus();

// Recover the scalar as a `BigInteger` for comparison.
// As `bits_le[size_in_bits..]` is guaranteed to be zero from the above logic,
// and `bits_le` is greater than `size_in_data_bits`, it is safe to truncate `bits_le` to `size_in_bits`.
let scalar = E::BigInteger::from_bits_le(&bits_le[..size_in_bits])?;

// Ensure the scalar is less than `Scalar::MODULUS`.
ensure!(scalar < modulus_minus_one, "The scalar is greater than or equal to the modulus.");
ensure!(scalar < modulus, "The scalar is greater than or equal to the modulus.");

// Return the scalar.
Ok(Scalar { scalar: E::Scalar::from_bigint(scalar).ok_or_else(|| anyhow!("Invalid scalar from bits"))? })
Expand Down

0 comments on commit 1583ecb

Please sign in to comment.