Skip to content

Commit 456d222

Browse files
authored
Create AutonomousThreatIntel.sol
1 parent b01bea5 commit 456d222

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.8.20;
3+
4+
/// @title AutonomousThreatIntel
5+
/// @notice Decentralized, unstoppable AI-driven threat report and intelligence hub.
6+
contract AutonomousThreatIntel {
7+
struct ThreatReport {
8+
address reporter;
9+
string target; // Target system or address
10+
string description; // Threat description
11+
string aiAssessment;
12+
uint256 severity; // 1 (Critical) - 5 (Low)
13+
uint256 timestamp;
14+
bool aiValidated;
15+
}
16+
17+
uint256 public totalThreats;
18+
address public aiAgent;
19+
mapping(uint256 => ThreatReport) public threats;
20+
21+
event ThreatSubmitted(uint256 indexed reportId, address indexed reporter, string target, string description);
22+
event ThreatAssessed(uint256 indexed reportId, string aiAssessment, uint256 severity);
23+
24+
modifier onlyAIAgent() {
25+
require(msg.sender == aiAgent, "Not authorized");
26+
_;
27+
}
28+
29+
constructor(address _aiAgent) {
30+
aiAgent = _aiAgent;
31+
}
32+
33+
function submitThreat(string memory target, string memory description) public returns (uint256) {
34+
totalThreats++;
35+
threats[totalThreats] = ThreatReport({
36+
reporter: msg.sender,
37+
target: target,
38+
description: description,
39+
aiAssessment: "",
40+
severity: 0,
41+
timestamp: block.timestamp,
42+
aiValidated: false
43+
});
44+
emit ThreatSubmitted(totalThreats, msg.sender, target, description);
45+
return totalThreats;
46+
}
47+
48+
function aiAssessThreat(uint256 reportId, string memory aiAssessment, uint256 severity) public onlyAIAgent {
49+
ThreatReport storage report = threats[reportId];
50+
require(!report.aiValidated, "Already validated");
51+
require(severity > 0 && severity <= 5, "Severity must be 1-5");
52+
report.aiAssessment = aiAssessment;
53+
report.severity = severity;
54+
report.aiValidated = true;
55+
emit ThreatAssessed(reportId, aiAssessment, severity);
56+
}
57+
58+
function getThreat(uint256 reportId) external view returns (
59+
address reporter, string memory target, string memory description,
60+
string memory aiAssessment, uint256 severity, uint256 timestamp, bool aiValidated
61+
) {
62+
ThreatReport storage r = threats[reportId];
63+
return (r.reporter, r.target, r.description, r.aiAssessment, r.severity, r.timestamp, r.aiValidated);
64+
}
65+
}

0 commit comments

Comments
 (0)