From 3fa36d7a60cc5f1c4befa353edf7354e8fe28b4c Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Fri, 22 Jan 2021 22:59:14 +0000 Subject: [PATCH] Add test for circuit_dot_graph using SHA-256 --- src/gadget/sha256/table16.rs | 68 ++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/src/gadget/sha256/table16.rs b/src/gadget/sha256/table16.rs index ca2bf75c..2f37adea 100644 --- a/src/gadget/sha256/table16.rs +++ b/src/gadget/sha256/table16.rs @@ -320,3 +320,71 @@ trait Table16Assignment { Ok(cell) } } + +#[cfg(test)] +mod tests { + #[cfg(feature = "dev-graph")] + use crate::{ + arithmetic::FieldExt, + circuit::Chip, + circuit::{layouter, Layouter}, + gadget::sha256::{BlockWord, Sha256, Table16Chip, Table16Config, BLOCK_SIZE}, + pasta::Fq, + plonk::{Assignment, Circuit, ConstraintSystem, Error}, + }; + + #[cfg(feature = "dev-graph")] + #[test] + fn print_sha256_circuit() { + struct MyCircuit {} + + impl Circuit for MyCircuit { + type Config = Table16Config; + + fn configure(meta: &mut ConstraintSystem) -> Table16Config { + Table16Chip::configure(meta) + } + + fn synthesize( + &self, + cs: &mut impl Assignment, + config: Table16Config, + ) -> Result<(), Error> { + let mut layouter = layouter::SingleChip::, _>::new(cs, config)?; + Table16Chip::load(&mut layouter)?; + + // Test vector: "abc" + let test_input = [ + BlockWord::new(0b01100001011000100110001110000000), + BlockWord::new(0), + BlockWord::new(0), + BlockWord::new(0), + BlockWord::new(0), + BlockWord::new(0), + BlockWord::new(0), + BlockWord::new(0), + BlockWord::new(0), + BlockWord::new(0), + BlockWord::new(0), + BlockWord::new(0), + BlockWord::new(0), + BlockWord::new(0), + BlockWord::new(0), + ]; + + // Create a message of length 31 blocks + let mut input = Vec::with_capacity(31 * BLOCK_SIZE); + for _ in 0..31 { + input.extend_from_slice(&test_input); + } + + Sha256::digest(layouter.namespace(|| "'abc' * 31"), &input)?; + + Ok(()) + } + } + + let circuit: MyCircuit = MyCircuit {}; + eprintln!("{}", crate::dev::circuit_dot_graph::(&circuit)); + } +}