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

add diagnostic when KeyError is thrown by crytic-compile #2328

Closed
0xalpharush opened this issue Feb 20, 2024 · 0 comments
Closed

add diagnostic when KeyError is thrown by crytic-compile #2328

0xalpharush opened this issue Feb 20, 2024 · 0 comments
Labels
enhancement New feature or request High Priority

Comments

@0xalpharush
Copy link
Contributor

If a framework isn't cleaning its artifacts/build info it their entirety or --ignore-compile is used and the file was edited, we may hit an exception due to the offset being invalidated. We should provide a better diagnostic and suggest running the clean command

see #2296 (comment)

def _convert_source_mapping(
offset: str, compilation_unit: "SlitherCompilationUnit"
) -> Source: # pylint: disable=too-many-locals
"""
Convert a text offset to a real offset
see https://solidity.readthedocs.io/en/develop/miscellaneous.html#source-mappings
Returns:
(dict): {'start':0, 'length':0, 'filename': 'file.sol'}
"""
sourceUnits = compilation_unit.source_units
position = re.findall("([0-9]*):([0-9]*):([-]?[0-9]*)", offset)
if len(position) != 1:
return Source(compilation_unit)
s, l, f = position[0]
s = int(s)
l = int(l)
f = int(f)
if f not in sourceUnits:
new_source = Source(compilation_unit)
new_source.start = s
new_source.length = l
return new_source
filename_used = sourceUnits[f]
# If possible, convert the filename to its absolute/relative version
assert compilation_unit.core.crytic_compile
filename: Filename = compilation_unit.core.crytic_compile.filename_lookup(filename_used)
is_dependency = compilation_unit.core.crytic_compile.is_dependency(filename.absolute)
(lines, starting_column, ending_column) = _compute_line(compilation_unit, filename, s, l)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request High Priority
Projects
None yet
Development

No branches or pull requests

1 participant