MCPcopy Create free account
hub / github.com/ddkang/zkml / commit

Method commit

src/commitments/poseidon_commit.rs:106–148  ·  view source on GitHub ↗
(
    &self,
    mut layouter: impl Layouter<F>,
    _gadget_config: Rc<GadgetConfig>,
    _constants: &HashMap<i64, CellRc<F>>,
    values: &Vec<CellRc<F>>,
    blinding: CellRc<F>,
  )

Source from the content-addressed store, hash-verified

104 for PoseidonCommitChip<F, WIDTH, RATE, L>
105{
106 fn commit(
107 &self,
108 mut layouter: impl Layouter<F>,
109 _gadget_config: Rc<GadgetConfig>,
110 _constants: &HashMap<i64, CellRc<F>>,
111 values: &Vec<CellRc<F>>,
112 blinding: CellRc<F>,
113 ) -> Result<Vec<CellRc<F>>, Error> {
114 let chip = Pow5Chip::construct(self.poseidon_config.clone());
115 let mut hasher: MyHash<F, Pow5Chip<F, 3, 2>, P128Pow5T3Gen<F, 0>, ConstantLength<L>, 3, 2> =
116 Sponge::new(chip, layouter.namespace(|| "sponge"))
117 .map(|sponge| MyHash { sponge })
118 .unwrap();
119
120 let mut new_vals = values
121 .iter()
122 .map(|x| x.clone())
123 .chain(vec![blinding.clone()])
124 .collect::<Vec<_>>();
125 while new_vals.len() % L != 0 {
126 new_vals.push(blinding.clone());
127 }
128 for (i, value) in new_vals
129 .iter()
130 .map(|x| PaddedWord::Message((**x).clone()))
131 .chain(<ConstantLength<L> as Domain<F, RATE>>::padding(L).map(PaddedWord::Padding))
132 .enumerate()
133 {
134 hasher
135 .sponge
136 .absorb(layouter.namespace(|| format!("absorb {}", i)), value)
137 .unwrap();
138 }
139 let outp = hasher
140 .sponge
141 .finish_absorbing(layouter.namespace(|| "finish absorbing"))
142 .unwrap()
143 .squeeze(layouter.namespace(|| "squeeze"))
144 .unwrap();
145 let outp = Rc::new(outp);
146
147 Ok(vec![outp])
148 }
149}

Callers 2

assign_and_commitMethod · 0.80
copy_and_commitMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected