Use halo2 selector optimizations.

This commit is contained in:
therealyingtong 2021-07-26 20:54:27 +08:00
parent 65ccf80560
commit b3ccd3f0dd
11 changed files with 16 additions and 24 deletions

View File

@ -62,5 +62,5 @@ name = "small"
harness = false
[patch.crates-io]
halo2 = { git = "https://github.com/zcash/halo2.git", rev = "92645b6ee9a2a91649bf22caebe5b1017ff67198" }
halo2 = { git = "https://github.com/zcash/halo2.git", rev = "2e960317ae02c72dc3ff5a02c7d31f154d606748" }
zcash_note_encryption = { git = "https://github.com/zcash/librustzcash.git", rev = "cc533a9da4f6a7209a7be05f82b12a03969152c9" }

View File

@ -1033,7 +1033,7 @@ mod tests {
halo2::dev::CircuitLayout::default()
.show_labels(false)
.view_height(0..(1 << 11))
.render(&circuit, &root)
.render(K as usize, &circuit, &root)
.unwrap();
}
}

View File

@ -553,7 +553,7 @@ mod tests {
}
#[test]
fn ecc() {
fn ecc_chip() {
let k = 13;
let circuit = MyCircuit {};
let prover = MockProver::run(k, &circuit, vec![]).unwrap();
@ -571,7 +571,7 @@ mod tests {
let circuit = MyCircuit {};
halo2::dev::CircuitLayout::default()
.render(&circuit, &root)
.render(13, &circuit, &root)
.unwrap();
}
}

View File

@ -54,9 +54,7 @@ impl Config {
// We conditionally negate this result using `y_p = y_a * s`, where `s` is the sign.
// Check that the final `y_p = y_a` or `y_p = -y_a`
let y_check = q_mul_fixed_short.clone()
* (y_p.clone() - y_a.clone())
* (y_p.clone() + y_a.clone());
let y_check = (y_p.clone() - y_a.clone()) * (y_p.clone() + y_a.clone());
// Check that the correct sign is witnessed s.t. sign * y_p = y_a
let negation_check = sign * y_p - y_a;

View File

@ -847,7 +847,7 @@ mod tests {
output: None,
};
halo2::dev::CircuitLayout::default()
.render(&circuit, &root)
.render(6, &circuit, &root)
.unwrap();
}
}

View File

@ -654,7 +654,7 @@ mod tests {
let circuit = MyCircuit {};
halo2::dev::CircuitLayout::default()
.render(&circuit, &root)
.render(11, &circuit, &root)
.unwrap();
}
}

View File

@ -123,7 +123,7 @@ impl SinsemillaChip {
}
let config = SinsemillaConfig {
q_sinsemilla1: meta.selector(),
q_sinsemilla1: meta.complex_selector(),
q_sinsemilla2: meta.fixed_column(),
q_sinsemilla4: meta.selector(),
fixed_y_q,

View File

@ -41,10 +41,6 @@ impl GeneratorTableConfig {
q_s2.clone() * (q_s2.clone() - one)
};
let table_idx_cur = meta.query_fixed(table_idx, Rotation::cur());
let table_x_cur = meta.query_fixed(table_x, Rotation::cur());
let table_y_cur = meta.query_fixed(table_y, Rotation::cur());
// m_{i+1} = z_{i} - 2^K * (q_s2 - q_s3) * z_{i + 1}
// Note that the message words m_i's are 1-indexed while the
// running sum z_i's are 0-indexed.
@ -83,7 +79,7 @@ impl GeneratorTableConfig {
let x_p = q_s1.clone() * x_p + not_q_s1.clone() * init_x;
let y_p = q_s1 * y_p + not_q_s1 * init_y;
vec![(m, table_idx_cur), (x_p, table_x_cur), (y_p, table_y_cur)]
vec![(m, table_idx), (x_p, table_x), (y_p, table_y)]
});
}

View File

@ -343,7 +343,7 @@ pub mod tests {
let circuit = MyCircuit::default();
halo2::dev::CircuitLayout::default()
.show_labels(false)
.render(&circuit, &root)
.render(11, &circuit, &root)
.unwrap();
}
}

View File

@ -358,11 +358,11 @@ mod tests {
prover.verify(),
Err(vec![
VerifyFailure::Permutation {
column: (Any::Fixed, 1).into(),
column: (Any::Fixed, 0).into(),
row: 0
},
VerifyFailure::Permutation {
column: (Any::Fixed, 1).into(),
column: (Any::Fixed, 0).into(),
row: 1
},
VerifyFailure::Permutation {

View File

@ -52,8 +52,8 @@ impl<F: FieldExt + PrimeFieldBits, const K: usize> LookupRangeCheckConfig<F, K>
) -> Self {
meta.enable_equality(running_sum.into());
let q_lookup = meta.selector();
let q_lookup_short = meta.selector();
let q_lookup = meta.complex_selector();
let q_lookup_short = meta.complex_selector();
let q_lookup_bitshift = meta.selector();
let config = LookupRangeCheckConfig {
q_lookup,
@ -72,18 +72,16 @@ impl<F: FieldExt + PrimeFieldBits, const K: usize> LookupRangeCheckConfig<F, K>
// z_i = 2^{K}⋅z_{i + 1} + a_i
// => a_i = z_i - 2^{K}⋅z_{i + 1}
let word = z_cur - z_next * F::from_u64(1 << K);
let table = meta.query_fixed(config.table_idx, Rotation::cur());
vec![(q_lookup * word, table)]
vec![(q_lookup * word, config.table_idx)]
});
// Lookup used in range checks up to S bits, where S < K.
meta.lookup(|meta| {
let q_lookup_short = meta.query_selector(config.q_lookup_short);
let word = meta.query_advice(config.running_sum, Rotation::cur());
let table = meta.query_fixed(config.table_idx, Rotation::cur());
vec![(q_lookup_short * word, table)]
vec![(q_lookup_short * word, config.table_idx)]
});
// For short lookups, check that the word has been shifted by the correct number of bits.