# Architecture

<mark style="color:green;">**Core Platform Architecture:**</mark> VerAI’s architecture is a modular, scalable framework designed to leverage the power of BASE, an Ethereum Layer 2 (L2) rollup, optimizing for low-cost, high-throughput transactions while ensuring flexibility and future-proof integration. Each module operates independently, interacting via standardized APIs and protocols, enabling seamless adaptation to advancements in AI and blockchain technology.

<mark style="color:green;">**Key Architectural Modules:**</mark>

1\. **Resource Abstraction Layer (RAL).** The RAL standardizes heterogeneous computational resources (GPUs, CPUs) and datasets into uniform compute units and data tokens, simplifying access for Developers across BASE’s decentralized network and eliminating compatibility issues.

&#x32;**. Blockchain Layer on BASE.** VerAI operates on BASE, an Ethereum L2 rollup that delivers scalability with transaction costs reduced by up to 90% and enhanced throughput, ideal for decentralized AI workloads. The blockchain layer manages transactions, tokenomics, and governance via smart contracts, ensuring transparency and security. VerAI implements a hybrid consensus at the application level: Proof-of-Stake (PoS) for DAO governance and Proof-of-Compute (PoC) for validating computational contributions, complementing BASE’s optimistic rollup mechanism.

3\. **AI Training Engine:** The AI Training Engine enables distributed training of AI models by partitioning tasks across BASE’s high-speed network of nodes, minimizing latency and costs. Supporting frameworks like TensorFlow and PyTorch, it ensures high model accuracy and scalability for deep learning applications.

4\. **Decentralized Marketplace Module:**  The marketplace enables Contributors to offer compute power and datasets, and Developers to rent them using $VER tokens, VerAI’s native ERC-20 token on BASE. Dynamic pricing ensures efficient allocation:

$$
P\_r = P\_{\text{base}} \times \left( 1 + \frac{D}{S} \right)
$$

Where:

$$P\_r$$ : Price of resource ( r ).

$$P\_{\text{base}}$$ : Base price per unit.

$$D$$ : Demand for the resource.

$$S$$ : Supply of the resource.

$VER’s permit functionality (EIP-2612) allows gas-efficient approvals, reducing transaction costs on BASE.

<mark style="color:green;">**Blockchain Layer: Smart Contracts and Consensus**</mark>  Smart Contracts on BASE Smart contracts automate resource allocation, reward distribution, and governance. The $VER token contract, deployed at [0xea918b73145d32861ae2cfabf4abe3675415624c ](https://basescan.org/address/0x1301966394ad75cf4Ace0C709e16906691baf379#code)on BASE, is an ERC-20 token with permit, mint, and burn capabilities, enabling efficient payments and incentives:

```solidity
pragma solidity ^0.8.0;

contract VERToken {
    string public name = "VerAI";
    string public symbol = "VER";
    uint8 public decimals = 18;
    mapping(address => uint256) public balanceOf;

    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;
    function mint(address to, uint256 amount) external;
    function burn(uint256 amount) external;
}
```

Additional contracts manage resources and metadata, such as:

```solidity
pragma solidity ^0.8.0;

contract ResourceAllocation {
    struct Resource {
        address provider;
        uint256 capacity;
        uint256 price;
        bool isAvailable;
    }
    mapping(uint256 => Resource) public resources;
    event ResourceAllocated(uint256 resourceId, address user, uint256 price);

    function allocateResource(uint256 resourceId, address user) external payable {
        require(resources[resourceId].isAvailable, "Resource not available");
        require(msg.value >= resources[resourceId].price, "Insufficient payment");
        resources[resourceId].isAvailable = false;
        payable(resources[resourceId].provider).transfer(msg.value);
        emit ResourceAllocated(resourceId, user, msg.value);
    }
}
```

<mark style="color:green;">**Consensus Mechanisms:**</mark> VerAI leverages BASE’s optimistic rollup for transaction finality, relying on Ethereum L1’s PoS consensus for security. At the application level, VerAI implement

* **Proof-of-Stake (PoS)**: For DAO governance, allowing $VER holders to vote on platform upgrades.
* **Proof-of-Compute (PoC)**: Validates computational work with cryptographic proofs:

$$
P = H(T || \text{nonce})
$$

Where:

&#x20;: Proof submitted by the node.

$$(H)$$ : Cryptographic hash function (SHA-256).

$$(T)$$ : Computational task.

$${nonce}$$ : Unique random value.

<mark style="color:green;">**Decentralized Resource Management Protocol (DRMP)**</mark> The DRMP ensures efficient resource allocation on BASE:

* **Load Balancing:** Distributes tasks to prevent node overload:

$$
|L\_i - L\_{\text{avg}}| \leq \tau
$$

Where:

$$L\_i$$ : Load on node ( i ).

$$L\_{\text{avg}}$$ : Average network load.

$$tau$$ : Threshold for load deviation.

* **Resource Matching Algorithm:** Matches requests with resources:

```
function matchResources(requests, resources):
    sort resources by cost ascending
    allocation = {}
    for req in requests:
        for res in resources:
            if res.capacity >= req.demand and res.isAvailable:
                allocation[req.id] = res.id
                res.capacity -= req.demand
                res.isAvailable = false if res.capacity == 0
                break
    return allocation
```

* **Fraud Prevention:** PoC and BASE’s fraud proofs ensure integrity.

<mark style="color:green;">**Storage Solutions: IPFS and On-Chain Metadata**</mark>&#x20;

**IPFS for Dataset Storage**&#x20;

Datasets are stored off-chain on IPFS:

$$
\text{CID} = H(\text{dataset})
$$

Where: $$(H)$$ : is a cryptographic hash function (SHA-256).

<mark style="color:green;">**On-Chain Metadata on BASE**</mark>

Metadata (ownership, size, permissions) is stored on BASE:

```solidity
pragma solidity ^0.8.0;

contract DatasetMetadata {
    struct Dataset {
        address owner;
        string cid;
        uint256 size;
        bool isPublic;
        uint256 price;
    }
    mapping(uint256 => Dataset) public datasets;

    function addDataset(uint256 id, string memory cid, uint256 size, bool isPublic, uint256 price) external {
        datasets[id] = Dataset(msg.sender, cid, size, isPublic, price);
    }
}
```

<mark style="color:green;">**Networking Protocols for Distributed AI Training**</mark>&#x20;

**Task Partitioning**&#x20;

Models are split into sub-tasks:

$$
M = \bigcup\_{i=1}^P M\_i
$$

**Where:**

$$(M)$$ : Full model.

$$M\_i$$ : Sub-task on node ( i ).

$$(P)$$ : Number of partitions.

<mark style="color:green;">**Gradient Aggregation**</mark>&#x20;

Nodes synchronize updates using AllReduce:

$$
\theta\_{t+1} = \theta\_t - \alpha \nabla L(\theta\_t)
$$

**Where:**

$$theta\_t$$ : Parameters at iteration ( t ).

$$\alpha $$ : Learning rate.

$$\nabla L(\theta\_t) $$ : Gradient of the loss function.

<mark style="color:green;">**Fault Tolerance**</mark>

* **Checkpoints:** Saved to IPFS, with CIDs on BASE.
* **Redundancy:** Tasks reassigned on node failure, leveraging BASE’s high throughput.

\\
