From 2c96b24e151911c73b77f6e3b77a117a97bbb41e Mon Sep 17 00:00:00 2001 From: Sebastian T F Date: Wed, 21 Feb 2024 13:08:43 +0530 Subject: [PATCH] feat: render dot string to svg --- zk_prover/Cargo.lock | 92 +++++++++++++++++++++- zk_prover/Cargo.toml | 1 + zk_prover/prints/range-check-dot-graph.svg | 37 +++++++++ zk_prover/src/chips/range/tests.rs | 21 +++++ 4 files changed, 149 insertions(+), 2 deletions(-) create mode 100644 zk_prover/prints/range-check-dot-graph.svg diff --git a/zk_prover/Cargo.lock b/zk_prover/Cargo.lock index 7c2620c..77d7b26 100644 --- a/zk_prover/Cargo.lock +++ b/zk_prover/Cargo.lock @@ -1275,6 +1275,21 @@ dependencies = [ "libloading", ] +[[package]] +name = "dot-generator" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0aaac7ada45f71873ebce336491d1c1bc4a7c8042c7cea978168ad59e805b871" +dependencies = [ + "dot-structures", +] + +[[package]] +name = "dot-structures" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "675e35c02a51bb4d4618cb4885b3839ce6d1787c97b664474d9208d074742e20" + [[package]] name = "dunce" version = "1.0.4" @@ -2181,6 +2196,22 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "graphviz-rust" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "769bca09004f06ca60d9b5640e8bb9105e9ae6e11488d2bf75cb8a30c2ab436a" +dependencies = [ + "dot-generator", + "dot-structures", + "into-attr", + "into-attr-derive", + "pest", + "pest_derive", + "rand 0.8.5", + "tempfile", +] + [[package]] name = "group" version = "0.13.0" @@ -2553,6 +2584,28 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "into-attr" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18b48c537e49a709e678caec3753a7dba6854661a1eaa27675024283b3f8b376" +dependencies = [ + "dot-structures", +] + +[[package]] +name = "into-attr-derive" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecac7c1ae6cd2c6a3a64d1061a8bdc7f52ff62c26a831a2301e54c1b5d70d5b1" +dependencies = [ + "dot-generator", + "dot-structures", + "into-attr", + "quote", + "syn 1.0.109", +] + [[package]] name = "ipnet" version = "2.9.0" @@ -3282,15 +3335,49 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pest" -version = "2.7.6" +version = "2.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f200d8d83c44a45b21764d1916299752ca035d15ecd46faca3e9a2a2bf6ad06" +checksum = "219c0dcc30b6a27553f9cc242972b67f75b60eb0db71f0b5462f38b058c41546" dependencies = [ "memchr", "thiserror", "ucd-trie", ] +[[package]] +name = "pest_derive" +version = "2.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22e1288dbd7786462961e69bfd4df7848c1e37e8b74303dbdab82c3a9cdd2809" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1381c29a877c6d34b8c176e734f35d7f7f5b3adaefe940cb4d1bb7af94678e2e" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2", + "quote", + "syn 2.0.48", +] + +[[package]] +name = "pest_meta" +version = "2.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0934d6907f148c22a3acbda520c7eed243ad7487a30f51f6ce52b58b7077a8a" +dependencies = [ + "once_cell", + "pest", + "sha2", +] + [[package]] name = "petgraph" version = "0.6.4" @@ -4437,6 +4524,7 @@ dependencies = [ "csv", "ethers", "ff_ce", + "graphviz-rust", "halo2_gadgets", "halo2_proofs", "halo2_solidity_verifier", diff --git a/zk_prover/Cargo.toml b/zk_prover/Cargo.toml index bba8596..22aa8fb 100644 --- a/zk_prover/Cargo.toml +++ b/zk_prover/Cargo.toml @@ -13,6 +13,7 @@ dev-graph = ["halo2_proofs/dev-graph", "plotters"] halo2_proofs = { git = "https://github.com/summa-dev/halo2"} halo2_gadgets = { git = "https://github.com/summa-dev/halo2"} plotters = { version = "0.3.4", optional = true } +graphviz-rust = {version = "0.7.1", optional = true} rand = "0.8" ark-std = { version = "0.3.0", features = ["print-trace"] } tabbycat = { version = "0.1", features = ["attributes"], optional = true } diff --git a/zk_prover/prints/range-check-dot-graph.svg b/zk_prover/prints/range-check-dot-graph.svg new file mode 100644 index 0000000..308cecd --- /dev/null +++ b/zk_prover/prints/range-check-dot-graph.svg @@ -0,0 +1,37 @@ + + + + + + +circuit + + + +0 + +add chip + + + +1 + +checking value a is in range + + + +2 + +checking value b is in range + + + +3 + +checking value c is in range + + + diff --git a/zk_prover/src/chips/range/tests.rs b/zk_prover/src/chips/range/tests.rs index 35c5b3a..24e233a 100644 --- a/zk_prover/src/chips/range/tests.rs +++ b/zk_prover/src/chips/range/tests.rs @@ -298,6 +298,13 @@ mod testing { fn print_range_check_dot_graph() { use std::io::Write; + use graphviz_rust::{ + cmd::{CommandArg, Format}, + dot_structures::*, + exec, parse, + printer::PrinterContext, + }; + let circuit = TestCircuit::<4> { a: Fp::from(0x1f2f3f4f), b: Fp::from(1), @@ -308,5 +315,19 @@ mod testing { dot_graph.write_all(dot_string.as_bytes()).unwrap(); print!("{}", dot_string); + + // * Following svg generation requires graphviz client to be installed: https://graphviz.org/download/#executable-packages + // * Might be easier to use Graphviz Interactive Preview extension in VSCode to open the .dot file + // * https://marketplace.visualstudio.com/items?itemName=tintinweb.graphviz-interactive-preview + let g: Graph = parse(&dot_string).unwrap(); + exec( + g, + &mut PrinterContext::default(), + vec![ + Format::Svg.into(), + CommandArg::Output("prints/range-check-dot-graph.svg".to_string()), + ], + ) + .unwrap(); } }