Skip to content

Commit

Permalink
Arrabbiata: forbid writing on the next row when last row
Browse files Browse the repository at this point in the history
  • Loading branch information
dannywillems committed Feb 4, 2025
1 parent c63b1cb commit e77f8c3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
6 changes: 4 additions & 2 deletions arrabbiata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ pub const NUMBER_OF_COLUMNS: usize = 15;
// FIXME:
// We will increase the IVC circuit size step by step, while we are finishing
// the implementation.
// 1. We start by absorbing all the accumulators of each column.
// 1. We start by absorbing all the accumulators of each column. Adding one for
// now as the Poseidon circuit writes on the next row. This would be changing in
// the near future as we're polishing the circuit.
pub const IVC_CIRCUIT_SIZE: usize =
(PlonkSpongeConstants::PERM_ROUNDS_FULL / 5) * NUMBER_OF_COLUMNS;
(PlonkSpongeConstants::PERM_ROUNDS_FULL / 5) * NUMBER_OF_COLUMNS + 1;

/// The maximum number of public inputs the circuit can use per row
/// We do have 15 for now as we want to compute 5 rounds of poseidon per row
Expand Down
9 changes: 7 additions & 2 deletions arrabbiata/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,11 @@ pub fn main() {
"Building the IVC circuit. A total number of {} rows will be filled from the witness row {}",
IVC_CIRCUIT_SIZE, env.current_row,
);
// Build the IVC circuit
for i in 0..IVC_CIRCUIT_SIZE {
// Build the verifier circuit
// FIXME: Minus one as the last row of the verifier circuit is a
// Poseidon hash, and we write on the next row. We don't want to execute
// a new instruction for the verifier circuit here.
for i in 0..IVC_CIRCUIT_SIZE - 1 {
let instr = env.fetch_instruction();
debug!(
"Running IVC row {} (instruction = {:?}, witness row = {})",
Expand All @@ -94,6 +97,8 @@ pub fn main() {
env.current_instruction = env.fetch_next_instruction();
env.reset();
}
// FIXME: additional row for the Poseidon hash
env.reset();

debug!(
"Witness for iteration {i} computed in {elapsed} μs",
Expand Down
13 changes: 10 additions & 3 deletions arrabbiata/src/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,17 +284,24 @@ where
let Column::X(idx) = col else {
unimplemented!("Only works for private inputs")
};
let modulus: BigInt = if self.current_iteration % 2 == 0 {
E1::ScalarField::modulus_biguint().into()
let (modulus, srs_size): (BigInt, usize) = if self.current_iteration % 2 == 0 {
(
E1::ScalarField::modulus_biguint().into(),
self.srs_e1.size(),
)
} else {
E2::ScalarField::modulus_biguint().into()
(
E2::ScalarField::modulus_biguint().into(),
self.srs_e2.size(),
)
};
let v = v.mod_floor(&modulus);
match row {
CurrOrNext::Curr => {
self.state[idx].clone_from(&v);
}
CurrOrNext::Next => {
assert!(self.current_row < srs_size - 1, "The witness builder is writing on the last row. It does not make sense to write on the next row after the last row");
self.next_state[idx].clone_from(&v);
}
}
Expand Down

0 comments on commit e77f8c3

Please sign in to comment.