From 68878d88b18f0b699a354d25a10dd9d63ee9201a Mon Sep 17 00:00:00 2001 From: therealyingtong Date: Sat, 5 Jun 2021 00:54:10 +0800 Subject: [PATCH] sinsemilla::merkle.rs: Add MerkleChip --- src/circuit/gadget/sinsemilla/merkle.rs | 2 +- src/circuit/gadget/sinsemilla/merkle/chip.rs | 53 ++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 src/circuit/gadget/sinsemilla/merkle/chip.rs diff --git a/src/circuit/gadget/sinsemilla/merkle.rs b/src/circuit/gadget/sinsemilla/merkle.rs index 91883281..9d5e05c2 100644 --- a/src/circuit/gadget/sinsemilla/merkle.rs +++ b/src/circuit/gadget/sinsemilla/merkle.rs @@ -12,7 +12,7 @@ use crate::{ }; use std::{convert::TryInto, iter}; -// mod chip; +mod chip; /// 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. diff --git a/src/circuit/gadget/sinsemilla/merkle/chip.rs b/src/circuit/gadget/sinsemilla/merkle/chip.rs new file mode 100644 index 00000000..d10b6048 --- /dev/null +++ b/src/circuit/gadget/sinsemilla/merkle/chip.rs @@ -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; 5], + l_star_plus1: Column, + perm: Permutation, + lookup_config: LookupRangeCheckConfig, + pub(super) cond_swap_config: CondSwapConfig, + pub(super) sinsemilla_config: SinsemillaConfig, +} + +#[derive(Clone, Debug)] +pub struct MerkleChip { + config: MerkleConfig, +} + +impl Chip for MerkleChip { + type Config = MerkleConfig; + type Loaded = (); + + fn config(&self) -> &Self::Config { + &self.config + } + + fn loaded(&self) -> &Self::Loaded { + &() + } +}