Smart Contract Overview
AIA_Chain.sol
The AIA_Chain contract is the core of the AIA network, implementing a permissionless proof-of-computation consensus mechanism with privacy-preserving features.
Contract Address
- Polygon Amoy Testnet: Set in your
.envfile asVITE_AIA_CHAIN_ADDRESS
Key Features
1. Permissionless Validation
No registration or staking required. Anyone can:
- Submit contributions
- Validate contributions
- Earn rewards based on performance
2. Fee-Based Economics
Contributors pay fees that get distributed to validators:
uint256 public baseFeePerRequest = 0.001 MATIC;
uint256 public feePerValidator = 0.0002 MATIC per validator;
uint256 public priorityFee = 0.005 MATIC;
3. Privacy Infrastructure
- Public key registry for encryption
- Encrypted data storage on-chain
- Secure communication between parties
Core Functions
For Contributors
submitContribution
function submitContribution(
bytes32 _gradientHash,
bytes32 _proofHash,
string memory _encryptedData,
uint256 _epsilon,
uint8 _requestedValidators,
bool _isPriority
) external payable returns (bytes32)
Parameters:
_gradientHash: Hash of the gradient data (for federated learning)_proofHash: Zero-knowledge proof hash_encryptedData: Encrypted message content (for AI inference)_epsilon: Privacy budget to use (scaled by 1e6)_requestedValidators: Number of validators needed_isPriority: Whether to prioritize this request
Returns: Contribution ID
Fee Calculation:
fee = baseFeePerRequest + (_requestedValidators * feePerValidator) + (isPriority ? priorityFee : 0)
For Validators
registerPublicKey
function registerPublicKey(string memory _publicKey) external
Registers a validator's public key for encryption purposes.
Events:
event PublicKeyRegistered(address indexed validator, string publicKey);
submitValidationWork
function submitValidationWork(
bytes32 _contributionId,
uint256 _computeTimeSeconds,
bytes32 _validationProof,
string memory _encryptedResponse,
uint256 _qualityScore
) external
Parameters:
_contributionId: ID of the contribution being validated_computeTimeSeconds: Time taken to compute (used for reward calculation)_validationProof: Proof of computation_encryptedResponse: Encrypted AI response for contributor_qualityScore: Self-reported quality (0-100)
Reward Calculation: Rewards are distributed when enough validators have submitted work:
reward = (baseShare * qualityScore) / 100
Where baseShare = totalFee / requestedValidators
Data Structures
Contribution
struct Contribution {
address contributor;
bytes32 gradientHash;
bytes32 proofHash;
string encryptedData;
uint256 epsilon;
uint256 timestamp;
uint256 validatorCount;
uint8 requestedValidators;
bool isVerified;
uint256 averageQualityScore;
uint256 totalRewardDistributed;
uint256 requestFee;
}
ValidationWork
struct ValidationWork {
address validator;
uint256 computeTimeSeconds;
uint256 qualityScore;
bytes32 validationProof;
string encryptedResponse;
uint256 submissionTime;
uint256 rewardEarned;
bool isPaid;
}
View Functions
getUserStats
function getUserStats(address _user) external view returns (
uint256 rep,
uint256 contribCount,
uint256 privacyBudget,
uint256 privacyRemaining
)
getValidatorStats
function getValidatorStats(address _validator) external view returns (
uint256 totalEarnings,
uint256 validationCount,
uint256 averageEarningsPerValidation
)
getContributionValidations
function getContributionValidations(bytes32 _contributionId) external view returns (
address[] memory validators,
uint256[] memory qualityScores,
uint256[] memory computeTimes,
uint256[] memory rewards,
string[] memory encryptedResponses
)
Privacy Budget System
Each contributor has a lifetime privacy budget:
uint256 public maxPrivacyBudgetPerUser = 10.0 epsilon;
This prevents privacy leakage in differential privacy scenarios.
Events
event ContributionSubmitted(address indexed contributor, bytes32 contributionId);
event ValidationWorkSubmitted(address indexed validator, bytes32 indexed contributionId, uint256 computeTime, uint256 qualityScore);
event PublicKeyRegistered(address indexed validator, string publicKey);
event ContributionVerified(bytes32 indexed contributionId, uint256 averageQuality, uint256 totalReward);
event ValidatorPaid(address indexed validator, bytes32 indexed contributionId, uint256 amount, uint256 timeMultiplier, uint256 qualityMultiplier, bool consensusBonus);
Governance Parameters
Only the contract owner can update these:
function updateRewardParameters(...) external onlyOwner
function updateValidationParameters(...) external onlyOwner
Current Settings:
minValidatorsRequired = 3contributionTimeout = 1 hourmaxComputeTimePerValidation = 300 secondsconsensusThreshold = 10 points
Security Considerations
Reentrancy Protection
The contract transfers rewards at the end of validation to prevent reentrancy attacks.
Input Validation
All user inputs are validated:
- Quality scores must be ≤ 100
- Compute time must be > 0 and ≤ max allowed
- Privacy budget must not exceed limits
Duplicate Prevention
Validators cannot validate the same contribution twice.
Deployment
See the deployment guide for instructions on deploying to testnets and mainnet.