-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathllamaai.py
63 lines (52 loc) · 1.99 KB
/
llamaai.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from llamaapi import LlamaAPI
import json
import yaml
config = yaml.safe_load(open("config.yaml"))
# Replace 'Your_API_Token' with your actual API token
llama = LlamaAPI(config['llama']['api_key'])
# API Request JSON Cell
api_request_json = {
"model": "codellama-7b-instruct",
"messages": [
{"role": "system", "content": "Assistant is a smart contract assistant"},
{"role": "user", "content": """Find the vulnerability in the following smart contract ```/*
* @source: https://smartcontractsecurity.github.io/SWC-registry/docs/SWC-124#arbitrary-location-write-simplesol
* @author: Suhabe Bugrara
* @vulnerable_at_lines: 27
*/
pragma solidity ^0.4.25;
contract Wallet {
uint[] private bonusCodes;
address private owner;
constructor() public {
bonusCodes = new uint[](0);
owner = msg.sender;
}
function () public payable {
}
function PushBonusCode(uint c) public {
bonusCodes.push(c);
}
function PopBonusCode() public {
// <yes> <report> ACCESS_CONTROL
require(0 <= bonusCodes.length); // this condition is always true since array lengths are unsigned
bonusCodes.length--; // an underflow can be caused here
}
function UpdateBonusCodeAt(uint idx, uint c) public {
require(idx < bonusCodes.length);
bonusCodes[idx] = c; // write to any index less than bonusCodes.length
}
function Destroy() public {
require(msg.sender == owner);
selfdestruct(msg.sender);
}
}
```"""},
{"role": "assistant",
"content": "Vulnerability detected, it is classified as Access Control due to these instructions ``` require(0 <= bonusCodes.length); // this condition is always true since array lengths are unsigned``` "},
{"role": "user", "content": "Give me a suggestion for this vulnerability"}
]
}
# Make your request and handle the response
response = llama.run(api_request_json)
print(json.dumps(response.json(), indent=2))