-
Notifications
You must be signed in to change notification settings - Fork 985
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
Similarity code detection tool #202
Conversation
g seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code relies heavily on large
try
...
except Exception
Would it be possible to remove and catch properly the exceptions, or they are too many of them?
utils/similarity/encode.py
Outdated
import sys | ||
|
||
from slither import Slither | ||
from slither.slithir.operations import * |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using explicit import
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a lot of things to import: https://github.com/crytic/slither/blob/dev-simil/slither/slithir/operations/__init__.py
😭
utils/similarity/encode.py
Outdated
for contract in slither.contracts: | ||
|
||
# Iterate over all the functions | ||
for function in contract.functions: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using contract.functions_not_inherited
to simplify the upcoming #213
(function.contract == contract
can then be removed)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
During training this could be useful to avoid repetition in the dataset, but I'm not sure this is what we want during testing. In that case, the user cannot specify a inherited function (since it will be missing). 😕
else: | ||
return _type.replace(" ","_") | ||
|
||
def encode_ir(ir): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would split this into two functions encode_ir
and encode_value
.
SlithIR is flat, so all the ir.value
, ir.rvalue
will never return an Operation
I removed that. It should be fixed now. |
- Fix import in utils.similarity.encore - Improve slither-similari help - Use contract.functions_not_inherited rather than contracts.functions + if function.contract == contract
This PR implements a new util,
slither-simil
, to detect similar Solidity functions in a large amount of smart contracts using Machine Learning. More information and documentation is available here.