-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
27163ec
commit 8a48aef
Showing
5 changed files
with
125 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub(crate) mod ecc; | ||
pub(crate) mod orchard_action; | ||
pub(crate) mod sinsemilla; | ||
pub(crate) mod utilities; |
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 @@ | ||
mod merkle; |
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,115 @@ | ||
use halo2::{ | ||
circuit::{Cell, Chip, Layouter, Region}, | ||
plonk::{Advice, Column, ConstraintSystem, Error, Permutation}, | ||
}; | ||
use pasta_curves::arithmetic::{CurveAffine, FieldExt}; | ||
use std::marker::PhantomData; | ||
|
||
use crate::circuit::gadget::{ | ||
ecc::{ | ||
chip::{EccChip, EccConfig}, | ||
EccInstructions, | ||
}, | ||
sinsemilla::{SinsemillaChip, SinsemillaConfig, SinsemillaInstructions}, | ||
utilities::{UtilitiesChip, UtilitiesConfig, UtilitiesInstructions, Var}, | ||
}; | ||
use std::convert::TryInto; | ||
|
||
enum Node<F: FieldExt> { | ||
Leaf(Var<F>), | ||
Inner(Var<F>), | ||
Sibling(Var<F>), | ||
} | ||
struct Root<F: FieldExt>(pub Var<F>); | ||
|
||
pub trait MerkleInstructions<F: FieldExt, const MERKLE_DEPTH: usize>: | ||
UtilitiesInstructions<F> | ||
{ | ||
/// Check the validity of a Merkle path from a given leaf to a claimed root. | ||
fn merkle_path_check( | ||
&self, | ||
layouter: impl Layouter<F>, | ||
root: Option<[u8; 32]>, | ||
leaf: Option<[u8; 32]>, | ||
merkle_path: [Option<[u8; 32]>; MERKLE_DEPTH], | ||
) -> Result<(), Error> { | ||
Ok(()) | ||
} | ||
} | ||
|
||
fn layer_hash<C: CurveAffine>( | ||
chip: MerkleChip<C>, | ||
layer: u16, | ||
left: Node<C::Base>, | ||
right: Node<C::Base>, | ||
) -> Result<Var<C::Base>, Error> { | ||
todo!() | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct MerkleConfig { | ||
config1: (UtilitiesConfig, SinsemillaConfig), | ||
config2: (UtilitiesConfig, SinsemillaConfig), | ||
} | ||
|
||
pub struct MerkleChip<C: CurveAffine> { | ||
config: MerkleConfig, | ||
_marker: PhantomData<C>, | ||
} | ||
|
||
impl<C: CurveAffine> Chip<C::Base> for MerkleChip<C> { | ||
type Config = MerkleConfig; | ||
type Loaded = (); | ||
|
||
fn config(&self) -> &Self::Config { | ||
&self.config | ||
} | ||
|
||
fn loaded(&self) -> &Self::Loaded { | ||
&() | ||
} | ||
} | ||
|
||
impl<C: CurveAffine> MerkleChip<C> { | ||
pub fn configure( | ||
meta: &mut ConstraintSystem<C::Base>, | ||
advices: [Column<Advice>; 10], | ||
perm: Permutation, | ||
) -> MerkleConfig { | ||
let ecc_config = EccChip::<C>::configure(meta, advices); | ||
|
||
let lookup = ( | ||
meta.fixed_column(), | ||
meta.fixed_column(), | ||
meta.fixed_column(), | ||
); | ||
let config1 = ( | ||
UtilitiesChip::configure(meta, advices.clone()[..5].try_into().unwrap(), perm.clone()), | ||
SinsemillaChip::<C>::configure( | ||
meta, | ||
ecc_config.clone(), | ||
advices.clone()[..5].try_into().unwrap(), | ||
lookup, | ||
perm.clone(), | ||
), | ||
); | ||
let config2 = ( | ||
UtilitiesChip::configure(meta, advices.clone()[5..].try_into().unwrap(), perm.clone()), | ||
SinsemillaChip::<C>::configure( | ||
meta, | ||
ecc_config, | ||
advices.clone()[5..].try_into().unwrap(), | ||
lookup, | ||
perm.clone(), | ||
), | ||
); | ||
MerkleConfig { config1, config2 } | ||
} | ||
|
||
pub fn construct(config: MerkleConfig) -> Self { | ||
MerkleChip { | ||
config, | ||
_marker: PhantomData, | ||
} | ||
} | ||
} |
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