From 3ba23f7a70171443400dc59ff48f132640b98546 Mon Sep 17 00:00:00 2001 From: Vladislav Volosnikov Date: Thu, 8 Aug 2024 16:58:29 +0200 Subject: [PATCH] Derive WitnessVarLengthEncodable for witnesses used in BWG (#44) --- src/base_structures/decommit_query/mod.rs | 10 ++++- src/base_structures/log_query/mod.rs | 13 +++++- .../precompile_input_outputs/mod.rs | 19 ++++++++- src/base_structures/register/mod.rs | 10 ++++- src/base_structures/vm_state/callstack.rs | 13 +++++- src/base_structures/vm_state/mod.rs | 23 +++++++++-- src/base_structures/vm_state/saved_context.rs | 5 ++- src/code_unpacker_sha256/input.rs | 40 ++++++++++++++++--- src/demux_log_queue/input.rs | 31 +++++++++++--- src/ecrecover/input.rs | 13 ++++-- src/eip_4844/input.rs | 12 +++++- .../circuit_inputs/main_vm.rs | 18 ++++++++- src/fsm_input_output/mod.rs | 40 +++++++++++++++++-- src/keccak256_round_function/buffer/mod.rs | 9 ++++- src/keccak256_round_function/input.rs | 19 ++++++++- src/keccak256_round_function/mod.rs | 10 ++++- src/linear_hasher/input.rs | 22 ++++++++-- src/log_sorter/input.rs | 31 +++++++++++--- src/ram_permutation/input.rs | 22 ++++++++-- src/recursion/leaf_layer/input.rs | 13 ++++-- src/secp256r1_verify/input.rs | 10 ++++- src/sha256_round_function/input.rs | 19 ++++++++- src/sha256_round_function/mod.rs | 10 ++++- src/sort_decommittment_requests/input.rs | 31 +++++++++++--- src/storage_application/input.rs | 31 +++++++++++--- .../input.rs | 30 ++++++++++++-- .../input.rs | 21 ++++++++-- 27 files changed, 450 insertions(+), 75 deletions(-) diff --git a/src/base_structures/decommit_query/mod.rs b/src/base_structures/decommit_query/mod.rs index affabdd..4a25da2 100644 --- a/src/base_structures/decommit_query/mod.rs +++ b/src/base_structures/decommit_query/mod.rs @@ -11,13 +11,21 @@ use boojum::gadgets::traits::allocatable::CSPlaceholder; use boojum::gadgets::traits::allocatable::{CSAllocatable, CSAllocatableExt}; use boojum::gadgets::traits::castable::WitnessCastable; use boojum::gadgets::traits::encodable::CircuitVarLengthEncodable; +use boojum::gadgets::traits::encodable::WitnessVarLengthEncodable; use boojum::gadgets::traits::encodable::{CircuitEncodable, CircuitEncodableExt}; use boojum::gadgets::traits::selectable::Selectable; use boojum::gadgets::traits::witnessable::WitnessHookable; use boojum::gadgets::u32::UInt32; use boojum::{field::SmallField, gadgets::u256::UInt256}; -#[derive(Derivative, CSAllocatable, CSSelectable, WitnessHookable, CSVarLengthEncodable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + WitnessHookable, + CSVarLengthEncodable, + WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] pub struct DecommitQuery { pub code_hash: UInt256, diff --git a/src/base_structures/log_query/mod.rs b/src/base_structures/log_query/mod.rs index 4d42995..72b8c2d 100644 --- a/src/base_structures/log_query/mod.rs +++ b/src/base_structures/log_query/mod.rs @@ -9,7 +9,9 @@ use boojum::gadgets::traits::allocatable::CSPlaceholder; use boojum::gadgets::traits::allocatable::{CSAllocatable, CSAllocatableExt}; use boojum::gadgets::traits::castable::WitnessCastable; use boojum::gadgets::traits::encodable::CircuitEncodableExt; -use boojum::gadgets::traits::encodable::{CircuitEncodable, CircuitVarLengthEncodable}; +use boojum::gadgets::traits::encodable::{ + CircuitEncodable, CircuitVarLengthEncodable, WitnessVarLengthEncodable, +}; use boojum::gadgets::traits::selectable::Selectable; use boojum::gadgets::traits::witnessable::WitnessHookable; use boojum::gadgets::u160::{recompose_address_from_u32x5, UInt160}; @@ -18,7 +20,14 @@ use boojum::gadgets::u32::UInt32; use boojum::gadgets::u8::UInt8; use cs_derive::*; -#[derive(Derivative, CSAllocatable, CSSelectable, WitnessHookable, CSVarLengthEncodable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + WitnessHookable, + CSVarLengthEncodable, + WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug, Hash)] pub struct LogQuery { pub address: UInt160, diff --git a/src/base_structures/precompile_input_outputs/mod.rs b/src/base_structures/precompile_input_outputs/mod.rs index cc31420..b13bd20 100644 --- a/src/base_structures/precompile_input_outputs/mod.rs +++ b/src/base_structures/precompile_input_outputs/mod.rs @@ -13,11 +13,19 @@ use boojum::gadgets::traits::allocatable::CSAllocatable; use boojum::gadgets::traits::allocatable::CSPlaceholder; use boojum::gadgets::traits::auxiliary::PrettyComparison; use boojum::gadgets::traits::encodable::CircuitVarLengthEncodable; +use boojum::gadgets::traits::encodable::WitnessVarLengthEncodable; use boojum::gadgets::traits::selectable::Selectable; use boojum::gadgets::traits::witnessable::WitnessHookable; use cs_derive::*; -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] #[DerivePrettyComparison("true")] pub struct PrecompileFunctionInputData { @@ -36,7 +44,14 @@ impl CSPlaceholder for PrecompileFunctionInputData { } } -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] #[DerivePrettyComparison("true")] pub struct PrecompileFunctionOutputData { diff --git a/src/base_structures/register/mod.rs b/src/base_structures/register/mod.rs index 780e1c1..c7bc681 100644 --- a/src/base_structures/register/mod.rs +++ b/src/base_structures/register/mod.rs @@ -11,12 +11,20 @@ use boojum::cs::traits::cs::DstBuffer; use boojum::cs::Variable; use boojum::gadgets::traits::allocatable::{CSAllocatable, CSAllocatableExt}; use boojum::gadgets::traits::encodable::CircuitVarLengthEncodable; +use boojum::gadgets::traits::encodable::WitnessVarLengthEncodable; use boojum::gadgets::traits::selectable::Selectable; use boojum::gadgets::traits::witnessable::WitnessHookable; use cs_derive::*; -#[derive(Derivative, CSSelectable, CSAllocatable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSSelectable, + CSAllocatable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug, Hash)] pub struct VMRegister { pub is_pointer: Boolean, diff --git a/src/base_structures/vm_state/callstack.rs b/src/base_structures/vm_state/callstack.rs index 4ab9ac9..c142be4 100644 --- a/src/base_structures/vm_state/callstack.rs +++ b/src/base_structures/vm_state/callstack.rs @@ -1,7 +1,14 @@ use super::*; use boojum::serde_utils::BigArraySerde; -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] #[CSSelectableBound( "where [(); as CSAllocatableExt>::INTERNAL_STRUCT_LEN]:" @@ -40,7 +47,9 @@ use crate::base_structures::vm_state::saved_context::ExecutionContextRecord; // execution context that keeps all explicit data about the current execution frame, // and avoid recomputing of quantities that also do not change between calls -#[derive(Derivative, CSAllocatable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, CSAllocatable, CSVarLengthEncodable, WitnessHookable, WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] pub struct FullExecutionContext { pub saved_context: ExecutionContextRecord, diff --git a/src/base_structures/vm_state/mod.rs b/src/base_structures/vm_state/mod.rs index 4dd3fc6..290f639 100644 --- a/src/base_structures/vm_state/mod.rs +++ b/src/base_structures/vm_state/mod.rs @@ -9,6 +9,7 @@ use boojum::gadgets::num::Num; use boojum::gadgets::traits::allocatable::*; use boojum::gadgets::traits::auxiliary::PrettyComparison; use boojum::gadgets::traits::encodable::CircuitVarLengthEncodable; +use boojum::gadgets::traits::encodable::WitnessVarLengthEncodable; use boojum::gadgets::traits::selectable::*; use boojum::gadgets::traits::witnessable::WitnessHookable; use boojum::gadgets::u16::UInt16; @@ -29,7 +30,9 @@ pub const QUEUE_STATE_WIDTH: usize = 4; use zkevm_opcode_defs::REGISTERS_COUNT; -#[derive(Derivative, CSAllocatable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, CSAllocatable, CSVarLengthEncodable, WitnessHookable, WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] pub struct ArithmeticFlagsPort { pub overflow_or_less_than: Boolean, @@ -83,7 +86,14 @@ impl ArithmeticFlagsPort { } } -#[derive(Derivative, CSSelectable, CSAllocatable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSSelectable, + CSAllocatable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] #[CSSelectableBound( "where [(); as CSAllocatableExt>::INTERNAL_STRUCT_LEN]:" @@ -153,7 +163,14 @@ impl CSPlaceholder for VmLocalState { } } -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] pub struct GlobalContext { pub zkporter_is_available: Boolean, diff --git a/src/base_structures/vm_state/saved_context.rs b/src/base_structures/vm_state/saved_context.rs index 170c037..57f2216 100644 --- a/src/base_structures/vm_state/saved_context.rs +++ b/src/base_structures/vm_state/saved_context.rs @@ -4,6 +4,7 @@ use boojum::cs::Variable; use boojum::gadgets::traits::allocatable::CSAllocatableExt; use boojum::gadgets::traits::castable::WitnessCastable; use boojum::gadgets::traits::encodable::CircuitEncodable; +use boojum::gadgets::traits::encodable::WitnessVarLengthEncodable; use boojum::gadgets::traits::selectable::parallel_select_variables; use cs_derive::*; use ethereum_types::Address; @@ -31,7 +32,9 @@ use super::*; // - per-context computed rollback segment length // - per-context rollback_head -#[derive(Derivative, CSAllocatable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, CSAllocatable, CSVarLengthEncodable, WitnessHookable, WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] pub struct ExecutionContextRecord { pub this: UInt160, // unfortunately delegatecall mangles this field - it can not be restored from callee's caller diff --git a/src/code_unpacker_sha256/input.rs b/src/code_unpacker_sha256/input.rs index 930b714..e0e2b8c 100644 --- a/src/code_unpacker_sha256/input.rs +++ b/src/code_unpacker_sha256/input.rs @@ -7,8 +7,8 @@ use boojum::gadgets::{ boolean::Boolean, queue::*, traits::{ - allocatable::*, encodable::CircuitVarLengthEncodable, selectable::Selectable, - witnessable::WitnessHookable, + allocatable::*, encodable::CircuitVarLengthEncodable, encodable::WitnessVarLengthEncodable, + selectable::Selectable, witnessable::WitnessHookable, }, u16::UInt16, u256::UInt256, @@ -18,7 +18,14 @@ use boojum::serde_utils::BigArraySerde; use cs_derive::*; use derivative::*; -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] pub struct CodeDecommittmentFSM { pub sha256_inner_state: [UInt32; 8], // 8 uint32 words of internal sha256 state @@ -53,7 +60,14 @@ impl CSPlaceholder for CodeDecommittmentFSM { } } -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] #[DerivePrettyComparison("true")] pub struct CodeDecommitterFSMInputOutput { @@ -73,7 +87,14 @@ impl CSPlaceholder for CodeDecommitterFSMInputOutput { } } -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] pub struct CodeDecommitterInputData { pub memory_queue_initial_state: QueueState, @@ -92,7 +113,14 @@ impl CSPlaceholder for CodeDecommitterInputData { } } -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] #[DerivePrettyComparison("true")] pub struct CodeDecommitterOutputData { diff --git a/src/demux_log_queue/input.rs b/src/demux_log_queue/input.rs index 573a168..77f378d 100644 --- a/src/demux_log_queue/input.rs +++ b/src/demux_log_queue/input.rs @@ -12,8 +12,8 @@ use boojum::gadgets::{ boolean::Boolean, queue::*, traits::{ - allocatable::*, encodable::CircuitVarLengthEncodable, selectable::Selectable, - witnessable::WitnessHookable, + allocatable::*, encodable::CircuitVarLengthEncodable, encodable::WitnessVarLengthEncodable, + selectable::Selectable, witnessable::WitnessHookable, }, }; use boojum::serde_utils::BigArraySerde; @@ -22,7 +22,14 @@ use derivative::*; use super::NUM_DEMUX_OUTPUTS; -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] #[DerivePrettyComparison("true")] pub struct LogDemuxerFSMInputOutput { @@ -40,7 +47,14 @@ impl CSPlaceholder for LogDemuxerFSMInputOutput { } } -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] #[DerivePrettyComparison("true")] pub struct LogDemuxerInputData { @@ -55,7 +69,14 @@ impl CSPlaceholder for LogDemuxerInputData { } } -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] #[DerivePrettyComparison("true")] pub struct LogDemuxerOutputData { diff --git a/src/ecrecover/input.rs b/src/ecrecover/input.rs index 2581b39..089d034 100644 --- a/src/ecrecover/input.rs +++ b/src/ecrecover/input.rs @@ -7,11 +7,18 @@ use boojum::cs::Variable; use boojum::gadgets::queue::*; use boojum::gadgets::traits::allocatable::CSAllocatable; use boojum::gadgets::traits::allocatable::CSPlaceholder; -use boojum::gadgets::traits::encodable::CircuitVarLengthEncodable; - use boojum::gadgets::traits::auxiliary::PrettyComparison; +use boojum::gadgets::traits::encodable::CircuitVarLengthEncodable; +use boojum::gadgets::traits::encodable::WitnessVarLengthEncodable; -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] #[DerivePrettyComparison("true")] pub struct EcrecoverCircuitFSMInputOutput { diff --git a/src/eip_4844/input.rs b/src/eip_4844/input.rs index fe1e732..a815029 100644 --- a/src/eip_4844/input.rs +++ b/src/eip_4844/input.rs @@ -11,7 +11,8 @@ use boojum::gadgets::u8::UInt8; use boojum::gadgets::{ boolean::Boolean, traits::{ - encodable::CircuitVarLengthEncodable, selectable::Selectable, witnessable::WitnessHookable, + encodable::CircuitVarLengthEncodable, encodable::WitnessVarLengthEncodable, + selectable::Selectable, witnessable::WitnessHookable, }, }; use boojum::serde_utils::BigArraySerde; @@ -27,7 +28,14 @@ pub struct BlobChunk { pub inner: [UInt8; BLOB_CHUNK_SIZE], } -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitVarLengthEncodable, + WitnessHookable, +)] #[derivative(Clone, Copy, Debug)] #[DerivePrettyComparison("true")] pub struct EIP4844OutputData { diff --git a/src/fsm_input_output/circuit_inputs/main_vm.rs b/src/fsm_input_output/circuit_inputs/main_vm.rs index 4a2c639..b5717ba 100644 --- a/src/fsm_input_output/circuit_inputs/main_vm.rs +++ b/src/fsm_input_output/circuit_inputs/main_vm.rs @@ -4,7 +4,14 @@ use crate::base_structures::vm_state::*; use boojum::gadgets::queue::*; use boojum::serde_utils::BigArraySerde; -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Debug)] pub struct VmInputData { pub rollback_queue_tail_for_block: [Num; QUEUE_STATE_WIDTH], @@ -27,7 +34,14 @@ impl CSPlaceholder for VmInputData { } } -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Debug)] #[DerivePrettyComparison("true")] pub struct VmOutputData { diff --git a/src/fsm_input_output/mod.rs b/src/fsm_input_output/mod.rs index 43fbbe6..3fa5e1d 100644 --- a/src/fsm_input_output/mod.rs +++ b/src/fsm_input_output/mod.rs @@ -13,6 +13,7 @@ use boojum::gadgets::num::Num; use boojum::gadgets::traits::allocatable::CSAllocatable; use boojum::gadgets::traits::allocatable::CSPlaceholder; use boojum::gadgets::traits::encodable::CircuitVarLengthEncodable; +use boojum::gadgets::traits::encodable::WitnessVarLengthEncodable; use boojum::gadgets::traits::round_function::CircuitRoundFunction; use boojum::gadgets::traits::selectable::Selectable; use boojum::gadgets::traits::witnessable::WitnessHookable; @@ -33,9 +34,24 @@ where #[derivative(Clone, Debug)] pub struct ClosedFormInput< F: SmallField, - T: Clone + std::fmt::Debug + CSAllocatable + CircuitVarLengthEncodable + WitnessHookable, - IN: Clone + std::fmt::Debug + CSAllocatable + CircuitVarLengthEncodable + WitnessHookable, - OUT: Clone + std::fmt::Debug + CSAllocatable + CircuitVarLengthEncodable + WitnessHookable, + T: Clone + + std::fmt::Debug + + CSAllocatable + + CircuitVarLengthEncodable + + WitnessVarLengthEncodable + + WitnessHookable, + IN: Clone + + std::fmt::Debug + + CSAllocatable + + CircuitVarLengthEncodable + + WitnessVarLengthEncodable + + WitnessHookable, + OUT: Clone + + std::fmt::Debug + + CSAllocatable + + CircuitVarLengthEncodable + + WitnessVarLengthEncodable + + WitnessHookable, > where >::Witness: serde::Serialize + serde::de::DeserializeOwned + Eq, >::Witness: serde::Serialize + serde::de::DeserializeOwned + Eq, @@ -55,16 +71,19 @@ impl< + std::fmt::Debug + CSAllocatable + CircuitVarLengthEncodable + + WitnessVarLengthEncodable + WitnessHookable, IN: Clone + std::fmt::Debug + CSAllocatable + CircuitVarLengthEncodable + + WitnessVarLengthEncodable + WitnessHookable, OUT: Clone + std::fmt::Debug + CSAllocatable + CircuitVarLengthEncodable + + WitnessVarLengthEncodable + WitnessHookable, > ClosedFormInput where @@ -143,16 +162,19 @@ impl< + std::fmt::Debug + CSAllocatable + CircuitVarLengthEncodable + + WitnessVarLengthEncodable + WitnessHookable, IN: Clone + std::fmt::Debug + CSAllocatable + CircuitVarLengthEncodable + + WitnessVarLengthEncodable + WitnessHookable, OUT: Clone + std::fmt::Debug + CSAllocatable + CircuitVarLengthEncodable + + WitnessVarLengthEncodable + WitnessHookable, > std::default::Default for ClosedFormInputWitness where @@ -165,7 +187,14 @@ where } } -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Debug)] pub struct ClosedFormInputCompactForm { pub start_flag: Boolean, @@ -255,16 +284,19 @@ impl ClosedFormInputCompactForm { + std::fmt::Debug + CSAllocatable + CircuitVarLengthEncodable + + WitnessVarLengthEncodable + WitnessHookable, IN: Clone + std::fmt::Debug + CSAllocatable + CircuitVarLengthEncodable + + WitnessVarLengthEncodable + WitnessHookable, OUT: Clone + std::fmt::Debug + CSAllocatable + CircuitVarLengthEncodable + + WitnessVarLengthEncodable + WitnessHookable, R: CircuitRoundFunction, >( diff --git a/src/keccak256_round_function/buffer/mod.rs b/src/keccak256_round_function/buffer/mod.rs index 6747331..1c5a5f4 100644 --- a/src/keccak256_round_function/buffer/mod.rs +++ b/src/keccak256_round_function/buffer/mod.rs @@ -2,7 +2,14 @@ use super::*; use crate::boojum::gadgets::traits::auxiliary::PrettyComparison; use crate::boojum::serde_utils::BigArraySerde; -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] #[DerivePrettyComparison("true")] pub struct ByteBuffer { diff --git a/src/keccak256_round_function/input.rs b/src/keccak256_round_function/input.rs index 480b518..a8cb8e8 100644 --- a/src/keccak256_round_function/input.rs +++ b/src/keccak256_round_function/input.rs @@ -10,6 +10,7 @@ use boojum::gadgets::queue::*; use boojum::gadgets::traits::allocatable::CSAllocatable; use boojum::gadgets::traits::allocatable::CSPlaceholder; use boojum::gadgets::traits::encodable::CircuitVarLengthEncodable; +use boojum::gadgets::traits::encodable::WitnessVarLengthEncodable; use boojum::cs::traits::cs::ConstraintSystem; use boojum::field::SmallField; @@ -23,7 +24,14 @@ use boojum::serde_utils::BigArraySerde; pub const MEMORY_QUERIES_PER_CYCLE: usize = 6; pub const KECCAK_PRECOMPILE_BUFFER_SIZE: usize = MEMORY_QUERIES_PER_CYCLE * 32; -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] #[DerivePrettyComparison("true")] pub struct Keccak256RoundFunctionFSM { @@ -57,7 +65,14 @@ impl CSPlaceholder for Keccak256RoundFunctionFSM { } } -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] #[DerivePrettyComparison("true")] pub struct Keccak256RoundFunctionFSMInputOutput { diff --git a/src/keccak256_round_function/mod.rs b/src/keccak256_round_function/mod.rs index 8f49c57..e1b9337 100644 --- a/src/keccak256_round_function/mod.rs +++ b/src/keccak256_round_function/mod.rs @@ -32,6 +32,7 @@ use boojum::gadgets::queue::QueueState; use boojum::gadgets::traits::allocatable::CSAllocatable; use boojum::gadgets::traits::allocatable::{CSAllocatableExt, CSPlaceholder}; use boojum::gadgets::traits::encodable::CircuitVarLengthEncodable; +use boojum::gadgets::traits::encodable::WitnessVarLengthEncodable; use boojum::gadgets::traits::round_function::CircuitRoundFunction; use boojum::gadgets::u160::UInt160; use boojum::gadgets::u8::UInt8; @@ -42,7 +43,14 @@ pub mod buffer; pub mod input; use self::input::*; -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] // #[DerivePrettyComparison("true")] pub struct Keccak256PrecompileCallParams { diff --git a/src/linear_hasher/input.rs b/src/linear_hasher/input.rs index 280caec..c479618 100644 --- a/src/linear_hasher/input.rs +++ b/src/linear_hasher/input.rs @@ -12,15 +12,22 @@ use boojum::gadgets::{ boolean::Boolean, queue::*, traits::{ - allocatable::*, encodable::CircuitVarLengthEncodable, selectable::Selectable, - witnessable::WitnessHookable, + allocatable::*, encodable::CircuitVarLengthEncodable, encodable::WitnessVarLengthEncodable, + selectable::Selectable, witnessable::WitnessHookable, }, }; use boojum::serde_utils::BigArraySerde; use cs_derive::*; use derivative::*; -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] #[DerivePrettyComparison("true")] pub struct LinearHasherInputData { @@ -35,7 +42,14 @@ impl CSPlaceholder for LinearHasherInputData { } } -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] #[DerivePrettyComparison("true")] pub struct LinearHasherOutputData { diff --git a/src/log_sorter/input.rs b/src/log_sorter/input.rs index ee2d1de..04f7cf1 100644 --- a/src/log_sorter/input.rs +++ b/src/log_sorter/input.rs @@ -12,8 +12,8 @@ use boojum::gadgets::{ num::Num, queue::*, traits::{ - allocatable::*, encodable::CircuitVarLengthEncodable, selectable::Selectable, - witnessable::WitnessHookable, + allocatable::*, encodable::CircuitVarLengthEncodable, encodable::WitnessVarLengthEncodable, + selectable::Selectable, witnessable::WitnessHookable, }, }; use boojum::serde_utils::BigArraySerde; @@ -22,7 +22,14 @@ use derivative::*; use crate::DEFAULT_NUM_PERMUTATION_ARGUMENT_REPETITIONS; -#[derive(Derivative, CSAllocatable, CSVarLengthEncodable, CSSelectable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSVarLengthEncodable, + CSSelectable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] #[DerivePrettyComparison("true")] pub struct EventsDeduplicatorFSMInputOutput { @@ -51,7 +58,14 @@ impl CSPlaceholder for EventsDeduplicatorFSMInputOutput { } } -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] #[DerivePrettyComparison("true")] pub struct EventsDeduplicatorInputData { @@ -68,7 +82,14 @@ impl CSPlaceholder for EventsDeduplicatorInputData { } } -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] #[DerivePrettyComparison("true")] pub struct EventsDeduplicatorOutputData { diff --git a/src/ram_permutation/input.rs b/src/ram_permutation/input.rs index 099c413..c1d1ee1 100644 --- a/src/ram_permutation/input.rs +++ b/src/ram_permutation/input.rs @@ -12,8 +12,8 @@ use boojum::gadgets::{ queue::full_state_queue::*, queue::*, traits::{ - allocatable::*, encodable::CircuitVarLengthEncodable, selectable::Selectable, - witnessable::WitnessHookable, + allocatable::*, encodable::CircuitVarLengthEncodable, encodable::WitnessVarLengthEncodable, + selectable::Selectable, witnessable::WitnessHookable, }, u256::UInt256, u32::UInt32, @@ -22,7 +22,14 @@ use boojum::serde_utils::BigArraySerde; use cs_derive::*; use derivative::*; -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Debug)] pub struct RamPermutationInputData { pub unsorted_queue_initial_state: QueueState, @@ -46,7 +53,14 @@ impl CSPlaceholder for RamPermutationInputData { pub const RAM_SORTING_KEY_LENGTH: usize = 3; pub const RAM_FULL_KEY_LENGTH: usize = 2; -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] #[DerivePrettyComparison("true")] pub struct RamPermutationFSMInputOutput { diff --git a/src/recursion/leaf_layer/input.rs b/src/recursion/leaf_layer/input.rs index 825b024..323f50c 100644 --- a/src/recursion/leaf_layer/input.rs +++ b/src/recursion/leaf_layer/input.rs @@ -11,8 +11,8 @@ use boojum::gadgets::traits::auxiliary::PrettyComparison; use boojum::gadgets::{ boolean::Boolean, traits::{ - allocatable::*, encodable::CircuitVarLengthEncodable, selectable::Selectable, - witnessable::WitnessHookable, + allocatable::*, encodable::CircuitVarLengthEncodable, encodable::WitnessVarLengthEncodable, + selectable::Selectable, witnessable::WitnessHookable, }, }; use cs_derive::*; @@ -20,7 +20,14 @@ use cs_derive::*; use boojum::field::FieldExtension; use boojum::serde_utils::BigArraySerde; -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] #[DerivePrettyComparison("true")] pub struct RecursionLeafParameters { diff --git a/src/secp256r1_verify/input.rs b/src/secp256r1_verify/input.rs index 0147328..79cfc1e 100644 --- a/src/secp256r1_verify/input.rs +++ b/src/secp256r1_verify/input.rs @@ -8,10 +8,18 @@ use boojum::gadgets::queue::*; use boojum::gadgets::traits::allocatable::CSAllocatable; use boojum::gadgets::traits::allocatable::CSPlaceholder; use boojum::gadgets::traits::encodable::CircuitVarLengthEncodable; +use boojum::gadgets::traits::encodable::WitnessVarLengthEncodable; use boojum::gadgets::traits::auxiliary::PrettyComparison; -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] #[DerivePrettyComparison("true")] pub struct Secp256r1VerifyCircuitFSMInputOutput { diff --git a/src/sha256_round_function/input.rs b/src/sha256_round_function/input.rs index b6f81c5..ac45eac 100644 --- a/src/sha256_round_function/input.rs +++ b/src/sha256_round_function/input.rs @@ -9,6 +9,7 @@ use boojum::gadgets::queue::*; use boojum::gadgets::traits::allocatable::CSAllocatable; use boojum::gadgets::traits::allocatable::CSPlaceholder; use boojum::gadgets::traits::encodable::CircuitVarLengthEncodable; +use boojum::gadgets::traits::encodable::WitnessVarLengthEncodable; use boojum::cs::traits::cs::ConstraintSystem; use boojum::field::SmallField; @@ -18,7 +19,14 @@ use boojum::gadgets::traits::selectable::Selectable; use boojum::gadgets::traits::witnessable::WitnessHookable; use boojum::serde_utils::BigArraySerde; -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] #[DerivePrettyComparison("true")] pub struct Sha256RoundFunctionFSM { @@ -47,7 +55,14 @@ impl CSPlaceholder for Sha256RoundFunctionFSM { } } -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] #[DerivePrettyComparison("true")] pub struct Sha256RoundFunctionFSMInputOutput { diff --git a/src/sha256_round_function/mod.rs b/src/sha256_round_function/mod.rs index 400ec6d..20437b1 100644 --- a/src/sha256_round_function/mod.rs +++ b/src/sha256_round_function/mod.rs @@ -30,6 +30,7 @@ use boojum::gadgets::sha256::{self}; use boojum::gadgets::traits::allocatable::CSAllocatable; use boojum::gadgets::traits::allocatable::{CSAllocatableExt, CSPlaceholder}; use boojum::gadgets::traits::encodable::CircuitVarLengthEncodable; +use boojum::gadgets::traits::encodable::WitnessVarLengthEncodable; use boojum::gadgets::traits::round_function::CircuitRoundFunction; use boojum::gadgets::u160::UInt160; use boojum::gadgets::u8::UInt8; @@ -38,7 +39,14 @@ use std::sync::{Arc, RwLock}; pub mod input; use self::input::*; -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] // #[DerivePrettyComparison("true")] pub struct Sha256PrecompileCallParams { diff --git a/src/sort_decommittment_requests/input.rs b/src/sort_decommittment_requests/input.rs index 6ac8739..c2d3f56 100644 --- a/src/sort_decommittment_requests/input.rs +++ b/src/sort_decommittment_requests/input.rs @@ -9,8 +9,8 @@ use boojum::gadgets::u32::UInt32; use boojum::gadgets::{ boolean::Boolean, traits::{ - allocatable::*, encodable::CircuitVarLengthEncodable, selectable::Selectable, - witnessable::WitnessHookable, + allocatable::*, encodable::CircuitVarLengthEncodable, encodable::WitnessVarLengthEncodable, + selectable::Selectable, witnessable::WitnessHookable, }, }; use boojum::serde_utils::BigArraySerde; @@ -18,7 +18,14 @@ use cs_derive::*; pub const PACKED_KEY_LENGTH: usize = 8 + 1; -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] #[DerivePrettyComparison("true")] pub struct CodeDecommittmentsDeduplicatorFSMInputOutput { @@ -54,7 +61,14 @@ impl CSPlaceholder for CodeDecommittmentsDeduplicatorFSMInputO } } -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] #[DerivePrettyComparison("true")] pub struct CodeDecommittmentsDeduplicatorInputData { @@ -73,7 +87,14 @@ impl CSPlaceholder for CodeDecommittmentsDeduplicatorInputData } } -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] #[DerivePrettyComparison("true")] pub struct CodeDecommittmentsDeduplicatorOutputData { diff --git a/src/storage_application/input.rs b/src/storage_application/input.rs index 5eb45bc..9d03d59 100644 --- a/src/storage_application/input.rs +++ b/src/storage_application/input.rs @@ -12,8 +12,8 @@ use boojum::gadgets::{ boolean::Boolean, queue::*, traits::{ - allocatable::*, encodable::CircuitVarLengthEncodable, selectable::Selectable, - witnessable::WitnessHookable, + allocatable::*, encodable::CircuitVarLengthEncodable, encodable::WitnessVarLengthEncodable, + selectable::Selectable, witnessable::WitnessHookable, }, }; use boojum::serde_utils::BigArraySerde; @@ -23,7 +23,14 @@ use std::collections::VecDeque; pub const STORAGE_DEPTH: usize = 256; -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] #[DerivePrettyComparison("true")] pub struct StorageApplicationFSMInputOutput { @@ -50,7 +57,14 @@ impl CSPlaceholder for StorageApplicationFSMInputOutput { } } -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] #[DerivePrettyComparison("true")] pub struct StorageApplicationInputData { @@ -71,7 +85,14 @@ impl CSPlaceholder for StorageApplicationInputData { } } -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] #[DerivePrettyComparison("true")] pub struct StorageApplicationOutputData { diff --git a/src/storage_validity_by_grand_product/input.rs b/src/storage_validity_by_grand_product/input.rs index cd2656a..a029b70 100644 --- a/src/storage_validity_by_grand_product/input.rs +++ b/src/storage_validity_by_grand_product/input.rs @@ -12,7 +12,8 @@ use boojum::{ num::*, queue::*, traits::{ - allocatable::*, encodable::CircuitVarLengthEncodable, selectable::Selectable, + allocatable::*, encodable::CircuitVarLengthEncodable, + encodable::WitnessVarLengthEncodable, selectable::Selectable, witnessable::WitnessHookable, }, u160::*, @@ -31,7 +32,14 @@ use super::TimestampedStorageLogRecord; // FSM -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] #[DerivePrettyComparison("true")] pub struct StorageDeduplicatorFSMInputOutput { @@ -79,7 +87,14 @@ impl CSPlaceholder for StorageDeduplicatorFSMInputOutput { } } -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Debug)] pub struct StorageDeduplicatorInputData { pub shard_id_to_process: UInt8, @@ -97,7 +112,14 @@ impl CSPlaceholder for StorageDeduplicatorInputData { } } -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] #[DerivePrettyComparison("true")] pub struct StorageDeduplicatorOutputData { diff --git a/src/transient_storage_validity_by_grand_product/input.rs b/src/transient_storage_validity_by_grand_product/input.rs index 23aec0c..1da18ce 100644 --- a/src/transient_storage_validity_by_grand_product/input.rs +++ b/src/transient_storage_validity_by_grand_product/input.rs @@ -12,7 +12,8 @@ use boojum::{ num::*, queue::*, traits::{ - allocatable::*, encodable::CircuitVarLengthEncodable, selectable::Selectable, + allocatable::*, encodable::CircuitVarLengthEncodable, + encodable::WitnessVarLengthEncodable, selectable::Selectable, witnessable::WitnessHookable, }, u256::*, @@ -29,7 +30,14 @@ pub const TRANSIENT_STORAGE_VALIDITY_CHECK_PACKED_KEY_LENGTH: usize = 1 + 1 + 5 // FSM -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Copy, Debug)] #[DerivePrettyComparison("true")] pub struct TransientStorageDeduplicatorFSMInputOutput { @@ -65,7 +73,14 @@ impl CSPlaceholder for TransientStorageDeduplicatorFSMInputOut } } -#[derive(Derivative, CSAllocatable, CSSelectable, CSVarLengthEncodable, WitnessHookable)] +#[derive( + Derivative, + CSAllocatable, + CSSelectable, + CSVarLengthEncodable, + WitnessHookable, + WitVarLengthEncodable, +)] #[derivative(Clone, Debug)] pub struct TransientStorageDeduplicatorInputData { pub unsorted_log_queue_state: QueueState,