mul_fixed: Avoid computing fixed constants during proving

This decreases proving time in the Action circuit by 17%.
This commit is contained in:
Jack Grigg 2021-06-16 16:01:30 +01:00 committed by therealyingtong
parent b15343f6f7
commit e726fee19b
1 changed files with 14 additions and 3 deletions

View File

@ -211,7 +211,9 @@ impl<const NUM_WINDOWS: usize> Config<NUM_WINDOWS> {
base: OrchardFixedBases, base: OrchardFixedBases,
fixed_column: Column<Fixed>, fixed_column: Column<Fixed>,
) -> Result<(), Error> { ) -> Result<(), Error> {
let (lagrange_coeffs, z) = match base { let mut constants = None;
let build_constants = || match base {
OrchardFixedBases::ValueCommitV => { OrchardFixedBases::ValueCommitV => {
assert_eq!(NUM_WINDOWS, constants::NUM_WINDOWS_SHORT); assert_eq!(NUM_WINDOWS, constants::NUM_WINDOWS_SHORT);
let base = ValueCommitV::get(); let base = ValueCommitV::get();
@ -250,7 +252,13 @@ impl<const NUM_WINDOWS: usize> Config<NUM_WINDOWS> {
}, },
self.lagrange_coeffs[k], self.lagrange_coeffs[k],
window + offset, window + offset,
|| Ok(lagrange_coeffs[window].0[k]), || {
if constants.as_ref().is_none() {
constants = Some(build_constants());
}
let lagrange_coeffs = &constants.as_ref().unwrap().0;
Ok(lagrange_coeffs[window].0[k])
},
)?; )?;
} }
@ -259,7 +267,10 @@ impl<const NUM_WINDOWS: usize> Config<NUM_WINDOWS> {
|| format!("z-value for window: {:?}", window), || format!("z-value for window: {:?}", window),
self.fixed_z, self.fixed_z,
window + offset, window + offset,
|| Ok(z[window]), || {
let z = &constants.as_ref().unwrap().1;
Ok(z[window])
}
)?; )?;
} }