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

Similarity code detection tool #202

Merged
merged 30 commits into from
May 13, 2019
Merged

Similarity code detection tool #202

merged 30 commits into from
May 13, 2019

Conversation

ggrieco-tob
Copy link
Member

@ggrieco-tob ggrieco-tob commented Apr 18, 2019

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.

@CLAassistant
Copy link

CLAassistant commented Apr 20, 2019

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
2 out of 3 committers have signed the CLA.

✅ montyly
✅ ggrieco-tob
❌ g


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.

@ggrieco-tob ggrieco-tob marked this pull request as ready for review May 7, 2019 21:21
Copy link
Member

@montyly montyly left a 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/cache.py Outdated Show resolved Hide resolved
import sys

from slither import Slither
from slither.slithir.operations import *
Copy link
Member

Choose a reason for hiding this comment

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

Consider using explicit import

Copy link
Member Author

Choose a reason for hiding this comment

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

for contract in slither.contracts:

# Iterate over all the functions
for function in contract.functions:
Copy link
Member

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)

Copy link
Member Author

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). 😕

utils/similarity/__main__.py Show resolved Hide resolved
else:
return _type.replace(" ","_")

def encode_ir(ir):
Copy link
Member

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

utils/similarity/plot.py Show resolved Hide resolved
utils/similarity/__init__.py Outdated Show resolved Hide resolved
@ggrieco-tob
Copy link
Member Author

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?

I removed that. It should be fixed now.

montyly and others added 3 commits May 13, 2019 12:24
- Fix import in utils.similarity.encore
- Improve slither-similari help
- Use contract.functions_not_inherited rather than contracts.functions + if function.contract == contract
@montyly montyly merged commit c017f7a into master May 13, 2019
@montyly montyly deleted the dev-simil branch May 13, 2019 19:41
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