mirror of https://github.com/zcash/orchard.git
mul_fixed_*::tests: Constrain zero outputs in mul_fixed tests.
Co-authored-by: Jack Grigg <jack@electriccoin.co>
This commit is contained in:
parent
9fd4d7df27
commit
d550e156d9
|
@ -544,6 +544,7 @@ mod tests {
|
||||||
super::chip::mul_fixed::full_width::tests::test_mul_fixed(
|
super::chip::mul_fixed::full_width::tests::test_mul_fixed(
|
||||||
chip.clone(),
|
chip.clone(),
|
||||||
layouter.namespace(|| "full-width fixed-base scalar mul"),
|
layouter.namespace(|| "full-width fixed-base scalar mul"),
|
||||||
|
&zero,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -552,6 +553,7 @@ mod tests {
|
||||||
super::chip::mul_fixed::short::tests::test_mul_fixed_short(
|
super::chip::mul_fixed::short::tests::test_mul_fixed_short(
|
||||||
chip.clone(),
|
chip.clone(),
|
||||||
layouter.namespace(|| "signed short fixed-base scalar mul"),
|
layouter.namespace(|| "signed short fixed-base scalar mul"),
|
||||||
|
&zero,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -560,6 +562,7 @@ mod tests {
|
||||||
super::chip::mul_fixed::base_field_elem::tests::test_mul_fixed_base_field(
|
super::chip::mul_fixed::base_field_elem::tests::test_mul_fixed_base_field(
|
||||||
chip,
|
chip,
|
||||||
layouter.namespace(|| "fixed-base scalar mul with base field element"),
|
layouter.namespace(|| "fixed-base scalar mul with base field element"),
|
||||||
|
&zero,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -248,7 +248,7 @@ pub mod tests {
|
||||||
use crate::circuit::gadget::{
|
use crate::circuit::gadget::{
|
||||||
ecc::{
|
ecc::{
|
||||||
chip::{EccChip, OrchardFixedBasesFull},
|
chip::{EccChip, OrchardFixedBasesFull},
|
||||||
FixedPoint,
|
FixedPoint, Point,
|
||||||
},
|
},
|
||||||
utilities::{CellValue, UtilitiesInstructions},
|
utilities::{CellValue, UtilitiesInstructions},
|
||||||
};
|
};
|
||||||
|
@ -257,6 +257,7 @@ pub mod tests {
|
||||||
pub fn test_mul_fixed_base_field(
|
pub fn test_mul_fixed_base_field(
|
||||||
chip: EccChip,
|
chip: EccChip,
|
||||||
mut layouter: impl Layouter<pallas::Base>,
|
mut layouter: impl Layouter<pallas::Base>,
|
||||||
|
zero: &Point<pallas::Affine, EccChip>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
impl UtilitiesInstructions<pallas::Base> for EccChip {
|
impl UtilitiesInstructions<pallas::Base> for EccChip {
|
||||||
type Var = CellValue<pallas::Base>;
|
type Var = CellValue<pallas::Base>;
|
||||||
|
@ -269,6 +270,7 @@ pub mod tests {
|
||||||
chip.clone(),
|
chip.clone(),
|
||||||
layouter.namespace(|| "commit_ivk_r"),
|
layouter.namespace(|| "commit_ivk_r"),
|
||||||
commit_ivk_r,
|
commit_ivk_r,
|
||||||
|
&zero,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// note_commit_r
|
// note_commit_r
|
||||||
|
@ -278,6 +280,7 @@ pub mod tests {
|
||||||
chip.clone(),
|
chip.clone(),
|
||||||
layouter.namespace(|| "note_commit_r"),
|
layouter.namespace(|| "note_commit_r"),
|
||||||
note_commit_r,
|
note_commit_r,
|
||||||
|
&zero,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// nullifier_k
|
// nullifier_k
|
||||||
|
@ -287,6 +290,7 @@ pub mod tests {
|
||||||
chip.clone(),
|
chip.clone(),
|
||||||
layouter.namespace(|| "nullifier_k"),
|
layouter.namespace(|| "nullifier_k"),
|
||||||
nullifier_k,
|
nullifier_k,
|
||||||
|
&zero,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// value_commit_r
|
// value_commit_r
|
||||||
|
@ -296,12 +300,18 @@ pub mod tests {
|
||||||
chip.clone(),
|
chip.clone(),
|
||||||
layouter.namespace(|| "value_commit_r"),
|
layouter.namespace(|| "value_commit_r"),
|
||||||
value_commit_r,
|
value_commit_r,
|
||||||
|
&zero,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// spend_auth_g
|
// spend_auth_g
|
||||||
let spend_auth_g = OrchardFixedBasesFull::SpendAuthG;
|
let spend_auth_g = OrchardFixedBasesFull::SpendAuthG;
|
||||||
let spend_auth_g = FixedPoint::from_inner(chip.clone(), spend_auth_g);
|
let spend_auth_g = FixedPoint::from_inner(chip.clone(), spend_auth_g);
|
||||||
test_single_base(chip, layouter.namespace(|| "spend_auth_g"), spend_auth_g)?;
|
test_single_base(
|
||||||
|
chip,
|
||||||
|
layouter.namespace(|| "spend_auth_g"),
|
||||||
|
spend_auth_g,
|
||||||
|
&zero,
|
||||||
|
)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -311,6 +321,7 @@ pub mod tests {
|
||||||
chip: EccChip,
|
chip: EccChip,
|
||||||
mut layouter: impl Layouter<pallas::Base>,
|
mut layouter: impl Layouter<pallas::Base>,
|
||||||
base: FixedPoint<pallas::Affine, EccChip>,
|
base: FixedPoint<pallas::Affine, EccChip>,
|
||||||
|
zero: &Point<pallas::Affine, EccChip>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let column = chip.config().advices[0];
|
let column = chip.config().advices[0];
|
||||||
|
|
||||||
|
@ -356,7 +367,9 @@ pub mod tests {
|
||||||
column,
|
column,
|
||||||
Some(scalar_fixed),
|
Some(scalar_fixed),
|
||||||
)?;
|
)?;
|
||||||
|
let result =
|
||||||
base.mul_base_field_elem(layouter.namespace(|| "mul by zero"), scalar_fixed)?;
|
base.mul_base_field_elem(layouter.namespace(|| "mul by zero"), scalar_fixed)?;
|
||||||
|
result.constrain_equal(layouter.namespace(|| "[0]B = 𝒪"), &zero)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// [-1]B is the largest base field element
|
// [-1]B is the largest base field element
|
||||||
|
|
|
@ -62,13 +62,14 @@ pub mod tests {
|
||||||
|
|
||||||
use crate::circuit::gadget::ecc::{
|
use crate::circuit::gadget::ecc::{
|
||||||
chip::{EccChip, OrchardFixedBasesFull},
|
chip::{EccChip, OrchardFixedBasesFull},
|
||||||
FixedPoint, ScalarFixed,
|
FixedPoint, Point, ScalarFixed,
|
||||||
};
|
};
|
||||||
use crate::constants;
|
use crate::constants;
|
||||||
|
|
||||||
pub fn test_mul_fixed(
|
pub fn test_mul_fixed(
|
||||||
chip: EccChip,
|
chip: EccChip,
|
||||||
mut layouter: impl Layouter<pallas::Base>,
|
mut layouter: impl Layouter<pallas::Base>,
|
||||||
|
zero: &Point<pallas::Affine, EccChip>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
// commit_ivk_r
|
// commit_ivk_r
|
||||||
let commit_ivk_r = OrchardFixedBasesFull::CommitIvkR;
|
let commit_ivk_r = OrchardFixedBasesFull::CommitIvkR;
|
||||||
|
@ -77,6 +78,7 @@ pub mod tests {
|
||||||
chip.clone(),
|
chip.clone(),
|
||||||
layouter.namespace(|| "commit_ivk_r"),
|
layouter.namespace(|| "commit_ivk_r"),
|
||||||
commit_ivk_r,
|
commit_ivk_r,
|
||||||
|
&zero,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// note_commit_r
|
// note_commit_r
|
||||||
|
@ -86,6 +88,7 @@ pub mod tests {
|
||||||
chip.clone(),
|
chip.clone(),
|
||||||
layouter.namespace(|| "note_commit_r"),
|
layouter.namespace(|| "note_commit_r"),
|
||||||
note_commit_r,
|
note_commit_r,
|
||||||
|
&zero,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// nullifier_k
|
// nullifier_k
|
||||||
|
@ -95,6 +98,7 @@ pub mod tests {
|
||||||
chip.clone(),
|
chip.clone(),
|
||||||
layouter.namespace(|| "nullifier_k"),
|
layouter.namespace(|| "nullifier_k"),
|
||||||
nullifier_k,
|
nullifier_k,
|
||||||
|
&zero,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// value_commit_r
|
// value_commit_r
|
||||||
|
@ -104,12 +108,18 @@ pub mod tests {
|
||||||
chip.clone(),
|
chip.clone(),
|
||||||
layouter.namespace(|| "value_commit_r"),
|
layouter.namespace(|| "value_commit_r"),
|
||||||
value_commit_r,
|
value_commit_r,
|
||||||
|
&zero,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// spend_auth_g
|
// spend_auth_g
|
||||||
let spend_auth_g = OrchardFixedBasesFull::SpendAuthG;
|
let spend_auth_g = OrchardFixedBasesFull::SpendAuthG;
|
||||||
let spend_auth_g = FixedPoint::from_inner(chip.clone(), spend_auth_g);
|
let spend_auth_g = FixedPoint::from_inner(chip.clone(), spend_auth_g);
|
||||||
test_single_base(chip, layouter.namespace(|| "spend_auth_g"), spend_auth_g)?;
|
test_single_base(
|
||||||
|
chip,
|
||||||
|
layouter.namespace(|| "spend_auth_g"),
|
||||||
|
spend_auth_g,
|
||||||
|
&zero,
|
||||||
|
)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -119,6 +129,7 @@ pub mod tests {
|
||||||
chip: EccChip,
|
chip: EccChip,
|
||||||
mut layouter: impl Layouter<pallas::Base>,
|
mut layouter: impl Layouter<pallas::Base>,
|
||||||
base: FixedPoint<pallas::Affine, EccChip>,
|
base: FixedPoint<pallas::Affine, EccChip>,
|
||||||
|
zero: &Point<pallas::Affine, EccChip>,
|
||||||
) -> Result<(), Error>
|
) -> Result<(), Error>
|
||||||
where
|
where
|
||||||
pallas::Scalar: PrimeFieldBits,
|
pallas::Scalar: PrimeFieldBits,
|
||||||
|
@ -166,7 +177,8 @@ pub mod tests {
|
||||||
layouter.namespace(|| "ScalarFixed"),
|
layouter.namespace(|| "ScalarFixed"),
|
||||||
Some(scalar_fixed),
|
Some(scalar_fixed),
|
||||||
)?;
|
)?;
|
||||||
base.mul(layouter.namespace(|| "mul by zero"), &scalar_fixed)?;
|
let result = base.mul(layouter.namespace(|| "mul by zero"), &scalar_fixed)?;
|
||||||
|
result.constrain_equal(layouter.namespace(|| "[0]B = 𝒪"), &zero)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// [-1]B is the largest scalar field element.
|
// [-1]B is the largest scalar field element.
|
||||||
|
|
|
@ -157,13 +157,14 @@ pub mod tests {
|
||||||
use halo2::{circuit::Layouter, plonk::Error};
|
use halo2::{circuit::Layouter, plonk::Error};
|
||||||
use pasta_curves::{arithmetic::FieldExt, pallas};
|
use pasta_curves::{arithmetic::FieldExt, pallas};
|
||||||
|
|
||||||
use crate::circuit::gadget::ecc::{chip::EccChip, FixedPointShort, ScalarFixedShort};
|
use crate::circuit::gadget::ecc::{chip::EccChip, FixedPointShort, Point, ScalarFixedShort};
|
||||||
use crate::constants::load::ValueCommitV;
|
use crate::constants::load::ValueCommitV;
|
||||||
|
|
||||||
#[allow(clippy::op_ref)]
|
#[allow(clippy::op_ref)]
|
||||||
pub fn test_mul_fixed_short(
|
pub fn test_mul_fixed_short(
|
||||||
chip: EccChip,
|
chip: EccChip,
|
||||||
mut layouter: impl Layouter<pallas::Base>,
|
mut layouter: impl Layouter<pallas::Base>,
|
||||||
|
zero: &Point<pallas::Affine, EccChip>,
|
||||||
) -> Result<(), Error>
|
) -> Result<(), Error>
|
||||||
where
|
where
|
||||||
pallas::Scalar: PrimeFieldBits,
|
pallas::Scalar: PrimeFieldBits,
|
||||||
|
@ -181,7 +182,8 @@ pub mod tests {
|
||||||
layouter.namespace(|| "ScalarFixedShort"),
|
layouter.namespace(|| "ScalarFixedShort"),
|
||||||
Some(scalar_fixed),
|
Some(scalar_fixed),
|
||||||
)?;
|
)?;
|
||||||
value_commit_v.mul(layouter.namespace(|| "mul"), &scalar_fixed)?;
|
let result = value_commit_v.mul(layouter.namespace(|| "mul by zero"), &scalar_fixed)?;
|
||||||
|
result.constrain_equal(layouter.namespace(|| "[0]B = 𝒪"), &zero)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Random [a]B
|
// Random [a]B
|
||||||
|
|
Loading…
Reference in New Issue