fullcodec_plonk/plonkup/table/preprocess.rs
1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4//
5// Copyright (c) DUSK NETWORK. All rights reserved.
6
7use crate::commitment_scheme::{CommitKey, Commitment};
8use crate::error::Error;
9use crate::fft::{EvaluationDomain, Polynomial};
10use crate::plonkup::{LookupTable, MultiSet};
11
12/// This table will be the preprocessed version of the
13/// precomputed table, T, with arity 4. This structure
14/// is passed to the proof alongside the table of witness
15/// values.
16#[derive(Clone, Eq, PartialEq, Debug)]
17pub struct PreprocessedLookupTable {
18 /// This is the circuit size
19 pub n: u32,
20
21 /// This is the first column in the preprocessed
22 /// table containing a MultiSet, Commitments to the
23 /// MultiSet and the coefficients as a Polynomial
24 pub(crate) t_1: (MultiSet, Commitment, Polynomial),
25
26 /// This is the second column in the preprocessed
27 /// table containing a MultiSet, Commitments to the
28 /// MultiSet and the coefficients as a Polynomial
29 pub(crate) t_2: (MultiSet, Commitment, Polynomial),
30
31 /// This is the third column in the preprocessed
32 /// table containing a MultiSet, Commitments to the
33 /// MultiSet and the coefficients as a Polynomial
34 pub(crate) t_3: (MultiSet, Commitment, Polynomial),
35
36 /// This is the fourth column in the preprocessed
37 /// table containing a MultiSet, Commitments to the
38 /// MultiSet and the coefficients as a Polynomial
39 pub(crate) t_4: (MultiSet, Commitment, Polynomial),
40}
41
42impl PreprocessedLookupTable {
43 /// This function takes in a precomputed look up table and
44 /// pads it to the length of the circuit entries, as a power
45 /// of 2. The function then interpolates a polynomial from the
46 /// padded table and makes a commitment to the poly. The
47 /// outputted struct will be used in the proof alongside our
48 /// circuit witness table.
49 pub fn preprocess(
50 table: &LookupTable,
51 commit_key: &CommitKey,
52 n: u32,
53 ) -> Result<Self, Error> {
54 let domain: EvaluationDomain =
55 EvaluationDomain::new(n as usize).unwrap();
56
57 let columned_table = table.vec_to_multiset();
58 let mut t_1 = columned_table.0;
59 let mut t_2 = columned_table.1;
60 let mut t_3 = columned_table.2;
61 let mut t_4 = columned_table.3;
62
63 t_1.pad(n);
64 t_2.pad(n);
65 t_3.pad(n);
66 t_4.pad(n);
67
68 let t_1_poly = t_1.to_polynomial(&domain);
69 let t_2_poly = t_2.to_polynomial(&domain);
70 let t_3_poly = t_3.to_polynomial(&domain);
71 let t_4_poly = t_4.to_polynomial(&domain);
72
73 let t_1_commit = commit_key.commit(&t_1_poly)?;
74 let t_2_commit = commit_key.commit(&t_2_poly)?;
75 let t_3_commit = commit_key.commit(&t_3_poly)?;
76 let t_4_commit = commit_key.commit(&t_4_poly)?;
77
78 Ok(PreprocessedLookupTable {
79 n,
80 t_1: (t_1, t_1_commit, t_1_poly),
81 t_2: (t_2, t_2_commit, t_2_poly),
82 t_3: (t_3, t_3_commit, t_3_poly),
83 t_4: (t_4, t_4_commit, t_4_poly),
84 })
85 }
86}