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

Circuit: optimized short range check on 4 and 5 bits #86

Merged
merged 6 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
13 changes: 8 additions & 5 deletions src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ mod note_commit;
mod value_commit_orchard;

/// Size of the Orchard circuit.
const K: u32 = 12;
const K: u32 = 11;

// Absolute offsets for public inputs.
const ANCHOR: usize = 0;
Expand Down Expand Up @@ -342,10 +342,12 @@ impl plonk::Circuit<pallas::Base> for Circuit {

// Fixed columns for the Sinsemilla generator lookup table
let table_idx = meta.lookup_table_column();
let table_range_check_tag = meta.lookup_table_column();
let lookup = (
table_idx,
meta.lookup_table_column(),
meta.lookup_table_column(),
table_range_check_tag,
);

// Instance column used for public inputs
Expand Down Expand Up @@ -381,7 +383,8 @@ impl plonk::Circuit<pallas::Base> for Circuit {

// We have a lot of free space in the right-most advice columns; use one of them
// for all of our range checks.
let range_check = LookupRangeCheckConfig::configure(meta, advices[9], table_idx);
let range_check =
LookupRangeCheckConfig::configure(meta, advices[9], table_idx, table_range_check_tag);

// Configuration for curve point operations.
// This uses 10 advice columns and spans the whole circuit.
Expand Down Expand Up @@ -1287,8 +1290,8 @@ mod tests {
K,
&circuits[0],
);
assert_eq!(usize::from(circuit_cost.proof_size(1)), 5088);
assert_eq!(usize::from(circuit_cost.proof_size(2)), 7360);
assert_eq!(usize::from(circuit_cost.proof_size(1)), 5120);
assert_eq!(usize::from(circuit_cost.proof_size(2)), 7392);
usize::from(circuit_cost.proof_size(instances.len()))
};

Expand Down Expand Up @@ -1405,7 +1408,7 @@ mod tests {
let test_case_bytes = fs::read("src/circuit_proof_test_case.bin").unwrap();
read_test_case(&test_case_bytes[..]).expect("proof must be valid")
};
assert_eq!(proof.0.len(), 5088);
assert_eq!(proof.0.len(), 5120);

assert!(proof.verify(&vk, &[instance]).is_ok());
}
Expand Down
9 changes: 8 additions & 1 deletion src/circuit/commit_ivk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,10 +734,12 @@ mod tests {
}

let table_idx = meta.lookup_table_column();
let table_range_check_tag = meta.lookup_table_column();
let lookup = (
table_idx,
meta.lookup_table_column(),
meta.lookup_table_column(),
table_range_check_tag,
);
let lagrange_coeffs = [
meta.fixed_column(),
Expand All @@ -750,7 +752,12 @@ mod tests {
meta.fixed_column(),
];

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 sinsemilla_config = SinsemillaChip::<
OrchardHashDomains,
OrchardCommitDomains,
Expand Down
8 changes: 7 additions & 1 deletion src/circuit/gadget/mux_chip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ mod tests {
MuxChip::configure(meta, advices[0], advices[1], advices[2], advices[3]);

let table_idx = meta.lookup_table_column();
let table_range_check_tag = meta.lookup_table_column();

let lagrange_coeffs = [
meta.fixed_column(),
Expand All @@ -228,7 +229,12 @@ mod tests {
];
meta.enable_constant(lagrange_coeffs[0]);

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::<OrchardFixedBases>::configure(
meta,
Expand Down
9 changes: 8 additions & 1 deletion src/circuit/note_commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@
/// ------------------------------------
/// | j | j_0 | j_1 | 1 |
///
/// https://p.z.cash/orchard-0.1:note-commit-decomposition-j?partial

Check warning on line 749 in src/circuit/note_commit.rs

View workflow job for this annotation

GitHub Actions / Intra-doc links

this URL is not a hyperlink

Check warning on line 749 in src/circuit/note_commit.rs

View workflow job for this annotation

GitHub Actions / Intra-doc links

this URL is not a hyperlink
#[derive(Clone, Debug)]
struct DecomposeJ {
q_notecommit_j: Selector,
Expand Down Expand Up @@ -2369,10 +2369,12 @@
}

let table_idx = meta.lookup_table_column();
let table_range_check_tag = meta.lookup_table_column();
let lookup = (
table_idx,
meta.lookup_table_column(),
meta.lookup_table_column(),
table_range_check_tag,
);
let lagrange_coeffs = [
meta.fixed_column(),
Expand All @@ -2385,7 +2387,12 @@
meta.fixed_column(),
];

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 sinsemilla_config = SinsemillaChip::<
OrchardHashDomains,
OrchardCommitDomains,
Expand Down
9 changes: 8 additions & 1 deletion src/circuit/value_commit_orchard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,12 @@ mod tests {
meta.enable_equality(primary);

let table_idx = meta.lookup_table_column();
let table_range_check_tag = meta.lookup_table_column();
let lookup = (
table_idx,
meta.lookup_table_column(),
meta.lookup_table_column(),
table_range_check_tag,
);

let lagrange_coeffs = [
Expand All @@ -187,7 +189,12 @@ mod tests {
];
meta.enable_constant(lagrange_coeffs[0]);

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 sinsemilla_config = SinsemillaChip::configure(
meta,
Expand Down
Loading
Loading