Skip to content
Smart Contracts Reference

Smart Contracts Reference

The middleware functionality is powered by a suite of smart contracts deployed on an Ethereum-based blockchain. Below is a summary of each contract and its primary methods.

RoleManagement Contract

Implements role-based access control (RBAC) following ERC interfaces for ACL.

Core Methods:

  • grantRole(bytes32 role, address account): Assigns a role to an account (requires admin role).
  • revokeRole(bytes32 role, address account): Removes a role from an account (requires admin role).
  • hasRole(bytes32 role, address account): Checks if an account has a specific role.
  • getRolesOf(address account): Returns all roles assigned to an account.

Metadata & Management:

  • createRole(bytes32 role, bytes32 adminOfRole, string name, string desc, string uri, bytes data): Creates a new role with metadata.
  • destroyRole(bytes32 role, bytes data): Destroys a role.
  • setRolePower(bytes32 role, bytes4 method, bytes data): Sets method permissions for a role.
  • roleName(bytes32 role): Returns role name.
  • roleDescription(bytes32 role): Returns role description.
  • roleURI(bytes32 role): Returns role metadata URI.

AIModelRegistry Contract

Handles AI model registration, ownership, and versioning.

  • registerAIModel(bytes32 _id, address _userDID, bytes32 _hash): Registers a new AI model with hash.
  • updateAIModel(address _userDID, bytes32 _id, bytes32 _newHash): Updates an existing model hash.
  • getAIModel(bytes32 _id): Retrieves model hash and owner address.
  • getOwner(bytes32 _id): Returns the owner of a specific model.
  • transferOwnership(bytes32 _id, address _newOwner): Transfers model ownership (admin only).

DatasetRegistry Contract

Manages dataset registration, ownership, and versioning.

  • registerDataset(bytes32 _id, address _userDID, bytes32 _hash): Registers a new dataset with hash.
  • updateDataset(address _userDID, bytes32 _id, bytes32 _newHash): Updates a dataset hash.
  • getDataset(bytes32 _id): Retrieves dataset hash and owner address.
  • getOwner(bytes32 _id): Returns the owner of a specific dataset.
  • transferOwnership(bytes32 _id, address _newOwner): Transfers dataset ownership (admin only).

HardwareRegistry Contract

Manages hardware device registration, ownership, and versioning.

  • registerHardware(bytes32 _id, address _userDID, bytes32 _hash): Registers a new hardware device with hash (requires HARDWARE_OWNER_ROLE).
  • updateHardware(address _userDID, bytes32 _id, bytes32 _newHash): Updates hardware information (requires HARDWARE_OWNER_ROLE or HARDWARE_OPERATOR_ROLE with delegation).
  • deleteHardware(address _userDID, bytes32 _id): Deletes a hardware device (requires HARDWARE_OWNER_ROLE or HARDWARE_OPERATOR_ROLE with delegation).
  • getHardware(bytes32 _id): Retrieves hardware hash and owner address.
  • getOwner(bytes32 _id): Returns the owner of a specific hardware device.
  • transferOwnership(bytes32 _id, address _newOwner): Transfers hardware ownership to a new owner (admin only).

Note: Hardware details (URI, specifications) are stored off-chain. The contract stores only the hash of the hardware metadata for verification.

Benchmarking Contract

Manages AI model benchmarking requests and encrypted results with license validation.

Methods:

  • registerBenchmark(address _userDID, bytes32 _id, string _modelHash, string _datasetHash, string _target, string _runtime, string _benchmarkType): Registers a new benchmark request (requires BENCHMARKING_REQUESTER role and valid license).
  • registerDevice(address _userDID, bytes32 _id, bytes32 _deviceId): Associates a hardware device with a benchmark (requires BENCHMARKING_PRODUCER role and hardware ownership).
  • setBenchmarkResult(address _userDID, bytes32 _id, string _iv, string _ciphertext, string _authTag, bytes32 _reportHash): Stores encrypted benchmark results (requires BENCHMARKING_PRODUCER role).
  • getBenchmark(bytes32 _id): Retrieves benchmark details (userDID, modelHash, datasetHash, target, runtime, deviceId).
  • getBenchmarkResult(bytes32 _id): Retrieves encrypted benchmark results (userDID, iv, ciphertext, authTag, reportHash).
  • pause(address userDID): Pauses the contract (requires ADMIN_ROLE).
  • unpause(address userDID): Unpauses the contract (requires ADMIN_ROLE).

Events:

  • BenchmarkRequested(bytes32 id, address userDID, string modelHash, string datasetHash, string target, string runtime, string benchmarkType)
  • BenchmarkManaged(bytes32 id, address userDID, string modelHash, string datasetHash, bytes32 deviceId)
  • DeviceRegistered(bytes32 id, address userDID, bytes32 deviceId)

Benchmark Types: The contract supports TYPE1, TYPE2, and TYPE3 benchmarks, validated against hardware licenses.

PolicyManager Contract

Manages user and hardware policies, and issues licenses for benchmarking access.

License Structure: Each license includes:

  • hash: Policy hash
  • expirationTime: Unix timestamp for expiration (0 for no expiration)
  • type1, type2, type3: Booleans indicating which benchmark types are allowed
  • singleUse: If true, license is consumed after one use

Policy Management:

  • addUserPolicy(address _userDID, address _did, bytes32 _hash): Adds or updates a policy for a user (requires LICENSE_MANAGER_ROLE).
  • removeUserPolicy(address _userDID, address _did): Removes a user policy (requires LICENSE_MANAGER_ROLE).
  • addHardwarePolicy(address _userDID, bytes32 _id, bytes32 _hash): Adds or updates a policy for hardware (requires LICENSE_MANAGER_ROLE).
  • removeHardwarePolicy(address _userDID, bytes32 _id): Removes a hardware policy (requires LICENSE_MANAGER_ROLE).
  • getUserPolicy(address _did): Retrieves the policy hash for a user.
  • getHardwarePolicy(bytes32 _id): Retrieves the policy hash for hardware.

License Management:

  • issueLicense(address _userDID, address _did, bytes32 _id, bytes32 _hash, bool _singleUse, uint256 _durationInSeconds, bool type1, bool type2, bool type3): Issues a license to an identity for specific hardware (requires LICENSE_MANAGER_ROLE).
    • _durationInSeconds: Duration in seconds (0 for no expiration)
    • type1, type2, type3: Enable specific benchmark types
  • revokeLicense(address _userDID, address _did, bytes32 _id): Revokes a license (requires LICENSE_MANAGER_ROLE).
  • consumeLicense(address _did, bytes32 _id): Consumes a single-use license (called by Benchmarking contract).
  • isLicenseValid(address _did, bytes32 _id, string benchmarkType): Checks if a license is valid for a benchmark type.
  • getLicense(address _did, bytes32 _id): Retrieves full license details.
  • setBenchmarking(address _benchmarkingAddress): Sets the benchmarking contract address (requires root/owner).
  • pause(address userDID): Pauses the contract (requires ADMIN_ROLE).
  • unpause(address userDID): Unpauses the contract (requires ADMIN_ROLE).

Events:

  • UserPolicyCreated(address indexed did, bytes32 hash)
  • UserPolicyRemoved(address indexed did)
  • HardwarePolicyCreated(bytes32 indexed id, bytes32 hash)
  • HardwarePolicyRemoved(bytes32 indexed did)
  • LicenseIssued(address indexed did, bytes32 indexed id, bytes32 hash, uint256 expirationTime)
  • LicenseRevoked(address indexed did, bytes32 indexed id)
  • BenchmarkingAddressSet(address indexed newBenchmarking)

Integration: The PolicyManager works with the Benchmarking contract to enforce license requirements before allowing benchmark requests.

AccessControl Contract

Manages access to datasets, AI models, and hardware with time-based and usage-based constraints.

Resource Types:

  • ResourceType.DATASET (0)
  • ResourceType.AI_MODEL (1)
  • ResourceType.HARDWARE (2)

Methods:

  • grantAccess(address _userDID, address _identity, bytes32 _resourceId, ResourceType _resourceType, uint256 _expirationTime, uint256 _usageLimit, bool _indefinite): Grants access with constraints (requires ACCESS_MANAGER_ROLE or RESOURCE_OWNER_ROLE).
    • _expirationTime: Unix timestamp for expiration (0 for no time limit)
    • _usageLimit: Maximum number of uses (0 for unlimited)
    • _indefinite: If true, access never expires
  • revokeAccess(address _userDID, address _identity, bytes32 _resourceId, ResourceType _resourceType): Revokes access.
  • registerAccess(address _userDID, address _identity, bytes32 _resourceId, ResourceType _resourceType): Registers a resource usage (increments usage counter).
  • checkAccess(address _identity, bytes32 _resourceId): Verifies if identity has valid access rights.

Marketplace Contract

Lists datasets, AI models, and hardware resources for sale using the reward token.

Resource Types:

  • ResourceType.DATASET (0)
  • ResourceType.AI_MODEL (1)
  • ResourceType.HARDWARE (2)

Methods:

  • listResource(address _userDID, bytes32 _resourceId, uint256 _price, ResourceType _resourceType): Lists a resource in the marketplace (requires SELLER_ROLE and resource ownership).
  • buyResource(address _userDID, bytes32 _resourceId): Purchases a listed resource using reward tokens (requires BUYER_ROLE and approved token transfer).
  • removeListing(address _userDID, bytes32 _resourceId): Removes a listing from marketplace (requires MARKETPLACE_OPERATOR_ROLE).
  • getListing(bytes32 _resourceId): Retrieves listing details (seller, buyer, price, resourceType, bought status).

Token Payments: The contract uses RewardToken for payments. Buyers must approve the marketplace contract before purchasing.

RewardToken Contract

An ERC-20 token for rewards and marketplace transactions.

  • Includes standard ERC-20 methods (transfer, balanceOf, etc.).
  • mint(to, amount): Mints new tokens, restricted to authorized roles.

RewardManager Contract

Manages the issuance and distribution of reward tokens based on rules and actions.

Roles:

  • REWARD_ADMIN_ROLE: Can create/remove reward rules and issue manual rewards
  • REWARD_DISTRIBUTOR_ROLE: Can issue rewards for on-chain actions
  • ORACLE_ROLE: Can issue rewards for off-chain actions

Reward Rule Management:

  • setRewardRule(address _userDID, bytes32 _action, uint256 _rewardAmount): Creates or updates a reward rule for an action (requires REWARD_ADMIN_ROLE).
  • removeRewardRule(address _userDID, bytes32 _action): Removes a reward rule (requires REWARD_ADMIN_ROLE).
  • getRewardByRule(bytes32 _action): Retrieves the reward amount for an action.

Reward Distribution:

  • manualReward(string _id, address _userDID, address _identity, uint256 _rewardAmount): Issues a manual reward of any amount (requires REWARD_ADMIN_ROLE).
  • rewardOnChainAction(string _id, address _userDID, address _identity, bytes32 _action): Issues rewards for on-chain actions based on rules (requires REWARD_DISTRIBUTOR_ROLE).
  • rewardOffChainAction(string _id, address _userDID, address _identity, bytes32 _action): Issues rewards for verified off-chain actions (requires ORACLE_ROLE).
  • getRewardHistory(address _identity): Returns total rewards received by an identity.

Events: Each reward type emits a specific event (ManualRewardCreated, OnChainRewardCreated, OffChainRewardCreated) with a unique ID for tracking.

IdentityManagement Contract

Implements decentralized identity (DID) management based on ERC-1056.

  • identityOwner(identity): Returns the owner of a DID.
  • changeOwner(identity, newOwner): Changes the DID owner.
  • addDelegate(...) / revokeDelegate(...): Manages delegates.
  • setAttribute(...) / revokeAttribute(...): Manages DID attributes.