@@ -49,7 +49,7 @@ impl Solc {
4949 SourceCodeData :: SolSingleFile ( source_code) => {
5050 if has_dangerous_imports ( & source_code) {
5151 return Err ( ContractVerifierError :: InvalidSourcePath (
52- "import with absolute or traversal path" . to_owned ( ) ,
52+ "import with absolute path" . to_owned ( ) ,
5353 ) ) ;
5454 }
5555 let source = Source {
@@ -85,7 +85,7 @@ impl Solc {
8585 for source in compiler_input. sources . values ( ) {
8686 if has_dangerous_imports ( & source. content ) {
8787 return Err ( ContractVerifierError :: InvalidSourcePath (
88- "import with absolute or traversal path" . to_owned ( ) ,
88+ "import with absolute path" . to_owned ( ) ,
8989 ) ) ;
9090 }
9191 }
@@ -123,6 +123,105 @@ impl Solc {
123123 }
124124}
125125
126+ #[ cfg( test) ]
127+ mod tests {
128+ use zksync_types:: contract_verification:: api:: CompilerVersions ;
129+
130+ use super :: * ;
131+
132+ #[ test]
133+ fn build_input_allows_relative_parent_imports_in_standard_json ( ) {
134+ let input = serde_json:: json!( {
135+ "language" : "Solidity" ,
136+ "sources" : {
137+ "src/Counter.sol" : {
138+ "content" : r#"
139+ pragma solidity ^0.8.20;
140+ import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
141+
142+ contract Counter is OwnableUpgradeable {
143+ function initialize(address owner) external initializer {
144+ __Ownable_init(owner);
145+ }
146+ }
147+ "# ,
148+ } ,
149+ "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol" : {
150+ "content" : r#"
151+ pragma solidity ^0.8.20;
152+ import "../utils/ContextUpgradeable.sol";
153+ import "@openzeppelin/contracts/proxy/utils/Initializable.sol";
154+
155+ abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
156+ address private _owner;
157+
158+ function __Ownable_init(address initialOwner) internal onlyInitializing {
159+ _owner = initialOwner;
160+ }
161+ }
162+ "# ,
163+ } ,
164+ "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol" : {
165+ "content" : r#"
166+ pragma solidity ^0.8.20;
167+ import "@openzeppelin/contracts/proxy/utils/Initializable.sol";
168+
169+ abstract contract ContextUpgradeable is Initializable {
170+ function _msgSender() internal view virtual returns (address) {
171+ return msg.sender;
172+ }
173+ }
174+ "# ,
175+ } ,
176+ "@openzeppelin/contracts/proxy/utils/Initializable.sol" : {
177+ "content" : r#"
178+ pragma solidity ^0.8.20;
179+
180+ abstract contract Initializable {
181+ modifier initializer() {
182+ _;
183+ }
184+
185+ modifier onlyInitializing() {
186+ _;
187+ }
188+ }
189+ "# ,
190+ } ,
191+ } ,
192+ "settings" : {
193+ "optimizer" : {
194+ "enabled" : true ,
195+ } ,
196+ } ,
197+ } ) ;
198+ let req = VerificationIncomingRequest {
199+ contract_address : Default :: default ( ) ,
200+ source_code_data : SourceCodeData :: StandardJsonInput ( input. as_object ( ) . unwrap ( ) . clone ( ) ) ,
201+ contract_name : "src/Counter.sol:Counter" . to_owned ( ) ,
202+ compiler_versions : CompilerVersions :: Solc {
203+ compiler_solc_version : "0.8.26" . to_owned ( ) ,
204+ compiler_zksolc_version : None ,
205+ } ,
206+ optimization_used : true ,
207+ optimizer_mode : None ,
208+ constructor_arguments : Default :: default ( ) ,
209+ is_system : false ,
210+ force_evmla : false ,
211+ evm_specific : Default :: default ( ) ,
212+ } ;
213+
214+ let built = Solc :: build_input ( req) . expect ( "relative parent imports should be allowed" ) ;
215+
216+ assert_eq ! ( built. file_name, "src/Counter.sol" ) ;
217+ assert_eq ! ( built. contract_name, "Counter" ) ;
218+ assert ! ( built
219+ . standard_json
220+ . sources
221+ . contains_key( "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol" ) ) ;
222+ }
223+ }
224+
126225#[ async_trait]
127226impl Compiler < SolcInput > for Solc {
128227 async fn compile (
@@ -141,6 +240,7 @@ impl Compiler<SolcInput> for Solc {
141240 . arg ( "--standard-json" )
142241 . arg ( "--allow-paths" )
143242 . arg ( compile_dir. path ( ) )
243+ . current_dir ( compile_dir. path ( ) )
144244 . stdin ( Stdio :: piped ( ) )
145245 . stdout ( Stdio :: piped ( ) )
146246 . stderr ( Stdio :: piped ( ) )
0 commit comments