@@ -5,7 +5,7 @@ use cairo_lib::utils::bitwise::reverse_endianness_u256;
55enum TaskStatus {
66 NONE ,
77 SCHEDULED ,
8- FINALIZED
8+ FINALIZED ,
99}
1010
1111#[derive(Drop , Serde , starknet:: Store )]
@@ -55,8 +55,9 @@ pub trait IDataProcessor<TContractState> {
5555
5656 /// Requests the execution of a task with a module
5757 fn requestDataProcessorExecutionOfTask (ref self : TContractState , module_task : ModuleTask );
58-
59- /// Authenticates the execution of a task is finalized by verifying the locally computed fact with the FactsRegistry
58+
59+ /// Authenticates the execution of a task is finalized by verifying the locally computed fact
60+ /// with the FactsRegistry
6061 fn authenticateDataProcessorTaskExecution (ref self : TContractState , task_data : TaskData );
6162
6263 /// Returns the status of a task
@@ -69,8 +70,7 @@ pub trait IDataProcessor<TContractState> {
6970#[starknet:: component]
7071pub mod data_processor_component {
7172 use crate :: {
72- state :: state_component,
73- mmr_core :: mmr_core_component :: MmrCoreExternalImpl ,
73+ state :: state_component, mmr_core :: mmr_core_component :: MmrCoreExternalImpl ,
7474 mmr_core :: POSEIDON_HASHING_FUNCTION ,
7575 cairo_fact_registry :: {cairo_fact_registry_component, ICairoFactRegistry },
7676 };
@@ -136,54 +136,69 @@ pub mod data_processor_component {
136136 > of IDataProcessor <ComponentState <TContractState >> {
137137 // ========================= Setup Functions ========================= //
138138
139- fn setDataProcessorProgramHash (ref self : ComponentState <TContractState >, program_hash : felt252 ) {
139+ fn setDataProcessorProgramHash (
140+ ref self : ComponentState <TContractState >, program_hash : felt252 ,
141+ ) {
140142 get_dep_component! (@ self , Ownable ). assert_only_owner ();
141143
142144 self . authorizedProgramHashes. entry (program_hash ). write (true );
143- self . emit (Event :: ProgramHashEnabled (ProgramHashEnabled {program_hash }))
145+ self . emit (Event :: ProgramHashEnabled (ProgramHashEnabled { program_hash }))
144146 }
145147
146- fn disableProgramHashes (ref self : ComponentState <TContractState >, program_hashes : Span <felt252 >) {
148+ fn disableProgramHashes (
149+ ref self : ComponentState <TContractState >, program_hashes : Span <felt252 >,
150+ ) {
147151 get_dep_component! (@ self , Ownable ). assert_only_owner ();
148152
149153 for program_hash in program_hashes {
150154 self . authorizedProgramHashes. entry (* program_hash ). write (false );
151155 };
152- self . emit (Event :: ProgramHashesDisabled (ProgramHashesDisabled { program_hashes }));
156+ self . emit (Event :: ProgramHashesDisabled (ProgramHashesDisabled { program_hashes }));
153157 }
154158
155- fn isProgramHashAuthorized (self : @ ComponentState <TContractState >, program_hash : felt252 ) -> bool {
159+ fn isProgramHashAuthorized (
160+ self : @ ComponentState <TContractState >, program_hash : felt252 ,
161+ ) -> bool {
156162 self . authorizedProgramHashes. entry (program_hash ). read ()
157163 }
158164
159165 // ========================= Core Functions ========================= //
160166
161- fn requestDataProcessorExecutionOfTask (ref self : ComponentState <TContractState >, module_task : ModuleTask ) {
167+ fn requestDataProcessorExecutionOfTask (
168+ ref self : ComponentState <TContractState >, module_task : ModuleTask ,
169+ ) {
162170 let mut keccak_input = array! [module_task . program_hash];
163171 for input in module_task . inputs {
164172 keccak_input . append (* input );
165173 };
166- let task_commitment = reverse_endianness_u256 (keccak_u256s_be_inputs (keccak_input . span ()));
167-
174+ let task_commitment = reverse_endianness_u256 (
175+ keccak_u256s_be_inputs (keccak_input . span ()),
176+ );
177+
168178 let cached_result = self . cachedTasksResult. entry (task_commitment );
169179 let cached_result_status = cached_result . status. read ();
170180 if cached_result_status == TaskStatus :: FINALIZED {
171- self . emit (Event :: TaskAlreadyStored (TaskAlreadyStored {task_commitment } ));
181+ self . emit (Event :: TaskAlreadyStored (TaskAlreadyStored { task_commitment } ));
172182 } else {
173183 // Ensure task is not already scheduled
174184 assert (cached_result_status == TaskStatus :: NONE , ' DOUBLE_REGISTRATION' );
175-
185+
176186 // Store the task result
177- cached_result . write (TaskResult { status : TaskStatus :: SCHEDULED , result : 0 });
178-
179- self . emit (Event :: ModuleTaskScheduled (ModuleTaskScheduled {module_task } ));
187+ cached_result . write (TaskResult { status : TaskStatus :: SCHEDULED , result : 0 });
188+
189+ self . emit (Event :: ModuleTaskScheduled (ModuleTaskScheduled { module_task } ));
180190 }
181191 }
182192
183- fn authenticateDataProcessorTaskExecution (ref self : ComponentState <TContractState >, task_data : TaskData ) {
184- let task_hash = u256 {low : task_data . task_hash_low, high : task_data . task_hash_high };
193+ fn authenticateDataProcessorTaskExecution (
194+ ref self : ComponentState <TContractState >, task_data : TaskData ,
195+ ) {
196+ let task_hash = u256 { low : task_data . task_hash_low, high : task_data . task_hash_high };
185197
186- assert (self . cachedTasksResult. entry (task_hash ). status. read () != TaskStatus :: FINALIZED , ' TaskAlreadyFinalized' );
198+ assert (
199+ self . cachedTasksResult. entry (task_hash ). status. read () != TaskStatus :: FINALIZED ,
200+ ' TaskAlreadyFinalized' ,
201+ );
187202
188203 assert (self . isProgramHashAuthorized (task_data . program_hash), ' UnauthorizedProgramHash' );
189204
@@ -200,7 +215,14 @@ pub mod data_processor_component {
200215
201216 let state = get_dep_component! (@ self , State );
202217 for mmr in task_data . mmr_data {
203- let mmr_root = state . mmrs. entry (* mmr . chain_id). entry (* mmr . mmr_id). entry (POSEIDON_HASHING_FUNCTION ). mmr_size_to_root. entry (* mmr . mmr_size). read ();
218+ let mmr_root = state
219+ . mmrs
220+ . entry (* mmr . chain_id)
221+ . entry (* mmr . mmr_id)
222+ . entry (POSEIDON_HASHING_FUNCTION )
223+ . mmr_size_to_root
224+ . entry (* mmr . mmr_size)
225+ . read ();
204226 assert (mmr_root != 0 , ' InvalidMmrRoot' );
205227 program_output . append ((* mmr . mmr_id). try_into (). expect (' mmr_id not felt252' ));
206228 program_output . append ((* mmr . mmr_size). try_into (). expect (' mmr_size not felt252' ));
@@ -213,18 +235,27 @@ pub mod data_processor_component {
213235 let cairo_fact_registry = get_dep_component! (@ self , CairoFactRegistry );
214236 assert (cairo_fact_registry . isCairoFactValidForInternal (fact_hash ), ' Invalid fact' );
215237
216- let task_result = u256 {low : task_data . task_result_low, high : task_data . task_result_high};
238+ let task_result = u256 {
239+ low : task_data . task_result_low, high : task_data . task_result_high,
240+ };
217241
218242 // Store the task result
219- self . cachedTasksResult. entry (task_hash ). write (TaskResult {status : TaskStatus :: FINALIZED , result : task_result });
220- self . emit (Event :: TaskFinalized (TaskFinalized {task_hash , task_result }));
243+ self
244+ . cachedTasksResult
245+ . entry (task_hash )
246+ . write (TaskResult { status : TaskStatus :: FINALIZED , result : task_result });
247+ self . emit (Event :: TaskFinalized (TaskFinalized { task_hash , task_result }));
221248 }
222249
223- fn getDataProcessorTaskStatus (self : @ ComponentState <TContractState >, task_commitment : u256 ) -> TaskStatus {
250+ fn getDataProcessorTaskStatus (
251+ self : @ ComponentState <TContractState >, task_commitment : u256 ,
252+ ) -> TaskStatus {
224253 self . cachedTasksResult. entry (task_commitment ). status. read ()
225254 }
226255
227- fn getDataProcessorFinalizedTaskResult (self : @ ComponentState <TContractState >, task_commitment : u256 ) -> u256 {
256+ fn getDataProcessorFinalizedTaskResult (
257+ self : @ ComponentState <TContractState >, task_commitment : u256 ,
258+ ) -> u256 {
228259 let task_result = self . cachedTasksResult. entry (task_commitment ). read ();
229260
230261 // Ensure task is finalized
0 commit comments