Skip to content

Commit

Permalink
Arrabbiata/witness: implement and accumulate the program state
Browse files Browse the repository at this point in the history
  • Loading branch information
dannywillems committed Feb 13, 2025
1 parent d07777a commit 1dee9fc
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
3 changes: 1 addition & 2 deletions arrabbiata/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ pub fn main() {
r = env.challenges[ChallengeTerm::RelationRandomiser].to_str_radix(16)
);

// FIXME:
// Compute the accumulated witness
env.accumulate_program_state();

// FIXME:
// Compute the accumulation of the commitments to the witness columns
Expand Down
55 changes: 55 additions & 0 deletions arrabbiata/src/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1297,4 +1297,59 @@ where
self.prover_sponge_state = state.try_into().unwrap();
}
}

/// Accumulate the program state (or in other words,
/// the witness), by adding the last computed program state into the
/// program state accumulator.
///
/// This method is supposed to be called after the program state has been
/// committed (by calling [self.commit_state]) and absorbed (by calling
/// [self.absorb_state]). The "relation randomiser" must also have been
/// coined and saved in the environment before, by calling
/// [self.coin_challenge].
///
/// The program state is accumulated into a different accumulator, depending
/// on the curve currently being used.
///
/// This is part of the work the prover of the accumulation/folding scheme.
///
/// This must translate the following equation:
/// ```text
/// acc_(p, n + 1) = acc_(p, n) * chal w
/// OR
/// acc_(q, n + 1) = acc_(q, n) * chal w
/// ```
/// where acc and w are vectors of the same size.
pub fn accumulate_program_state(&mut self) {
let chal = self.challenges[ChallengeTerm::RelationRandomiser].clone();
if self.current_iteration % 2 == 0 {
let modulus: BigInt = E1::ScalarField::modulus_biguint().into();
self.accumulated_witness_e1 = self
.accumulated_witness_e1
.iter()
.zip(self.witness.iter())
.map(|(evals_accumulator, evals_witness)| {
evals_accumulator
.iter()
.zip(evals_witness.iter())
.map(|(acc, w)| (acc + chal.clone() * w).mod_floor(&modulus))
.collect()
})
.collect();
} else {
let modulus: BigInt = E2::ScalarField::modulus_biguint().into();
self.accumulated_witness_e2 = self
.accumulated_witness_e2
.iter()
.zip(self.witness.iter())
.map(|(evals_accumulator, evals_witness)| {
evals_accumulator
.iter()
.zip(evals_witness.iter())
.map(|(acc, w)| (acc + chal.clone() * w).mod_floor(&modulus))
.collect()
})
.collect();
}
}
}

0 comments on commit 1dee9fc

Please sign in to comment.