|
570 | 570 | //! +-----------------------------+
|
571 | 571 | //! ```
|
572 | 572 |
|
573 |
| -use crate::{ |
574 |
| - column::Gadget, curve::PlonkSpongeConstants, MAXIMUM_FIELD_SIZE_IN_BITS, NUMBER_OF_COLUMNS, |
575 |
| -}; |
| 573 | +use crate::{curve::PlonkSpongeConstants, MAXIMUM_FIELD_SIZE_IN_BITS, NUMBER_OF_COLUMNS}; |
576 | 574 | use ark_ff::{One, Zero};
|
577 | 575 | use log::debug;
|
578 | 576 | use mina_poseidon::constants::SpongeConstants;
|
@@ -621,6 +619,11 @@ pub enum Instruction {
|
621 | 619 | NoOp,
|
622 | 620 | }
|
623 | 621 |
|
| 622 | +/// The first instruction in the verifier circuit (often shortened in "IVC" in |
| 623 | +/// the crate) is the Poseidon permutation. It is used to start hashing the |
| 624 | +/// public input. |
| 625 | +pub const VERIFIER_STARTING_INSTRUCTION: Instruction = Instruction::PoseidonSpongeAbsorb; |
| 626 | + |
624 | 627 | /// Define the side of the temporary accumulator.
|
625 | 628 | /// When computing G1 + G2, the interpreter will load G1 and after that G2.
|
626 | 629 | /// This enum is used to decide which side fetching into the cells.
|
@@ -662,9 +665,6 @@ pub trait InterpreterEnv {
|
662 | 665 | /// Set the value of the variable at the given position for the current row
|
663 | 666 | fn write_column(&mut self, col: Self::Position, v: Self::Variable) -> Self::Variable;
|
664 | 667 |
|
665 |
| - /// Activate the gadget for the row. |
666 |
| - fn activate_gadget(&mut self, gadget: Gadget); |
667 |
| - |
668 | 668 | /// Build the constant zero
|
669 | 669 | fn zero(&self) -> Self::Variable;
|
670 | 670 |
|
@@ -874,7 +874,6 @@ pub fn run_ivc<E: InterpreterEnv>(env: &mut E, instr: Instruction) {
|
874 | 874 | assert!(processing_bit < MAXIMUM_FIELD_SIZE_IN_BITS, "Invalid bit index. The fields are maximum on {MAXIMUM_FIELD_SIZE_IN_BITS} bits, therefore we cannot process the bit {processing_bit}");
|
875 | 875 | assert!(i_comm < NUMBER_OF_COLUMNS, "Invalid index. We do only support the scaling of the commitments to the columns, for now. We must additionally support the scaling of cross-terms and error terms");
|
876 | 876 | debug!("Processing scaling of commitment {i_comm}, bit {processing_bit}");
|
877 |
| - env.activate_gadget(Gadget::EllipticCurveScaling); |
878 | 877 | // When processing the first bit, we must load the scalar, and it
|
879 | 878 | // comes from previous computation.
|
880 | 879 | // The two first columns are supposed to be used for the output.
|
@@ -1018,7 +1017,6 @@ pub fn run_ivc<E: InterpreterEnv>(env: &mut E, instr: Instruction) {
|
1018 | 1017 | };
|
1019 | 1018 | }
|
1020 | 1019 | Instruction::EllipticCurveAddition(i_comm) => {
|
1021 |
| - env.activate_gadget(Gadget::EllipticCurveAddition); |
1022 | 1020 | assert!(i_comm < NUMBER_OF_COLUMNS, "Invalid index. We do only support the addition of the commitments to the columns, for now. We must additionally support the scaling of cross-terms and error terms");
|
1023 | 1021 | let (x1, y1) = {
|
1024 | 1022 | let x1 = env.allocate();
|
@@ -1075,8 +1073,6 @@ pub fn run_ivc<E: InterpreterEnv>(env: &mut E, instr: Instruction) {
|
1075 | 1073 | starting_round + 5
|
1076 | 1074 | );
|
1077 | 1075 |
|
1078 |
| - env.activate_gadget(Gadget::PoseidonFullRound(starting_round)); |
1079 |
| - |
1080 | 1076 | let round_input_positions: Vec<E::Position> = (0..PlonkSpongeConstants::SPONGE_WIDTH)
|
1081 | 1077 | .map(|_i| env.allocate())
|
1082 | 1078 | .collect();
|
@@ -1146,8 +1142,6 @@ pub fn run_ivc<E: InterpreterEnv>(env: &mut E, instr: Instruction) {
|
1146 | 1142 | });
|
1147 | 1143 | }
|
1148 | 1144 | Instruction::PoseidonSpongeAbsorb => {
|
1149 |
| - env.activate_gadget(Gadget::PoseidonSpongeAbsorb); |
1150 |
| - |
1151 | 1145 | let round_input_positions: Vec<E::Position> = (0..PlonkSpongeConstants::SPONGE_WIDTH
|
1152 | 1146 | - 1)
|
1153 | 1147 | .map(|_i| env.allocate())
|
@@ -1186,3 +1180,50 @@ pub fn run_ivc<E: InterpreterEnv>(env: &mut E, instr: Instruction) {
|
1186 | 1180 | // Compute the hash of the public input
|
1187 | 1181 | // FIXME: add the verification key. We should have a hash of it.
|
1188 | 1182 | }
|
| 1183 | + |
| 1184 | +/// Describe the control-flow for the verifier circuit. |
| 1185 | +pub fn fetch_next_instruction(current_instruction: Instruction) -> Instruction { |
| 1186 | + match current_instruction { |
| 1187 | + Instruction::PoseidonFullRound(i) => { |
| 1188 | + if i < PlonkSpongeConstants::PERM_ROUNDS_FULL - 5 { |
| 1189 | + Instruction::PoseidonFullRound(i + 5) |
| 1190 | + } else { |
| 1191 | + // FIXME: for now, we continue absorbing because the current |
| 1192 | + // code, while fetching the values to absorb, raises an |
| 1193 | + // exception when we absorbed everythimg, and the main file |
| 1194 | + // handles the halt by filling as many rows as expected (see |
| 1195 | + // [VERIFIER_CIRCUIT_SIZE]). |
| 1196 | + Instruction::PoseidonSpongeAbsorb |
| 1197 | + } |
| 1198 | + } |
| 1199 | + Instruction::PoseidonSpongeAbsorb => { |
| 1200 | + // Whenever we absorbed a value, we run the permutation. |
| 1201 | + Instruction::PoseidonFullRound(0) |
| 1202 | + } |
| 1203 | + Instruction::EllipticCurveScaling(i_comm, bit) => { |
| 1204 | + // TODO: we still need to substract (or not?) the blinder. |
| 1205 | + // Maybe we can avoid this by aggregating them. |
| 1206 | + // TODO: we also need to aggregate the cross-terms. |
| 1207 | + // Therefore i_comm must also take into the account the number |
| 1208 | + // of cross-terms. |
| 1209 | + assert!(i_comm < NUMBER_OF_COLUMNS, "Maximum number of columns reached ({NUMBER_OF_COLUMNS}), increase the number of columns"); |
| 1210 | + assert!(bit < MAXIMUM_FIELD_SIZE_IN_BITS, "Maximum number of bits reached ({MAXIMUM_FIELD_SIZE_IN_BITS}), increase the number of bits"); |
| 1211 | + if bit < MAXIMUM_FIELD_SIZE_IN_BITS - 1 { |
| 1212 | + Instruction::EllipticCurveScaling(i_comm, bit + 1) |
| 1213 | + } else if i_comm < NUMBER_OF_COLUMNS - 1 { |
| 1214 | + Instruction::EllipticCurveScaling(i_comm + 1, 0) |
| 1215 | + } else { |
| 1216 | + // We have computed all the bits for all the columns |
| 1217 | + Instruction::NoOp |
| 1218 | + } |
| 1219 | + } |
| 1220 | + Instruction::EllipticCurveAddition(i_comm) => { |
| 1221 | + if i_comm < NUMBER_OF_COLUMNS - 1 { |
| 1222 | + Instruction::EllipticCurveAddition(i_comm + 1) |
| 1223 | + } else { |
| 1224 | + Instruction::NoOp |
| 1225 | + } |
| 1226 | + } |
| 1227 | + Instruction::NoOp => Instruction::NoOp, |
| 1228 | + } |
| 1229 | +} |
0 commit comments