Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug-Candidate]: Ternary operator are not convertible to SlithIR #2609

Open
cb-elileers opened this issue Dec 2, 2024 · 1 comment
Open
Labels
bug-candidate Bugs reports that are not yet confirmed

Comments

@cb-elileers
Copy link

Describe the issue:

When attempting to run Slither on https://github.com/xenoliss/keyspace-v3 I get an error on the SlithIR generation. I believe it might be due to the code instantiating a function based on the results of the ternary.

Code example to reproduce the issue:

// Keystore.sol
        // breaks SlithIR generation
        (uint256 currentConfigNonce, function (ConfigLib.Config calldata) returns (bytes32) applyConfigInternal) = block
            .chainid == masterChainId
            ? (_sMaster().configNonce, _applyMasterConfig)
            : (_sReplica().currentConfigNonce, _applyReplicaConfig);

        // ternary rewritten as if else does not break SlithIR generation
        uint256 currentConfigNonce;
        function (ConfigLib.Config calldata) returns (bytes32) applyConfigInternal;

        if (block.chainid == masterChainId) {
            currentConfigNonce = _sMaster().configNonce;
            applyConfigInternal= _applyMasterConfig;
        } else {
            currentConfigNonce = _sReplica().currentConfigNonce;
            applyConfigInternal= _applyReplicaConfig;
        }

Version:

0.10.2

Relevant log output:

➜  contracts git:(main) ✗ slither .
'forge clean' running (wd: /Users/eli/Downloads/keyspace-v3/contracts)
'forge config --json' running
'forge build --build-info --skip */test/** */script/** --force' running (wd: /Users/eli/Downloads/keyspace-v3/contracts)
ERROR:ContractSolcParsing:Missing function Variable not found: require(bool,error) (context ConfigLib src/libs/ConfigLib.sol#4-60 (1 - 2))
ERROR:ContractSolcParsing:Missing function Variable not found: require(bool,error) (context EIP4788Lib src/libs/l1-state-root/EIP4788Lib.sol#6-178 (1 - 2))
ERROR:ContractSolcParsing:Missing function Variable not found: require(bool,error) (context L1BlockLib src/libs/l1-state-root/L1BlockLib.sol#7-100 (1 - 2))
ERROR:ContractSolcParsing:Missing modifier Variable not found: require(bool,error) (context Keystore src/Keystore.sol#33-457 (1 - 2))
ERROR:ContractSolcParsing:Missing function Variable not found: require(bool,error) (context Keystore src/Keystore.sol#33-457 (1 - 2))
ERROR:ContractSolcParsing:Missing modifier Variable not found: require(bool,error) (context OPStackKeystore src/chains/OPStackKeystore.sol#27-142 (1 - 2))
ERROR:ContractSolcParsing:Missing function Variable not found: require(bool,error) (context OPStackKeystore src/chains/OPStackKeystore.sol#27-142 (1 - 2))
ERROR:ContractSolcParsing:Missing function Variable not found: require(bool,error) (context TransientUUPSUpgradeable src/examples/TransientUUPSUpgradeable.sol#6-41 (1 - 2))
ERROR:ContractSolcParsing:Missing modifier Variable not found: require(bool,error) (context MultiOwnableWallet src/examples/MultiOwnableWallet.opstack.sol#73-354 (1 - 2))
ERROR:ContractSolcParsing:Missing function Variable not found: require(bool,error) (context MultiOwnableWallet src/examples/MultiOwnableWallet.opstack.sol#73-354 (1 - 2))
ERROR:SlitherSolcParsing:
Failed to generate IR for Keystore.setConfig. Please open an issue https://github.com/crytic/slither/issues.
Keystore.setConfig (src/Keystore.sol#135-181):
        (currentConfigNonce,applyConfigInternal) = if block.chainid == masterChainId then (_sMaster().configNonce,_applyMasterConfig) else (_sReplica().currentConfigNonce,_applyReplicaConfig)
Traceback (most recent call last):
  File "/Users/eli/.pyenv/versions/3.12.2/lib/python3.12/site-packages/slither/__main__.py", line 859, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/eli/.pyenv/versions/3.12.2/lib/python3.12/site-packages/slither/__main__.py", line 107, in process_all
    ) = process_single(compilation, args, detector_classes, printer_classes)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/eli/.pyenv/versions/3.12.2/lib/python3.12/site-packages/slither/__main__.py", line 80, in process_single
    slither = Slither(target, ast_format=ast, **vars(args))
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/eli/.pyenv/versions/3.12.2/lib/python3.12/site-packages/slither/slither.py", line 199, in __init__
    self._init_parsing_and_analyses(kwargs.get("skip_analyze", False))
  File "/Users/eli/.pyenv/versions/3.12.2/lib/python3.12/site-packages/slither/slither.py", line 219, in _init_parsing_and_analyses
    raise e
  File "/Users/eli/.pyenv/versions/3.12.2/lib/python3.12/site-packages/slither/slither.py", line 215, in _init_parsing_and_analyses
    parser.analyze_contracts()
  File "/Users/eli/.pyenv/versions/3.12.2/lib/python3.12/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 593, in analyze_contracts
    self._convert_to_slithir()
  File "/Users/eli/.pyenv/versions/3.12.2/lib/python3.12/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 827, in _convert_to_slithir
    raise e
  File "/Users/eli/.pyenv/versions/3.12.2/lib/python3.12/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 812, in _convert_to_slithir
    func.generate_slithir_and_analyze()
  File "/Users/eli/.pyenv/versions/3.12.2/lib/python3.12/site-packages/slither/core/declarations/function.py", line 1830, in generate_slithir_and_analyze
    node.slithir_generation()
  File "/Users/eli/.pyenv/versions/3.12.2/lib/python3.12/site-packages/slither/core/cfg/node.py", line 717, in slithir_generation
    self._irs = convert_expression(expression, self)  # type:ignore
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/eli/.pyenv/versions/3.12.2/lib/python3.12/site-packages/slither/slithir/convert.py", line 115, in convert_expression
    visitor = ExpressionToSlithIR(expression, node)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/eli/.pyenv/versions/3.12.2/lib/python3.12/site-packages/slither/visitors/slithir/expression_to_slithir.py", line 174, in __init__
    self._visit_expression(self.expression)
  File "/Users/eli/.pyenv/versions/3.12.2/lib/python3.12/site-packages/slither/visitors/expression/expression.py", line 43, in _visit_expression
    self._visit_assignement_operation(expression)
  File "/Users/eli/.pyenv/versions/3.12.2/lib/python3.12/site-packages/slither/visitors/expression/expression.py", line 99, in _visit_assignement_operation
    self._visit_expression(expression.expression_right)
  File "/Users/eli/.pyenv/versions/3.12.2/lib/python3.12/site-packages/slither/visitors/expression/expression.py", line 93, in _visit_expression
    self._post_visit(expression)
  File "/Users/eli/.pyenv/versions/3.12.2/lib/python3.12/site-packages/slither/visitors/expression/expression.py", line 276, in _post_visit
    self._post_conditional_expression(expression)
  File "/Users/eli/.pyenv/versions/3.12.2/lib/python3.12/site-packages/slither/visitors/slithir/expression_to_slithir.py", line 435, in _post_conditional_expression
    raise SlithIRError(f"Ternary operator are not convertible to SlithIR {expression}")
slither.slithir.exceptions.SlithIRError: Ternary operator are not convertible to SlithIR if block.chainid == masterChainId then (_sMaster().configNonce,_applyMasterConfig) else (_sReplica().currentConfigNonce,_applyReplicaConfig)
ERROR:root:Error:
ERROR:root:Ternary operator are not convertible to SlithIR if block.chainid == masterChainId then (_sMaster().configNonce,_applyMasterConfig) else (_sReplica().currentConfigNonce,_applyReplicaConfig)
ERROR:root:Please report an issue to https://github.com/crytic/slither/issues
@cb-elileers cb-elileers added the bug-candidate Bugs reports that are not yet confirmed label Dec 2, 2024
@smonicas
Copy link
Contributor

smonicas commented Dec 3, 2024

Hi. This issue seems to be fixed in slither's dev branch however your codebase is affected by #2610. To run slither you have to install it from the dev branch and rename the authorizationProof argument to validationProof.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-candidate Bugs reports that are not yet confirmed
Projects
None yet
Development

No branches or pull requests

2 participants