Created
December 5, 2023 21:40
-
-
Save m9800/3565b0f97e91640286f6ac9f3a68a586 to your computer and use it in GitHub Desktop.
Santuary search
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import re | |
import csv | |
# Sanctuary link : https://github.com/tintinweb/smart-contract-sanctuary-ethereum/tree/015d0105102504dc8733a18c3543f87f1829a5e8 | |
# Patterns | |
erc2771_pattern = re.compile(r".*import.*ERC2771.*") | |
multicall_pattern = re.compile(r".*import.*Multicall.*") | |
vulnerable = [] | |
def search_patterns_in_sol(directory): | |
for root, dirs, files in os.walk(directory): | |
for file in files: | |
found_erc2771 = False | |
found_multicall = False | |
# if file.endswith('.sol'): | |
with open(os.path.join(root, file), 'r') as file: | |
for line in file: | |
if erc2771_pattern.match(line): | |
found_erc2771 = True | |
if multicall_pattern.match(line): | |
found_multicall = True | |
if found_erc2771 and found_multicall: | |
vulnerable.append(file) | |
# Folder containing directories with .sol files | |
root_folder = "./sanctuary/smart-contract-sanctuary-ethereum/contracts/mainnet" | |
# Search in each directory | |
for directory in os.listdir(root_folder): | |
full_path = os.path.join(root_folder, directory) | |
if os.path.isdir(full_path): | |
search_patterns_in_sol(full_path) | |
# Create and write to CSV file | |
with open('vulnerableProtocols.csv', 'w', newline='') as csvfile: | |
csvwriter = csv.writer(csvfile) | |
for item in vulnerable: | |
address, name = item.split("_", 1) | |
name = name.replace(".sol", "") # Remove the .sol extension | |
csvwriter.writerow([address, name]) | |
print("CSV file created successfully.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment