11use std:: convert:: From ;
22use std:: fmt;
3- use std:: sync:: { Arc , LazyLock , Mutex } ;
3+ #[ cfg( feature = "block-composition" ) ]
4+ use std:: sync:: atomic:: { AtomicU64 , Ordering } ;
5+ use std:: sync:: Arc ;
46
57use ark_ec:: short_weierstrass:: { Affine , Projective , SWCurveConfig } ;
68use ark_ff:: { BigInt , PrimeField } ;
@@ -25,8 +27,6 @@ use starknet_api::transaction::fields::{Calldata, ContractAddressSalt};
2527use starknet_api:: transaction:: { EventContent , EventData , EventKey , L2ToL1Payload } ;
2628use starknet_types_core:: felt:: Felt ;
2729
28- #[ cfg( feature = "block-composition" ) ]
29- use crate :: execution:: call_info:: SyscallCount ;
3030use crate :: execution:: call_info:: { MessageToL1 , Retdata } ;
3131use crate :: execution:: common_hints:: ExecutionMode ;
3232use crate :: execution:: entry_point:: {
@@ -49,8 +49,7 @@ pub const CALL_CONTRACT_SELECTOR_NAME: &str = "call_contract";
4949pub const LIBRARY_CALL_SELECTOR_NAME : & str = "library_call" ;
5050
5151#[ cfg( feature = "block-composition" ) ]
52- pub static SYSCALL_COUNTER : LazyLock < Mutex < SyscallCount > > =
53- LazyLock :: new ( || Mutex :: new ( SyscallCount ( 0 ) ) ) ;
52+ pub static SYSCALL_COUNTER : AtomicU64 = AtomicU64 :: new ( 0 ) ;
5453
5554pub struct NativeSyscallHandler < ' state > {
5655 pub base : Box < SyscallHandlerBase < ' state > > ,
@@ -247,7 +246,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
247246 remaining_gas : & mut u64 ,
248247 ) -> SyscallResult < Felt > {
249248 #[ cfg( feature = "block-composition" ) ]
250- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
249+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
251250
252251 self . pre_execute_syscall (
253252 remaining_gas,
@@ -262,8 +261,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
262261
263262 fn get_execution_info ( & mut self , remaining_gas : & mut u64 ) -> SyscallResult < ExecutionInfo > {
264263 #[ cfg( feature = "block-composition" ) ]
265- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
266-
264+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
267265
268266 self . pre_execute_syscall (
269267 remaining_gas,
@@ -285,7 +283,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
285283 remaining_gas : & mut u64 ,
286284 ) -> SyscallResult < Felt > {
287285 #[ cfg( feature = "block-composition" ) ]
288- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
286+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
289287
290288 self . pre_execute_syscall (
291289 remaining_gas,
@@ -303,7 +301,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
303301
304302 fn get_execution_info_v2 ( & mut self , remaining_gas : & mut u64 ) -> SyscallResult < ExecutionInfoV2 > {
305303 #[ cfg( feature = "block-composition" ) ]
306- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
304+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
307305
308306 self . pre_execute_syscall (
309307 remaining_gas,
@@ -328,7 +326,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
328326 remaining_gas : & mut u64 ,
329327 ) -> SyscallResult < ( Felt , Vec < Felt > ) > {
330328 #[ cfg( feature = "block-composition" ) ]
331- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
329+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
332330 // The cost of deploying a contract is the base cost plus the linear cost of the calldata
333331 // len.
334332 let total_gas_cost =
@@ -353,7 +351,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
353351 }
354352 fn replace_class ( & mut self , class_hash : Felt , remaining_gas : & mut u64 ) -> SyscallResult < ( ) > {
355353 #[ cfg( feature = "block-composition" ) ]
356- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
354+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
357355 self . pre_execute_syscall (
358356 remaining_gas,
359357 self . gas_costs ( ) . syscalls . replace_class . base_syscall_cost ( ) ,
@@ -373,7 +371,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
373371 remaining_gas : & mut u64 ,
374372 ) -> SyscallResult < Vec < Felt > > {
375373 #[ cfg( feature = "block-composition" ) ]
376- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
374+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
377375 self . pre_execute_syscall (
378376 remaining_gas,
379377 self . gas_costs ( ) . syscalls . library_call . base_syscall_cost ( ) ,
@@ -419,7 +417,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
419417 remaining_gas : & mut u64 ,
420418 ) -> SyscallResult < Vec < Felt > > {
421419 #[ cfg( feature = "block-composition" ) ]
422- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
420+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
423421
424422 self . pre_execute_syscall (
425423 remaining_gas,
@@ -478,7 +476,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
478476 remaining_gas : & mut u64 ,
479477 ) -> SyscallResult < Felt > {
480478 #[ cfg( feature = "block-composition" ) ]
481- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
479+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
482480
483481 self . pre_execute_syscall (
484482 remaining_gas,
@@ -506,7 +504,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
506504 remaining_gas : & mut u64 ,
507505 ) -> SyscallResult < ( ) > {
508506 #[ cfg( feature = "block-composition" ) ]
509- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
507+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
510508
511509 self . pre_execute_syscall (
512510 remaining_gas,
@@ -533,7 +531,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
533531 remaining_gas : & mut u64 ,
534532 ) -> SyscallResult < ( ) > {
535533 #[ cfg( feature = "block-composition" ) ]
536- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
534+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
537535
538536 self . pre_execute_syscall (
539537 remaining_gas,
@@ -556,7 +554,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
556554 remaining_gas : & mut u64 ,
557555 ) -> SyscallResult < ( ) > {
558556 #[ cfg( feature = "block-composition" ) ]
559- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
557+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
560558
561559 self . pre_execute_syscall (
562560 remaining_gas,
@@ -572,7 +570,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
572570
573571 fn keccak ( & mut self , input : & [ u64 ] , remaining_gas : & mut u64 ) -> SyscallResult < U256 > {
574572 #[ cfg( feature = "block-composition" ) ]
575- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
573+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
576574
577575 self . pre_execute_syscall (
578576 remaining_gas,
@@ -595,7 +593,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
595593 remaining_gas : & mut u64 ,
596594 ) -> SyscallResult < Option < Secp256k1Point > > {
597595 #[ cfg( feature = "block-composition" ) ]
598- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
596+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
599597
600598 self . pre_execute_syscall (
601599 remaining_gas,
@@ -614,7 +612,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
614612 remaining_gas : & mut u64 ,
615613 ) -> SyscallResult < Secp256k1Point > {
616614 #[ cfg( feature = "block-composition" ) ]
617- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
615+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
618616 self . pre_execute_syscall (
619617 remaining_gas,
620618 self . gas_costs ( ) . syscalls . secp256k1_add . base_syscall_cost ( ) ,
@@ -630,7 +628,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
630628 remaining_gas : & mut u64 ,
631629 ) -> SyscallResult < Secp256k1Point > {
632630 #[ cfg( feature = "block-composition" ) ]
633- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
631+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
634632
635633 self . pre_execute_syscall (
636634 remaining_gas,
@@ -647,7 +645,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
647645 remaining_gas : & mut u64 ,
648646 ) -> SyscallResult < Option < Secp256k1Point > > {
649647 #[ cfg( feature = "block-composition" ) ]
650- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
648+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
651649
652650 self . pre_execute_syscall (
653651 remaining_gas,
@@ -665,7 +663,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
665663 remaining_gas : & mut u64 ,
666664 ) -> SyscallResult < ( U256 , U256 ) > {
667665 #[ cfg( feature = "block-composition" ) ]
668- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
666+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
669667 self . pre_execute_syscall (
670668 remaining_gas,
671669 self . gas_costs ( ) . syscalls . secp256k1_get_xy . base_syscall_cost ( ) ,
@@ -681,7 +679,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
681679 remaining_gas : & mut u64 ,
682680 ) -> SyscallResult < Option < Secp256r1Point > > {
683681 #[ cfg( feature = "block-composition" ) ]
684- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
682+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
685683
686684 self . pre_execute_syscall (
687685 remaining_gas,
@@ -700,7 +698,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
700698 remaining_gas : & mut u64 ,
701699 ) -> SyscallResult < Secp256r1Point > {
702700 #[ cfg( feature = "block-composition" ) ]
703- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
701+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
704702
705703 self . pre_execute_syscall (
706704 remaining_gas,
@@ -716,7 +714,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
716714 remaining_gas : & mut u64 ,
717715 ) -> SyscallResult < Secp256r1Point > {
718716 #[ cfg( feature = "block-composition" ) ]
719- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
717+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
720718
721719 self . pre_execute_syscall (
722720 remaining_gas,
@@ -733,7 +731,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
733731 remaining_gas : & mut u64 ,
734732 ) -> SyscallResult < Option < Secp256r1Point > > {
735733 #[ cfg( feature = "block-composition" ) ]
736- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
734+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
737735
738736 self . pre_execute_syscall (
739737 remaining_gas,
@@ -751,7 +749,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
751749 remaining_gas : & mut u64 ,
752750 ) -> SyscallResult < ( U256 , U256 ) > {
753751 #[ cfg( feature = "block-composition" ) ]
754- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
752+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
755753
756754 self . pre_execute_syscall (
757755 remaining_gas,
@@ -768,7 +766,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
768766 remaining_gas : & mut u64 ,
769767 ) -> SyscallResult < ( ) > {
770768 #[ cfg( feature = "block-composition" ) ]
771- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
769+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
772770
773771 self . pre_execute_syscall (
774772 remaining_gas,
@@ -796,7 +794,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
796794 remaining_gas : & mut u64 ,
797795 ) -> SyscallResult < Vec < Felt > > {
798796 #[ cfg( feature = "block-composition" ) ]
799- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
797+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
800798 todo ! (
801799 "implement meta_tx_v0 {:?}" ,
802800 ( address, entry_point_selector, calldata, signature, remaining_gas)
0 commit comments