slither icon indicating copy to clipboard operation
slither copied to clipboard

[Bug]: Failed to generate IR for a function

Open dnkolegov opened this issue 1 year ago • 3 comments

Describe the issue:

Slither prints out the following error when we try to run it on https://github.com/matter-labs/era-contracts/tree/dev/l1-contracts:

ERROR:SlitherSolcParsing:
Failed to generate IR for TestnetVerifier.prepareAggregatedCommitment. Please open an issue https://github.com/crytic/slither/issues.
TestnetVerifier.prepareAggregatedCommitment (contracts/state-transition/Verifier.sol#1397-1603)

Code example to reproduce the issue:

https://github.com/matter-labs/era-contracts/blob/dev/l1-contracts/contracts/state-transition/Verifier.sol

Version:

0.10.1

Relevant log output:

slither --config-file ./slither.config.json  .
'forge clean' running (wd: /Users/user/projects/aon/era-contracts/l1-contracts)
'forge config --json' running
'forge build --build-info --skip */test/** */script/** --force' running (wd: /Users/user/projects/aon/era-contracts/l1-contracts)
ERROR:SlitherSolcParsing:
Failed to generate IR for TestnetVerifier.prepareAggregatedCommitment. Please open an issue https://github.com/crytic/slither/issues.
TestnetVerifier.prepareAggregatedCommitment (contracts/state-transition/Verifier.sol#1397-1603):
 	aggregationChallenge_verify_asm_0_prepareAggregatedCommitment = 1
	mstore(uint256,uint256)(AGGREGATED_AT_Z_X_SLOT,mload(uint256)(QUERIES_AT_Z_0_X_SLOT))
	mstore(uint256,uint256)(AGGREGATED_AT_Z_Y_SLOT,mload(uint256)(QUERIES_AT_Z_0_Y_SLOT))
	aggregatedOpeningAtZ_verify_asm_0_prepareAggregatedCommitment = mload(uint256)(PROOF_QUOTIENT_POLY_OPENING_AT_Z_SLOT)
	pointAddIntoDest(AGGREGATED_AT_Z_X_SLOT,QUERIES_AT_Z_1_X_SLOT,AGGREGATED_AT_Z_X_SLOT)
	aggregationChallenge_verify_asm_0_prepareAggregatedCommitment = mulmod(uint256,uint256,uint256)(aggregationChallenge_verify_asm_0_prepareAggregatedCommitment,mload(uint256)(STATE_V_SLOT),R_MOD)
	aggregatedOpeningAtZ_verify_asm_0_prepareAggregatedCommitment = addmod(uint256,uint256,uint256)(aggregatedOpeningAtZ_verify_asm_0_prepareAggregatedCommitment,mulmod(uint256,uint256,uint256)(aggregationChallenge_verify_asm_0_prepareAggregatedCommitment,mload(uint256)(PROOF_LINEARISATION_POLY_OPENING_AT_Z_SLOT),R_MOD),R_MOD)
	(aggregationChallenge_verify_asm_0_prepareAggregatedCommitment,aggregatedOpeningAtZ_verify_asm_0_prepareAggregatedCommitment) = updateAggregationChallenge(PROOF_STATE_POLYS_0_X_SLOT,PROOF_STATE_POLYS_0_OPENING_AT_Z_SLOT,aggregationChallenge_verify_asm_0_prepareAggregatedCommitment,aggregatedOpeningAtZ_verify_asm_0_prepareAggregatedCommitment)
	(aggregationChallenge_verify_asm_0_prepareAggregatedCommitment,aggregatedOpeningAtZ_verify_asm_0_prepareAggregatedCommitment) = updateAggregationChallenge(PROOF_STATE_POLYS_1_X_SLOT,PROOF_STATE_POLYS_1_OPENING_AT_Z_SLOT,aggregationChallenge_verify_asm_0_prepareAggregatedCommitment,aggregatedOpeningAtZ_verify_asm_0_prepareAggregatedCommitment)
	(aggregationChallenge_verify_asm_0_prepareAggregatedCommitment,aggregatedOpeningAtZ_verify_asm_0_prepareAggregatedCommitment) = updateAggregationChallenge(PROOF_STATE_POLYS_2_X_SLOT,PROOF_STATE_POLYS_2_OPENING_AT_Z_SLOT,aggregationChallenge_verify_asm_0_prepareAggregatedCommitment,aggregatedOpeningAtZ_verify_asm_0_prepareAggregatedCommitment)
	aggregationChallenge_verify_asm_0_prepareAggregatedCommitment = mulmod(uint256,uint256,uint256)(aggregationChallenge_verify_asm_0_prepareAggregatedCommitment,mload(uint256)(STATE_V_SLOT),R_MOD)
	firstDCoeff_verify_asm_0_prepareAggregatedCommitment = aggregationChallenge_verify_asm_0_prepareAggregatedCommitment
	aggregatedOpeningAtZ_verify_asm_0_prepareAggregatedCommitment = addmod(uint256,uint256,uint256)(aggregatedOpeningAtZ_verify_asm_0_prepareAggregatedCommitment,mulmod(uint256,uint256,uint256)(aggregationChallenge_verify_asm_0_prepareAggregatedCommitment,mload(uint256)(PROOF_STATE_POLYS_3_OPENING_AT_Z_SLOT),R_MOD),R_MOD)
	(aggregationChallenge_verify_asm_0_prepareAggregatedCommitment,aggregatedOpeningAtZ_verify_asm_0_prepareAggregatedCommitment) = updateAggregationChallenge(VK_GATE_SELECTORS_0_X_SLOT,PROOF_GATE_SELECTORS_0_OPENING_AT_Z_SLOT,aggregationChallenge_verify_asm_0_prepareAggregatedCommitment,aggregatedOpeningAtZ_verify_asm_0_prepareAggregatedCommitment)
	(aggregationChallenge_verify_asm_0_prepareAggregatedCommitment,aggregatedOpeningAtZ_verify_asm_0_prepareAggregatedCommitment) = updateAggregationChallenge(VK_PERMUTATION_0_X_SLOT,PROOF_COPY_PERMUTATION_POLYS_0_OPENING_AT_Z_SLOT,aggregationChallenge_verify_asm_0_prepareAggregatedCommitment,aggregatedOpeningAtZ_verify_asm_0_prepareAggregatedCommitment)
	(aggregationChallenge_verify_asm_0_prepareAggregatedCommitment,aggregatedOpeningAtZ_verify_asm_0_prepareAggregatedCommitment) = updateAggregationChallenge(VK_PERMUTATION_1_X_SLOT,PROOF_COPY_PERMUTATION_POLYS_1_OPENING_AT_Z_SLOT,aggregationChallenge_verify_asm_0_prepareAggregatedCommitment,aggregatedOpeningAtZ_verify_asm_0_prepareAggregatedCommitment)
	(aggregationChallenge_verify_asm_0_prepareAggregatedCommitment,aggregatedOpeningAtZ_verify_asm_0_prepareAggregatedCommitment) = updateAggregationChallenge(VK_PERMUTATION_2_X_SLOT,PROOF_COPY_PERMUTATION_POLYS_2_OPENING_AT_Z_SLOT,aggregationChallenge_verify_asm_0_prepareAggregatedCommitment,aggregatedOpeningAtZ_verify_asm_0_prepareAggregatedCommitment)
	aggregationChallenge_verify_asm_0_prepareAggregatedCommitment = mulmod(uint256,uint256,uint256)(aggregationChallenge_verify_asm_0_prepareAggregatedCommitment,mload(uint256)(STATE_V_SLOT),R_MOD)
	firstTCoeff_verify_asm_0_prepareAggregatedCommitment = aggregationChallenge_verify_asm_0_prepareAggregatedCommitment
	aggregatedOpeningAtZ_verify_asm_0_prepareAggregatedCommitment = addmod(uint256,uint256,uint256)(aggregatedOpeningAtZ_verify_asm_0_prepareAggregatedCommitment,mulmod(uint256,uint256,uint256)(aggregationChallenge_verify_asm_0_prepareAggregatedCommitment,mload(uint256)(PROOF_LOOKUP_T_POLY_OPENING_AT_Z_SLOT),R_MOD),R_MOD)
	(aggregationChallenge_verify_asm_0_prepareAggregatedCommitment,aggregatedOpeningAtZ_verify_asm_0_prepareAggregatedCommitment) = updateAggregationChallenge(VK_LOOKUP_SELECTOR_X_SLOT,PROOF_LOOKUP_SELECTOR_POLY_OPENING_AT_Z_SLOT,aggregationChallenge_verify_asm_0_prepareAggregatedCommitment,aggregatedOpeningAtZ_verify_asm_0_prepareAggregatedCommitment)
	(aggregationChallenge_verify_asm_0_prepareAggregatedCommitment,aggregatedOpeningAtZ_verify_asm_0_prepareAggregatedCommitment) = updateAggregationChallenge(VK_LOOKUP_TABLE_TYPE_X_SLOT,PROOF_LOOKUP_TABLE_TYPE_POLY_OPENING_AT_Z_SLOT,aggregationChallenge_verify_asm_0_prepareAggregatedCommitment,aggregatedOpeningAtZ_verify_asm_0_prepareAggregatedCommitment)
	mstore(uint256,uint256)(AGGREGATED_OPENING_AT_Z_SLOT,aggregatedOpeningAtZ_verify_asm_0_prepareAggregatedCommitment)
	aggregationChallenge_verify_asm_0_prepareAggregatedCommitment = mulmod(uint256,uint256,uint256)(aggregationChallenge_verify_asm_0_prepareAggregatedCommitment,mload(uint256)(STATE_V_SLOT),R_MOD)
	copyPermutationCoeff_verify_asm_0_prepareAggregatedCommitment = addmod(uint256,uint256,uint256)(mload(uint256)(COPY_PERMUTATION_FIRST_AGGREGATED_COMMITMENT_COEFF),mulmod(uint256,uint256,uint256)(aggregationChallenge_verify_asm_0_prepareAggregatedCommitment,mload(uint256)(STATE_U_SLOT),R_MOD),R_MOD)
	pointMulIntoDest(PROOF_COPY_PERMUTATION_GRAND_PRODUCT_X_SLOT,copyPermutationCoeff_verify_asm_0_prepareAggregatedCommitment,AGGREGATED_AT_Z_OMEGA_X_SLOT)
	aggregatedOpeningAtZOmega_verify_asm_0_prepareAggregatedCommitment = mulmod(uint256,uint256,uint256)(mload(uint256)(PROOF_COPY_PERMUTATION_GRAND_PRODUCT_OPENING_AT_Z_OMEGA_SLOT),aggregationChallenge_verify_asm_0_prepareAggregatedCommitment,R_MOD)
	(aggregationChallenge_verify_asm_0_prepareAggregatedCommitment,aggregatedOpeningAtZOmega_verify_asm_0_prepareAggregatedCommitment) = updateAggregationChallenge(PROOF_STATE_POLYS_3_X_SLOT,PROOF_STATE_POLYS_3_OPENING_AT_Z_OMEGA_SLOT,firstDCoeff_verify_asm_0_prepareAggregatedCommitment,aggregationChallenge_verify_asm_0_prepareAggregatedCommitment,aggregatedOpeningAtZOmega_verify_asm_0_prepareAggregatedCommitment)
	(aggregationChallenge_verify_asm_0_prepareAggregatedCommitment,aggregatedOpeningAtZOmega_verify_asm_0_prepareAggregatedCommitment) = updateAggregationChallenge(PROOF_LOOKUP_S_POLY_X_SLOT,PROOF_LOOKUP_S_POLY_OPENING_AT_Z_OMEGA_SLOT,mload(uint256)(LOOKUP_S_FIRST_AGGREGATED_COMMITMENT_COEFF),aggregationChallenge_verify_asm_0_prepareAggregatedCommitment,aggregatedOpeningAtZOmega_verify_asm_0_prepareAggregatedCommitment)
	(aggregationChallenge_verify_asm_0_prepareAggregatedCommitment,aggregatedOpeningAtZOmega_verify_asm_0_prepareAggregatedCommitment) = updateAggregationChallenge(PROOF_LOOKUP_GRAND_PRODUCT_X_SLOT,PROOF_LOOKUP_GRAND_PRODUCT_OPENING_AT_Z_OMEGA_SLOT,mload(uint256)(LOOKUP_GRAND_PRODUCT_FIRST_AGGREGATED_COMMITMENT_COEFF),aggregationChallenge_verify_asm_0_prepareAggregatedCommitment,aggregatedOpeningAtZOmega_verify_asm_0_prepareAggregatedCommitment)
	(aggregationChallenge_verify_asm_0_prepareAggregatedCommitment,aggregatedOpeningAtZOmega_verify_asm_0_prepareAggregatedCommitment) = updateAggregationChallenge(QUERIES_T_POLY_AGGREGATED_X_SLOT,PROOF_LOOKUP_T_POLY_OPENING_AT_Z_OMEGA_SLOT,firstTCoeff_verify_asm_0_prepareAggregatedCommitment,aggregationChallenge_verify_asm_0_prepareAggregatedCommitment,aggregatedOpeningAtZOmega_verify_asm_0_prepareAggregatedCommitment)
	mstore(uint256,uint256)(AGGREGATED_OPENING_AT_Z_OMEGA_SLOT,aggregatedOpeningAtZOmega_verify_asm_0_prepareAggregatedCommitment)
	u_verify_asm_0_prepareAggregatedCommitment = mload(uint256)(STATE_U_SLOT)
	pointAddIntoDest(AGGREGATED_AT_Z_X_SLOT,AGGREGATED_AT_Z_OMEGA_X_SLOT,PAIRING_PAIR_WITH_GENERATOR_X_SLOT)
	aggregatedValue_verify_asm_0_prepareAggregatedCommitment = addmod(uint256,uint256,uint256)(mulmod(uint256,uint256,uint256)(mload(uint256)(AGGREGATED_OPENING_AT_Z_OMEGA_SLOT),u_verify_asm_0_prepareAggregatedCommitment,R_MOD),mload(uint256)(AGGREGATED_OPENING_AT_Z_SLOT),R_MOD)
	mstore(uint256,uint256)(PAIRING_BUFFER_POINT_X_SLOT,1)
	mstore(uint256,uint256)(PAIRING_BUFFER_POINT_Y_SLOT,2)
	pointMulIntoDest(PAIRING_BUFFER_POINT_X_SLOT,aggregatedValue_verify_asm_0_prepareAggregatedCommitment,PAIRING_BUFFER_POINT_X_SLOT)
Traceback (most recent call last):
  File "/Users/user/Library/Python/3.9/bin/slither", line 8, in <module>
    sys.exit(main())
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/slither/__main__.py", line 746, in main
    main_impl(all_detector_classes=detectors, all_printer_classes=printers)
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/slither/__main__.py", line 852, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/slither/__main__.py", line 107, in process_all
    ) = process_single(compilation, args, detector_classes, printer_classes)
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/slither/__main__.py", line 80, in process_single
    slither = Slither(target, ast_format=ast, **vars(args))
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/slither/slither.py", line 150, in __init__
    self._init_parsing_and_analyses(kwargs.get("skip_analyze", False))
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/slither/slither.py", line 170, in _init_parsing_and_analyses
    raise e
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/slither/slither.py", line 166, in _init_parsing_and_analyses
    parser.analyze_contracts()
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 556, in analyze_contracts
    self._convert_to_slithir()
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 782, in _convert_to_slithir
    raise e
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 767, in _convert_to_slithir
    func.generate_slithir_and_analyze()
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/slither/core/declarations/function.py", line 1772, in generate_slithir_and_analyze
    node.slithir_generation()
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/slither/core/cfg/node.py", line 717, in slithir_generation
    self._irs = convert_expression(expression, self)  # type:ignore
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/slither/slithir/convert.py", line 118, in convert_expression
    result = apply_ir_heuristics(result, node, is_solidity)
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/slither/slithir/convert.py", line 2039, in apply_ir_heuristics
    convert_constant_types(irs)
  File "/Users/user/Library/Python/3.9/lib/python/site-packages/slither/slithir/convert.py", line 1955, in convert_constant_types
    assert len(types) == len(ir.arguments)
AssertionError

dnkolegov avatar Mar 19 '24 19:03 dnkolegov

I'm trying to reproduce this locally but having some issue building the project. It seems some files do not have AST in the artifacts

What is this for? https://github.com/matter-labs/era-contracts/pull/280/files#diff-31f243de25cd22d26922f0b35d200fa11869ad856b935862e7874340b4abe1eeR39-R43

Do I need to delete these prior to running slither?

0xalpharush avatar Mar 29 '24 04:03 0xalpharush

This is to run slither. We could not run slither with those files, so I opened this bug and removed the files. To reproduce the bug you do not need to remove them

dnkolegov avatar Mar 29 '24 09:03 dnkolegov

I had to run rm -rf ./l1-contracts/contracts/state-transition/utils/ since the build-info in out/ only contained the Yul file for me and we only support inline Yul in Solidity contracts.

From @smonicas : The issue in Verifier.sol is due to not creating new scope for anonymous blocks when parsing yul but im not sure what is the correct way to fix it. Here then the function is searched by name and there wold be both functions (two samename functions as for example instead of only the correct one). Should we create a new yulblock in convert_yul_block or it would be enough to create a new scope and add to the scope a father attribute, or something else? Reproducer

contract T {
 function a() public {
  assembly {
    {
      function samename() {}
      samename()
    }
    {      
      function samename(r) {}
      samename(2)
    }
  }
 }
}

0xalpharush avatar Mar 29 '24 13:03 0xalpharush