plonky2/src/target.rs

34 lines
1003 B
Rust
Raw Normal View History

2021-06-22 15:34:50 +02:00
use std::ops::Range;
2021-02-09 21:25:21 -08:00
use crate::circuit_data::CircuitConfig;
use crate::wire::Wire;
/// A location in the witness.
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
2021-02-26 13:18:41 -08:00
pub enum Target {
2021-02-09 21:25:21 -08:00
Wire(Wire),
PublicInput { index: usize },
/// A target that doesn't have any inherent location in the witness (but it can be copied to
/// another target that does). This is useful for representing intermediate values in witness
/// generation.
VirtualTarget { index: usize },
2021-02-09 21:25:21 -08:00
}
2021-02-26 13:18:41 -08:00
impl Target {
2021-02-09 21:25:21 -08:00
pub fn wire(gate: usize, input: usize) -> Self {
Self::Wire(Wire { gate, input })
}
2021-05-07 11:30:03 +02:00
pub fn is_routable(&self, config: &CircuitConfig) -> bool {
2021-02-09 21:25:21 -08:00
match self {
2021-02-26 13:18:41 -08:00
Target::Wire(wire) => wire.is_routable(config),
Target::PublicInput { .. } => true,
Target::VirtualTarget { .. } => true,
2021-02-09 21:25:21 -08:00
}
}
pub fn wires_from_range(gate: usize, range: Range<usize>) -> Vec<Self> {
range.map(|i| Self::wire(gate, i)).collect()
}
2021-02-09 21:25:21 -08:00
}