11//! Module containing the fault proof test fixture.
22
3- use alloy_primitives:: { BlockHash , BlockNumber , Bytes , ChainId , B256 , U256 } ;
3+ use alloy_primitives:: { BlockHash , BlockNumber , Bytes , B256 } ;
4+ use hashbrown:: HashMap ;
5+ use kona_derive:: types:: RollupConfig ;
46use serde:: { Deserialize , Serialize } ;
57use serde_repr:: { Deserialize_repr , Serialize_repr } ;
6- use hashbrown:: HashMap ;
78
89/// The fault proof fixture is the top-level object that contains
910/// everything needed to run a fault proof test.
1011#[ derive( Serialize , Deserialize , Debug , Default , PartialEq , Eq ) ]
1112#[ serde( rename_all = "camelCase" ) ]
1213pub struct FaultProofFixture {
13- /// The inputs to the fault proof test.
14- pub inputs : FaultProofInputs ,
15- /// The expected status of the fault proof test.
16- pub expected_status : FaultProofStatus ,
17- /// The witness data for the fault proof test.
18- pub witness_data : HashMap < U256 , Bytes > ,
14+ /// The inputs to the fault proof test.
15+ pub inputs : FaultProofInputs ,
16+ /// The expected status of the fault proof test.
17+ pub expected_status : FaultProofStatus ,
18+ /// The witness data for the fault proof test.
19+ pub witness_data : HashMap < B256 , Bytes > ,
1920}
2021
2122/// The fault proof inputs are the inputs to the fault proof test.
2223#[ derive( Serialize , Deserialize , Debug , Default , PartialEq , Eq ) ]
2324#[ serde( rename_all = "camelCase" ) ]
2425pub struct FaultProofInputs {
25- /// The L1 head block hash.
26- pub l1_head : BlockHash ,
27- /// The L2 head block hash.
28- pub l2_head : BlockHash ,
29- /// The claimed L2 output root to validate.
30- pub l2_claim : B256 ,
31- /// The agreed L2 output root to start derivation from.
32- pub l2_output_root : B256 ,
33- /// The L2 block number that the claim is from.
34- pub l2_block_number : BlockNumber ,
35- /// The L2 chain ID that the claim is from .
36- pub l2_chain_id : ChainId ,
26+ /// The L1 head block hash.
27+ pub l1_head : BlockHash ,
28+ /// The L2 head block hash.
29+ pub l2_head : BlockHash ,
30+ /// The claimed L2 output root to validate.
31+ pub l2_claim : B256 ,
32+ /// The agreed L2 output root to start derivation from.
33+ pub l2_output_root : B256 ,
34+ /// The L2 block number that the claim is from.
35+ pub l2_block_number : BlockNumber ,
36+ /// The configuration of the l2 chain .
37+ pub rollup_config : RollupConfig ,
3738}
3839
3940/// The fault proof status is the result of executing the fault proof program.
4041#[ derive( Serialize_repr , Deserialize_repr , Debug , Default , PartialEq , Eq ) ]
4142#[ repr( u8 ) ]
4243pub enum FaultProofStatus {
43- /// The claim is valid.
44- #[ default]
45- Valid = 0 ,
46- /// The claim is invalid.
47- Invalid = 1 ,
48- /// Executing the program resulted in a panic.
49- Panic = 2 ,
50- /// The program has not exited.
51- Unfinished = 3 ,
52- /// The status is unknown.
53- Unknown
44+ /// The claim is valid.
45+ #[ default]
46+ Valid = 0 ,
47+ /// The claim is invalid.
48+ Invalid = 1 ,
49+ /// Executing the program resulted in a panic.
50+ Panic = 2 ,
51+ /// The program has not exited.
52+ Unfinished = 3 ,
53+ /// The status is unknown.
54+ Unknown ,
5455}
5556
5657#[ cfg( test) ]
5758mod tests {
58- use super :: * ;
59+ use kona_derive:: types:: BASE_MAINNET_CONFIG ;
60+
61+ use super :: * ;
5962
60- #[ test]
61- fn test_serialize_fault_proof_status ( ) {
62- let statuses = vec ! [
63- FaultProofStatus :: Valid ,
64- FaultProofStatus :: Invalid ,
65- FaultProofStatus :: Panic ,
66- FaultProofStatus :: Unfinished ,
67- FaultProofStatus :: Unknown ,
68- ] ;
63+ #[ test]
64+ fn test_serialize_fault_proof_status ( ) {
65+ let statuses = vec ! [
66+ FaultProofStatus :: Valid ,
67+ FaultProofStatus :: Invalid ,
68+ FaultProofStatus :: Panic ,
69+ FaultProofStatus :: Unfinished ,
70+ FaultProofStatus :: Unknown ,
71+ ] ;
6972
70- for status in statuses {
71- let serialized_status = serde_json:: to_string ( & status) . expect ( "failed to serialize status" ) ;
72- let deserialized_status = serde_json:: from_str :: < FaultProofStatus > ( & serialized_status)
73- . expect ( "failed to deserialize status" ) ;
74- assert_eq ! ( status, deserialized_status) ;
73+ for status in statuses {
74+ let serialized_status =
75+ serde_json:: to_string ( & status) . expect ( "failed to serialize status" ) ;
76+ let deserialized_status = serde_json:: from_str :: < FaultProofStatus > ( & serialized_status)
77+ . expect ( "failed to deserialize status" ) ;
78+ assert_eq ! ( status, deserialized_status) ;
79+ }
7580 }
76- }
7781
78- #[ test]
79- fn test_serialize_fault_proof_inputs ( ) {
80- let inputs = FaultProofInputs {
81- l1_head : B256 :: from ( [ 1 ; 32 ] ) ,
82- l2_head : B256 :: from ( [ 2 ; 32 ] ) ,
83- l2_claim : B256 :: from ( [ 3 ; 32 ] ) ,
84- l2_output_root : B256 :: from ( [ 4 ; 32 ] ) ,
85- l2_block_number : 1337 ,
86- l2_chain_id : 42 ,
87- } ;
82+ #[ test]
83+ fn test_serialize_fault_proof_inputs ( ) {
84+ let inputs = FaultProofInputs {
85+ l1_head : B256 :: from ( [ 1 ; 32 ] ) ,
86+ l2_head : B256 :: from ( [ 2 ; 32 ] ) ,
87+ l2_claim : B256 :: from ( [ 3 ; 32 ] ) ,
88+ l2_output_root : B256 :: from ( [ 4 ; 32 ] ) ,
89+ l2_block_number : 1337 ,
90+ rollup_config : BASE_MAINNET_CONFIG ,
91+ } ;
8892
89- let serialized_inputs = serde_json:: to_string ( & inputs) . expect ( "failed to serialize inputs" ) ;
90- let deserialized_inputs = serde_json:: from_str :: < FaultProofInputs > ( & serialized_inputs)
91- . expect ( "failed to deserialize inputs" ) ;
92- assert_eq ! ( inputs, deserialized_inputs) ;
93- }
93+ let serialized_inputs = serde_json:: to_string ( & inputs) . expect ( "failed to serialize inputs" ) ;
94+ let deserialized_inputs = serde_json:: from_str :: < FaultProofInputs > ( & serialized_inputs)
95+ . expect ( "failed to deserialize inputs" ) ;
96+ assert_eq ! ( inputs, deserialized_inputs) ;
97+ }
9498
95- #[ test]
96- fn test_serialize_fault_proof_fixture ( ) {
97- let mut witness_data = HashMap :: new ( ) ;
98- witness_data. insert ( U256 :: from ( 1 ) , Bytes :: from ( [ 1 ; 32 ] ) ) ;
99- witness_data. insert ( U256 :: from ( 2 ) , Bytes :: from ( [ 2 ; 32 ] ) ) ;
99+ #[ test]
100+ fn test_serialize_fault_proof_fixture ( ) {
101+ let mut witness_data = HashMap :: new ( ) ;
102+ witness_data. insert ( B256 :: random ( ) , Bytes :: from ( [ 1 ; 32 ] ) ) ;
103+ witness_data. insert ( B256 :: random ( ) , Bytes :: from ( [ 2 ; 32 ] ) ) ;
100104
101- let fixture = FaultProofFixture {
102- inputs : FaultProofInputs {
103- l1_head : B256 :: from ( [ 1 ; 32 ] ) ,
104- l2_head : B256 :: from ( [ 2 ; 32 ] ) ,
105- l2_claim : B256 :: from ( [ 3 ; 32 ] ) ,
106- l2_output_root : B256 :: from ( [ 4 ; 32 ] ) ,
107- l2_block_number : 1337 ,
108- l2_chain_id : 42 ,
109- } ,
110- expected_status : FaultProofStatus :: Valid ,
111- witness_data : witness_data,
112- } ;
105+ let fixture = FaultProofFixture {
106+ inputs : FaultProofInputs {
107+ l1_head : B256 :: from ( [ 1 ; 32 ] ) ,
108+ l2_head : B256 :: from ( [ 2 ; 32 ] ) ,
109+ l2_claim : B256 :: from ( [ 3 ; 32 ] ) ,
110+ l2_output_root : B256 :: from ( [ 4 ; 32 ] ) ,
111+ l2_block_number : 1337 ,
112+ rollup_config : BASE_MAINNET_CONFIG ,
113+ } ,
114+ expected_status : FaultProofStatus :: Valid ,
115+ witness_data : witness_data,
116+ } ;
113117
114- let serialized_fixture = serde_json:: to_string ( & fixture) . expect ( "failed to serialize fixture" ) ;
115- let deserialized_fixture = serde_json:: from_str :: < FaultProofFixture > ( & serialized_fixture)
116- . expect ( "failed to deserialize fixture" ) ;
117- assert_eq ! ( fixture, deserialized_fixture) ;
118- }
119- }
118+ let serialized_fixture =
119+ serde_json:: to_string ( & fixture) . expect ( "failed to serialize fixture" ) ;
120+ let deserialized_fixture = serde_json:: from_str :: < FaultProofFixture > ( & serialized_fixture)
121+ . expect ( "failed to deserialize fixture" ) ;
122+ assert_eq ! ( fixture, deserialized_fixture) ;
123+ }
124+ }
0 commit comments