Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimized short range check on 4 and 5 bits #21

Merged
merged 4 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 57 additions & 57 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,36 @@ jobs:
${{ steps.prepare.outputs.feature-flags }}
${{ matrix.extra_flags }}

test-32-bit:
name: Test on i686-unknown-linux-gnu${{ matrix.name_suffix }}
runs-on: ubuntu-latest
strategy:
matrix:
stage: [stable, beta, nightly]
include:
- stage: beta
name_suffix: " with beta features"
- stage: nightly
name_suffix: " with nightly features"

steps:
- uses: actions/checkout@v3
- id: prepare
uses: ./.github/actions/prepare
with:
beta-features: ${{ matrix.stage == 'beta' }}
nightly-features: ${{ matrix.stage == 'nightly' }}
- name: Install cross-platform support dependencies
run: sudo apt install gcc-multilib
- run: rustup target add i686-unknown-linux-gnu
- name: Run tests
run: >
cargo test
--verbose
--release
--workspace
--target i686-unknown-linux-gnu
${{ steps.prepare.outputs.feature-flags }}
# test-32-bit:
# name: Test on i686-unknown-linux-gnu${{ matrix.name_suffix }}
# runs-on: ubuntu-latest
# strategy:
# matrix:
# stage: [stable, beta, nightly]
# include:
# - stage: beta
# name_suffix: " with beta features"
# - stage: nightly
# name_suffix: " with nightly features"
#
# steps:
# - uses: actions/checkout@v3
# - id: prepare
# uses: ./.github/actions/prepare
# with:
# beta-features: ${{ matrix.stage == 'beta' }}
# nightly-features: ${{ matrix.stage == 'nightly' }}
# - name: Install cross-platform support dependencies
# run: sudo apt install gcc-multilib
# - run: rustup target add i686-unknown-linux-gnu
# - name: Run tests
# run: >
# cargo test
# --verbose
# --release
# --workspace
# --target i686-unknown-linux-gnu
# ${{ steps.prepare.outputs.feature-flags }}

build:
name: Build target ${{ matrix.target }}
Expand Down Expand Up @@ -125,33 +125,33 @@ jobs:
- name: Test halo2 book
run: mdbook test -L target/debug/deps book/

codecov:
name: Code coverage
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
# Use stable for this to ensure that cargo-tarpaulin can be built.
- id: prepare
uses: ./.github/actions/prepare
with:
toolchain: stable
nightly-features: true
- name: Install cargo-tarpaulin
uses: actions-rs/cargo@v1
with:
command: install
args: cargo-tarpaulin
- name: Generate coverage report
uses: actions-rs/cargo@v1
with:
command: tarpaulin
args: >
${{ steps.prepare.outputs.feature-flags }}
--timeout 600
--out Xml
- name: Upload coverage to Codecov
uses: codecov/[email protected]
# codecov:
# name: Code coverage
# runs-on: ubuntu-latest
#
# steps:
# - uses: actions/checkout@v3
# # Use stable for this to ensure that cargo-tarpaulin can be built.
# - id: prepare
# uses: ./.github/actions/prepare
# with:
# toolchain: stable
# nightly-features: true
# - name: Install cargo-tarpaulin
# uses: actions-rs/cargo@v1
# with:
# command: install
# args: cargo-tarpaulin
# - name: Generate coverage report
# uses: actions-rs/cargo@v1
# with:
# command: tarpaulin
# args: >
# ${{ steps.prepare.outputs.feature-flags }}
# --timeout 600
# --out Xml
# - name: Upload coverage to Codecov
# uses: codecov/[email protected]

doc-links:
name: Intra-doc links
Expand Down
8 changes: 7 additions & 1 deletion halo2_gadgets/src/ecc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,7 @@ pub(crate) mod tests {
meta.advice_column(),
];
let lookup_table = meta.lookup_table_column();
let table_range_check_tag = meta.lookup_table_column();
let lagrange_coeffs = [
meta.fixed_column(),
meta.fixed_column(),
Expand All @@ -807,7 +808,12 @@ pub(crate) mod tests {
let constants = meta.fixed_column();
meta.enable_constant(constants);

let range_check = LookupRangeCheckConfig::configure(meta, advices[9], lookup_table);
let range_check = LookupRangeCheckConfig::configure(
meta,
advices[9],
lookup_table,
table_range_check_tag,
);
EccChip::<TestFixedBases>::configure(meta, advices, lagrange_coeffs, range_check)
}

Expand Down
18 changes: 15 additions & 3 deletions halo2_gadgets/src/ecc/chip/mul_fixed/short.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ pub mod tests {
meta.advice_column(),
];
let lookup_table = meta.lookup_table_column();
let table_range_check_tag = meta.lookup_table_column();
let lagrange_coeffs = [
meta.fixed_column(),
meta.fixed_column(),
Expand All @@ -523,7 +524,12 @@ pub mod tests {
let constants = meta.fixed_column();
meta.enable_constant(constants);

let range_check = LookupRangeCheckConfig::configure(meta, advices[9], lookup_table);
let range_check = LookupRangeCheckConfig::configure(
meta,
advices[9],
lookup_table,
table_range_check_tag,
);
EccChip::<TestFixedBases>::configure(meta, advices, lagrange_coeffs, range_check)
}

Expand Down Expand Up @@ -644,7 +650,7 @@ pub mod tests {
)],
},
VerifyFailure::Permutation {
column: (Any::Fixed, 9).into(),
column: (Any::Fixed, 10).into(),
location: FailureLocation::OutsideRegion { row: 0 },
},
VerifyFailure::Permutation {
Expand Down Expand Up @@ -827,6 +833,7 @@ pub mod tests {
meta.advice_column(),
];
let lookup_table = meta.lookup_table_column();
let table_range_check_tag = meta.lookup_table_column();
let lagrange_coeffs = [
meta.fixed_column(),
meta.fixed_column(),
Expand All @@ -842,7 +849,12 @@ pub mod tests {
let constants = meta.fixed_column();
meta.enable_constant(constants);

let range_check = LookupRangeCheckConfig::configure(meta, advices[9], lookup_table);
let range_check = LookupRangeCheckConfig::configure(
meta,
advices[9],
lookup_table,
table_range_check_tag,
);
EccChip::<TestFixedBases>::configure(meta, advices, lagrange_coeffs, range_check)
}

Expand Down
9 changes: 8 additions & 1 deletion halo2_gadgets/src/sinsemilla.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ pub(crate) mod tests {
meta.enable_constant(constants);

let table_idx = meta.lookup_table_column();
let table_range_check_tag = meta.lookup_table_column();
let lagrange_coeffs = [
meta.fixed_column(),
meta.fixed_column(),
Expand All @@ -602,9 +603,15 @@ pub(crate) mod tests {
table_idx,
meta.lookup_table_column(),
meta.lookup_table_column(),
table_range_check_tag,
);

let range_check = LookupRangeCheckConfig::configure(meta, advices[9], table_idx);
let range_check = LookupRangeCheckConfig::configure(
meta,
advices[9],
table_idx,
table_range_check_tag,
);

let ecc_config =
EccChip::<TestFixedBases>::configure(meta, advices, lagrange_coeffs, range_check);
Expand Down
3 changes: 2 additions & 1 deletion halo2_gadgets/src/sinsemilla/chip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ where
advices: [Column<Advice>; 5],
witness_pieces: Column<Advice>,
fixed_y_q: Column<Fixed>,
lookup: (TableColumn, TableColumn, TableColumn),
lookup: (TableColumn, TableColumn, TableColumn, TableColumn),
range_check: LookupRangeCheckConfig<pallas::Base, { sinsemilla::K }>,
) -> <Self as Chip<pallas::Base>>::Config {
// Enable equality on all advice columns
Expand All @@ -178,6 +178,7 @@ where
table_idx: lookup.0,
table_x: lookup.1,
table_y: lookup.2,
table_range_check_tag: lookup.3,
},
lookup_config: range_check,
_marker: PhantomData,
Expand Down
63 changes: 62 additions & 1 deletion halo2_gadgets/src/sinsemilla/chip/generator_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use halo2_proofs::{
};

use super::{CommitDomains, FixedPoints, HashDomains};
use crate::sinsemilla::primitives::{self as sinsemilla, SINSEMILLA_S};
use crate::sinsemilla::primitives::{self as sinsemilla, K, SINSEMILLA_S};
use pasta_curves::pallas;

/// Table containing independent generators S[0..2^k]
Expand All @@ -15,6 +15,7 @@ pub struct GeneratorTableConfig {
pub table_idx: TableColumn,
pub table_x: TableColumn,
pub table_y: TableColumn,
pub table_range_check_tag: TableColumn,
}

impl GeneratorTableConfig {
Expand Down Expand Up @@ -90,6 +91,66 @@ impl GeneratorTableConfig {
)?;
table.assign_cell(|| "table_x", self.table_x, index, || Value::known(*x))?;
table.assign_cell(|| "table_y", self.table_y, index, || Value::known(*y))?;
table.assign_cell(
|| "table_range_check_tag",
self.table_range_check_tag,
index,
|| Value::known(pallas::Base::zero()),
)?;
if index < (1 << 4) {
let new_index = index + (1 << K);
table.assign_cell(
|| "table_idx",
self.table_idx,
new_index,
|| Value::known(pallas::Base::from(index as u64)),
)?;
table.assign_cell(
|| "table_x",
self.table_x,
new_index,
|| Value::known(*x),
)?;
table.assign_cell(
|| "table_y",
self.table_y,
new_index,
|| Value::known(*y),
)?;
table.assign_cell(
|| "table_range_check_tag",
self.table_range_check_tag,
new_index,
|| Value::known(pallas::Base::from(4_u64)),
)?;
}
if index < (1 << 5) {
let new_index = index + (1 << 10) + (1 << 4);
table.assign_cell(
|| "table_idx",
self.table_idx,
new_index,
|| Value::known(pallas::Base::from(index as u64)),
)?;
table.assign_cell(
|| "table_x",
self.table_x,
new_index,
|| Value::known(*x),
)?;
table.assign_cell(
|| "table_y",
self.table_y,
new_index,
|| Value::known(*y),
)?;
table.assign_cell(
|| "table_range_check_tag",
self.table_range_check_tag,
new_index,
|| Value::known(pallas::Base::from(5_u64)),
)?;
}
}
Ok(())
},
Expand Down
4 changes: 3 additions & 1 deletion halo2_gadgets/src/sinsemilla/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,11 @@ pub mod tests {
meta.lookup_table_column(),
meta.lookup_table_column(),
meta.lookup_table_column(),
meta.lookup_table_column(),
);

let range_check = LookupRangeCheckConfig::configure(meta, advices[9], lookup.0);
let range_check =
LookupRangeCheckConfig::configure(meta, advices[9], lookup.0, lookup.3);

let sinsemilla_config_1 = SinsemillaChip::configure(
meta,
Expand Down
Loading