AI-powered, verifiable smart contract simulation built for GenLayer
This project implements an Intelligent Contract System using FastAPI, designed for the GenLayer ecosystem.
It combines AI-based evaluation with a deterministic verification layer to simulate verifiable computation.
Key capabilities include:
- Evaluating user input through an AI logic module
- Recomputing outputs for deterministic verification
- Maintaining contract state and execution history for auditability
👉 This demonstrates how intelligent contracts can operate in a scalable, transparent, and verifiable way.
- 🤖 AI-powered evaluation (
ai.py) - ✅ Deterministic verification layer (
verifier.py) - 🧾 State management (pending → verified / rejected)
- 📜 Execution history tracking (audit log)
- 🔐 SHA-256 hashing for integrity
- ⚡ Modular FastAPI architecture
- 🧪 Unit testing included
intelligent-contract/
│
├── app/
│ ├── __init__.py
│ ├── contract.py # Core intelligent contract logic
│ ├── ai.py # AI evaluation logic
│ ├── verifier.py # Verification logic
│ ├── models.py # Data models (Pydantic)
│ ├── config.py # Environment config
│
├── api/
│ ├── main.py # FastAPI entry point
│ ├── routes/
│ │ └── contract.py # API routes
│
├── tests/
│ ├── test_contract.py # Unit tests
│
├── .env.example
├── requirements.txt
├── README.md
└── run.py
git clone https://github.com/mrtrangith2023/intelligent-contract.git
cd intelligent-contract
pip install -r requirements.txt
uvicorn api.main:app --reload
Base URL:
http://localhost:8000/api
Submit request for AI evaluation
Request
{
"user": "alice",
"amount": 100
}Response
{
"request_id": "uuid",
"result": {
"score": 0.9,
"decision": "approved"
},
"status": "pending"
}👉 This output demonstrates AI evaluation + verifiable execution.
{
"request_id": "abc123",
"result": {
"score": 0.9,
"decision": "approved"
},
"status": "pending"
}Verify result deterministically
Response
{
"valid": true,
"status": "verified"
}View execution logs (audit trail)
Get stored contract state
- AI evaluates input data (e.g., scoring logic)
- Decision is generated (
approved/rejected) - Verification recomputes result to ensure correctness
👉 This simulates verifiable computation in smart contracts
- SHA-256 hashing ensures data integrity
- Every action is logged with hash + timestamp
- History acts like a blockchain audit log
Run tests:
pytest
Example:
def test_submit_and_verify():
contract = IntelligentContract("0xADMIN")
res = contract.submit_request("user", {"amount": 100})
assert contract.verify(res["request_id"])["valid"] is TrueSwagger UI:
http://localhost:8000/docs
- Database persistence (PostgreSQL / Redis)
- Authentication (JWT)
- Advanced AI models
- On-chain integration (GenLayer L1)
This project demonstrates:
- AI + Smart Contract integration
- Verifiable execution model
- Modular backend architecture
- Real-world scalable design
👉 Aligned with GenLayer vision of intelligent, verifiable computation
TAM Web3 Builder | Exploring AI x Blockchain 🚀
- GitHub Repo: https://github.com/mrtrangith2023/intelligent-contract
- Demo: Swagger UI (
/docs)
🔥 Built for GenLayer Testnet Mission