halo2_gadgets: Migrate from bigint to uint

Closes zcash/halo2#457.
This commit is contained in:
Jack Grigg
2022-02-01 16:19:53 +00:00
parent 4bb7496b6f
commit c6886600a9
3 changed files with 11 additions and 3 deletions

View File

@@ -22,7 +22,6 @@ rustdoc-args = ["--cfg", "docsrs", "--html-in-header", "../katex-header.html"]
[dependencies]
arrayvec = "0.7.0"
bigint = "4"
bitvec = "0.22"
ff = "0.11"
group = "0.11"
@@ -32,6 +31,7 @@ pasta_curves = "0.3"
proptest = { version = "1.0.0", optional = true }
rand = "0.8"
subtle = "2.3"
uint = "=0.9.1" # uint 0.9.2 bumps the MSRV to 1.56.1
# Developer tooling dependencies
plotters = { version = "0.3.0", optional = true }

View File

@@ -8,7 +8,6 @@ use std::{
ops::{Deref, Range},
};
use bigint::U256;
use ff::PrimeField;
use halo2_proofs::{
arithmetic::FieldExt,
@@ -16,6 +15,7 @@ use halo2_proofs::{
plonk::{Advice, Column, ConstraintSystem, Error, Selector},
poly::Rotation,
};
use uint::construct_uint;
use pasta_curves::pallas;
@@ -425,6 +425,10 @@ impl<F: FieldExt> Deref for Z<F> {
}
fn decompose_for_scalar_mul(scalar: Option<&pallas::Base>) -> Vec<Option<bool>> {
construct_uint! {
struct U256(4);
}
let bitstring = scalar.map(|scalar| {
// We use `k = scalar + t_q` in the double-and-add algorithm, where
// the scalar field `F_q = 2^254 + t_q`.

View File

@@ -182,7 +182,6 @@ pub fn i2lebsp<const NUM_BITS: usize>(int: u64) -> [bool; NUM_BITS] {
#[cfg(test)]
mod tests {
use super::*;
use bigint::U256;
use group::ff::{Field, PrimeField};
use halo2_proofs::{
circuit::{Layouter, SimpleFloorPlanner},
@@ -195,6 +194,7 @@ mod tests {
use rand::rngs::OsRng;
use std::convert::TryInto;
use std::iter;
use uint::construct_uint;
#[test]
fn test_range_check() {
@@ -281,6 +281,10 @@ mod tests {
fn test_bitrange_subset() {
let rng = OsRng;
construct_uint! {
struct U256(4);
}
// Subset full range.
{
let field_elem = pallas::Base::random(rng);