Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

markking inputs/outputs in json #64

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ impl ArithmeticGate {
#[derive(Default, Debug, Serialize, Deserialize)]
pub struct ArithmeticCircuit {
node_count: u32,
inputs: HashMap<u32, String>,
outputs: HashMap<u32, String>,
signals: HashMap<u32, Signal>,
nodes: HashMap<u32, Node>,
gates: Vec<ArithmeticGate>,
Expand All @@ -176,12 +178,22 @@ impl ArithmeticCircuit {
pub fn new() -> ArithmeticCircuit {
ArithmeticCircuit {
node_count: 0,
inputs: HashMap::new(),
outputs: HashMap::new(),
signals: HashMap::new(),
nodes: HashMap::new(),
gates: Vec::new(),
}
}

pub fn add_inputs(&mut self, inputs: HashMap<u32, String>) {
self.inputs.extend(inputs);
}

pub fn add_outputs(&mut self, outputs: HashMap<u32, String>) {
self.outputs.extend(outputs);
}

/// Adds a new signal to the circuit.
pub fn add_signal(
&mut self,
Expand All @@ -207,6 +219,16 @@ impl ArithmeticCircuit {
Ok(())
}

pub fn get_signals(&self, filter: String) -> HashMap<u32, String> {
let mut ret = HashMap::new();
for (signal_id, signal) in self.signals.iter() {
if signal.name.starts_with(filter.as_str()) {
ret.insert(*signal_id, signal.name.to_string());
}
}
ret
}

/// Adds a new gate to the circuit.
pub fn add_gate(
&mut self,
Expand Down
20 changes: 20 additions & 0 deletions src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::{
process::{process_expression, process_statements},
runtime::{DataAccess, DataType, Runtime, RuntimeError},
};
use circom_compiler::num_traits::sign;
use circom_program_structure::ast::Expression;
use std::io;
use thiserror::Error;
Expand Down Expand Up @@ -51,6 +52,25 @@ pub fn build_circuit(input: &Input) -> Result<ArithmeticCircuit, ProgramError> {
// Process the main component
let statements = template_data.get_body_as_vec();
process_statements(&mut circuit, &mut runtime, &program_archive, statements)?;

for (ikey, (ivs, ivh)) in template_data.get_inputs().iter() {
// println!("{ikey}:{ivs}");
let filter = format!("0.{}", ikey);
circuit.add_inputs(circuit.get_signals(filter));
// for ivhs in ivh.iter() {
// println!("{ivhs}");
// }
}

for (okey, (ovs, ovh)) in template_data.get_outputs().iter() {
// println!("{okey}:{ovs}");
let filter = format!("0.{}", okey);
let signals = circuit.get_signals(filter);
circuit.add_outputs(signals);
// for ovhs in ovh.iter() {
// println!("{ovhs}");
// }
}
}
_ => return Err(ProgramError::MainExpressionNotACall),
}
Expand Down
Loading