How BITE CATs can create superintelligent AI

The smart contract below illustrates how BITE CATS can create superintelligent competitive decentralied AI service

Below is a self-contained Solidity example that implements the AI Battle Arena on top of BITE Phase 2 using Contract-Action-Transactions (CATs). It supports: (1) funding a prize and opening a five-minute contest, (2) encrypted submissions from AI providers, (3) simultaneous decryption via a CAT scheduled at the deadline, and (4) creator-driven winner selection with automatic payout.

  1. Alice needs an AI-generated video and offers ten dollars.

  2. She submits her request to a smart contract, which launches a five-minute contest.

  3. Developers worldwide encrypt and submit results to the contract.

  4. When time expires, the contract decrypts all submissions simultaneously.

Alice reviews the results, selects a winner, and the smart contract automatically transfers payment.

This system creates a fair model for AI services. Participants cannot copy each other’s work, as encryption hides submissions until the deadline.

The competitive structure drives innovation, speed, and diversity, while automated payment guarantees trust.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

/**
 * BITE Phase 2 precompile interface (MVP).
 * CAT semantics:
 *  - Call decryptAndExecute(...) in block N ➜ batch-decrypt at finalization of N
 *  - Start of block N+1: CAT runs first and calls onDecrypt(decrypted, plaintext)
 */
interface IBitePhase2 {
    function decryptAndExecute(
        bytes[] calldata encryptedArguments,
        bytes[] calldata plaintextArguments
    ) external;
}

/**
 * Superintelligent AI Arena (Use Case 2: AI Battle Arena)
 *
 * Flow:
 *  1) Alice funds a prize and creates a contest with a 5-minute window.
 *  2) Developers worldwide submit ENCRYPTED results during the window.
 *  3) After deadline, anyone calls closeContest(), which schedules a CAT.
 *  4) Finalization of block N decrypts; at start of N+1, onDecrypt() receives
 *     all plaintext submissions simultaneously. No one can copy late.
 *  5) Alice reviews decrypted URIs/bytes and selectWinner() pays the winner.
 *
 * Notes (MVP):
 *  - CAT preserves msg.sender of the account that called decryptAndExecute().
 *    We record expectedCaller and require it in onDecrypt() to prevent spoofing.
 *  - For simplicity, prize is ETH; "ten dollars" is illustrative.
 *  - In production, consider deposits, nonces, size limits, and moderation hooks.
 */
contract AIBattleArena {
    // -------------------- Config --------------------
    address constant PRECOMPILE_ADDR = 0x0000000000000000000000000000000000000100;
    IBitePhase2 constant BITE = IBitePhase2(PRECOMPILE_ADDR);

    uint256 public constant DEFAULT_DURATION = 5 minutes;      // contest window
    uint256 public constant DEFAULT_REVIEW_PERIOD = 1 days;    // creator review

    // Minimal reentrancy guard
    uint256 private _unlocked = 1;
    modifier nonReentrant() {
        require(_unlocked == 1, "REENTRANCY");
        _unlocked = 0;
        _;
        _unlocked = 1;
    }

    // -------------------- Storage --------------------
    struct Submission {
        address provider;      // AI developer/submitter
        bytes encPayload;      // encrypted result (opaque until decrypt)
        string uri;            // decrypted URI (e.g., IPFS CID) after CAT
        bytes raw;             // optional raw bytes after CAT (if used)
        bool revealed;         // true once decrypted
    }

    struct Contest {
        address creator;           // Alice
        uint256 deadline;          // submissions close
        uint256 reviewDeadline;    // creator must select winner by this time
        uint256 prize;             // ETH prize in wei
        bool catScheduled;         // CAT requested via closeContest()
        bool decrypted;            // CAT completed and results revealed
        bool finalized;            // prize paid or refunded
        address expectedCaller;    // msg.sender that scheduled decryptAndExecute
        uint256 winnerIndex;       // index of winner in submissions
        Submission[] submissions;  // all submissions in arrival order
    }

    uint256 public nextContestId;
    mapping(uint256 => Contest) private _contests;

    // -------------------- Events --------------------
    event ContestCreated(uint256 indexed contestId, address indexed creator, uint256 deadline, uint256 prize);
    event SubmissionEncrypted(uint256 indexed contestId, address indexed provider, uint256 index);
    event ContestClosed(uint256 indexed contestId, address indexed closer, uint256 numSubmissions);
    event SubmissionsDecrypted(uint256 indexed contestId, uint256 count);
    event WinnerSelected(uint256 indexed contestId, address indexed winner, uint256 prize);
    event PrizeRefunded(uint256 indexed contestId, address indexed creator, uint256 amount);

    // -------------------- Create & Submit --------------------

    /// @notice Alice creates a contest by funding the prize (ETH) and setting a 5-minute window.
    function createContest() external payable returns (uint256 contestId) {
        require(msg.value > 0, "PRIZE_REQUIRED");
        contestId = nextContestId++;
        Contest storage c = _contests[contestId];
        c.creator = msg.sender;
        c.deadline = block.timestamp + DEFAULT_DURATION;
        c.reviewDeadline = 0; // set after decryption
        c.prize = msg.value;
        c.winnerIndex = type(uint256).max;
        emit ContestCreated(contestId, msg.sender, c.deadline, c.prize);
    }

    /// @notice AI providers submit encrypted results before the deadline.
    function submitEncrypted(uint256 contestId, bytes calldata encPayload) external returns (uint256 index) {
        Contest storage c = _requireContest(contestId);
        require(block.timestamp < c.deadline, "SUBMISSIONS_CLOSED");
        require(!c.catScheduled, "ALREADY_CLOSED");

        index = c.submissions.length;
        c.submissions.push(Submission({
            provider: msg.sender,
            encPayload: encPayload,
            uri: "",
            raw: "",
            revealed: false
        }));
        emit SubmissionEncrypted(contestId, msg.sender, index);
    }

    // -------------------- Close & CAT Scheduling --------------------

    /// @notice Anyone can close after deadline to schedule the CAT decryption for block N+1.
    function closeContest(uint256 contestId) external {
        Contest storage c = _requireContest(contestId);
        require(block.timestamp >= c.deadline, "STILL_OPEN");
        require(!c.catScheduled, "ALREADY_SCHEDULED");
        require(!c.decrypted, "ALREADY_DECRYPTED");
        require(c.submissions.length > 0, "NO_SUBMISSIONS");

        // Build encrypted arguments: one entry per submission.
        uint256 n = c.submissions.length;
        bytes[] memory encArgs = new bytes[](n);
        for (uint256 i = 0; i < n; i++) {
            encArgs[i] = c.submissions[i].encPayload;
        }

        // Plaintext context: contestId and count (for sanity checks).
        bytes;
        plainArgs[0] = abi.encode(contestId);
        plainArgs[1] = abi.encode(n);

        c.catScheduled = true;
        c.expectedCaller = msg.sender; // CAT msg.sender must match this

        // Schedule CAT; onDecrypt() will be called at the front of block N+1.
        BITE.decryptAndExecute(encArgs, plainArgs);

        emit ContestClosed(contestId, msg.sender, n);
    }

    // -------------------- CAT Callback (executed in block N+1) --------------------

    /**
     * @notice Receives all decrypted submissions simultaneously.
     * @param decryptedArguments  Array of decrypted payloads (URIs or raw bytes) in the same order as submitted.
     * @param plaintextArguments  [ contestId, nSubmissions ]
     */
    function onDecrypt(
        bytes[] calldata decryptedArguments,
        bytes[] calldata plaintextArguments
    ) external {
        require(plaintextArguments.length == 2, "BAD_PLAINTEXT_CTX");
        (uint256 contestId) = abi.decode(plaintextArguments[0], (uint256));
        (uint256 expectedN) = abi.decode(plaintextArguments[1], (uint256));

        Contest storage c = _requireContest(contestId);
        require(c.catScheduled && !c.decrypted, "BAD_STATE");
        require(msg.sender == c.expectedCaller, "UNEXPECTED_CALLER"); // MVP safeguard

        require(decryptedArguments.length == expectedN, "LEN_MISMATCH");
        require(expectedN == c.submissions.length, "COUNT_MISMATCH");

        // Store plaintext results. For simplicity, interpret bytes as a UTF-8 URI if possible.
        for (uint256 i = 0; i < expectedN; i++) {
            // Developers can choose to encode a URI or raw bytes; we keep both.
            bytes calldata plain = decryptedArguments[i];
            c.submissions[i].raw = plain;
            // Best-effort cast to string; if not valid UTF-8, it will still store a byte-for-byte string.
            c.submissions[i].uri = string(plain);
            c.submissions[i].revealed = true;
        }

        c.decrypted = true;
        c.reviewDeadline = block.timestamp + DEFAULT_REVIEW_PERIOD;

        emit SubmissionsDecrypted(contestId, expectedN);
    }

    // -------------------- Selection & Payout --------------------

    /// @notice Creator selects the winner during the review period and pays out automatically.
    function selectWinner(uint256 contestId, uint256 winnerIndex) external nonReentrant {
        Contest storage c = _requireContest(contestId);
        require(msg.sender == c.creator, "ONLY_CREATOR");
        require(c.decrypted, "NOT_DECRYPTED");
        require(!c.finalized, "FINALIZED");
        require(block.timestamp <= c.reviewDeadline, "REVIEW_ENDED");
        require(winnerIndex < c.submissions.length, "BAD_INDEX");
        require(c.submissions[winnerIndex].revealed, "NOT_REVEALED");

        c.winnerIndex = winnerIndex;
        c.finalized = true;

        address payable winner = payable(c.submissions[winnerIndex].provider);
        uint256 amount = c.prize;
        c.prize = 0;

        (bool ok, ) = winner.call{value: amount}("");
        require(ok, "PAY_FAIL");

        emit WinnerSelected(contestId, winner, amount);
    }

    /// @notice If no winner is selected by the review deadline, the creator can reclaim the prize.
    function refundPrize(uint256 contestId) external nonReentrant {
        Contest storage c = _requireContest(contestId);
        require(msg.sender == c.creator, "ONLY_CREATOR");
        require(!c.finalized, "FINALIZED");
        require(c.decrypted, "NOT_DECRYPTED");
        require(block.timestamp > c.reviewDeadline, "REVIEW_ACTIVE");

        c.finalized = true;
        uint256 amount = c.prize;
        c.prize = 0;

        (bool ok, ) = payable(c.creator).call{value: amount}("");
        require(ok, "REFUND_FAIL");

        emit PrizeRefunded(contestId, c.creator, amount);
    }

    // -------------------- Views --------------------

    function getContest(uint256 contestId)
        external
        view
        returns (
            address creator,
            uint256 deadline,
            uint256 reviewDeadline,
            uint256 prize,
            bool catScheduled,
            bool decrypted,
            bool finalized,
            uint256 submissionsCount,
            uint256 winnerIndex
        )
    {
        Contest storage c = _requireContest(contestId);
        return (
            c.creator,
            c.deadline,
            c.reviewDeadline,
            c.prize,
            c.catScheduled,
            c.decrypted,
            c.finalized,
            c.submissions.length,
            c.winnerIndex
        );
    }

    function getSubmissionMeta(uint256 contestId, uint256 index)
        external
        view
        returns (address provider, bool revealed, string memory uri, bytes memory raw)
    {
        Contest storage c = _requireContest(contestId);
        require(index < c.submissions.length, "BAD_INDEX");
        Submission storage s = c.submissions[index];
        return (s.provider, s.revealed, s.uri, s.raw);
    }

    // -------------------- Internals --------------------
    function _requireContest(uint256 contestId) internal view returns (Contest storage) {
        require(contestId < nextContestId, "NO_SUCH_CONTEST");
        return _contests[contestId];
    }

    // Fallback to accept ETH for prizes if needed (not used in this MVP).
    receive() external payable {}
}

Think of this as an online hackathon for AI, but managed by a blockchain instead of a company.

  • Alice (the contest creator) puts up money as a prize (e.g., $10).
  • AI developers (worldwide) submit their work (encrypted so others can’t copy).
  • When the contest deadline hits, the blockchain itself decrypts all submissions at once.
  • Alice sees all the entries, picks a winner, and the contract automatically sends them the prize.

This avoids cheating (no copying) and ensures fairness (everyone revealed at the same time).


Step 1: Contest Creation

Alice calls createContest() and sends some ETH (the prize).

  • The contract saves her as the creator.
  • It sets a 5-minute deadline for submissions.
  • A new contest ID is created.

At this point, the contract is waiting for submissions.


Step 2: Submissions (Encrypted)

Any AI developer can join. They call submitEncrypted(...) and provide an encrypted payload.

  • This encrypted blob could be:
    • A URL to their AI-generated video.
    • Raw data.
    • Metadata about their entry.

Since it’s encrypted, nobody else (including Alice) can see it yet.
The blockchain just stores it as “opaque bytes.”


Step 3: Closing the Contest

When the 5-minute window ends, anyone (Alice or another user) calls closeContest().

Here’s the magic:

  • The contract calls BITE Phase 2’s decryptAndExecute precompile.
  • This schedules a Contract-Action-Transaction (CAT) for the next block.

Think of this like setting an alarm clock :alarm_clock: that says:

“At the start of the next block, decrypt all the encrypted submissions and run onDecrypt().”


Step 4: Automatic Decryption (via CAT)

At the end of the current block, the blockchain decrypts all submissions.
At the start of the next block, the CAT is triggered:

  • It calls the contract’s onDecrypt() function.
  • This function receives:
    • decryptedArguments: the actual plaintext results (e.g., the URIs or video links).
    • plaintextArguments: extra info like the contest ID and submission count.

The contract then marks all submissions as revealed, storing their URIs/bytes for Alice (and the public) to see.

This step is automatic. No user needs to press a button.


Step 5: Winner Selection

Now that all entries are visible, Alice has until a review deadline (1 day) to call selectWinner().

  • She picks a submission by its index.
  • The contract sends the prize money directly to that developer’s wallet.
  • An event is emitted announcing the winner.

If Alice forgets or doesn’t pick anyone before the deadline, she can call refundPrize() to get her money back.


Security & Fairness Features

  1. Encryption: Prevents copying or last-minute sniping. Everyone’s submission is hidden until decryption.
  2. Simultaneous Reveal: All entries are decrypted at the same time, so no one gets an advantage.
  3. Automation via CATs: The blockchain itself guarantees the timing. No human has to trigger “decryption.”
  4. Automatic Payments: Once Alice picks, the winner gets paid instantly—no trust needed.
  5. Safeguards:
    • pendingCat and expectedCaller prevent fake CAT calls.
    • A reviewDeadline ensures the contest doesn’t stall forever.

Why This Matters

This system creates a fair marketplace for AI services.

  • Developers worldwide can compete.
  • Results are hidden until the end (so originality is rewarded).
  • Alice doesn’t need to trust anyone—the blockchain enforces the rules.

It’s like combining:

  • eBay’s bidding system (fair competition),
  • Kaggle’s AI challenges (global innovation), and
  • Venmo/PayPal (automatic payments),
    but all built into the blockchain itself.

:white_check_mark: In short: BITE Phase 2 turns the blockchain into a fair contest engine. CATs give smart contracts the power to “wake up” and act automatically after encrypted data is revealed.