From ae52138df7a8e37e6479dba1a2d47780dea6fc37 Mon Sep 17 00:00:00 2001 From: Andrew Morris Date: Thu, 9 May 2024 10:50:20 +1000 Subject: [PATCH] Fix warnings --- src/circuit.rs | 13 +++++++++++-- tests/mat_elem_mul.rs | 2 +- tests/sum.rs | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/circuit.rs b/src/circuit.rs index 351f20a..09e7fc9 100644 --- a/src/circuit.rs +++ b/src/circuit.rs @@ -18,6 +18,7 @@ use serde::{Deserialize, Serialize}; use sim_circuit::circuit::{Circuit as SimCircuit, Gate as SimGate, Node as SimNode, Operation}; use std::collections::HashMap; use thiserror::Error; +use sim_circuit::circuit::CircuitError as SimCircuitError; /// Types of gates that can be used in an arithmetic circuit. #[derive(Debug, Serialize, Deserialize)] @@ -446,14 +447,14 @@ impl ArithmeticCircuit { { new_node.set_value(value); } - sim_circuit.add_node(id, new_node); + sim_circuit.add_node(id, new_node)?; } // Add gates for gate in &self.gates { let operation = Operation::from(&gate.op); let sim_gate = SimGate::new(operation, gate.lh_in, gate.rh_in, gate.out); - sim_circuit.add_gate(sim_gate); + sim_circuit.add_gate(sim_gate)?; } Ok(sim_circuit) @@ -528,6 +529,8 @@ pub enum CircuitError { MPZCircuitError(MpzCircuitError), #[error("MPZ arithmetic circuit builder error")] MPZCircuitBuilderError, + #[error("Circuit simulation error")] + SimCircuitError(SimCircuitError), #[error(transparent)] ParseIntError(#[from] std::num::ParseIntError), #[error("Signal already declared")] @@ -549,3 +552,9 @@ impl From for CircuitError { CircuitError::MPZCircuitError(e) } } + +impl From for CircuitError { + fn from(e: SimCircuitError) -> Self { + CircuitError::SimCircuitError(e) + } +} diff --git a/tests/mat_elem_mul.rs b/tests/mat_elem_mul.rs index a11b3db..030f164 100644 --- a/tests/mat_elem_mul.rs +++ b/tests/mat_elem_mul.rs @@ -6,7 +6,7 @@ const TEST_FILE_PATH: &str = "./tests/circuits/matElemMul.circom"; fn test_matrix_element_multiplication() { let input = Input::new(TEST_FILE_PATH.into(), "./".into()).unwrap(); let circuit = build_circuit(&input).unwrap(); - let mut sim_circuit = circuit.build_sim_circuit().unwrap(); + let sim_circuit = circuit.build_sim_circuit().unwrap(); let circuit_input = vec![2, 2, 2, 2, 2, 2, 2, 2]; let res = sim_circuit.execute(&circuit_input).unwrap(); diff --git a/tests/sum.rs b/tests/sum.rs index fea1c40..4334b8b 100644 --- a/tests/sum.rs +++ b/tests/sum.rs @@ -6,7 +6,7 @@ const TEST_FILE_PATH: &str = "./tests/circuits/sum.circom"; fn test_sum() { let input = Input::new(TEST_FILE_PATH.into(), "./".into()).unwrap(); let circuit = build_circuit(&input).unwrap(); - let mut sim_circuit = circuit.build_sim_circuit().unwrap(); + let sim_circuit = circuit.build_sim_circuit().unwrap(); let circuit_input = vec![1, 2]; let res = sim_circuit.execute(&circuit_input).unwrap();