Add an element to the accumulator and state. Reads and writes to state. Described in section 2 of the paper
(
&self,
element: G::ScalarField,
sk: &SecretKey<G::ScalarField>,
initial_elements_store: &dyn InitialElementsStore<G::ScalarField>,
state: &mut dyn State<G::Sc
| 248 | |
| 249 | /// Add an element to the accumulator and state. Reads and writes to state. Described in section 2 of the paper |
| 250 | pub fn add( |
| 251 | &self, |
| 252 | element: G::ScalarField, |
| 253 | sk: &SecretKey<G::ScalarField>, |
| 254 | initial_elements_store: &dyn InitialElementsStore<G::ScalarField>, |
| 255 | state: &mut dyn State<G::ScalarField>, |
| 256 | ) -> Result<Self, VBAccumulatorError> { |
| 257 | if self.max_size() == state.size() { |
| 258 | return Err(VBAccumulatorError::AccumulatorFull); |
| 259 | } |
| 260 | if !self.is_element_acceptable(&element, initial_elements_store) { |
| 261 | return Err(VBAccumulatorError::ProhibitedElement); |
| 262 | } |
| 263 | |
| 264 | // TODO: Check if it's more efficient to always have a window table of setup parameter `P` and |
| 265 | // multiply `P` by `f_V` rather than multiplying `y_plus_alpha` by `V`. Use `windowed_mul` from FixedBase |
| 266 | let (y_plus_alpha, V) = self._add(element, sk, state)?; |
| 267 | let f_V = y_plus_alpha * self.f_V; |
| 268 | Ok(self.get_updated(f_V, V)) |
| 269 | } |
| 270 | |
| 271 | /// Compute new accumulated value after batch addition. |
| 272 | pub fn compute_new_post_add_batch( |