Skip to content

Conversation

@0xOmarA
Copy link
Contributor

@0xOmarA 0xOmarA commented Jul 15, 2025

Summary

Fixed a compilation bug where the compiler was not given all of the smart contracts required for the compilation.

Description

I recently encountered the following error:

  2025-07-15T16:36:00.519627Z ERROR revive_dt_format::input: Attempted to lookup ABI of contract but it wasn't found, contract_name: "Main", available_abis: []
    at crates/format/src/input.rs:127 on main ThreadId(1)
    in revive_dt_core::driver::Executing case with case: "entry", case_idx: 0
    in retester::Running driver with metadata_file_path: "era-compiler-tests/solidity/complex/create/create/test.json"

Where it looks like the ABI for one of our contracts is not being found by our code.

Looking more into the logs, I saw the following output from the compiler when trying to perform the compilation:

2025-07-15T16:40:32.738931Z DEBUG revive_dt_compiler::solc: return: Ok(CompilerOutput { input: CompilerInput { extra_options: (), input: Input { language: Solidity, sources: {"era-compiler-tests/solidity/complex/create/create/main.sol": Source { content: "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.4.16;\n\nimport \"./callable.sol\";\n\ncontract Main {\n    function main() external returns(uint256) {\n        Callable callable = new Callable();\n\n        callable.set(10);\n        return callable.get();\n    }\n}\n" }}, settings: Settings { evm_version: None, libraries: Some({}), remappings: None, output_selection: Some(Selection { all: Some(File { per_file: Some({AST}), per_contract: Some({MethodIdentifiers, EVMBC, Metadata, EVMDBC, Yul}) }), files: {} }), via_ir: Some(true), optimizer: Optimizer { enabled: true, mode: None, details: Some(Details { peephole: false, inliner: None, jumpdest_remover: false, order_literals: false, deduplicate: false, cse: false, constant_optimizer: false }), fallback_to_optimizing_for_size: Some(false) }, metadata: None, polkavm: None } } }, output: Output { contracts: None, sources: Some({}), errors: Some([Error { component: "general", error_code: Some("6275"), formatted_message: "ParserError: Source \"era-compiler-tests/solidity/complex/create/create/callable.sol\" not found: File outside of allowed directories. The following are allowed: \".\".\n --> era-compiler-tests/solidity/complex/create/create/main.sol:5:1:\n  |\n5 | import \"./callable.sol\";\n  | ^^^^^^^^^^^^^^^^^^^^^^^^\n\n", message: "Source \"era-compiler-tests/solidity/complex/create/create/callable.sol\" not found: File outside of allowed directories. The following are allowed: \".\".", severity: "error", source_location: Some(SourceLocation { file: "era-compiler-tests/solidity/complex/create/create/main.sol", start: 60, end: 84 }), type: "ParserError" }]), version: None, long_version: None, revive_version: None }, error: None })
    at crates/compiler/src/solc.rs:20 on main ThreadId(1)
    in revive_dt_compiler::solc::build with input: CompilerInput { extra_options: (), input: Input { language: Solidity, sources: {"era-compiler-tests/solidity/complex/create/create/main.sol": Source { content: "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.4.16;\n\nimport \"./callable.sol\";\n\ncontract Main {\n    function main() external returns(uint256) {\n        Callable callable = new Callable();\n\n        callable.set(10);\n        return callable.get();\n    }\n}\n" }}, settings: Settings { evm_version: None, libraries: Some({}), remappings: None, output_selection: Some(Selection { all: Some(File { per_file: Some({AST}), per_contract: Some({MethodIdentifiers, EVMBC, Metadata, EVMDBC, Yul}) }), files: {} }), via_ir: Some(true), optimizer: Optimizer { enabled: true, mode: None, details: Some(Details { peephole: false, inliner: None, jumpdest_remover: false, order_literals: false, deduplicate: false, cse: false, constant_optimizer: false }), fallback_to_optimizing_for_size: Some(false) }, metadata: None, polkavm: None } } }
    in retester::Running driver with metadata_file_path: "era-compiler-tests/solidity/complex/create/create/test.json"

Which is a pretty long log, but the most important piece of this log is the following:

ParserError: Source \"era-compiler-tests/solidity/complex/create/create/callable.sol\" not found: File outside of allowed directories. The following are allowed: \".\".\n --> era-compiler-tests/solidity/complex/create/create/main.sol:5:1:\n  |\n5 | import \"./callable.sol\";\n  | ^^^^^^^^^^^^^^^^^^^^^^^^\n\n

Looking at the specific metadata file that we're trying to test we see the following:

{
    "cases": [
        {
            "name": "entry",
            "inputs": [
                {
                    "instance": "Main",
                    "method": "main",
                    "calldata": []
                }
            ],
            "expected": [
                "10"
            ]
        }
    ],
    "contracts": {
        "Main": "main.sol:Main"
    }
}

Where the callable.sol is indeed not one of the listed contracts. Our code relied on compiling just the contracts listed there and nothing else, which doesn't work in cases like this where the contract includes imports.

I believe that the matterlabs tests are created in a way where we should compile all of the contracts for a particular metadata file. Therefore, I changed the code to compile all files in the metadata file directory with the sol extension and not just the ones listed in the metadata file.

This has fixed the issue that we've been seeing.

@0xOmarA 0xOmarA requested a review from xermicus July 15, 2025 16:50
let mut compiler = Compiler::<T::Compiler>::new()
let compiler = Compiler::<T::Compiler>::new()
.base_path(metadata.directory()?.display().to_string())
.allow_path(metadata.directory()?.display().to_string())
Copy link
Contributor Author

@0xOmarA 0xOmarA Jul 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the compiler is not using the allow_path argument at all at the moment which I plan to address in a future PR where we make some of these options more explicit, more structured, and make it clearer when they're being used.

@0xOmarA 0xOmarA marked this pull request as draft July 15, 2025 18:11
@0xOmarA
Copy link
Contributor Author

0xOmarA commented Jul 15, 2025

Converted this into a draft PR as I see that the issue persists still with other test cases and therefore I think that deeper investigation is needed.

@0xOmarA 0xOmarA marked this pull request as ready for review July 15, 2025 21:56
@0xOmarA 0xOmarA added this pull request to the merge queue Jul 16, 2025
Merged via the queue into main with commit baa11ad Jul 16, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants