Skip to content

Commit

Permalink
feat: render dot string to svg
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastiantf committed Feb 21, 2024
1 parent 0d38c87 commit 2c96b24
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 2 deletions.
92 changes: 90 additions & 2 deletions zk_prover/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions zk_prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
37 changes: 37 additions & 0 deletions zk_prover/prints/range-check-dot-graph.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions zk_prover/src/chips/range/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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();
}
}

0 comments on commit 2c96b24

Please sign in to comment.