ci: clean up CI workflows and fix package dependencies
Some checks failed
Integration Tests / test-service-integration (push) Successful in 2m16s
Package Tests / Python package - aitbc-agent-sdk (push) Successful in 25s
Package Tests / Python package - aitbc-core (push) Successful in 22s
Package Tests / Python package - aitbc-crypto (push) Successful in 14s
Package Tests / Python package - aitbc-sdk (push) Successful in 18s
Package Tests / JavaScript package - aitbc-sdk-js (push) Successful in 6s
Package Tests / JavaScript package - aitbc-token (push) Successful in 21s
Production Tests / Production Integration Tests (push) Failing after 10s
Python Tests / test-python (push) Failing after 2m41s
Security Scanning / security-scan (push) Failing after 46s
Smart Contract Tests / test-solidity (map[name:aitbc-token path:packages/solidity/aitbc-token]) (push) Successful in 16s
Smart Contract Tests / lint-solidity (push) Successful in 12s

- Simplified npm install commands in CI workflows by removing fallback logic
- Added aitbc-crypto local dependency installation for aitbc-sdk in package-tests.yml
- Removed aitbc-token specific Hardhat dependency workarounds from package-tests.yml
- Fixed bare except clause in agent_daemon.py to catch specific json.JSONDecodeError
- Moved aitbc-crypto from poetry.dependencies to standard dependencies in aitbc-sdk
- Fixed MyPy type errors in receip
This commit is contained in:
aitbc
2026-04-19 19:24:09 +02:00
parent 0fc735b802
commit 625c1b7812
29 changed files with 3386 additions and 3377 deletions

View File

@@ -1,61 +1,76 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";
import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import { AccessControl } from "@openzeppelin/contracts/access/AccessControl.sol";
import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import { MessageHashUtils } from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
/// @title AIToken
/// @notice ERC20 token that mints units for providers based on attested compute receipts
contract AIToken is ERC20, AccessControl {
using ECDSA for bytes32;
using MessageHashUtils for bytes32;
using ECDSA for bytes32;
using MessageHashUtils for bytes32;
bytes32 public constant COORDINATOR_ROLE = keccak256("COORDINATOR_ROLE");
bytes32 public constant ATTESTOR_ROLE = keccak256("ATTESTOR_ROLE");
bytes32 public constant COORDINATOR_ROLE = keccak256("COORDINATOR_ROLE");
bytes32 public constant ATTESTOR_ROLE = keccak256("ATTESTOR_ROLE");
/// @notice Tracks consumed receipt hashes to prevent replay
mapping(bytes32 => bool) public consumedReceipts;
/// @notice Tracks consumed receipt hashes to prevent replay
mapping(bytes32 => bool) public consumedReceipts;
event ReceiptConsumed(bytes32 indexed receiptHash, address indexed provider, uint256 units, address indexed attestor);
event ReceiptConsumed(
bytes32 indexed receiptHash,
address indexed provider,
uint256 units,
address indexed attestor
);
constructor(address admin) ERC20("AIToken", "AIT") {
_grantRole(DEFAULT_ADMIN_ROLE, admin);
}
constructor(address admin) ERC20("AIToken", "AIT") {
_grantRole(DEFAULT_ADMIN_ROLE, admin);
}
/// @notice Mint tokens for a provider when coordinator submits a valid attested receipt
/// @param provider Address of the compute provider receiving minted tokens
/// @param units Amount of tokens to mint
/// @param receiptHash Unique hash representing the off-chain receipt
/// @param signature Coordinator-attested signature authorizing the mint
function mintWithReceipt(
address provider,
uint256 units,
bytes32 receiptHash,
bytes calldata signature
) external onlyRole(COORDINATOR_ROLE) {
require(provider != address(0), "invalid provider");
require(units > 0, "invalid units");
require(!consumedReceipts[receiptHash], "receipt already consumed");
/// @notice Mint tokens for a provider when coordinator submits a valid attested receipt
/// @param provider Address of the compute provider receiving minted tokens
/// @param units Amount of tokens to mint
/// @param receiptHash Unique hash representing the off-chain receipt
/// @param signature Coordinator-attested signature authorizing the mint
function mintWithReceipt(
address provider,
uint256 units,
bytes32 receiptHash,
bytes calldata signature
) external onlyRole(COORDINATOR_ROLE) {
require(provider != address(0), "invalid provider");
require(units > 0, "invalid units");
require(!consumedReceipts[receiptHash], "receipt already consumed");
bytes32 digest = _mintDigest(provider, units, receiptHash);
address attestor = digest.recover(signature);
require(hasRole(ATTESTOR_ROLE, attestor), "invalid attestor signature");
bytes32 digest = _mintDigest(provider, units, receiptHash);
address attestor = digest.recover(signature);
require(hasRole(ATTESTOR_ROLE, attestor), "invalid attestor signature");
consumedReceipts[receiptHash] = true;
_mint(provider, units);
consumedReceipts[receiptHash] = true;
_mint(provider, units);
emit ReceiptConsumed(receiptHash, provider, units, attestor);
}
emit ReceiptConsumed(receiptHash, provider, units, attestor);
}
/// @notice Helper to compute the signed digest required for minting
function mintDigest(address provider, uint256 units, bytes32 receiptHash) external view returns (bytes32) {
return _mintDigest(provider, units, receiptHash);
}
/// @notice Helper to compute the signed digest required for minting
function mintDigest(
address provider,
uint256 units,
bytes32 receiptHash
) external view returns (bytes32) {
return _mintDigest(provider, units, receiptHash);
}
function _mintDigest(address provider, uint256 units, bytes32 receiptHash) internal view returns (bytes32) {
bytes32 structHash = keccak256(abi.encode(block.chainid, address(this), provider, units, receiptHash));
return structHash.toEthSignedMessageHash();
}
function _mintDigest(
address provider,
uint256 units,
bytes32 receiptHash
) internal view returns (bytes32) {
bytes32 structHash = keccak256(
abi.encode(block.chainid, address(this), provider, units, receiptHash)
);
return structHash.toEthSignedMessageHash();
}
}

View File

@@ -1,46 +1,61 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";
import { AccessControl } from "@openzeppelin/contracts/access/AccessControl.sol";
/// @title AITokenRegistry
/// @notice Tracks permitted providers and staking requirements for AIToken minting
contract AITokenRegistry is AccessControl {
bytes32 public constant COORDINATOR_ROLE = keccak256("COORDINATOR_ROLE");
bytes32 public constant COORDINATOR_ROLE = keccak256("COORDINATOR_ROLE");
struct ProviderInfo {
bool active;
uint256 collateral;
}
struct ProviderInfo {
bool active;
uint256 collateral;
}
mapping(address => ProviderInfo) public providers;
mapping(address => ProviderInfo) public providers;
event ProviderRegistered(address indexed provider, uint256 collateral);
event ProviderUpdated(address indexed provider, bool active, uint256 collateral);
event ProviderRegistered(address indexed provider, uint256 collateral);
event ProviderUpdated(
address indexed provider,
bool active,
uint256 collateral
);
constructor(address admin) {
_grantRole(DEFAULT_ADMIN_ROLE, admin);
}
constructor(address admin) {
_grantRole(DEFAULT_ADMIN_ROLE, admin);
}
function registerProvider(address provider, uint256 collateral) external onlyRole(COORDINATOR_ROLE) {
require(provider != address(0), "invalid provider");
require(!providers[provider].active, "already registered");
providers[provider] = ProviderInfo({active: true, collateral: collateral});
emit ProviderRegistered(provider, collateral);
}
function registerProvider(
address provider,
uint256 collateral
) external onlyRole(COORDINATOR_ROLE) {
require(provider != address(0), "invalid provider");
require(!providers[provider].active, "already registered");
providers[provider] = ProviderInfo({
active: true,
collateral: collateral
});
emit ProviderRegistered(provider, collateral);
}
function updateProvider(
address provider,
bool active,
uint256 collateral
) external onlyRole(COORDINATOR_ROLE) {
require(provider != address(0), "invalid provider");
require(providers[provider].active || active, "provider not registered");
providers[provider] = ProviderInfo({active: active, collateral: collateral});
emit ProviderUpdated(provider, active, collateral);
}
function updateProvider(
address provider,
bool active,
uint256 collateral
) external onlyRole(COORDINATOR_ROLE) {
require(provider != address(0), "invalid provider");
require(providers[provider].active || active, "provider not registered");
providers[provider] = ProviderInfo({
active: active,
collateral: collateral
});
emit ProviderUpdated(provider, active, collateral);
}
function providerInfo(address provider) external view returns (ProviderInfo memory) {
return providers[provider];
}
function providerInfo(
address provider
) external view returns (ProviderInfo memory) {
return providers[provider];
}
}