@@ -22,7 +22,7 @@ pub trait EvmcVm {
22
22
/// This is called for every incoming message.
23
23
fn execute < ' a > (
24
24
& self ,
25
- revision : ffi :: evmc_revision ,
25
+ revision : Revision ,
26
26
code : & ' a [ u8 ] ,
27
27
message : & ' a ExecutionMessage ,
28
28
context : Option < & ' a mut ExecutionContext < ' a > > ,
@@ -32,7 +32,7 @@ pub trait EvmcVm {
32
32
/// EVMC result structure.
33
33
#[ derive( Debug ) ]
34
34
pub struct ExecutionResult {
35
- status_code : ffi :: evmc_status_code ,
35
+ status_code : StatusCode ,
36
36
gas_left : i64 ,
37
37
output : Option < Vec < u8 > > ,
38
38
create_address : Option < Address > ,
@@ -41,7 +41,7 @@ pub struct ExecutionResult {
41
41
/// EVMC execution message structure.
42
42
#[ derive( Debug ) ]
43
43
pub struct ExecutionMessage {
44
- kind : ffi :: evmc_call_kind ,
44
+ kind : MessageKind ,
45
45
flags : u32 ,
46
46
depth : i32 ,
47
47
gas : i64 ,
@@ -65,11 +65,7 @@ pub struct ExecutionContext<'a> {
65
65
66
66
impl ExecutionResult {
67
67
/// Manually create a result.
68
- pub fn new (
69
- _status_code : ffi:: evmc_status_code ,
70
- _gas_left : i64 ,
71
- _output : Option < & [ u8 ] > ,
72
- ) -> Self {
68
+ pub fn new ( _status_code : StatusCode , _gas_left : i64 , _output : Option < & [ u8 ] > ) -> Self {
73
69
ExecutionResult {
74
70
status_code : _status_code,
75
71
gas_left : _gas_left,
@@ -84,21 +80,21 @@ impl ExecutionResult {
84
80
85
81
/// Create failure result.
86
82
pub fn failure ( ) -> Self {
87
- ExecutionResult :: new ( ffi :: evmc_status_code :: EVMC_FAILURE , 0 , None )
83
+ ExecutionResult :: new ( StatusCode :: EVMC_FAILURE , 0 , None )
88
84
}
89
85
90
86
/// Create a revert result.
91
87
pub fn revert ( _gas_left : i64 , _output : Option < & [ u8 ] > ) -> Self {
92
- ExecutionResult :: new ( ffi :: evmc_status_code :: EVMC_REVERT , _gas_left, _output)
88
+ ExecutionResult :: new ( StatusCode :: EVMC_REVERT , _gas_left, _output)
93
89
}
94
90
95
91
/// Create a successful result.
96
92
pub fn success ( _gas_left : i64 , _output : Option < & [ u8 ] > ) -> Self {
97
- ExecutionResult :: new ( ffi :: evmc_status_code :: EVMC_SUCCESS , _gas_left, _output)
93
+ ExecutionResult :: new ( StatusCode :: EVMC_SUCCESS , _gas_left, _output)
98
94
}
99
95
100
96
/// Read the status code.
101
- pub fn status_code ( & self ) -> ffi :: evmc_status_code {
97
+ pub fn status_code ( & self ) -> StatusCode {
102
98
self . status_code
103
99
}
104
100
@@ -121,7 +117,7 @@ impl ExecutionResult {
121
117
122
118
impl ExecutionMessage {
123
119
pub fn new (
124
- kind : ffi :: evmc_call_kind ,
120
+ kind : MessageKind ,
125
121
flags : u32 ,
126
122
depth : i32 ,
127
123
gas : i64 ,
@@ -149,7 +145,7 @@ impl ExecutionMessage {
149
145
}
150
146
151
147
/// Read the message kind.
152
- pub fn kind ( & self ) -> ffi :: evmc_call_kind {
148
+ pub fn kind ( & self ) -> MessageKind {
153
149
self . kind
154
150
}
155
151
@@ -239,7 +235,7 @@ impl<'a> ExecutionContext<'a> {
239
235
address : & Address ,
240
236
key : & Bytes32 ,
241
237
value : & Bytes32 ,
242
- ) -> ffi :: evmc_storage_status {
238
+ ) -> StorageStatus {
243
239
unsafe {
244
240
assert ! ( ( * self . host) . set_storage. is_some( ) ) ;
245
241
( * self . host ) . set_storage . unwrap ( ) (
@@ -501,9 +497,9 @@ mod tests {
501
497
502
498
#[ test]
503
499
fn result_new ( ) {
504
- let r = ExecutionResult :: new ( ffi :: evmc_status_code :: EVMC_FAILURE , 420 , None ) ;
500
+ let r = ExecutionResult :: new ( StatusCode :: EVMC_FAILURE , 420 , None ) ;
505
501
506
- assert ! ( r. status_code( ) == ffi :: evmc_status_code :: EVMC_FAILURE ) ;
502
+ assert ! ( r. status_code( ) == StatusCode :: EVMC_FAILURE ) ;
507
503
assert ! ( r. gas_left( ) == 420 ) ;
508
504
assert ! ( r. output( ) . is_none( ) ) ;
509
505
assert ! ( r. create_address( ) . is_none( ) ) ;
@@ -526,7 +522,7 @@ mod tests {
526
522
#[ test]
527
523
fn result_from_ffi ( ) {
528
524
let f = ffi:: evmc_result {
529
- status_code : ffi :: evmc_status_code :: EVMC_SUCCESS ,
525
+ status_code : StatusCode :: EVMC_SUCCESS ,
530
526
gas_left : 1337 ,
531
527
output_data : Box :: into_raw ( Box :: new ( [ 0xde , 0xad , 0xbe , 0xef ] ) ) as * const u8 ,
532
528
output_size : 4 ,
@@ -537,7 +533,7 @@ mod tests {
537
533
538
534
let r: ExecutionResult = f. into ( ) ;
539
535
540
- assert ! ( r. status_code( ) == ffi :: evmc_status_code :: EVMC_SUCCESS ) ;
536
+ assert ! ( r. status_code( ) == StatusCode :: EVMC_SUCCESS ) ;
541
537
assert ! ( r. gas_left( ) == 1337 ) ;
542
538
assert ! ( r. output( ) . is_some( ) ) ;
543
539
assert ! ( r. output( ) . unwrap( ) . len( ) == 4 ) ;
@@ -547,15 +543,15 @@ mod tests {
547
543
#[ test]
548
544
fn result_into_heap_ffi ( ) {
549
545
let r = ExecutionResult :: new (
550
- ffi :: evmc_status_code :: EVMC_FAILURE ,
546
+ StatusCode :: EVMC_FAILURE ,
551
547
420 ,
552
548
Some ( & [ 0xc0 , 0xff , 0xee , 0x71 , 0x75 ] ) ,
553
549
) ;
554
550
555
551
let f: * const ffi:: evmc_result = r. into ( ) ;
556
552
assert ! ( !f. is_null( ) ) ;
557
553
unsafe {
558
- assert ! ( ( * f) . status_code == ffi :: evmc_status_code :: EVMC_FAILURE ) ;
554
+ assert ! ( ( * f) . status_code == StatusCode :: EVMC_FAILURE ) ;
559
555
assert ! ( ( * f) . gas_left == 420 ) ;
560
556
assert ! ( !( * f) . output_data. is_null( ) ) ;
561
557
assert ! ( ( * f) . output_size == 5 ) ;
@@ -572,12 +568,12 @@ mod tests {
572
568
573
569
#[ test]
574
570
fn result_into_heap_ffi_empty_data ( ) {
575
- let r = ExecutionResult :: new ( ffi :: evmc_status_code :: EVMC_FAILURE , 420 , None ) ;
571
+ let r = ExecutionResult :: new ( StatusCode :: EVMC_FAILURE , 420 , None ) ;
576
572
577
573
let f: * const ffi:: evmc_result = r. into ( ) ;
578
574
assert ! ( !f. is_null( ) ) ;
579
575
unsafe {
580
- assert ! ( ( * f) . status_code == ffi :: evmc_status_code :: EVMC_FAILURE ) ;
576
+ assert ! ( ( * f) . status_code == StatusCode :: EVMC_FAILURE ) ;
581
577
assert ! ( ( * f) . gas_left == 420 ) ;
582
578
assert ! ( ( * f) . output_data. is_null( ) ) ;
583
579
assert ! ( ( * f) . output_size == 0 ) ;
@@ -591,14 +587,14 @@ mod tests {
591
587
#[ test]
592
588
fn result_into_stack_ffi ( ) {
593
589
let r = ExecutionResult :: new (
594
- ffi :: evmc_status_code :: EVMC_FAILURE ,
590
+ StatusCode :: EVMC_FAILURE ,
595
591
420 ,
596
592
Some ( & [ 0xc0 , 0xff , 0xee , 0x71 , 0x75 ] ) ,
597
593
) ;
598
594
599
595
let f: ffi:: evmc_result = r. into ( ) ;
600
596
unsafe {
601
- assert ! ( f. status_code == ffi :: evmc_status_code :: EVMC_FAILURE ) ;
597
+ assert ! ( f. status_code == StatusCode :: EVMC_FAILURE ) ;
602
598
assert ! ( f. gas_left == 420 ) ;
603
599
assert ! ( !f. output_data. is_null( ) ) ;
604
600
assert ! ( f. output_size == 5 ) ;
@@ -615,11 +611,11 @@ mod tests {
615
611
616
612
#[ test]
617
613
fn result_into_stack_ffi_empty_data ( ) {
618
- let r = ExecutionResult :: new ( ffi :: evmc_status_code :: EVMC_FAILURE , 420 , None ) ;
614
+ let r = ExecutionResult :: new ( StatusCode :: EVMC_FAILURE , 420 , None ) ;
619
615
620
616
let f: ffi:: evmc_result = r. into ( ) ;
621
617
unsafe {
622
- assert ! ( f. status_code == ffi :: evmc_status_code :: EVMC_FAILURE ) ;
618
+ assert ! ( f. status_code == StatusCode :: EVMC_FAILURE ) ;
623
619
assert ! ( f. gas_left == 420 ) ;
624
620
assert ! ( f. output_data. is_null( ) ) ;
625
621
assert ! ( f. output_size == 0 ) ;
@@ -639,7 +635,7 @@ mod tests {
639
635
let create2_salt = Bytes32 { bytes : [ 255u8 ; 32 ] } ;
640
636
641
637
let ret = ExecutionMessage :: new (
642
- ffi :: evmc_call_kind :: EVMC_CALL ,
638
+ MessageKind :: EVMC_CALL ,
643
639
44 ,
644
640
66 ,
645
641
4466 ,
@@ -650,7 +646,7 @@ mod tests {
650
646
create2_salt,
651
647
) ;
652
648
653
- assert_eq ! ( ret. kind( ) , ffi :: evmc_call_kind :: EVMC_CALL ) ;
649
+ assert_eq ! ( ret. kind( ) , MessageKind :: EVMC_CALL ) ;
654
650
assert_eq ! ( ret. flags( ) , 44 ) ;
655
651
assert_eq ! ( ret. depth( ) , 66 ) ;
656
652
assert_eq ! ( ret. gas( ) , 4466 ) ;
@@ -670,7 +666,7 @@ mod tests {
670
666
let create2_salt = Bytes32 { bytes : [ 255u8 ; 32 ] } ;
671
667
672
668
let msg = ffi:: evmc_message {
673
- kind : ffi :: evmc_call_kind :: EVMC_CALL ,
669
+ kind : MessageKind :: EVMC_CALL ,
674
670
flags : 44 ,
675
671
depth : 66 ,
676
672
gas : 4466 ,
@@ -704,7 +700,7 @@ mod tests {
704
700
let create2_salt = Bytes32 { bytes : [ 255u8 ; 32 ] } ;
705
701
706
702
let msg = ffi:: evmc_message {
707
- kind : ffi :: evmc_call_kind :: EVMC_CALL ,
703
+ kind : MessageKind :: EVMC_CALL ,
708
704
flags : 44 ,
709
705
depth : 66 ,
710
706
gas : 4466 ,
@@ -768,16 +764,16 @@ mod tests {
768
764
769
765
ffi:: evmc_result {
770
766
status_code : if success {
771
- ffi :: evmc_status_code :: EVMC_SUCCESS
767
+ StatusCode :: EVMC_SUCCESS
772
768
} else {
773
- ffi :: evmc_status_code :: EVMC_INTERNAL_ERROR
769
+ StatusCode :: EVMC_INTERNAL_ERROR
774
770
} ,
775
771
gas_left : 2 ,
776
772
// NOTE: we are passing the input pointer here, but for testing the lifetime is ok
777
773
output_data : msg. input_data ,
778
774
output_size : msg. input_size ,
779
775
release : None ,
780
- create_address : ffi :: evmc_address :: default ( ) ,
776
+ create_address : Address :: default ( ) ,
781
777
padding : [ 0u8 ; 4 ] ,
782
778
}
783
779
}
@@ -832,61 +828,61 @@ mod tests {
832
828
#[ test]
833
829
fn test_call_empty_data ( ) {
834
830
// This address is useless. Just a dummy parameter for the interface function.
835
- let test_addr = ffi :: evmc_address { bytes : [ 0u8 ; 20 ] } ;
831
+ let test_addr = Address :: default ( ) ;
836
832
let host = get_dummy_host_interface ( ) ;
837
833
let host_context = std:: ptr:: null_mut ( ) ;
838
834
let mut exe_context = ExecutionContext :: new ( & host, host_context) ;
839
835
840
836
let message = ExecutionMessage :: new (
841
- ffi :: evmc_call_kind :: EVMC_CALL ,
837
+ MessageKind :: EVMC_CALL ,
842
838
0 ,
843
839
0 ,
844
840
6566 ,
845
841
test_addr,
846
842
test_addr,
847
843
None ,
848
- ffi :: evmc_uint256be :: default ( ) ,
849
- ffi :: evmc_bytes32 :: default ( ) ,
844
+ Uint256 :: default ( ) ,
845
+ Bytes32 :: default ( ) ,
850
846
) ;
851
847
852
848
let b = exe_context. call ( & message) ;
853
849
854
- assert_eq ! ( b. status_code( ) , ffi :: evmc_status_code :: EVMC_SUCCESS ) ;
850
+ assert_eq ! ( b. status_code( ) , StatusCode :: EVMC_SUCCESS ) ;
855
851
assert_eq ! ( b. gas_left( ) , 2 ) ;
856
852
assert ! ( b. output( ) . is_none( ) ) ;
857
853
assert ! ( b. create_address( ) . is_some( ) ) ;
858
- assert_eq ! ( b. create_address( ) . unwrap( ) , & ffi :: evmc_address :: default ( ) ) ;
854
+ assert_eq ! ( b. create_address( ) . unwrap( ) , & Address :: default ( ) ) ;
859
855
}
860
856
861
857
#[ test]
862
858
fn test_call_with_data ( ) {
863
859
// This address is useless. Just a dummy parameter for the interface function.
864
- let test_addr = ffi :: evmc_address { bytes : [ 0u8 ; 20 ] } ;
860
+ let test_addr = Address :: default ( ) ;
865
861
let host = get_dummy_host_interface ( ) ;
866
862
let host_context = std:: ptr:: null_mut ( ) ;
867
863
let mut exe_context = ExecutionContext :: new ( & host, host_context) ;
868
864
869
865
let data = vec ! [ 0xc0 , 0xff , 0xfe ] ;
870
866
871
867
let message = ExecutionMessage :: new (
872
- ffi :: evmc_call_kind :: EVMC_CALL ,
868
+ MessageKind :: EVMC_CALL ,
873
869
0 ,
874
870
0 ,
875
871
6566 ,
876
872
test_addr,
877
873
test_addr,
878
874
Some ( & data) ,
879
- ffi :: evmc_uint256be :: default ( ) ,
880
- ffi :: evmc_bytes32 :: default ( ) ,
875
+ Uint256 :: default ( ) ,
876
+ Bytes32 :: default ( ) ,
881
877
) ;
882
878
883
879
let b = exe_context. call ( & message) ;
884
880
885
- assert_eq ! ( b. status_code( ) , ffi :: evmc_status_code :: EVMC_SUCCESS ) ;
881
+ assert_eq ! ( b. status_code( ) , StatusCode :: EVMC_SUCCESS ) ;
886
882
assert_eq ! ( b. gas_left( ) , 2 ) ;
887
883
assert ! ( b. output( ) . is_some( ) ) ;
888
884
assert_eq ! ( b. output( ) . unwrap( ) , & data) ;
889
885
assert ! ( b. create_address( ) . is_some( ) ) ;
890
- assert_eq ! ( b. create_address( ) . unwrap( ) , & ffi :: evmc_address :: default ( ) ) ;
886
+ assert_eq ! ( b. create_address( ) . unwrap( ) , & Address :: default ( ) ) ;
891
887
}
892
888
}
0 commit comments