8000 add support for multiple rust smart contracts by jpmonette · Pull Request #3 · solanaizer/solanaizer-action · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

add support for multiple rust smart contracts #3

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

Merged
merged 1 commit into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions ai_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ def analyze_vulnerability_with_gpt(api_key, file_content, filename: Path):

If you find no errors, you should return an empty array.

You are an Solana smart contract auditor. You are an expert at finding vulnerabilities that can be exploited by bad people.
The filename key should contain the name of the module.

Only output vulnerabilities which you are certain pose security risks.
You are an Solana smart contract auditor. You are an expert at finding vulnerabilities that can be exploited by bad people.

```rs
'{file_content}'
Expand All @@ -52,7 +52,7 @@ def analyze_vulnerability_with_gpt(api_key, file_content, filename: Path):
if response.ok:
response_json = response.json()
response_content = response_json["choices"][0]["message"]["content"].replace("```json", "").replace("```", "")
if (response_content != ""):
if (response_content != "" or response_content != None or response_content != []):
parsed = json.loads(response_content)

for item in parsed:
Expand All @@ -72,4 +72,3 @@ def analyze_vulnerability_with_gpt(api_key, file_content, filename: Path):
error_message = f"Failed to get a valid response from OpenAI: {response.status_code} - {response.text}"
raise IOError(error_message)


2 changes: 0 additions & 2 deletions requirements.txt

This file was deleted.

21 changes: 15 additions & 6 deletions solanaizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,22 @@ def validate_file_content(file_path: Path):

return analyze_vulnerability_with_gpt(API_KEY, content, file_path)

def get_rust_files(directory):
rust_files = []
for root, _, files in os.walk(directory):
for file in files:
if file.endswith(".rs"):
rust_files.append(os.path.join(root, file))
return rust_files

if __name__ == "__main__":
suffix = "src/lib.rs"
bug_free = "programs/bug-free-contract-1/"
non_bug_free = "programs/buggy-contract-1/"
dir_to_search = "programs/"

rust_files = get_rust_files(dir_to_search)

file_path_bug_free = Path(bug_free + suffix)
file_path_buggy = Path(non_bug_free + suffix)
json_dumps = []
for rust_file in rust_files:
rust_file_path = Path(rust_file)
json_dumps += validate_file_content(rust_file_path)

print(json.dumps(validate_file_content(file_path_bug_free) + validate_file_content(file_path_buggy)))
print(json.dumps(json_dumps))
0