|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | +pragma solidity ^0.8.20; |
| 3 | + |
| 4 | +/// @title AutonomousAIModelRegistry |
| 5 | +/// @notice Decentralized, unstoppable registry for AI models, upgrades, and activation. |
| 6 | +contract AutonomousAIModelRegistry { |
| 7 | + struct Model { |
| 8 | + string name; |
| 9 | + string version; |
| 10 | + string ipfsHash; // Location of the model weights, manifest, or code |
| 11 | + address submitter; |
| 12 | + bool verified; |
| 13 | + bool active; |
| 14 | + uint256 timestamp; |
| 15 | + } |
| 16 | + |
| 17 | + uint256 public totalModels; |
| 18 | + mapping(uint256 => Model) public models; |
| 19 | + address public owner; |
| 20 | + address public verifier; // Can be an AI agent or DAO agent |
| 21 | + |
| 22 | + event ModelSubmitted(uint256 indexed modelId, string name, string version, string ipfsHash, address submitter); |
| 23 | + event ModelVerified(uint256 indexed modelId, bool verified, address verifier); |
| 24 | + event ModelActivated(uint256 indexed modelId, bool active); |
| 25 | + |
| 26 | + modifier onlyVerifier() { |
| 27 | + require(msg.sender == verifier, "Not authorized"); |
| 28 | + _; |
| 29 | + } |
| 30 | + |
| 31 | + modifier onlyOwner() { |
| 32 | + require(msg.sender == owner, "Only owner"); |
| 33 | + _; |
| 34 | + } |
| 35 | + |
| 36 | + constructor(address _verifier) { |
| 37 | + owner = msg.sender; |
| 38 | + verifier = _verifier; |
| 39 | + } |
| 40 | + |
| 41 | + function submitModel(string memory name, string memory version, string memory ipfsHash) public returns (uint256) { |
| 42 | + totalModels++; |
| 43 | + models[totalModels] = Model({ |
| 44 | + name: name, |
| 45 | + version: version, |
| 46 | + ipfsHash: ipfsHash, |
| 47 | + submitter: msg.sender, |
| 48 | + verified: false, |
| 49 | + active: false, |
| 50 | + timestamp: block.timestamp |
| 51 | + }); |
| 52 | + emit ModelSubmitted(totalModels, name, version, ipfsHash, msg.sender); |
| 53 | + return totalModels; |
| 54 | + } |
| 55 | + |
| 56 | + function verifyModel(uint256 modelId, bool status) public onlyVerifier { |
| 57 | + models[modelId].verified = status; |
| 58 | + emit ModelVerified(modelId, status, msg.sender); |
| 59 | + } |
| 60 | + |
| 61 | + function activateModel(uint256 modelId, bool status) public onlyOwner { |
| 62 | + require(models[modelId].verified, "Model must be verified"); |
| 63 | + models[modelId].active = status; |
| 64 | + emit ModelActivated(modelId, status); |
| 65 | + } |
| 66 | + |
| 67 | + function setVerifier(address _verifier) public onlyOwner { |
| 68 | + verifier = _verifier; |
| 69 | + } |
| 70 | + |
| 71 | + function getModel(uint256 modelId) external view returns ( |
| 72 | + string memory, string memory, string memory, address, bool, bool, uint256 |
| 73 | + ) { |
| 74 | + Model storage m = models[modelId]; |
| 75 | + return (m.name, m.version, m.ipfsHash, m.submitter, m.verified, m.active, m.timestamp); |
| 76 | + } |
| 77 | +} |
0 commit comments