1
1
use std:: convert:: From ;
2
2
use 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 ;
4
6
5
7
use ark_ec:: short_weierstrass:: { Affine , Projective , SWCurveConfig } ;
6
8
use ark_ff:: { BigInt , PrimeField } ;
@@ -25,8 +27,6 @@ use starknet_api::transaction::fields::{Calldata, ContractAddressSalt};
25
27
use starknet_api:: transaction:: { EventContent , EventData , EventKey , L2ToL1Payload } ;
26
28
use starknet_types_core:: felt:: Felt ;
27
29
28
- #[ cfg( feature = "block-composition" ) ]
29
- use crate :: execution:: call_info:: SyscallCount ;
30
30
use crate :: execution:: call_info:: { MessageToL1 , Retdata } ;
31
31
use crate :: execution:: common_hints:: ExecutionMode ;
32
32
use crate :: execution:: entry_point:: {
@@ -49,8 +49,7 @@ pub const CALL_CONTRACT_SELECTOR_NAME: &str = "call_contract";
49
49
pub const LIBRARY_CALL_SELECTOR_NAME : & str = "library_call" ;
50
50
51
51
#[ 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 ) ;
54
53
55
54
pub struct NativeSyscallHandler < ' state > {
56
55
pub base : Box < SyscallHandlerBase < ' state > > ,
@@ -247,7 +246,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
247
246
remaining_gas : & mut u64 ,
248
247
) -> SyscallResult < Felt > {
249
248
#[ cfg( feature = "block-composition" ) ]
250
- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
249
+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
251
250
252
251
self . pre_execute_syscall (
253
252
remaining_gas,
@@ -262,8 +261,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
262
261
263
262
fn get_execution_info ( & mut self , remaining_gas : & mut u64 ) -> SyscallResult < ExecutionInfo > {
264
263
#[ cfg( feature = "block-composition" ) ]
265
- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
266
-
264
+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
267
265
268
266
self . pre_execute_syscall (
269
267
remaining_gas,
@@ -285,7 +283,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
285
283
remaining_gas : & mut u64 ,
286
284
) -> SyscallResult < Felt > {
287
285
#[ cfg( feature = "block-composition" ) ]
288
- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
286
+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
289
287
290
288
self . pre_execute_syscall (
291
289
remaining_gas,
@@ -303,7 +301,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
303
301
304
302
fn get_execution_info_v2 ( & mut self , remaining_gas : & mut u64 ) -> SyscallResult < ExecutionInfoV2 > {
305
303
#[ cfg( feature = "block-composition" ) ]
306
- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
304
+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
307
305
308
306
self . pre_execute_syscall (
309
307
remaining_gas,
@@ -328,7 +326,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
328
326
remaining_gas : & mut u64 ,
329
327
) -> SyscallResult < ( Felt , Vec < Felt > ) > {
330
328
#[ cfg( feature = "block-composition" ) ]
331
- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
329
+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
332
330
// The cost of deploying a contract is the base cost plus the linear cost of the calldata
333
331
// len.
334
332
let total_gas_cost =
@@ -353,7 +351,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
353
351
}
354
352
fn replace_class ( & mut self , class_hash : Felt , remaining_gas : & mut u64 ) -> SyscallResult < ( ) > {
355
353
#[ cfg( feature = "block-composition" ) ]
356
- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
354
+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
357
355
self . pre_execute_syscall (
358
356
remaining_gas,
359
357
self . gas_costs ( ) . syscalls . replace_class . base_syscall_cost ( ) ,
@@ -373,7 +371,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
373
371
remaining_gas : & mut u64 ,
374
372
) -> SyscallResult < Vec < Felt > > {
375
373
#[ cfg( feature = "block-composition" ) ]
376
- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
374
+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
377
375
self . pre_execute_syscall (
378
376
remaining_gas,
379
377
self . gas_costs ( ) . syscalls . library_call . base_syscall_cost ( ) ,
@@ -419,7 +417,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
419
417
remaining_gas : & mut u64 ,
420
418
) -> SyscallResult < Vec < Felt > > {
421
419
#[ cfg( feature = "block-composition" ) ]
422
- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
420
+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
423
421
424
422
self . pre_execute_syscall (
425
423
remaining_gas,
@@ -478,7 +476,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
478
476
remaining_gas : & mut u64 ,
479
477
) -> SyscallResult < Felt > {
480
478
#[ cfg( feature = "block-composition" ) ]
481
- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
479
+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
482
480
483
481
self . pre_execute_syscall (
484
482
remaining_gas,
@@ -506,7 +504,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
506
504
remaining_gas : & mut u64 ,
507
505
) -> SyscallResult < ( ) > {
508
506
#[ cfg( feature = "block-composition" ) ]
509
- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
507
+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
510
508
511
509
self . pre_execute_syscall (
512
510
remaining_gas,
@@ -533,7 +531,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
533
531
remaining_gas : & mut u64 ,
534
532
) -> SyscallResult < ( ) > {
535
533
#[ cfg( feature = "block-composition" ) ]
536
- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
534
+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
537
535
538
536
self . pre_execute_syscall (
539
537
remaining_gas,
@@ -556,7 +554,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
556
554
remaining_gas : & mut u64 ,
557
555
) -> SyscallResult < ( ) > {
558
556
#[ cfg( feature = "block-composition" ) ]
559
- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
557
+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
560
558
561
559
self . pre_execute_syscall (
562
560
remaining_gas,
@@ -572,7 +570,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
572
570
573
571
fn keccak ( & mut self , input : & [ u64 ] , remaining_gas : & mut u64 ) -> SyscallResult < U256 > {
574
572
#[ cfg( feature = "block-composition" ) ]
575
- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
573
+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
576
574
577
575
self . pre_execute_syscall (
578
576
remaining_gas,
@@ -595,7 +593,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
595
593
remaining_gas : & mut u64 ,
596
594
) -> SyscallResult < Option < Secp256k1Point > > {
597
595
#[ cfg( feature = "block-composition" ) ]
598
- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
596
+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
599
597
600
598
self . pre_execute_syscall (
601
599
remaining_gas,
@@ -614,7 +612,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
614
612
remaining_gas : & mut u64 ,
615
613
) -> SyscallResult < Secp256k1Point > {
616
614
#[ cfg( feature = "block-composition" ) ]
617
- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
615
+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
618
616
self . pre_execute_syscall (
619
617
remaining_gas,
620
618
self . gas_costs ( ) . syscalls . secp256k1_add . base_syscall_cost ( ) ,
@@ -630,7 +628,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
630
628
remaining_gas : & mut u64 ,
631
629
) -> SyscallResult < Secp256k1Point > {
632
630
#[ cfg( feature = "block-composition" ) ]
633
- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
631
+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
634
632
635
633
self . pre_execute_syscall (
636
634
remaining_gas,
@@ -647,7 +645,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
647
645
remaining_gas : & mut u64 ,
648
646
) -> SyscallResult < Option < Secp256k1Point > > {
649
647
#[ cfg( feature = "block-composition" ) ]
650
- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
648
+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
651
649
652
650
self . pre_execute_syscall (
653
651
remaining_gas,
@@ -665,7 +663,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
665
663
remaining_gas : & mut u64 ,
666
664
) -> SyscallResult < ( U256 , U256 ) > {
667
665
#[ cfg( feature = "block-composition" ) ]
668
- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
666
+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
669
667
self . pre_execute_syscall (
670
668
remaining_gas,
671
669
self . gas_costs ( ) . syscalls . secp256k1_get_xy . base_syscall_cost ( ) ,
@@ -681,7 +679,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
681
679
remaining_gas : & mut u64 ,
682
680
) -> SyscallResult < Option < Secp256r1Point > > {
683
681
#[ cfg( feature = "block-composition" ) ]
684
- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
682
+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
685
683
686
684
self . pre_execute_syscall (
687
685
remaining_gas,
@@ -700,7 +698,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
700
698
remaining_gas : & mut u64 ,
701
699
) -> SyscallResult < Secp256r1Point > {
702
700
#[ cfg( feature = "block-composition" ) ]
703
- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
701
+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
704
702
705
703
self . pre_execute_syscall (
706
704
remaining_gas,
@@ -716,7 +714,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
716
714
remaining_gas : & mut u64 ,
717
715
) -> SyscallResult < Secp256r1Point > {
718
716
#[ cfg( feature = "block-composition" ) ]
719
- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
717
+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
720
718
721
719
self . pre_execute_syscall (
722
720
remaining_gas,
@@ -733,7 +731,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
733
731
remaining_gas : & mut u64 ,
734
732
) -> SyscallResult < Option < Secp256r1Point > > {
735
733
#[ cfg( feature = "block-composition" ) ]
736
- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
734
+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
737
735
738
736
self . pre_execute_syscall (
739
737
remaining_gas,
@@ -751,7 +749,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
751
749
remaining_gas : & mut u64 ,
752
750
) -> SyscallResult < ( U256 , U256 ) > {
753
751
#[ cfg( feature = "block-composition" ) ]
754
- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
752
+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
755
753
756
754
self . pre_execute_syscall (
757
755
remaining_gas,
@@ -768,7 +766,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
768
766
remaining_gas : & mut u64 ,
769
767
) -> SyscallResult < ( ) > {
770
768
#[ cfg( feature = "block-composition" ) ]
771
- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
769
+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
772
770
773
771
self . pre_execute_syscall (
774
772
remaining_gas,
@@ -796,7 +794,7 @@ impl StarknetSyscallHandler for &mut NativeSyscallHandler<'_> {
796
794
remaining_gas : & mut u64 ,
797
795
) -> SyscallResult < Vec < Felt > > {
798
796
#[ cfg( feature = "block-composition" ) ]
799
- SYSCALL_COUNTER . lock ( ) . unwrap ( ) . increase ( ) ;
797
+ SYSCALL_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
800
798
todo ! (
801
799
"implement meta_tx_v0 {:?}" ,
802
800
( address, entry_point_selector, calldata, signature, remaining_gas)
0 commit comments