diff --git a/README.md b/README.md index 51bf091..2f9ade7 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ -# Cognitive Routing Protocol (CRP) +# Cognitive Routing Protocol (CRP) — Simulation Prototype -[![Project Status: Prototype Complete](https://img.shields.io/badge/status-prototype_complete-brightgreen.svg)](https://github.com/Yudis-bit/Cognitive-Routing-Protocol) +[![Project Status: Prototype Complete](https://img.shields.io/badge/status-prototype-green.svg)](https://github.com/Yudis-bit/Cognitive-Routing-Protocol) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) -This repository contains the complete architecture and functional prototype for the **Cognitive Routing Protocol (CRP)**, a Layer-0/Layer-1 enhancement protocol designed to fundamentally reshape the efficiency, resilience, and profitability of Decentralized Physical Infrastructure Networks (DePIN). +A seeded Python simulation exploring adaptive routing with Multi-Armed Bandit reinforcement learning, comparing a cognitive router against a static Dijkstra baseline. Includes a reference Solidity `NodeRegistry` contract for on-chain node registration and staking. --- @@ -83,7 +83,7 @@ To run this project locally, you'll need to set up both the simulation and contr * [x] **Phase 2: "Dumb" Router (Baseline)** - Dijkstra's algorithm implementation for benchmarking. * [x] **Phase 3: Cognitive Node (AI Core)** - AI agent implementation with a Multi-Armed Bandit model. * [x] **Phase 4: Integration & Comparative Analysis** - Validation of CRP's performance benefits. -* [x] **Phase 5: On-Chain Component Design (Solidity)** - Smart contract architecture for trust and staking. +* [x] **Phase 5: On-Chain Component Design (Solidity)** — Reference interface and stub contract implemented; on-chain integration and testing is future work. ## Contributing diff --git a/contracts/contracts/INodeRegistry.sol b/contracts/contracts/INodeRegistry.sol index e69de29..5b414fc 100644 --- a/contracts/contracts/INodeRegistry.sol +++ b/contracts/contracts/INodeRegistry.sol @@ -0,0 +1,9 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.20; + +interface INodeRegistry { + function registerNode(bytes32 nodeId) external; + function stake(bytes32 nodeId) external payable; + function getTrustScore(bytes32 nodeId) external view returns (uint256); + function isRegistered(bytes32 nodeId) external view returns (bool); +} \ No newline at end of file diff --git a/contracts/contracts/NodeRegistry.sol b/contracts/contracts/NodeRegistry.sol index e69de29..1be4bde 100644 --- a/contracts/contracts/NodeRegistry.sol +++ b/contracts/contracts/NodeRegistry.sol @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.20; + +import {INodeRegistry} from "./INodeRegistry.sol"; + +contract NodeRegistry is INodeRegistry { + mapping(bytes32 => bool) private _registered; + mapping(bytes32 => uint256) private _stakes; + mapping(bytes32 => uint256) private _trustScores; + + function registerNode(bytes32 nodeId) external override { + require(!_registered[nodeId], "already registered"); + _registered[nodeId] = true; + _trustScores[nodeId] = 100; + } + + function stake(bytes32 nodeId) external payable override { + require(_registered[nodeId], "not registered"); + _stakes[nodeId] += msg.value; + } + + function getTrustScore(bytes32 nodeId) external view override returns (uint256) { + return _trustScores[nodeId]; + } + + function isRegistered(bytes32 nodeId) external view override returns (bool) { + return _registered[nodeId]; + } +} \ No newline at end of file diff --git a/contracts/hardhat.config.js b/contracts/hardhat.config.js index e69de29..d528cb6 100644 --- a/contracts/hardhat.config.js +++ b/contracts/hardhat.config.js @@ -0,0 +1,6 @@ +require("@nomicfoundation/hardhat-toolbox"); + +/** @type import('hardhat/config').HardhatUserConfig */ +module.exports = { + solidity: "0.8.20", +}; \ No newline at end of file diff --git a/contracts/package.json b/contracts/package.json index 9c6c526..ad3e265 100644 --- a/contracts/package.json +++ b/contracts/package.json @@ -12,6 +12,10 @@ "author": "", "license": "ISC", "description": "", + "devDependencies": { + "@nomicfoundation/hardhat-toolbox": "^4.0.0", + "hardhat": "^2.22.0" + }, "dependencies": { "@openzeppelin/contracts": "^5.4.0" }