From 0ccb773f14fc597e3952988bd5cb2e2a2cdc0ed0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Nicolas?= <info@nau.re> Date: Sat, 18 Feb 2023 03:12:15 +0100 Subject: [PATCH 1/4] test/unwrap_value: escape Value safety in the dev module --- halo2_proofs/src/circuit.rs | 1 + halo2_proofs/src/circuit/value.rs | 7 +++++++ halo2_proofs/src/dev.rs | 2 ++ 3 files changed, 10 insertions(+) diff --git a/halo2_proofs/src/circuit.rs b/halo2_proofs/src/circuit.rs index d0b1e0c02b..3f1fab2336 100644 --- a/halo2_proofs/src/circuit.rs +++ b/halo2_proofs/src/circuit.rs @@ -12,6 +12,7 @@ use crate::{ }; mod value; +pub(crate) use value::value_dev; pub use value::Value; pub mod floor_planner; diff --git a/halo2_proofs/src/circuit/value.rs b/halo2_proofs/src/circuit/value.rs index e6ae26cd1b..a0187f2c1e 100644 --- a/halo2_proofs/src/circuit/value.rs +++ b/halo2_proofs/src/circuit/value.rs @@ -696,3 +696,10 @@ impl<F: Field> Value<Assigned<F>> { } } } + +/// Utilities for tests and dev tools. +pub mod value_dev { + pub fn unwrap_value<T>(v: super::Value<T>) -> T { + v.inner.unwrap() + } +} diff --git a/halo2_proofs/src/dev.rs b/halo2_proofs/src/dev.rs index ca85811b0f..8045fb591d 100644 --- a/halo2_proofs/src/dev.rs +++ b/halo2_proofs/src/dev.rs @@ -48,6 +48,8 @@ mod graph; #[cfg_attr(docsrs, doc(cfg(feature = "dev-graph")))] pub use graph::{circuit_dot_graph, layout::CircuitLayout}; +pub use crate::circuit::value_dev::unwrap_value; + #[derive(Debug)] struct Region { /// The name of the region. Not required to be unique. From e6e8a112c469ea142c00d75bebc57b1eece4a573 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Nicolas?= <info@nau.re> Date: Sun, 5 Feb 2023 03:20:35 +0100 Subject: [PATCH 2/4] test/mock-prover-values: MockProver exposes the generated columns to tests --- halo2_proofs/src/dev.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/halo2_proofs/src/dev.rs b/halo2_proofs/src/dev.rs index 8045fb591d..014bebb767 100644 --- a/halo2_proofs/src/dev.rs +++ b/halo2_proofs/src/dev.rs @@ -600,6 +600,14 @@ impl<F: FieldExt> MockProver<F> { Ok(prover) } + pub fn advice_values(&self, column: Column<Advice>) -> &[CellValue<F>] { + &self.advice[column.index()] + } + + pub fn fixed_values(&self, column: Column<Fixed>) -> &[CellValue<F>] { + &self.fixed[column.index()] + } + /// Returns `Ok(())` if this `MockProver` is satisfied, or a list of errors indicating /// the reasons that the circuit is not satisfied. pub fn verify(&self) -> Result<(), Vec<VerifyFailure>> { From 8b692e00f3f3a606ca3220ae59ec034778f469dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Nicolas?= <info@nau.re> Date: Mon, 27 Feb 2023 14:02:58 +0100 Subject: [PATCH 3/4] test/mock-prover-values: doc --- halo2_proofs/src/circuit/value.rs | 1 + halo2_proofs/src/dev.rs | 3 +++ 2 files changed, 4 insertions(+) diff --git a/halo2_proofs/src/circuit/value.rs b/halo2_proofs/src/circuit/value.rs index a0187f2c1e..1e268b4fe3 100644 --- a/halo2_proofs/src/circuit/value.rs +++ b/halo2_proofs/src/circuit/value.rs @@ -699,6 +699,7 @@ impl<F: Field> Value<Assigned<F>> { /// Utilities for tests and dev tools. pub mod value_dev { + /// Get the contained known value, or panic. For tests only. pub fn unwrap_value<T>(v: super::Value<T>) -> T { v.inner.unwrap() } diff --git a/halo2_proofs/src/dev.rs b/halo2_proofs/src/dev.rs index 014bebb767..18b140872e 100644 --- a/halo2_proofs/src/dev.rs +++ b/halo2_proofs/src/dev.rs @@ -48,6 +48,7 @@ mod graph; #[cfg_attr(docsrs, doc(cfg(feature = "dev-graph")))] pub use graph::{circuit_dot_graph, layout::CircuitLayout}; +// Export utilities for external tests. pub use crate::circuit::value_dev::unwrap_value; #[derive(Debug)] @@ -600,10 +601,12 @@ impl<F: FieldExt> MockProver<F> { Ok(prover) } + /// Return the content of an advice column as assigned by the circuit. pub fn advice_values(&self, column: Column<Advice>) -> &[CellValue<F>] { &self.advice[column.index()] } + /// Return the content of a fixed column as assigned by the circuit. pub fn fixed_values(&self, column: Column<Fixed>) -> &[CellValue<F>] { &self.fixed[column.index()] } From 7f3ee6d4efba425340dc69ed5841f65870e20631 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Nicolas?= <info@nau.re> Date: Mon, 27 Feb 2023 17:00:08 +0100 Subject: [PATCH 4/4] mockprover-util: remove unwrap_value --- halo2_proofs/src/circuit.rs | 1 - halo2_proofs/src/circuit/value.rs | 8 -------- halo2_proofs/src/dev.rs | 3 --- 3 files changed, 12 deletions(-) diff --git a/halo2_proofs/src/circuit.rs b/halo2_proofs/src/circuit.rs index 3f1fab2336..d0b1e0c02b 100644 --- a/halo2_proofs/src/circuit.rs +++ b/halo2_proofs/src/circuit.rs @@ -12,7 +12,6 @@ use crate::{ }; mod value; -pub(crate) use value::value_dev; pub use value::Value; pub mod floor_planner; diff --git a/halo2_proofs/src/circuit/value.rs b/halo2_proofs/src/circuit/value.rs index 1e268b4fe3..e6ae26cd1b 100644 --- a/halo2_proofs/src/circuit/value.rs +++ b/halo2_proofs/src/circuit/value.rs @@ -696,11 +696,3 @@ impl<F: Field> Value<Assigned<F>> { } } } - -/// Utilities for tests and dev tools. -pub mod value_dev { - /// Get the contained known value, or panic. For tests only. - pub fn unwrap_value<T>(v: super::Value<T>) -> T { - v.inner.unwrap() - } -} diff --git a/halo2_proofs/src/dev.rs b/halo2_proofs/src/dev.rs index 6dc1a2b17d..d106c8925f 100644 --- a/halo2_proofs/src/dev.rs +++ b/halo2_proofs/src/dev.rs @@ -50,9 +50,6 @@ mod graph; #[cfg_attr(docsrs, doc(cfg(feature = "dev-graph")))] pub use graph::{circuit_dot_graph, layout::CircuitLayout}; -// Export utilities for external tests. -pub use crate::circuit::value_dev::unwrap_value; - #[derive(Debug)] struct Region { /// The name of the region. Not required to be unique.