forked from zcash/orchard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move derive_nullifier function into derive_nullifier.rs file
- Loading branch information
1 parent
9325ef1
commit 18b4452
Showing
6 changed files
with
138 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//! Derive nullifier logic for the Orchard circuit (Vanilla variation). | ||
|
||
pub(in crate::circuit) mod gadgets { | ||
use pasta_curves::pallas; | ||
|
||
use crate::{circuit::gadget::AddInstruction, constants::OrchardFixedBases}; | ||
use halo2_gadgets::{ | ||
ecc::{chip::EccPoint, EccInstructions, Point, X}, | ||
poseidon::{ | ||
primitives::{self as poseidon, ConstantLength}, | ||
PoseidonSpongeInstructions, | ||
}, | ||
}; | ||
use halo2_proofs::{ | ||
circuit::{AssignedCell, Layouter}, | ||
plonk, | ||
}; | ||
|
||
/// `DeriveNullifier` from [Section 4.16: Note Commitments and Nullifiers]. | ||
/// | ||
/// [Section 4.16: Note Commitments and Nullifiers]: https://zips.z.cash/protocol/protocol.pdf#commitmentsandnullifiers | ||
#[allow(clippy::too_many_arguments)] | ||
pub(in crate::circuit) fn derive_nullifier< | ||
PoseidonChip: PoseidonSpongeInstructions<pallas::Base, poseidon::P128Pow5T3, ConstantLength<2>, 3, 2>, | ||
AddChip: AddInstruction<pallas::Base>, | ||
EccChip: EccInstructions< | ||
pallas::Affine, | ||
FixedPoints = OrchardFixedBases, | ||
Point = EccPoint, | ||
Var = AssignedCell<pallas::Base, pallas::Base>, | ||
>, | ||
>( | ||
layouter: &mut impl Layouter<pallas::Base>, | ||
poseidon_chip: PoseidonChip, | ||
add_chip: AddChip, | ||
ecc_chip: EccChip, | ||
rho: AssignedCell<pallas::Base, pallas::Base>, | ||
psi: &AssignedCell<pallas::Base, pallas::Base>, | ||
cm: &Point<pallas::Affine, EccChip>, | ||
nk: AssignedCell<pallas::Base, pallas::Base>, | ||
) -> Result<X<pallas::Affine, EccChip>, plonk::Error> { | ||
crate::circuit::gadget::derive_nullifier( | ||
layouter, | ||
poseidon_chip, | ||
add_chip, | ||
ecc_chip, | ||
rho, | ||
psi, | ||
cm, | ||
nk, | ||
) | ||
.map(|res| res.extract_p()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,6 @@ | ||
//! Gadgets used in the Orchard circuit (Vanilla variation). | ||
|
||
use pasta_curves::pallas; | ||
|
||
use super::AddInstruction; | ||
use crate::constants::OrchardFixedBases; | ||
use halo2_gadgets::{ | ||
ecc::{chip::EccPoint, EccInstructions, Point, X}, | ||
poseidon::{ | ||
primitives::{self as poseidon, ConstantLength}, | ||
PoseidonSpongeInstructions, | ||
}, | ||
}; | ||
use halo2_proofs::{ | ||
circuit::{AssignedCell, Layouter}, | ||
plonk, | ||
}; | ||
|
||
/// `DeriveNullifier` from [Section 4.16: Note Commitments and Nullifiers]. | ||
/// | ||
/// [Section 4.16: Note Commitments and Nullifiers]: https://zips.z.cash/protocol/protocol.pdf#commitmentsandnullifiers | ||
#[allow(clippy::too_many_arguments)] | ||
pub(in crate::circuit) fn derive_nullifier< | ||
PoseidonChip: PoseidonSpongeInstructions<pallas::Base, poseidon::P128Pow5T3, ConstantLength<2>, 3, 2>, | ||
AddChip: AddInstruction<pallas::Base>, | ||
EccChip: EccInstructions< | ||
pallas::Affine, | ||
FixedPoints = OrchardFixedBases, | ||
Point = EccPoint, | ||
Var = AssignedCell<pallas::Base, pallas::Base>, | ||
>, | ||
>( | ||
layouter: &mut impl Layouter<pallas::Base>, | ||
poseidon_chip: PoseidonChip, | ||
add_chip: AddChip, | ||
ecc_chip: EccChip, | ||
rho: AssignedCell<pallas::Base, pallas::Base>, | ||
psi: &AssignedCell<pallas::Base, pallas::Base>, | ||
cm: &Point<pallas::Affine, EccChip>, | ||
nk: AssignedCell<pallas::Base, pallas::Base>, | ||
) -> Result<X<pallas::Affine, EccChip>, plonk::Error> { | ||
crate::circuit::gadget::derive_nullifier( | ||
layouter, | ||
poseidon_chip, | ||
add_chip, | ||
ecc_chip, | ||
rho, | ||
psi, | ||
cm, | ||
nk, | ||
) | ||
.map(|res| res.extract_p()) | ||
} | ||
|
||
pub(in crate::circuit) use super::commit_ivk::gadgets::commit_ivk; | ||
pub(in crate::circuit) use super::derive_nullifier::gadgets::derive_nullifier; | ||
pub(in crate::circuit) use super::note_commit::gadgets::note_commit; | ||
pub(in crate::circuit) use super::value_commit_orchard::gadgets::value_commit_orchard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
//! Derive nullifier logic for the Orchard circuit (ZSA variation). | ||
|
||
pub(in crate::circuit) mod gadgets { | ||
use group::Curve; | ||
use pasta_curves::{arithmetic::CurveExt, pallas}; | ||
|
||
use crate::{circuit::gadget::AddInstruction, constants::OrchardFixedBases}; | ||
use halo2_gadgets::{ | ||
ecc::{chip::EccPoint, EccInstructions, Point, X}, | ||
poseidon::{ | ||
primitives::{self as poseidon, ConstantLength}, | ||
PoseidonSpongeInstructions, | ||
}, | ||
utilities::cond_swap::CondSwapChip, | ||
}; | ||
use halo2_proofs::{ | ||
circuit::{AssignedCell, Layouter}, | ||
plonk, | ||
}; | ||
|
||
/// `DeriveNullifier` from [Section 4.16: Note Commitments and Nullifiers]. | ||
/// | ||
/// [Section 4.16: Note Commitments and Nullifiers]: https://zips.z.cash/protocol/protocol.pdf#commitmentsandnullifiers | ||
#[allow(clippy::too_many_arguments)] | ||
pub(in crate::circuit) fn derive_nullifier< | ||
PoseidonChip: PoseidonSpongeInstructions<pallas::Base, poseidon::P128Pow5T3, ConstantLength<2>, 3, 2>, | ||
AddChip: AddInstruction<pallas::Base>, | ||
EccChip: EccInstructions< | ||
pallas::Affine, | ||
FixedPoints = OrchardFixedBases, | ||
Point = EccPoint, | ||
Var = AssignedCell<pallas::Base, pallas::Base>, | ||
>, | ||
>( | ||
layouter: &mut impl Layouter<pallas::Base>, | ||
poseidon_chip: PoseidonChip, | ||
add_chip: AddChip, | ||
ecc_chip: EccChip, | ||
cond_swap_chip: CondSwapChip<pallas::Base>, | ||
rho: AssignedCell<pallas::Base, pallas::Base>, | ||
psi: &AssignedCell<pallas::Base, pallas::Base>, | ||
cm: &Point<pallas::Affine, EccChip>, | ||
nk: AssignedCell<pallas::Base, pallas::Base>, | ||
split_flag: AssignedCell<pallas::Base, pallas::Base>, | ||
) -> Result<X<pallas::Affine, EccChip>, plonk::Error> { | ||
let nf = crate::circuit::gadget::derive_nullifier( | ||
layouter, | ||
poseidon_chip, | ||
add_chip, | ||
ecc_chip.clone(), | ||
rho, | ||
psi, | ||
cm, | ||
nk, | ||
)?; | ||
|
||
// Add NullifierL to nf | ||
// split_note_nf = NullifierL + nf | ||
let nullifier_l = Point::new_from_constant( | ||
ecc_chip.clone(), | ||
layouter.namespace(|| "witness NullifierL constant"), | ||
pallas::Point::hash_to_curve("z.cash:Orchard")(b"L").to_affine(), | ||
)?; | ||
let split_note_nf = nullifier_l.add(layouter.namespace(|| "split_note_nf"), &nf)?; | ||
|
||
// Select the desired nullifier according to split_flag | ||
Ok(Point::from_inner( | ||
ecc_chip, | ||
cond_swap_chip.mux_on_points( | ||
layouter.namespace(|| "mux on nf"), | ||
&split_flag, | ||
nf.inner(), | ||
split_note_nf.inner(), | ||
)?, | ||
) | ||
.extract_p()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,6 @@ | ||
//! Gadgets used in the Orchard circuit (ZSA variation). | ||
|
||
use group::Curve; | ||
use pasta_curves::arithmetic::CurveExt; | ||
use pasta_curves::pallas; | ||
|
||
use super::AddInstruction; | ||
use crate::constants::OrchardFixedBases; | ||
use halo2_gadgets::{ | ||
ecc::{chip::EccPoint, EccInstructions, Point, X}, | ||
poseidon::{ | ||
primitives::{self as poseidon, ConstantLength}, | ||
PoseidonSpongeInstructions, | ||
}, | ||
utilities::cond_swap::CondSwapChip, | ||
}; | ||
use halo2_proofs::{ | ||
circuit::{AssignedCell, Layouter}, | ||
plonk, | ||
}; | ||
|
||
/// `DeriveNullifier` from [Section 4.16: Note Commitments and Nullifiers]. | ||
/// | ||
/// [Section 4.16: Note Commitments and Nullifiers]: https://zips.z.cash/protocol/protocol.pdf#commitmentsandnullifiers | ||
#[allow(clippy::too_many_arguments)] | ||
pub(in crate::circuit) fn derive_nullifier< | ||
PoseidonChip: PoseidonSpongeInstructions<pallas::Base, poseidon::P128Pow5T3, ConstantLength<2>, 3, 2>, | ||
AddChip: AddInstruction<pallas::Base>, | ||
EccChip: EccInstructions< | ||
pallas::Affine, | ||
FixedPoints = OrchardFixedBases, | ||
Point = EccPoint, | ||
Var = AssignedCell<pallas::Base, pallas::Base>, | ||
>, | ||
>( | ||
layouter: &mut impl Layouter<pallas::Base>, | ||
poseidon_chip: PoseidonChip, | ||
add_chip: AddChip, | ||
ecc_chip: EccChip, | ||
cond_swap_chip: CondSwapChip<pallas::Base>, | ||
rho: AssignedCell<pallas::Base, pallas::Base>, | ||
psi: &AssignedCell<pallas::Base, pallas::Base>, | ||
cm: &Point<pallas::Affine, EccChip>, | ||
nk: AssignedCell<pallas::Base, pallas::Base>, | ||
split_flag: AssignedCell<pallas::Base, pallas::Base>, | ||
) -> Result<X<pallas::Affine, EccChip>, plonk::Error> { | ||
let nf = crate::circuit::gadget::derive_nullifier( | ||
layouter, | ||
poseidon_chip, | ||
add_chip, | ||
ecc_chip.clone(), | ||
rho, | ||
psi, | ||
cm, | ||
nk, | ||
)?; | ||
|
||
// Add NullifierL to nf | ||
// split_note_nf = NullifierL + nf | ||
let nullifier_l = Point::new_from_constant( | ||
ecc_chip.clone(), | ||
layouter.namespace(|| "witness NullifierL constant"), | ||
pallas::Point::hash_to_curve("z.cash:Orchard")(b"L").to_affine(), | ||
)?; | ||
let split_note_nf = nullifier_l.add(layouter.namespace(|| "split_note_nf"), &nf)?; | ||
|
||
// Select the desired nullifier according to split_flag | ||
Ok(Point::from_inner( | ||
ecc_chip, | ||
cond_swap_chip.mux_on_points( | ||
layouter.namespace(|| "mux on nf"), | ||
&split_flag, | ||
nf.inner(), | ||
split_note_nf.inner(), | ||
)?, | ||
) | ||
.extract_p()) | ||
} | ||
|
||
pub(in crate::circuit) use super::commit_ivk::gadgets::commit_ivk; | ||
pub(in crate::circuit) use super::derive_nullifier::gadgets::derive_nullifier; | ||
pub(in crate::circuit) use super::note_commit::gadgets::note_commit; | ||
pub(in crate::circuit) use super::value_commit_orchard::gadgets::value_commit_orchard; |