mirror of https://github.com/zcash/halo2.git
sinsemilla::merkle.rs: Add MerkleChip
This commit is contained in:
parent
d090da0159
commit
68878d88b1
|
@ -12,7 +12,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
use std::{convert::TryInto, iter};
|
use std::{convert::TryInto, iter};
|
||||||
|
|
||||||
// mod chip;
|
mod chip;
|
||||||
|
|
||||||
/// Instructions to check the validity of a Merkle path of a given `PATH_LENGTH`.
|
/// Instructions to check the validity of a Merkle path of a given `PATH_LENGTH`.
|
||||||
/// The hash function used is a Sinsemilla instance with `K`-bit words.
|
/// The hash function used is a Sinsemilla instance with `K`-bit words.
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
use halo2::{
|
||||||
|
circuit::{Chip, Layouter},
|
||||||
|
plonk::{Advice, Column, ConstraintSystem, Error, Expression, Fixed, Permutation},
|
||||||
|
poly::Rotation,
|
||||||
|
};
|
||||||
|
use pasta_curves::{arithmetic::FieldExt, pallas};
|
||||||
|
|
||||||
|
use super::super::{
|
||||||
|
chip::{SinsemillaChip, SinsemillaConfig},
|
||||||
|
SinsemillaInstructions,
|
||||||
|
};
|
||||||
|
use super::MerkleInstructions;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
circuit::gadget::utilities::{
|
||||||
|
cond_swap::{CondSwapChip, CondSwapConfig, CondSwapInstructions},
|
||||||
|
copy,
|
||||||
|
lookup_range_check::LookupRangeCheckConfig,
|
||||||
|
CellValue, UtilitiesInstructions, Var,
|
||||||
|
},
|
||||||
|
constants::MERKLE_DEPTH_ORCHARD,
|
||||||
|
primitives::sinsemilla,
|
||||||
|
};
|
||||||
|
use ff::{PrimeField, PrimeFieldBits};
|
||||||
|
use std::{array, convert::TryInto};
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct MerkleConfig {
|
||||||
|
advices: [Column<Advice>; 5],
|
||||||
|
l_star_plus1: Column<Fixed>,
|
||||||
|
perm: Permutation,
|
||||||
|
lookup_config: LookupRangeCheckConfig<pallas::Base, { sinsemilla::K }>,
|
||||||
|
pub(super) cond_swap_config: CondSwapConfig,
|
||||||
|
pub(super) sinsemilla_config: SinsemillaConfig,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct MerkleChip {
|
||||||
|
config: MerkleConfig,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Chip<pallas::Base> for MerkleChip {
|
||||||
|
type Config = MerkleConfig;
|
||||||
|
type Loaded = ();
|
||||||
|
|
||||||
|
fn config(&self) -> &Self::Config {
|
||||||
|
&self.config
|
||||||
|
}
|
||||||
|
|
||||||
|
fn loaded(&self) -> &Self::Loaded {
|
||||||
|
&()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue