11use std:: collections:: HashMap ;
2+ use std:: iter:: once;
23
34use itertools:: { chain, Itertools } ;
45use num_traits:: Zero ;
@@ -31,13 +32,14 @@ use super::poseidon::air::{
3132} ;
3233use super :: range_checks_air:: {
3334 RangeChecksClaim , RangeChecksComponents , RangeChecksInteractionClaim ,
34- RangeChecksInteractionElements ,
3535} ;
3636use crate :: components:: {
3737 memory_address_to_id, memory_id_to_big, verify_bitwise_xor_4, verify_bitwise_xor_7,
3838 verify_bitwise_xor_8, verify_bitwise_xor_8_b, verify_bitwise_xor_9, verify_instruction,
3939} ;
40- use crate :: relations;
40+ use crate :: relations:: {
41+ self , MEMORY_ADDRESS_TO_ID_RELATION_ID , MEMORY_ID_TO_BIG_RELATION_ID , OPCODES_RELATION_ID ,
42+ } ;
4143use crate :: verifier:: RelationUse ;
4244
4345#[ derive( Serialize , Deserialize ) ]
@@ -255,30 +257,46 @@ impl PublicData {
255257 )
256258 . for_each ( |( addr, id, val) | {
257259 values_to_inverse. push (
258- <relations:: MemoryAddressToId as Relation < M31 , QM31 > >:: combine (
259- & lookup_elements. memory_address_to_id ,
260- & [ M31 :: from_u32_unchecked ( addr) , M31 :: from_u32_unchecked ( id) ] ,
260+ <relations:: CommonLookupElements as Relation < M31 , QM31 > >:: combine (
261+ & lookup_elements. common ,
262+ & [
263+ MEMORY_ADDRESS_TO_ID_RELATION_ID ,
264+ M31 :: from_u32_unchecked ( addr) ,
265+ M31 :: from_u32_unchecked ( id) ,
266+ ] ,
267+ ) ,
268+ ) ;
269+ values_to_inverse. push (
270+ <relations:: CommonLookupElements as Relation < M31 , QM31 > >:: combine (
271+ & lookup_elements. common ,
272+ & [
273+ [ MEMORY_ID_TO_BIG_RELATION_ID , M31 :: from_u32_unchecked ( id) ] . as_slice ( ) ,
274+ split_f252 ( val) . as_slice ( ) ,
275+ ]
276+ . concat ( ) ,
261277 ) ,
262278 ) ;
263- values_to_inverse. push ( <relations:: MemoryIdToBig as Relation < M31 , QM31 > >:: combine (
264- & lookup_elements. memory_id_to_value ,
265- & [
266- [ M31 :: from_u32_unchecked ( id) ] . as_slice ( ) ,
267- split_f252 ( val) . as_slice ( ) ,
268- ]
269- . concat ( ) ,
270- ) ) ;
271279 } ) ;
272280
281+ let final_state_tuple = once ( OPCODES_RELATION_ID )
282+ . chain ( self . final_state . values ( ) )
283+ . collect_vec ( ) ;
284+ let initial_state_tuple = once ( OPCODES_RELATION_ID )
285+ . chain ( self . initial_state . values ( ) )
286+ . collect_vec ( ) ;
273287 // Yield initial state and use the final.
274- values_to_inverse. push ( <relations:: Opcodes as Relation < M31 , QM31 > >:: combine (
275- & lookup_elements. opcodes ,
276- & self . final_state . values ( ) ,
277- ) ) ;
278- values_to_inverse. push ( -<relations:: Opcodes as Relation < M31 , QM31 > >:: combine (
279- & lookup_elements. opcodes ,
280- & self . initial_state . values ( ) ,
281- ) ) ;
288+ values_to_inverse. push (
289+ <relations:: CommonLookupElements as Relation < M31 , QM31 > >:: combine (
290+ & lookup_elements. common ,
291+ & final_state_tuple,
292+ ) ,
293+ ) ;
294+ values_to_inverse. push (
295+ -<relations:: CommonLookupElements as Relation < M31 , QM31 > >:: combine (
296+ & lookup_elements. common ,
297+ & initial_state_tuple,
298+ ) ,
299+ ) ;
282300
283301 let inverted_values = QM31 :: batch_inverse ( & values_to_inverse) ;
284302 inverted_values. iter ( ) . sum :: < QM31 > ( )
@@ -577,58 +595,12 @@ impl PublicMemory {
577595}
578596
579597pub struct CairoInteractionElements {
580- pub opcodes : relations:: Opcodes ,
581- pub verify_instruction : relations:: VerifyInstruction ,
582- pub blake_round : relations:: BlakeRound ,
583- pub blake_g : relations:: BlakeG ,
584- pub blake_sigma : relations:: BlakeRoundSigma ,
585- pub triple_xor_32 : relations:: TripleXor32 ,
586- pub poseidon_aggregator : relations:: PoseidonAggregator ,
587- pub poseidon_3_partial_rounds_chain : relations:: Poseidon3PartialRoundsChain ,
588- pub poseidon_full_round_chain : relations:: PoseidonFullRoundChain ,
589- pub cube_252 : relations:: Cube252 ,
590- pub poseidon_round_keys : relations:: PoseidonRoundKeys ,
591- pub range_check_252_width_27 : relations:: RangeCheck252Width27 ,
592- pub pedersen_aggregator : relations:: PedersenAggregator ,
593- pub partial_ec_mul : relations:: PartialEcMul ,
594- pub pedersen_points_table : relations:: PedersenPointsTable ,
595- pub memory_address_to_id : relations:: MemoryAddressToId ,
596- pub memory_id_to_value : relations:: MemoryIdToBig ,
597- pub range_checks : RangeChecksInteractionElements ,
598- pub verify_bitwise_xor_4 : relations:: VerifyBitwiseXor_4 ,
599- pub verify_bitwise_xor_7 : relations:: VerifyBitwiseXor_7 ,
600- pub verify_bitwise_xor_8 : relations:: VerifyBitwiseXor_8 ,
601- pub verify_bitwise_xor_8_b : relations:: VerifyBitwiseXor_8_B ,
602- pub verify_bitwise_xor_9 : relations:: VerifyBitwiseXor_9 ,
603- pub verify_bitwise_xor_12 : relations:: VerifyBitwiseXor_12 ,
598+ pub common : relations:: CommonLookupElements ,
604599}
605600impl CairoInteractionElements {
606601 pub fn draw ( channel : & mut impl Channel ) -> CairoInteractionElements {
607602 CairoInteractionElements {
608- opcodes : relations:: Opcodes :: draw ( channel) ,
609- verify_instruction : relations:: VerifyInstruction :: draw ( channel) ,
610- blake_round : relations:: BlakeRound :: draw ( channel) ,
611- blake_g : relations:: BlakeG :: draw ( channel) ,
612- blake_sigma : relations:: BlakeRoundSigma :: draw ( channel) ,
613- triple_xor_32 : relations:: TripleXor32 :: draw ( channel) ,
614- poseidon_aggregator : relations:: PoseidonAggregator :: draw ( channel) ,
615- poseidon_3_partial_rounds_chain : relations:: Poseidon3PartialRoundsChain :: draw ( channel) ,
616- poseidon_full_round_chain : relations:: PoseidonFullRoundChain :: draw ( channel) ,
617- cube_252 : relations:: Cube252 :: draw ( channel) ,
618- poseidon_round_keys : relations:: PoseidonRoundKeys :: draw ( channel) ,
619- range_check_252_width_27 : relations:: RangeCheck252Width27 :: draw ( channel) ,
620- pedersen_aggregator : relations:: PedersenAggregator :: draw ( channel) ,
621- partial_ec_mul : relations:: PartialEcMul :: draw ( channel) ,
622- pedersen_points_table : relations:: PedersenPointsTable :: draw ( channel) ,
623- memory_address_to_id : relations:: MemoryAddressToId :: draw ( channel) ,
624- memory_id_to_value : relations:: MemoryIdToBig :: draw ( channel) ,
625- range_checks : RangeChecksInteractionElements :: draw ( channel) ,
626- verify_bitwise_xor_4 : relations:: VerifyBitwiseXor_4 :: draw ( channel) ,
627- verify_bitwise_xor_7 : relations:: VerifyBitwiseXor_7 :: draw ( channel) ,
628- verify_bitwise_xor_8 : relations:: VerifyBitwiseXor_8 :: draw ( channel) ,
629- verify_bitwise_xor_8_b : relations:: VerifyBitwiseXor_8_B :: draw ( channel) ,
630- verify_bitwise_xor_9 : relations:: VerifyBitwiseXor_9 :: draw ( channel) ,
631- verify_bitwise_xor_12 : relations:: VerifyBitwiseXor_12 :: draw ( channel) ,
603+ common : relations:: CommonLookupElements :: draw ( channel) ,
632604 }
633605 }
634606}
@@ -739,16 +711,7 @@ impl CairoComponents {
739711 tree_span_provider,
740712 verify_instruction:: Eval {
741713 claim : cairo_claim. verify_instruction ,
742- memory_address_to_id_lookup_elements : interaction_elements
743- . memory_address_to_id
744- . clone ( ) ,
745- verify_instruction_lookup_elements : interaction_elements. verify_instruction . clone ( ) ,
746- memory_id_to_big_lookup_elements : interaction_elements. memory_id_to_value . clone ( ) ,
747- range_check_4_3_lookup_elements : interaction_elements. range_checks . rc_4_3 . clone ( ) ,
748- range_check_7_2_5_lookup_elements : interaction_elements
749- . range_checks
750- . rc_7_2_5
751- . clone ( ) ,
714+ common_lookup_elements : interaction_elements. common . clone ( ) ,
752715 } ,
753716 interaction_claim. verify_instruction . claimed_sum ,
754717 ) ;
@@ -781,34 +744,22 @@ impl CairoComponents {
781744 tree_span_provider,
782745 memory_address_to_id:: Eval :: new (
783746 cairo_claim. memory_address_to_id . clone ( ) ,
784- interaction_elements. memory_address_to_id . clone ( ) ,
747+ interaction_elements. common . clone ( ) ,
785748 ) ,
786749 interaction_claim. memory_address_to_id . clone ( ) . claimed_sum ,
787750 ) ;
788751
789752 let memory_id_to_value_components = memory_id_to_big:: big_components_from_claim (
790753 & cairo_claim. memory_id_to_value . big_log_sizes ,
791754 & interaction_claim. memory_id_to_value . big_claimed_sums ,
792- & interaction_elements. memory_id_to_value ,
793- & interaction_elements. range_checks . rc_9_9 ,
794- & interaction_elements. range_checks . rc_9_9_b ,
795- & interaction_elements. range_checks . rc_9_9_c ,
796- & interaction_elements. range_checks . rc_9_9_d ,
797- & interaction_elements. range_checks . rc_9_9_e ,
798- & interaction_elements. range_checks . rc_9_9_f ,
799- & interaction_elements. range_checks . rc_9_9_g ,
800- & interaction_elements. range_checks . rc_9_9_h ,
755+ & interaction_elements. common . clone ( ) ,
801756 tree_span_provider,
802757 ) ;
803758 let small_memory_id_to_value_component = memory_id_to_big:: SmallComponent :: new (
804759 tree_span_provider,
805760 memory_id_to_big:: SmallEval :: new (
806761 cairo_claim. memory_id_to_value . clone ( ) ,
807- interaction_elements. memory_id_to_value . clone ( ) ,
808- interaction_elements. range_checks . rc_9_9 . clone ( ) ,
809- interaction_elements. range_checks . rc_9_9_b . clone ( ) ,
810- interaction_elements. range_checks . rc_9_9_c . clone ( ) ,
811- interaction_elements. range_checks . rc_9_9_d . clone ( ) ,
762+ interaction_elements. common . clone ( ) ,
812763 ) ,
813764 interaction_claim
814765 . memory_id_to_value
@@ -817,56 +768,46 @@ impl CairoComponents {
817768 ) ;
818769 let range_checks_component = RangeChecksComponents :: new (
819770 tree_span_provider,
820- & interaction_elements. range_checks ,
771+ & interaction_elements. common ,
821772 & interaction_claim. range_checks ,
822773 ) ;
823774 let verify_bitwise_xor_4_component = verify_bitwise_xor_4:: Component :: new (
824775 tree_span_provider,
825776 verify_bitwise_xor_4:: Eval {
826777 claim : cairo_claim. verify_bitwise_xor_4 ,
827- verify_bitwise_xor_4_lookup_elements : interaction_elements
828- . verify_bitwise_xor_4
829- . clone ( ) ,
778+ common_lookup_elements : interaction_elements. common . clone ( ) ,
830779 } ,
831780 interaction_claim. verify_bitwise_xor_4 . claimed_sum ,
832781 ) ;
833782 let verify_bitwise_xor_7_component = verify_bitwise_xor_7:: Component :: new (
834783 tree_span_provider,
835784 verify_bitwise_xor_7:: Eval {
836785 claim : cairo_claim. verify_bitwise_xor_7 ,
837- verify_bitwise_xor_7_lookup_elements : interaction_elements
838- . verify_bitwise_xor_7
839- . clone ( ) ,
786+ common_lookup_elements : interaction_elements. common . clone ( ) ,
840787 } ,
841788 interaction_claim. verify_bitwise_xor_7 . claimed_sum ,
842789 ) ;
843790 let verify_bitwise_xor_8_component = verify_bitwise_xor_8:: Component :: new (
844791 tree_span_provider,
845792 verify_bitwise_xor_8:: Eval {
846793 claim : cairo_claim. verify_bitwise_xor_8 ,
847- verify_bitwise_xor_8_lookup_elements : interaction_elements
848- . verify_bitwise_xor_8
849- . clone ( ) ,
794+ common_lookup_elements : interaction_elements. common . clone ( ) ,
850795 } ,
851796 interaction_claim. verify_bitwise_xor_8 . claimed_sum ,
852797 ) ;
853798 let verify_bitwise_xor_8_b_component = verify_bitwise_xor_8_b:: Component :: new (
854799 tree_span_provider,
855800 verify_bitwise_xor_8_b:: Eval {
856801 claim : cairo_claim. verify_bitwise_xor_8_b ,
857- verify_bitwise_xor_8_b_lookup_elements : interaction_elements
858- . verify_bitwise_xor_8_b
859- . clone ( ) ,
802+ common_lookup_elements : interaction_elements. common . clone ( ) ,
860803 } ,
861804 interaction_claim. verify_bitwise_xor_8_b . claimed_sum ,
862805 ) ;
863806 let verify_bitwise_xor_9_component = verify_bitwise_xor_9:: Component :: new (
864807 tree_span_provider,
865808 verify_bitwise_xor_9:: Eval {
866809 claim : cairo_claim. verify_bitwise_xor_9 ,
867- verify_bitwise_xor_9_lookup_elements : interaction_elements
868- . verify_bitwise_xor_9
869- . clone ( ) ,
810+ common_lookup_elements : interaction_elements. common . clone ( ) ,
870811 } ,
871812 interaction_claim. verify_bitwise_xor_9 . claimed_sum ,
872813 ) ;
0 commit comments