use arrayvec::ArrayVec;
use super::*;
use crate::base_structures::vm_state::*;
use crate::base_structures::{
register::VMRegister,
vm_state::{callstack::Callstack, ArithmeticFlagsPort},
};
use boojum::field::SmallField;
use boojum::gadgets::num::Num;
use boojum::gadgets::{boolean::Boolean, u16::UInt16, u32::UInt32};
use crate::main_vm::opcodes::{AddSubRelation, MulDivRelation};
use zkevm_opcode_defs::REGISTERS_COUNT;
pub(crate) const MAX_SPONGES_PER_CYCLE: usize = 9;
pub(crate) const MAX_U32_CONDITIONAL_RANGE_CHECKS_PER_CYCLE: usize = 8;
pub(crate) const MAX_ADD_SUB_RELATIONS_PER_CYCLE: usize = 1;
pub(crate) const MAX_MUL_DIV_RELATIONS_PER_CYCLE: usize = 1;
pub(crate) const MAX_DECOMMIT_QUEUE_CANDIDATES: usize = 2;
#[derive(Derivative)]
#[derivative(Default(bound = ""))]
pub struct StateDiffsAccumulator<F: SmallField> {
pub dst_0_values: Vec<(bool, Boolean<F>, VMRegister<F>)>,
pub dst_1_values: Vec<(Boolean<F>, VMRegister<F>)>,
pub flags: Vec<(Boolean<F>, ArithmeticFlagsPort<F>)>,
pub specific_registers_updates: [Vec<(Boolean<F>, VMRegister<F>)>; REGISTERS_COUNT],
pub specific_registers_zeroing: [Vec<Boolean<F>>; REGISTERS_COUNT],
pub remove_ptr_on_specific_registers: [Vec<Boolean<F>>; REGISTERS_COUNT],
pub pending_exceptions: Vec<Boolean<F>>,
pub new_ergs_left_candidates: Vec<(Boolean<F>, UInt32<F>)>,
pub new_pc_candidates: Vec<(Boolean<F>, UInt16<F>)>,
pub new_tx_number: Option<(Boolean<F>, UInt32<F>)>,
pub new_pubdata_revert_counter: Option<(Boolean<F>, UInt32<F>)>,
pub new_heap_bounds: Vec<(Boolean<F>, UInt32<F>)>,
pub new_aux_heap_bounds: Vec<(Boolean<F>, UInt32<F>)>,
pub context_u128_candidates: Vec<(Boolean<F>, [UInt32<F>; 4])>,
pub callstacks: Vec<(Boolean<F>, Callstack<F>)>,
pub memory_page_counters: Option<UInt32<F>>,
pub decommitment_queue_candidates: ArrayVec<
(
Boolean<F>,
UInt32<F>,
[Num<F>; FULL_SPONGE_QUEUE_STATE_WIDTH],
),
MAX_DECOMMIT_QUEUE_CANDIDATES,
>,
pub memory_queue_candidates: Vec<(
Boolean<F>,
UInt32<F>,
[Num<F>; FULL_SPONGE_QUEUE_STATE_WIDTH],
)>,
pub log_queue_forward_candidates: Vec<(Boolean<F>, UInt32<F>, [Num<F>; QUEUE_STATE_WIDTH])>,
pub log_queue_rollback_candidates: Vec<(Boolean<F>, UInt32<F>, [Num<F>; QUEUE_STATE_WIDTH])>,
pub sponge_candidates_to_run: Vec<(
bool,
bool,
Boolean<F>,
ArrayVec<
(
Boolean<F>,
[Num<F>; FULL_SPONGE_QUEUE_STATE_WIDTH],
[Num<F>; FULL_SPONGE_QUEUE_STATE_WIDTH],
),
MAX_SPONGES_PER_CYCLE,
>,
)>,
pub u32_conditional_range_checks: Vec<(
Boolean<F>,
[UInt32<F>; MAX_U32_CONDITIONAL_RANGE_CHECKS_PER_CYCLE], // at the moment we only have one
)>,
pub add_sub_relations: Vec<(
Boolean<F>,
ArrayVec<AddSubRelation<F>, MAX_ADD_SUB_RELATIONS_PER_CYCLE>,
)>,
pub mul_div_relations: Vec<(
Boolean<F>,
ArrayVec<MulDivRelation<F>, MAX_MUL_DIV_RELATIONS_PER_CYCLE>,
)>,
pub pubdata_cost: Option<(Boolean<F>, UInt32<F>)>, }