Skip to content

Commit

Permalink
Implement SinsemillaInstructions for MerkleChip
Browse files Browse the repository at this point in the history
  • Loading branch information
therealyingtong committed Jun 3, 2021
1 parent d29bdbc commit 5ca5770
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions src/circuit/gadget/orchard_action/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,77 @@ impl<C: CurveAffine, const PATH_LENGTH: usize, const K: usize, const MAX_WORDS:
&()
}
}

impl<C: CurveAffine, const PATH_LENGTH: usize, const K: usize, const MAX_WORDS: usize>
SinsemillaInstructions<C, K, MAX_WORDS> for MerkleChip<C, PATH_LENGTH, K, MAX_WORDS>
{
type MessagePiece =
<SinsemillaChip<C, K, MAX_WORDS> as SinsemillaInstructions<C, K, MAX_WORDS>>::MessagePiece;

type CellValue =
<SinsemillaChip<C, K, MAX_WORDS> as SinsemillaInstructions<C, K, MAX_WORDS>>::CellValue;

type X = <SinsemillaChip<C, K, MAX_WORDS> as SinsemillaInstructions<C, K, MAX_WORDS>>::X;
type Point =
<SinsemillaChip<C, K, MAX_WORDS> as SinsemillaInstructions<C, K, MAX_WORDS>>::Point;
type FixedPoints =
<SinsemillaChip<C, K, MAX_WORDS> as SinsemillaInstructions<C, K, MAX_WORDS>>::FixedPoints;

type HashDomains =
<SinsemillaChip<C, K, MAX_WORDS> as SinsemillaInstructions<C, K, MAX_WORDS>>::HashDomains;
type CommitDomains =
<SinsemillaChip<C, K, MAX_WORDS> as SinsemillaInstructions<C, K, MAX_WORDS>>::CommitDomains;

fn witness_message(
&self,
layouter: impl Layouter<C::Base>,
message: Vec<Option<bool>>,
num_words: usize,
) -> Result<Vec<Self::MessagePiece>, Error> {
let config = self.config().sinsemilla_config.clone();
let chip = SinsemillaChip::<C, K, MAX_WORDS>::construct(config);
chip.witness_message(layouter, message, num_words)
}

fn witness_message_piece_bitstring(
&self,
layouter: impl Layouter<C::Base>,
message: Vec<Option<bool>>,
num_words: usize,
) -> Result<Self::MessagePiece, Error> {
let config = self.config().sinsemilla_config.clone();
let chip = SinsemillaChip::<C, K, MAX_WORDS>::construct(config);
chip.witness_message_piece_bitstring(layouter, message, num_words)
}

fn witness_message_piece_field(
&self,
layouter: impl Layouter<C::Base>,
value: Option<C::Base>,
num_words: usize,
) -> Result<Self::MessagePiece, Error> {
let config = self.config().sinsemilla_config.clone();
let chip = SinsemillaChip::<C, K, MAX_WORDS>::construct(config);
chip.witness_message_piece_field(layouter, value, num_words)
}

fn prepare_message_piece(cell: &Self::CellValue, length: usize) -> Self::MessagePiece {
SinsemillaChip::<C, K, MAX_WORDS>::prepare_message_piece(cell, length)
}

#[allow(non_snake_case)]
fn hash_to_point(
&self,
layouter: impl Layouter<C::Base>,
Q: C,
message: Vec<Self::MessagePiece>,
) -> Result<Self::Point, Error> {
let config = self.config().sinsemilla_config.clone();
let chip = SinsemillaChip::<C, K, MAX_WORDS>::construct(config);
chip.hash_to_point(layouter, Q, message)
}

fn extract(point: &Self::Point) -> &Self::X {
SinsemillaChip::<C, K, MAX_WORDS>::extract(point)
}
}

0 comments on commit 5ca5770

Please sign in to comment.