1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use ark_ff::Field;
use kimchi::circuits::polynomial::COLUMNS;
use serde::Serialize;
use serde_with::serde_as;
use std::array;

/// The type that represents the execution trace.
/// It represents a table of [COLUMNS] columns, with `n` rows.
/// `n` being the maximum size of the circuit, and the size of the domain.
#[serde_as]
#[derive(Debug, Serialize)]
pub struct Witness<F>
where
    F: Field,
{
    #[serde_as(as = "[Vec<o1_utils::serialization::SerdeAs>; COLUMNS]")]
    inner: [Vec<F>; COLUMNS],
}

impl<F> Witness<F>
where
    F: Field,
{
    /// Creates a new witness with `rows` rows.
    // TODO: deprecate this
    pub fn new(rows: usize) -> Self {
        Witness {
            inner: array::from_fn(|_| vec![F::zero(); rows]),
        }
    }

    /// Returns the inner witness.
    // TODO: deprecate this
    pub fn inner(self) -> [Vec<F>; COLUMNS] {
        self.inner
    }
}

impl<F> From<[Vec<F>; COLUMNS]> for Witness<F>
where
    F: Field,
{
    fn from(inner: [Vec<F>; COLUMNS]) -> Self {
        Witness { inner }
    }
}