@@ -506,6 +506,10 @@ pub struct Cheatcodes {
506506 /// This is set to `false`, once the startup migration is completed.
507507 pub startup_zk : bool ,
508508
509+ /// Factory deps stored through `zkUseFactoryDep`. These factory deps are used in the next
510+ /// CREATE or CALL, and cleared after.
511+ pub zk_use_factory_deps : Vec < String > ,
512+
509513 /// The list of factory_deps seen so far during a test or script execution.
510514 /// Ideally these would be persisted in the storage, but since modifying [revm::JournaledState]
511515 /// would be a significant refactor, we maintain the factory_dep part in the [Cheatcodes].
@@ -603,6 +607,7 @@ impl Cheatcodes {
603607 record_next_create_address : Default :: default ( ) ,
604608 persisted_factory_deps : Default :: default ( ) ,
605609 paymaster_params : None ,
610+ zk_use_factory_deps : Default :: default ( ) ,
606611 }
607612 }
608613
@@ -982,7 +987,16 @@ impl Cheatcodes {
982987 paymaster : paymaster_data. address . to_h160 ( ) ,
983988 paymaster_input : paymaster_data. input . to_vec ( ) ,
984989 } ) ;
985- if let Some ( factory_deps) = zk_tx {
990+ if let Some ( mut factory_deps) = zk_tx {
991+ let injected_factory_deps = self . zk_use_factory_deps . iter ( ) . map ( |contract| {
992+ crate :: fs:: get_artifact_code ( self , contract, false )
993+ . inspect ( |_| info ! ( contract, "pushing factory dep" ) )
994+ . unwrap_or_else ( |_| {
995+ panic ! ( "failed to get bytecode for factory deps contract {contract}" )
996+ } )
997+ . to_vec ( )
998+ } ) . collect_vec ( ) ;
999+ factory_deps. extend ( injected_factory_deps) ;
9861000 let mut batched =
9871001 foundry_zksync_core:: vm:: batch_factory_dependencies ( factory_deps) ;
9881002 debug ! ( batches = batched. len( ) , "splitting factory deps for broadcast" ) ;
@@ -1581,6 +1595,16 @@ impl Cheatcodes {
15811595 ecx_inner. journaled_state . state ( ) . get_mut ( & broadcast. new_origin ) . unwrap ( ) ;
15821596
15831597 let zk_tx = if self . use_zk_vm {
1598+ let injected_factory_deps = self . zk_use_factory_deps . iter ( ) . map ( |contract| {
1599+ crate :: fs:: get_artifact_code ( self , contract, false )
1600+ . inspect ( |_| info ! ( contract, "pushing factory dep" ) )
1601+ . unwrap_or_else ( |_| {
1602+ panic ! ( "failed to get bytecode for factory deps contract {contract}" )
1603+ } )
1604+ . to_vec ( )
1605+ } ) . collect_vec ( ) ;
1606+ factory_deps. extend ( injected_factory_deps. clone ( ) ) ;
1607+
15841608 let paymaster_params =
15851609 self . paymaster_params . clone ( ) . map ( |paymaster_data| PaymasterParams {
15861610 paymaster : paymaster_data. address . to_h160 ( ) ,
@@ -1594,7 +1618,8 @@ impl Cheatcodes {
15941618 } )
15951619 } else {
15961620 Some ( ZkTransactionMetadata {
1597- factory_deps : Default :: default ( ) ,
1621+ // For this case we use only the injected factory deps
1622+ factory_deps : injected_factory_deps,
15981623 paymaster_data : paymaster_params,
15991624 } )
16001625 }
0 commit comments