Skip to content
guidoalejoPublic

About

MVP Protocol for Vehicle Tokenization Using AI and Blockchain

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

AutoRWA: AI-Powered Vehicle Tokenization Protocol

Python Solidity FastAPI Foundry License

Disclaimer: This is an MVP for educational/research purposes. Not intended for production use without proper security audits and compliance reviews.

🎯 Overview

AutoRWA is an innovative Real-World Asset (RWA) tokenization platform that combines blockchain technology with machine learning to enable dynamic vehicle valuation and real-time risk management. The protocol tokenizes vehicle assets as ERC-721 NFTs with AI-powered price updates via an Oracle bridge.

Key Features

  • πŸ€– AI-Powered Valuation: Machine learning models provide real-time vehicle price predictions
  • ⛓️ Blockchain Integration: ERC-721 smart contracts with Oracle-based data updates
  • πŸ“Š Risk Scoring: Automated risk assessment using Random Forest models
  • πŸ”„ Oracle Bridge: Automated synchronization between ML predictions and blockchain state
  • 🌐 RESTful API: FastAPI-based service for ML predictions and vehicle data

πŸ—οΈ Architecture

graph TB
    subgraph "ML Engine"
        VE[Valuation Model<br/>Linear Regression<br/>RΒ² = 0.9455]
        RS[Risk Scoring<br/>Random Forest<br/>RΒ² = 0.9945]
        FE[Feature Engineering<br/>Preprocessing Pipeline]
    end
    
    subgraph "API Layer"
        API[FastAPI Gateway<br/>REST Endpoints<br/>/predict, /health]
    end
    
    subgraph "Oracle Bridge"
        OB[Oracle Bridge Service<br/>Web3 Integration<br/>Transaction Signing]
    end
    
    subgraph "Blockchain Layer"
        SC[VehicleAsset.sol<br/>ERC-721 Contract<br/>Access Control]
        BC[(Ethereum/Polygon<br/>Blockchain)]
    end
    
    FE --> VE
    FE --> RS
    VE --> API
    RS --> API
    API -->|HTTP POST| OB
    OB -->|updateAssetData()| SC
    SC -->|Events| BC
    BC -->|State Updates| OB
    
    style VE fill:#8bc34a
    style RS fill:#ffc107
    style API fill:#ff9800
    style OB fill:#2196f3
    style SC fill:#4caf50
Loading

System Flow

  1. ML Prediction: Vehicle data β†’ Feature Engineering β†’ ML Models β†’ Price & Risk Score
  2. API Service: FastAPI serves predictions via REST endpoints
  3. Oracle Bridge: Monitors ML API and updates blockchain via signed transactions
  4. Smart Contract: Stores vehicle data on-chain with role-based access control

πŸ“ Project Structure

AutoRWA/
β”œβ”€β”€ contracts/                 # Smart Contracts (Solidity)
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   └── VehicleAsset.sol   # ERC-721 contract with Oracle integration
β”‚   β”œβ”€β”€ test/
β”‚   β”‚   └── VehicleAsset.t.sol # Foundry test suite (20+ tests)
β”‚   β”œβ”€β”€ script/
β”‚   β”‚   └── Deploy.s.sol      # Deployment scripts
β”‚   └── foundry.toml          # Foundry configuration
β”‚
β”œβ”€β”€ backend/                   # Backend Services
β”‚   β”œβ”€β”€ main.py               # FastAPI application (800+ lines)
β”‚   β”œβ”€β”€ bridge.py             # Oracle Bridge service (700+ lines)
β”‚   └── README.md             # Backend documentation
β”‚
β”œβ”€β”€ ml_models/                 # Machine Learning Engine
β”‚   β”œβ”€β”€ valuation_engine.py  # ML pipeline and training
β”‚   β”œβ”€β”€ trained_models/       # Serialized models (.joblib)
β”‚   └── test_models.py        # Model validation tests
β”‚
β”œβ”€β”€ data/                      # Datasets
β”‚   └── simulation/           # Synthetic vehicle data
β”‚
β”œβ”€β”€ scripts/                   # Utility scripts
β”‚   └── demo_full_system.py   # End-to-end demonstration
β”‚
β”œβ”€β”€ .env.example              # Environment variables template
β”œβ”€β”€ requirements.txt          # Python dependencies
β”œβ”€β”€ .gitignore               # Git ignore rules
└── README.md                # This file

πŸš€ Quick Start

Prerequisites

  • Python 3.10+ (recommended: 3.11 or 3.12)
  • Foundry (for smart contract development and testing)
  • Node.js (optional, for Foundry installation)

Installation

  1. Clone the repository

    git clone https://github.com/yourusername/AutoRWA.git
    cd AutoRWA
  2. Install Foundry (if not already installed)

    # Linux/macOS
    curl -L https://foundry.paradigm.xyz | bash
    foundryup
    
    # Windows (PowerShell as Administrator)
    # Install Rust first: https://rustup.rs/
    # Then install Foundry via cargo
    cargo install foundry-cli foundryup
    foundryup
  3. Install Python dependencies

    pip install -r requirements.txt
  4. Set up environment variables

    cp .env.example .env
    # Edit .env and add your configuration:
    # - PRIVATE_KEY_ORACLE: Your Ethereum private key (for Oracle)
    # - RPC_URL: Blockchain RPC endpoint
    # - CONTRACT_ADDRESS: Deployed contract address (after deployment)
  5. Install Foundry dependencies (for smart contracts)

    cd contracts
    forge install

Running the System

  1. Start the ML API

    cd backend
    python main.py
    # API will be available at http://localhost:8000
  2. Deploy Smart Contract (local development)

    # Start local blockchain (Anvil)
    anvil
    
    # In another terminal, deploy contract
    cd contracts
    forge script script/Deploy.s.sol --rpc-url http://localhost:8545 --broadcast
  3. Start Oracle Bridge

    cd backend
    python bridge.py
    # Bridge will monitor ML API and update blockchain

Testing

Smart Contract Tests:

cd contracts
forge test -vv

Backend/ML Tests:

# Ensure API is running first
pytest test_api.py -v

πŸ”§ Configuration

Environment Variables

Create a .env file based on .env.example:

# Blockchain Configuration
RPC_URL="http://127.0.0.1:8545"
CHAIN_ID=31337
PRIVATE_KEY_ORACLE=""  # Must be set - no default for security
CONTRACT_ADDRESS=""    # Set after deployment

# ML API Configuration
ML_API_URL="http://localhost:8000"

# Oracle Configuration
UPDATE_INTERVAL_SECONDS=10
MAX_GAS_PRICE_GWEI=30
GAS_LIMIT=500000

⚠️ Security Note: Never commit your .env file. The .gitignore is configured to exclude it.

πŸ“Š ML Models

Valuation Model

  • Algorithm: Linear Regression
  • Performance: RΒ² = 0.9455
  • Features: Brand, Year, Kilometers, Accidents
  • Output: Estimated price in USD

Risk Scoring Model

  • Algorithm: Random Forest
  • Performance: RΒ² = 0.9945
  • Output: Risk score (0-100)

Training Models

To train new models:

cd ml_models
python valuation_engine.py

Models will be saved to ml_models/trained_models/.

πŸ” Security

Smart Contract Security

  • βœ… Access Control (OpenZeppelin)
  • βœ… ReentrancyGuard protection
  • βœ… Pausable emergency circuit breaker
  • βœ… Input validation and bounds checking

Backend Security

  • βœ… Environment variables for sensitive data
  • βœ… No hardcoded private keys
  • βœ… Input validation with Pydantic
  • βœ… Error handling and logging

πŸ“š Documentation

  • Smart Contracts: See contracts/README.md
  • Backend API: See backend/README.md
  • Oracle Bridge: See backend/ORACLE_README.md

πŸ§ͺ Testing

The project includes comprehensive test suites:

  • Smart Contracts: 20+ Foundry tests covering:

    • Admin minting functionality
    • Oracle update operations
    • Access control and security
    • Edge cases and validation
  • Backend: Integration tests for API endpoints and ML predictions

πŸ› οΈ Tech Stack

  • Blockchain: Solidity 0.8.20, Foundry, OpenZeppelin
  • Backend: Python 3.10+, FastAPI, Web3.py
  • ML: Scikit-learn, Pandas, NumPy, Joblib
  • Database: SQLite (MVP)

πŸ“ License

This project is licensed under the MIT License.

🀝 Contributing

Contributions are welcome! Please read the contributing guidelines and code of conduct before submitting PRs.

⚠️ Disclaimer

This is an MVP for educational/research purposes.

  • Not audited for production use
  • Not intended for handling real funds without proper security reviews
  • Models trained on synthetic data - not validated on real-world datasets
  • Use at your own risk

πŸ“§ Contact

For questions or support, please open an issue on GitHub.


Version: 1.0.0
Last Updated: January 2026

About

MVP Protocol for Vehicle Tokenization Using AI and Blockchain

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages