@@ -374,9 +374,13 @@ where
374374 }
375375 . abi_encode ( ) ;
376376 let SimulationSuccessResult { output, .. } =
377- self . simulate_call ( contract_address, calldata. into ( ) , None , ctx, evm) ?;
378- U256 :: abi_decode ( & output)
379- . map_err ( |_| BuilderTransactionError :: InvalidContract ( contract_address) )
377+ self . simulate_flashtestation_call ( contract_address, calldata, None , ctx, evm) ?;
378+ U256 :: abi_decode ( & output) . map_err ( |_| {
379+ BuilderTransactionError :: InvalidContract (
380+ contract_address,
381+ InvalidContractDataError :: OutputAbiDecodeError ,
382+ )
383+ } )
380384 }
381385
382386 fn registration_permit_signature (
@@ -396,28 +400,36 @@ where
396400 deadline : U256 :: from ( ctx. timestamp ( ) ) ,
397401 }
398402 . abi_encode ( ) ;
399- let SimulationSuccessResult { output, .. } = self . simulate_call (
403+ let SimulationSuccessResult { output, .. } = self . simulate_flashtestation_call (
400404 self . registry_address ,
401- struct_hash_calldata. into ( ) ,
405+ struct_hash_calldata,
402406 None ,
403407 ctx,
404408 evm,
405409 ) ?;
406- let struct_hash = B256 :: abi_decode ( & output)
407- . map_err ( |_| BuilderTransactionError :: InvalidContract ( self . registry_address ) ) ?;
410+ let struct_hash = B256 :: abi_decode ( & output) . map_err ( |_| {
411+ BuilderTransactionError :: InvalidContract (
412+ self . registry_address ,
413+ InvalidContractDataError :: OutputAbiDecodeError ,
414+ )
415+ } ) ?;
408416 let typed_data_hash_calldata = IFlashtestationRegistry :: hashTypedDataV4Call {
409417 structHash : struct_hash,
410418 }
411419 . abi_encode ( ) ;
412- let SimulationSuccessResult { output, .. } = self . simulate_call (
420+ let SimulationSuccessResult { output, .. } = self . simulate_flashtestation_call (
413421 self . registry_address ,
414- typed_data_hash_calldata. into ( ) ,
422+ typed_data_hash_calldata,
415423 None ,
416424 ctx,
417425 evm,
418426 ) ?;
419- let typed_data_hash = B256 :: abi_decode ( & output)
420- . map_err ( |_| BuilderTransactionError :: InvalidContract ( self . registry_address ) ) ?;
427+ let typed_data_hash = B256 :: abi_decode ( & output) . map_err ( |_| {
428+ BuilderTransactionError :: InvalidContract (
429+ self . registry_address ,
430+ InvalidContractDataError :: OutputAbiDecodeError ,
431+ )
432+ } ) ?;
421433 let signature = self . tee_service_signer . sign_message ( typed_data_hash) ?;
422434 Ok ( signature)
423435 }
@@ -441,17 +453,17 @@ where
441453 signature : signature. as_bytes ( ) . into ( ) ,
442454 }
443455 . abi_encode ( ) ;
444- let SimulationSuccessResult { gas_used, .. } = self . simulate_call (
456+ let SimulationSuccessResult { gas_used, .. } = self . simulate_flashtestation_call (
445457 self . registry_address ,
446- calldata. clone ( ) . into ( ) ,
458+ calldata. clone ( ) ,
447459 Some ( TEEServiceRegistered :: SIGNATURE_HASH ) ,
448460 ctx,
449461 evm,
450462 ) ?;
451463 let signed_tx = self . sign_tx (
452464 self . registry_address ,
453- self . builder_key ,
454- gas_used,
465+ self . builder_signer ,
466+ Some ( gas_used) ,
455467 calldata. into ( ) ,
456468 ctx,
457469 evm. db_mut ( ) ,
@@ -483,28 +495,36 @@ where
483495 nonce : permit_nonce,
484496 }
485497 . abi_encode ( ) ;
486- let SimulationSuccessResult { output, .. } = self . simulate_call (
498+ let SimulationSuccessResult { output, .. } = self . simulate_flashtestation_call (
487499 self . builder_policy_address ,
488- struct_hash_calldata. into ( ) ,
500+ struct_hash_calldata,
489501 None ,
490502 ctx,
491503 evm,
492504 ) ?;
493- let struct_hash = B256 :: abi_decode ( & output)
494- . map_err ( |_| BuilderTransactionError :: InvalidContract ( self . builder_policy_address ) ) ?;
505+ let struct_hash = B256 :: abi_decode ( & output) . map_err ( |_| {
506+ BuilderTransactionError :: InvalidContract (
507+ self . builder_policy_address ,
508+ InvalidContractDataError :: OutputAbiDecodeError ,
509+ )
510+ } ) ?;
495511 let typed_data_hash_calldata = IBlockBuilderPolicy :: getHashedTypeDataV4Call {
496512 structHash : struct_hash,
497513 }
498514 . abi_encode ( ) ;
499- let SimulationSuccessResult { output, .. } = self . simulate_call (
515+ let SimulationSuccessResult { output, .. } = self . simulate_flashtestation_call (
500516 self . builder_policy_address ,
501- typed_data_hash_calldata. into ( ) ,
517+ typed_data_hash_calldata,
502518 None ,
503519 ctx,
504520 evm,
505521 ) ?;
506- let typed_data_hash = B256 :: abi_decode ( & output)
507- . map_err ( |_| BuilderTransactionError :: InvalidContract ( self . builder_policy_address ) ) ?;
522+ let typed_data_hash = B256 :: abi_decode ( & output) . map_err ( |_| {
523+ BuilderTransactionError :: InvalidContract (
524+ self . builder_policy_address ,
525+ InvalidContractDataError :: OutputAbiDecodeError ,
526+ )
527+ } ) ?;
508528 let signature = self . tee_service_signer . sign_message ( typed_data_hash) ?;
509529 Ok ( signature)
510530 }
@@ -535,17 +555,17 @@ where
535555 eip712Sig : signature. as_bytes ( ) . into ( ) ,
536556 }
537557 . abi_encode ( ) ;
538- let SimulationSuccessResult { gas_used, .. } = self . simulate_call (
558+ let SimulationSuccessResult { gas_used, .. } = self . simulate_flashtestation_call (
539559 self . builder_policy_address ,
540- calldata. clone ( ) . into ( ) ,
560+ calldata. clone ( ) ,
541561 Some ( BlockBuilderProofVerified :: SIGNATURE_HASH ) ,
542562 ctx,
543563 evm,
544564 ) ?;
545565 let signed_tx = self . sign_tx (
546566 self . builder_policy_address ,
547- self . builder_key ,
548- gas_used,
567+ self . builder_signer ,
568+ Some ( gas_used) ,
549569 calldata. into ( ) ,
550570 ctx,
551571 evm. db_mut ( ) ,
@@ -559,6 +579,54 @@ where
559579 is_top_of_block : false ,
560580 } )
561581 }
582+
583+ fn simulate_flashtestation_call (
584+ & self ,
585+ contract_address : Address ,
586+ calldata : Vec < u8 > ,
587+ expected_topic : Option < B256 > ,
588+ ctx : & OpPayloadBuilderCtx < ExtraCtx > ,
589+ evm : & mut OpEvm <
590+ & mut State < StateProviderDatabase < impl StateProvider > > ,
591+ NoOpInspector ,
592+ PrecompilesMap ,
593+ > ,
594+ ) -> Result < SimulationSuccessResult , BuilderTransactionError > {
595+ let signed_tx = self . sign_tx (
596+ contract_address,
597+ self . builder_signer ,
598+ None ,
599+ calldata. into ( ) ,
600+ ctx,
601+ evm. db_mut ( ) ,
602+ ) ?;
603+ let revert_handler = if contract_address == self . registry_address {
604+ Self :: handle_registry_reverts
605+ } else {
606+ Self :: handle_block_builder_policy_reverts
607+ } ;
608+ self . simulate_call ( signed_tx, expected_topic, revert_handler, evm)
609+ }
610+
611+ fn handle_registry_reverts ( revert_output : Bytes ) -> BuilderTransactionError {
612+ let revert_reason =
613+ IFlashtestationRegistry :: IFlashtestationRegistryErrors :: abi_decode ( & revert_output)
614+ . map ( FlashtestationRevertReason :: FlashtestationRegistry )
615+ . unwrap_or_else ( |_| {
616+ FlashtestationRevertReason :: Unknown ( hex:: encode ( revert_output) )
617+ } ) ;
618+ BuilderTransactionError :: TransactionReverted ( Box :: new ( revert_reason) )
619+ }
620+
621+ fn handle_block_builder_policy_reverts ( revert_output : Bytes ) -> BuilderTransactionError {
622+ let revert_reason =
623+ IBlockBuilderPolicy :: IBlockBuilderPolicyErrors :: abi_decode ( & revert_output)
624+ . map ( FlashtestationRevertReason :: BlockBuilderPolicy )
625+ . unwrap_or_else ( |_| {
626+ FlashtestationRevertReason :: Unknown ( hex:: encode ( revert_output) )
627+ } ) ;
628+ BuilderTransactionError :: TransactionReverted ( Box :: new ( revert_reason) )
629+ }
562630}
563631
564632impl < ExtraCtx , Extra > BuilderTransactions < ExtraCtx , Extra >
0 commit comments