@@ -9,7 +9,7 @@ use foundry_compilers_artifacts::{
99 output_selection:: OutputSelection ,
1010 remappings:: Remapping ,
1111 sources:: { Source , Sources } ,
12- Error , EvmVersion , Settings , Severity , SolcInput ,
12+ BytecodeHash , Error , EvmVersion , Settings , Severity , SolcInput ,
1313} ;
1414use foundry_compilers_core:: error:: Result ;
1515use itertools:: Itertools ;
@@ -242,6 +242,7 @@ pub struct SolcRestrictions {
242242 pub evm_version : Restriction < EvmVersion > ,
243243 pub via_ir : Option < bool > ,
244244 pub optimizer_runs : Restriction < usize > ,
245+ pub bytecode_hash : Option < BytecodeHash > ,
245246}
246247
247248impl CompilerSettingsRestrictions for SolcRestrictions {
@@ -252,10 +253,19 @@ impl CompilerSettingsRestrictions for SolcRestrictions {
252253 }
253254 }
254255
256+ if let ( Some ( bytecode_hash) , Some ( other_bytecode_hash) ) =
257+ ( self . bytecode_hash , other. bytecode_hash )
258+ {
259+ if bytecode_hash != other_bytecode_hash {
260+ return None ;
261+ }
262+ }
263+
255264 Some ( Self {
256265 evm_version : self . evm_version . merge ( other. evm_version ) ?,
257266 via_ir : self . via_ir . or ( other. via_ir ) ,
258267 optimizer_runs : self . optimizer_runs . merge ( other. optimizer_runs ) ?,
268+ bytecode_hash : self . bytecode_hash . or ( other. bytecode_hash ) ,
259269 } )
260270 }
261271}
@@ -323,14 +333,17 @@ impl CompilerSettings for SolcSettings {
323333 fn satisfies_restrictions ( & self , restrictions : & Self :: Restrictions ) -> bool {
324334 let mut satisfies = true ;
325335
326- satisfies &= restrictions. evm_version . satisfies ( self . evm_version ) ;
327- satisfies &=
328- restrictions. via_ir . map_or ( true , |via_ir| via_ir == self . via_ir . unwrap_or_default ( ) ) ;
329- satisfies &= restrictions. optimizer_runs . satisfies ( self . optimizer . runs ) ;
336+ let SolcRestrictions { evm_version, via_ir, optimizer_runs, bytecode_hash } = restrictions;
337+
338+ satisfies &= evm_version. satisfies ( self . evm_version ) ;
339+ satisfies &= via_ir. map_or ( true , |via_ir| via_ir == self . via_ir . unwrap_or_default ( ) ) ;
340+ satisfies &= bytecode_hash. map_or ( true , |bytecode_hash| {
341+ self . metadata . as_ref ( ) . and_then ( |m| m. bytecode_hash ) == Some ( bytecode_hash)
342+ } ) ;
343+ satisfies &= optimizer_runs. satisfies ( self . optimizer . runs ) ;
330344
331345 // Ensure that we either don't have min optimizer runs set or that the optimizer is enabled
332- satisfies &= restrictions
333- . optimizer_runs
346+ satisfies &= optimizer_runs
334347 . min
335348 . map_or ( true , |min| min == 0 || self . optimizer . enabled . unwrap_or_default ( ) ) ;
336349
0 commit comments