///|
fn svg_escape(s : String) -> String {
let buf = StringBuilder()
for i = 0; i < s.length(); i = i + 1 {
let ch = s[i].to_int().unsafe_to_char()
match ch {
'&' => buf.write_string("&")
'<' => buf.write_string("<")
'>' => buf.write_string(">")
'"' => buf.write_string(""")
_ => buf.write_char(ch)
}
}
buf.to_string()
}
///|
fn short_dec(s : String, max_len : Int32) -> String {
if s.length() <= max_len {
s
} else {
let head = s[0:max_len - 6].to_owned()
let tail = s[s.length() - 4:].to_owned()
"\{head}..\{tail}"
}
}
///|
/// Render a native SVG diagram of the R1CS constraint network (wires and multiplication gates).
pub fn render_r1cs_svg(r1cs : R1cs, witness~ : Array[Fr]? = None) -> String {
let max_gates = if r1cs.constraints.length() > 14 {
14
} else {
r1cs.constraints.length()
}
let width = 820
let header_h = 72
let row_h = 34
let height = header_h + max_gates * row_h + 64
let buf = StringBuilder()
buf.write_string(
"")
buf.to_string()
}
///|
/// Render a native SVG summary of the 4-term Groth16 Optimal Ate Pairing check.
pub fn render_pairing_svg(
circuit_name : String,
num_constraints : Int32,
num_wires : Int32,
num_public : Int32,
verified : Bool,
proof : Proof,
) -> String {
let status_text = if verified { "VERIFIED (PASS)" } else { "REJECTED (FAIL)" }
let status_bg = if verified { "#14532d" } else { "#7f1d1d" }
let status_fg = if verified { "#4ade80" } else { "#f87171" }
let eq_sym = if verified { "= 1_GT" } else { "!= 1_GT" }
let pa_short = short_dec(proof.a.x.to_decimal(), 20)
let pb_short = short_dec(proof.b.x.c0.to_decimal(), 20)
let pc_short = short_dec(proof.c.x.to_decimal(), 20)
let buf = StringBuilder()
buf.write_string(
"")
buf.to_string()
}