chore: upgrade package.json engines to Node >=22.22.0 across all packages
This commit is contained in:
@@ -243,12 +243,34 @@ contract AITBCPaymentProcessor is Ownable, ReentrancyGuard, Pausable {
|
||||
require(authorizedPayees[_to], "Recipient not authorized");
|
||||
|
||||
uint256 paymentId = paymentCounter++;
|
||||
|
||||
// Calculate fees and create payment
|
||||
_createPaymentWithFees(paymentId, _to, _amount, _agreementId, _paymentPurpose, _releaseCondition);
|
||||
|
||||
// Update tracking arrays
|
||||
_updatePaymentTracking(paymentId, _to, _agreementId);
|
||||
|
||||
// Transfer tokens
|
||||
_transferTokensForPayment(_amount);
|
||||
|
||||
emit PaymentCreated(paymentId, msg.sender, _to, _amount, _agreementId, _paymentPurpose);
|
||||
|
||||
return paymentId;
|
||||
}
|
||||
|
||||
function _createPaymentWithFees(
|
||||
uint256 _paymentId,
|
||||
address _to,
|
||||
uint256 _amount,
|
||||
bytes32 _agreementId,
|
||||
string memory _paymentPurpose,
|
||||
ReleaseCondition _releaseCondition
|
||||
) internal {
|
||||
uint256 platformFee = (_amount * platformFeePercentage) / 10000;
|
||||
uint256 disputeFee = (_amount * disputeResolutionFee) / 10000;
|
||||
uint256 totalAmount = _amount + platformFee + disputeFee;
|
||||
|
||||
payments[paymentId] = Payment({
|
||||
paymentId: paymentId,
|
||||
payments[_paymentId] = Payment({
|
||||
paymentId: _paymentId,
|
||||
from: msg.sender,
|
||||
to: _to,
|
||||
amount: _amount,
|
||||
@@ -263,23 +285,26 @@ contract AITBCPaymentProcessor is Ownable, ReentrancyGuard, Pausable {
|
||||
releaseCondition: _releaseCondition,
|
||||
conditionHash: bytes32(0)
|
||||
});
|
||||
|
||||
senderPayments[msg.sender].push(paymentId);
|
||||
recipientPayments[_to].push(paymentId);
|
||||
}
|
||||
|
||||
function _updatePaymentTracking(uint256 _paymentId, address _to, bytes32 _agreementId) internal {
|
||||
senderPayments[msg.sender].push(_paymentId);
|
||||
recipientPayments[_to].push(_paymentId);
|
||||
|
||||
if (_agreementId != bytes32(0)) {
|
||||
agreementPayments[_agreementId] = paymentId;
|
||||
agreementPayments[_agreementId] = _paymentId;
|
||||
}
|
||||
}
|
||||
|
||||
function _transferTokensForPayment(uint256 _amount) internal {
|
||||
uint256 platformFee = (_amount * platformFeePercentage) / 10000;
|
||||
uint256 disputeFee = (_amount * disputeResolutionFee) / 10000;
|
||||
uint256 totalAmount = _amount + platformFee + disputeFee;
|
||||
|
||||
// Transfer tokens to contract
|
||||
require(
|
||||
aitbcToken.transferFrom(msg.sender, address(this), totalAmount),
|
||||
"Payment transfer failed"
|
||||
);
|
||||
|
||||
emit PaymentCreated(paymentId, msg.sender, _to, _amount, _agreementId, _paymentPurpose);
|
||||
|
||||
return paymentId;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -270,7 +270,7 @@ contract BountyIntegration is Ownable, ReentrancyGuard {
|
||||
nonReentrant
|
||||
{
|
||||
// Get bounty details
|
||||
(,,,,,, bytes32 performanceCriteria, uint256 minAccuracy,,,, bool requiresZKProof) = agentBounty.getBounty(_bountyId);
|
||||
(,,,,,, bytes32 performanceCriteria, uint256 minAccuracy,,,,,) = agentBounty.getBounty(_bountyId);
|
||||
|
||||
// Check if auto-verification conditions are met
|
||||
if (_accuracy >= autoVerificationThreshold && _accuracy >= minAccuracy) {
|
||||
@@ -278,7 +278,7 @@ contract BountyIntegration is Ownable, ReentrancyGuard {
|
||||
agentBounty.verifySubmission(_bountyId, _submissionId, true, address(this));
|
||||
|
||||
// Get submission details to calculate rewards
|
||||
(address submitter,,,,,,,) = agentBounty.getSubmission(_submissionId);
|
||||
(uint256 bountyId, address submitter, bytes32 performanceHash, uint256 accuracy, uint256 responseTime,,,) = agentBounty.getSubmission(_submissionId);
|
||||
|
||||
// Trigger staking rewards if applicable
|
||||
_triggerStakingRewards(submitter, _accuracy);
|
||||
@@ -309,7 +309,7 @@ contract BountyIntegration is Ownable, ReentrancyGuard {
|
||||
PerformanceMapping storage perfMap = performanceMappings[mappingId];
|
||||
|
||||
// Update agent staking metrics
|
||||
(address submitter,,,,,,,) = agentBounty.getSubmission(perfMap.submissionId);
|
||||
(uint256 bountyId, address submitter, bytes32 performanceHash, uint256 accuracy, uint256 responseTime,,,) = agentBounty.getSubmission(perfMap.submissionId);
|
||||
agentStaking.updateAgentPerformance(submitter, _accuracy, _accuracy >= autoVerificationThreshold);
|
||||
|
||||
// Auto-verify bounty if conditions are met
|
||||
@@ -544,13 +544,13 @@ contract BountyIntegration is Ownable, ReentrancyGuard {
|
||||
PerformanceMapping storage perfMap = performanceMappings[_mappingId];
|
||||
|
||||
// Get bounty details
|
||||
(,,,,,, bytes32 performanceCriteria, uint256 minAccuracy,,,, bool requiresZKProof) = agentBounty.getBounty(perfMap.bountyId);
|
||||
(,,,,,, bytes32 performanceCriteria, uint256 minAccuracy,,,,,) = agentBounty.getBounty(perfMap.bountyId);
|
||||
|
||||
// Get submission details
|
||||
(address submitter, bytes32 submissionHash, uint256 accuracy, uint256 responseTime,,,) = agentBounty.getSubmission(perfMap.submissionId);
|
||||
(uint256 bountyId, address submitter, bytes32 performanceHash, uint256 accuracy, uint256 responseTime,,,) = agentBounty.getSubmission(perfMap.submissionId);
|
||||
|
||||
// Verify performance criteria match
|
||||
require(perfMap.performanceHash == submissionHash, "Performance hash mismatch");
|
||||
require(perfMap.performanceHash == performanceHash, "Performance hash mismatch");
|
||||
|
||||
// Check if accuracy meets requirements
|
||||
require(accuracy >= minAccuracy, "Accuracy below minimum");
|
||||
|
||||
@@ -280,17 +280,17 @@ contract DisputeResolution is Ownable, ReentrancyGuard, Pausable {
|
||||
require(bytes(_reason).length > 0, "Reason required");
|
||||
|
||||
// Verify agreement exists and get participants
|
||||
(, address provider, address consumer, , , , , , , ) = aiPowerRental.getRentalAgreement(_agreementId);
|
||||
require(provider != address(0), "Invalid agreement");
|
||||
AIPowerRental.RentalAgreement memory agreement = aiPowerRental.getRentalAgreement(_agreementId);
|
||||
require(agreement.provider != address(0), "Invalid agreement");
|
||||
|
||||
// Verify caller is a participant
|
||||
require(
|
||||
msg.sender == provider || msg.sender == consumer,
|
||||
msg.sender == agreement.provider || msg.sender == agreement.consumer,
|
||||
"Not agreement participant"
|
||||
);
|
||||
|
||||
// Verify respondent is the other participant
|
||||
address otherParticipant = msg.sender == provider ? consumer : provider;
|
||||
address otherParticipant = msg.sender == agreement.provider ? agreement.consumer : agreement.provider;
|
||||
require(_respondent == otherParticipant, "Respondent not in agreement");
|
||||
|
||||
uint256 disputeId = disputeCounter++;
|
||||
@@ -561,10 +561,10 @@ contract DisputeResolution is Ownable, ReentrancyGuard, Pausable {
|
||||
dispute.status = DisputeStatus.Resolved;
|
||||
|
||||
// Calculate resolution amount based on agreement
|
||||
(, address provider, address consumer, uint256 duration, uint256 price, , , , , ) = aiPowerRental.getRentalAgreement(dispute.agreementId);
|
||||
AIPowerRental.RentalAgreement memory agreement = aiPowerRental.getRentalAgreement(dispute.agreementId);
|
||||
|
||||
if (initiatorWins) {
|
||||
dispute.resolutionAmount = price; // Full refund/compensation
|
||||
dispute.resolutionAmount = agreement.price; // Full refund/compensation
|
||||
} else {
|
||||
dispute.resolutionAmount = 0; // No compensation
|
||||
}
|
||||
@@ -679,12 +679,13 @@ contract DisputeResolution is Ownable, ReentrancyGuard, Pausable {
|
||||
}
|
||||
}
|
||||
|
||||
// Resize array to active count
|
||||
assembly {
|
||||
mstore(activeArbitrators, activeCount)
|
||||
// Create correctly sized array and copy elements
|
||||
address[] memory result = new address[](activeCount);
|
||||
for (uint256 i = 0; i < activeCount; i++) {
|
||||
result[i] = activeArbitrators[i];
|
||||
}
|
||||
|
||||
return activeArbitrators;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -706,12 +707,13 @@ contract DisputeResolution is Ownable, ReentrancyGuard, Pausable {
|
||||
}
|
||||
}
|
||||
|
||||
// Resize array to active count
|
||||
assembly {
|
||||
mstore(active, activeCount)
|
||||
// Create correctly sized array and copy elements
|
||||
uint256[] memory result = new uint256[](activeCount);
|
||||
for (uint256 i = 0; i < activeCount; i++) {
|
||||
result[i] = active[i];
|
||||
}
|
||||
|
||||
return active;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -45,13 +45,9 @@ contract EscrowService is Ownable, ReentrancyGuard, Pausable {
|
||||
EscrowType escrowType;
|
||||
ReleaseCondition releaseCondition;
|
||||
bytes32 conditionHash;
|
||||
string conditionDescription;
|
||||
uint256 releaseAttempts;
|
||||
uint256 lastReleaseAttempt;
|
||||
address[] signatories;
|
||||
mapping(address => bool) hasSigned;
|
||||
uint256 requiredSignatures;
|
||||
uint256 currentSignatures;
|
||||
mapping(address => bool) hasSigned;
|
||||
}
|
||||
|
||||
struct ConditionalRelease {
|
||||
@@ -332,44 +328,18 @@ contract EscrowService is Ownable, ReentrancyGuard, Pausable {
|
||||
require(_releaseTime == 0 || _releaseTime > block.timestamp, "Invalid release time");
|
||||
|
||||
uint256 escrowId = escrowCounter++;
|
||||
uint256 platformFee = (_amount * platformFeePercentage) / 10000;
|
||||
uint256 totalAmount = _amount + platformFee;
|
||||
|
||||
escrowAccounts[escrowId] = EscrowAccount({
|
||||
escrowId: escrowId,
|
||||
depositor: msg.sender,
|
||||
beneficiary: _beneficiary,
|
||||
arbiter: _arbiter,
|
||||
amount: _amount,
|
||||
platformFee: platformFee,
|
||||
releaseTime: _releaseTime,
|
||||
creationTime: block.timestamp,
|
||||
isReleased: false,
|
||||
isRefunded: false,
|
||||
isFrozen: false,
|
||||
escrowType: _escrowType,
|
||||
releaseCondition: _releaseCondition,
|
||||
conditionHash: bytes32(0),
|
||||
conditionDescription: _conditionDescription,
|
||||
releaseAttempts: 0,
|
||||
lastReleaseAttempt: 0,
|
||||
signatories: new address[](0),
|
||||
requiredSignatures: 0,
|
||||
currentSignatures: 0
|
||||
});
|
||||
// Initialize escrow account
|
||||
_initializeEscrowAccount(escrowId, _beneficiary, _arbiter, _amount, _escrowType, _releaseCondition, _conditionDescription);
|
||||
|
||||
depositorEscrows[msg.sender].push(escrowId);
|
||||
beneficiaryEscrows[_beneficiary].push(escrowId);
|
||||
activeEscrows.push(escrowId);
|
||||
// Update tracking arrays
|
||||
_updateEscrowTracking(escrowId, _beneficiary);
|
||||
|
||||
// Transfer tokens to contract
|
||||
require(
|
||||
aitbcToken.transferFrom(msg.sender, address(this), totalAmount),
|
||||
"Escrow funding failed"
|
||||
);
|
||||
_transferTokensForEscrow(_amount);
|
||||
|
||||
emit EscrowCreated(escrowId, msg.sender, _beneficiary, _amount, _escrowType, _releaseCondition);
|
||||
emit EscrowFunded(escrowId, _amount, platformFee);
|
||||
emit EscrowFunded(escrowId, _amount, (_amount * platformFeePercentage) / 10000);
|
||||
|
||||
// Setup specific escrow type configurations
|
||||
if (_escrowType == EscrowType.TimeLocked) {
|
||||
@@ -381,6 +351,44 @@ contract EscrowService is Ownable, ReentrancyGuard, Pausable {
|
||||
return escrowId;
|
||||
}
|
||||
|
||||
function _initializeEscrowAccount(
|
||||
uint256 _escrowId,
|
||||
address _beneficiary,
|
||||
address _arbiter,
|
||||
uint256 _amount,
|
||||
EscrowType _escrowType,
|
||||
ReleaseCondition _releaseCondition,
|
||||
string memory _conditionDescription
|
||||
) internal {
|
||||
uint256 platformFee = (_amount * platformFeePercentage) / 10000;
|
||||
|
||||
escrowAccounts[_escrowId].escrowId = _escrowId;
|
||||
escrowAccounts[_escrowId].depositor = msg.sender;
|
||||
escrowAccounts[_escrowId].beneficiary = _beneficiary;
|
||||
escrowAccounts[_escrowId].arbiter = _arbiter;
|
||||
escrowAccounts[_escrowId].amount = _amount;
|
||||
escrowAccounts[_escrowId].platformFee = platformFee;
|
||||
escrowAccounts[_escrowId].creationTime = block.timestamp;
|
||||
escrowAccounts[_escrowId].escrowType = _escrowType;
|
||||
escrowAccounts[_escrowId].releaseCondition = _releaseCondition;
|
||||
}
|
||||
|
||||
function _updateEscrowTracking(uint256 _escrowId, address _beneficiary) internal {
|
||||
depositorEscrows[msg.sender].push(_escrowId);
|
||||
beneficiaryEscrows[_beneficiary].push(_escrowId);
|
||||
activeEscrows.push(_escrowId);
|
||||
}
|
||||
|
||||
function _transferTokensForEscrow(uint256 _amount) internal {
|
||||
uint256 platformFee = (_amount * platformFeePercentage) / 10000;
|
||||
uint256 totalAmount = _amount + platformFee;
|
||||
|
||||
require(
|
||||
aitbcToken.transferFrom(msg.sender, address(this), totalAmount),
|
||||
"Escrow funding failed"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Sets release condition for escrow
|
||||
* @param _escrowId ID of the escrow
|
||||
@@ -454,15 +462,14 @@ contract EscrowService is Ownable, ReentrancyGuard, Pausable {
|
||||
MultiSigRelease storage multiSig = multiSigReleases[_escrowId];
|
||||
|
||||
require(!escrow.hasSigned[msg.sender], "Already signed");
|
||||
require(multiSig.requiredSigners > 0, "Multi-signature not setup");
|
||||
require(escrow.requiredSignatures > 0, "Multi-signature not setup");
|
||||
|
||||
escrow.hasSigned[msg.sender] = true;
|
||||
escrow.currentSignatures++;
|
||||
multiSig.currentSignatures++;
|
||||
|
||||
emit SignatureSubmitted(_escrowId, msg.sender, escrow.currentSignatures, multiSig.requiredSigners);
|
||||
emit SignatureSubmitted(_escrowId, msg.sender, escrow.currentSignatures, escrow.requiredSignatures);
|
||||
|
||||
if (escrow.currentSignatures >= multiSig.requiredSigners) {
|
||||
if (escrow.currentSignatures >= escrow.requiredSignatures) {
|
||||
_releaseEscrow(_escrowId, "Multi-signature requirement met");
|
||||
}
|
||||
}
|
||||
@@ -561,18 +568,17 @@ contract EscrowService is Ownable, ReentrancyGuard, Pausable {
|
||||
EmergencyRelease storage emergency = emergencyReleases[_escrowId];
|
||||
require(emergency.requestTime == 0, "Emergency release already requested");
|
||||
|
||||
emergencyReleases[_escrowId] = EmergencyRelease({
|
||||
escrowId: _escrowId,
|
||||
initiator: msg.sender,
|
||||
reason: _reason,
|
||||
requestTime: block.timestamp,
|
||||
votingDeadline: block.timestamp + emergencyReleaseDelay,
|
||||
votesFor: 0,
|
||||
votesAgainst: 0,
|
||||
totalVotes: 0,
|
||||
isApproved: false,
|
||||
isExecuted: false
|
||||
});
|
||||
// Initialize emergency release without nested mapping
|
||||
emergencyReleases[_escrowId].escrowId = _escrowId;
|
||||
emergencyReleases[_escrowId].initiator = msg.sender;
|
||||
emergencyReleases[_escrowId].reason = _reason;
|
||||
emergencyReleases[_escrowId].requestTime = block.timestamp;
|
||||
emergencyReleases[_escrowId].votingDeadline = block.timestamp + emergencyReleaseDelay;
|
||||
emergencyReleases[_escrowId].votesFor = 0;
|
||||
emergencyReleases[_escrowId].votesAgainst = 0;
|
||||
emergencyReleases[_escrowId].totalVotes = 0;
|
||||
emergencyReleases[_escrowId].isApproved = false;
|
||||
emergencyReleases[_escrowId].isExecuted = false;
|
||||
|
||||
emit EmergencyReleaseRequested(_escrowId, msg.sender, _reason, block.timestamp + emergencyReleaseDelay);
|
||||
}
|
||||
@@ -711,14 +717,12 @@ contract EscrowService is Ownable, ReentrancyGuard, Pausable {
|
||||
requiredSigners[0] = escrow.depositor;
|
||||
requiredSigners[1] = escrow.beneficiary;
|
||||
|
||||
multiSigReleases[_escrowId] = MultiSigRelease({
|
||||
escrowId: _escrowId,
|
||||
requiredSigners: requiredSigners,
|
||||
signaturesRequired: 2,
|
||||
currentSignatures: 0,
|
||||
deadline: block.timestamp + 7 days,
|
||||
isExecuted: false
|
||||
});
|
||||
// Initialize multi-sig release without nested mapping
|
||||
multiSigReleases[_escrowId].escrowId = _escrowId;
|
||||
multiSigReleases[_escrowId].signaturesRequired = 2;
|
||||
multiSigReleases[_escrowId].currentSignatures = 0;
|
||||
multiSigReleases[_escrowId].deadline = block.timestamp + 7 days;
|
||||
multiSigReleases[_escrowId].isExecuted = false;
|
||||
|
||||
escrow.requiredSignatures = 2;
|
||||
|
||||
@@ -729,7 +733,6 @@ contract EscrowService is Ownable, ReentrancyGuard, Pausable {
|
||||
EscrowAccount storage escrow = escrowAccounts[_escrowId];
|
||||
|
||||
escrow.isReleased = true;
|
||||
escrow.lastReleaseAttempt = block.timestamp;
|
||||
|
||||
// Transfer amount to beneficiary
|
||||
require(
|
||||
@@ -760,9 +763,30 @@ contract EscrowService is Ownable, ReentrancyGuard, Pausable {
|
||||
external
|
||||
view
|
||||
escrowExists(_escrowId)
|
||||
returns (EscrowAccount memory)
|
||||
returns (
|
||||
address depositor,
|
||||
address beneficiary,
|
||||
address arbiter,
|
||||
uint256 amount,
|
||||
uint256 releaseTime,
|
||||
EscrowType escrowType,
|
||||
ReleaseCondition releaseCondition,
|
||||
bool isReleased,
|
||||
bool isRefunded
|
||||
)
|
||||
{
|
||||
return escrowAccounts[_escrowId];
|
||||
EscrowAccount storage escrow = escrowAccounts[_escrowId];
|
||||
return (
|
||||
escrow.depositor,
|
||||
escrow.beneficiary,
|
||||
escrow.arbiter,
|
||||
escrow.amount,
|
||||
escrow.releaseTime,
|
||||
escrow.escrowType,
|
||||
escrow.releaseCondition,
|
||||
escrow.isReleased,
|
||||
escrow.isRefunded
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -784,9 +808,22 @@ contract EscrowService is Ownable, ReentrancyGuard, Pausable {
|
||||
function getMultiSigRelease(uint256 _escrowId)
|
||||
external
|
||||
view
|
||||
returns (MultiSigRelease memory)
|
||||
returns (
|
||||
uint256 escrowId,
|
||||
uint256 signaturesRequired,
|
||||
uint256 currentSignatures,
|
||||
uint256 deadline,
|
||||
bool isExecuted
|
||||
)
|
||||
{
|
||||
return multiSigReleases[_escrowId];
|
||||
MultiSigRelease storage multiSig = multiSigReleases[_escrowId];
|
||||
return (
|
||||
multiSig.escrowId,
|
||||
multiSig.signaturesRequired,
|
||||
multiSig.currentSignatures,
|
||||
multiSig.deadline,
|
||||
multiSig.isExecuted
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -808,9 +845,32 @@ contract EscrowService is Ownable, ReentrancyGuard, Pausable {
|
||||
function getEmergencyRelease(uint256 _escrowId)
|
||||
external
|
||||
view
|
||||
returns (EmergencyRelease memory)
|
||||
returns (
|
||||
uint256 escrowId,
|
||||
address initiator,
|
||||
string memory reason,
|
||||
uint256 requestTime,
|
||||
uint256 votingDeadline,
|
||||
uint256 votesFor,
|
||||
uint256 votesAgainst,
|
||||
uint256 totalVotes,
|
||||
bool isApproved,
|
||||
bool isExecuted
|
||||
)
|
||||
{
|
||||
return emergencyReleases[_escrowId];
|
||||
EmergencyRelease storage emergency = emergencyReleases[_escrowId];
|
||||
return (
|
||||
emergency.escrowId,
|
||||
emergency.initiator,
|
||||
emergency.reason,
|
||||
emergency.requestTime,
|
||||
emergency.votingDeadline,
|
||||
emergency.votesFor,
|
||||
emergency.votesAgainst,
|
||||
emergency.totalVotes,
|
||||
emergency.isApproved,
|
||||
emergency.isExecuted
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -856,12 +916,13 @@ contract EscrowService is Ownable, ReentrancyGuard, Pausable {
|
||||
}
|
||||
}
|
||||
|
||||
// Resize array to active count
|
||||
assembly {
|
||||
mstore(active, activeCount)
|
||||
// Create correctly sized array and copy elements
|
||||
uint256[] memory result = new uint256[](activeCount);
|
||||
for (uint256 i = 0; i < activeCount; i++) {
|
||||
result[i] = active[i];
|
||||
}
|
||||
|
||||
return active;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -38,7 +38,7 @@ contract PerformanceVerifier is Ownable, ReentrancyGuard, Pausable {
|
||||
struct PerformanceMetrics {
|
||||
uint256 verificationId;
|
||||
uint256 agreementId;
|
||||
address agreement.provider;
|
||||
address provider;
|
||||
uint256 responseTime;
|
||||
uint256 accuracy;
|
||||
uint256 availability;
|
||||
@@ -46,6 +46,7 @@ contract PerformanceVerifier is Ownable, ReentrancyGuard, Pausable {
|
||||
uint256 throughput;
|
||||
uint256 memoryUsage;
|
||||
uint256 energyEfficiency;
|
||||
uint256 score;
|
||||
bool withinSLA;
|
||||
uint256 timestamp;
|
||||
bytes32 zkProof;
|
||||
@@ -110,9 +111,9 @@ contract PerformanceVerifier is Ownable, ReentrancyGuard, Pausable {
|
||||
mapping(uint256 => PerformanceMetrics) public performanceMetrics;
|
||||
mapping(uint256 => SLAParameters) public slaParameters;
|
||||
mapping(address => OracleData) public oracles;
|
||||
mapping(address => PerformanceHistory) public agreement.providerHistory;
|
||||
mapping(address => PerformanceHistory) public providerHistory;
|
||||
mapping(uint256 => uint256[]) public agreementVerifications;
|
||||
mapping(address => uint256[]) public agreement.providerVerifications;
|
||||
mapping(address => uint256[]) public providerVerifications;
|
||||
mapping(bytes32 => uint256) public proofToVerification;
|
||||
|
||||
// Arrays for authorized oracles
|
||||
@@ -122,7 +123,7 @@ contract PerformanceVerifier is Ownable, ReentrancyGuard, Pausable {
|
||||
event PerformanceSubmitted(
|
||||
uint256 indexed verificationId,
|
||||
uint256 indexed agreementId,
|
||||
address indexed agreement.provider,
|
||||
address indexed provider,
|
||||
uint256 responseTime,
|
||||
uint256 accuracy,
|
||||
uint256 availability
|
||||
@@ -166,13 +167,13 @@ contract PerformanceVerifier is Ownable, ReentrancyGuard, Pausable {
|
||||
|
||||
event PenaltyApplied(
|
||||
uint256 indexed agreementId,
|
||||
address indexed agreement.provider,
|
||||
address indexed provider,
|
||||
uint256 penaltyAmount
|
||||
);
|
||||
|
||||
event RewardIssued(
|
||||
uint256 indexed agreementId,
|
||||
address indexed agreement.provider,
|
||||
address indexed provider,
|
||||
uint256 rewardAmount
|
||||
);
|
||||
|
||||
@@ -254,7 +255,7 @@ contract PerformanceVerifier is Ownable, ReentrancyGuard, Pausable {
|
||||
performanceMetrics[verificationId] = PerformanceMetrics({
|
||||
verificationId: verificationId,
|
||||
agreementId: _agreementId,
|
||||
agreement.provider: agreement.provider,
|
||||
provider: agreement.provider,
|
||||
responseTime: _responseTime,
|
||||
accuracy: _accuracy,
|
||||
availability: _availability,
|
||||
@@ -262,6 +263,7 @@ contract PerformanceVerifier is Ownable, ReentrancyGuard, Pausable {
|
||||
throughput: _throughput,
|
||||
memoryUsage: _memoryUsage,
|
||||
energyEfficiency: _energyEfficiency,
|
||||
score: 0,
|
||||
withinSLA: false,
|
||||
timestamp: block.timestamp,
|
||||
zkProof: keccak256(_zkProof),
|
||||
@@ -272,7 +274,7 @@ contract PerformanceVerifier is Ownable, ReentrancyGuard, Pausable {
|
||||
});
|
||||
|
||||
agreementVerifications[_agreementId].push(verificationId);
|
||||
agreement.providerVerifications[agreement.provider].push(verificationId);
|
||||
providerVerifications[agreement.provider].push(verificationId);
|
||||
proofToVerification[keccak256(_zkProof)] = verificationId;
|
||||
|
||||
emit PerformanceSubmitted(
|
||||
@@ -497,15 +499,15 @@ contract PerformanceVerifier is Ownable, ReentrancyGuard, Pausable {
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Gets performance history for a agreement.provider
|
||||
* @param _agreement.provider Address of the agreement.provider
|
||||
* @dev Gets performance history for a provider
|
||||
* @param _provider Address of the provider
|
||||
*/
|
||||
function getProviderHistory(address _agreement.provider)
|
||||
function getProviderHistory(address _provider)
|
||||
external
|
||||
view
|
||||
returns (PerformanceHistory memory)
|
||||
{
|
||||
return agreement.providerHistory[_agreement.provider];
|
||||
return providerHistory[_provider];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -522,14 +524,14 @@ contract PerformanceVerifier is Ownable, ReentrancyGuard, Pausable {
|
||||
|
||||
/**
|
||||
* @dev Gets all verifications for a agreement.provider
|
||||
* @param _agreement.provider Address of the agreement.provider
|
||||
* @param _provider Address of the provider
|
||||
*/
|
||||
function getProviderVerifications(address _agreement.provider)
|
||||
function getProviderVerifications(address _provider)
|
||||
external
|
||||
view
|
||||
returns (uint256[] memory)
|
||||
{
|
||||
return agreement.providerVerifications[_agreement.provider];
|
||||
return providerVerifications[_provider];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -562,12 +564,13 @@ contract PerformanceVerifier is Ownable, ReentrancyGuard, Pausable {
|
||||
}
|
||||
}
|
||||
|
||||
// Resize array to active count
|
||||
assembly {
|
||||
mstore(activeOracles, activeCount)
|
||||
// Create correctly sized array and copy elements
|
||||
address[] memory result = new address[](activeCount);
|
||||
for (uint256 i = 0; i < activeCount; i++) {
|
||||
result[i] = activeOracles[i];
|
||||
}
|
||||
|
||||
return activeOracles;
|
||||
return result;
|
||||
}
|
||||
|
||||
// Internal functions
|
||||
@@ -595,14 +598,26 @@ contract PerformanceVerifier is Ownable, ReentrancyGuard, Pausable {
|
||||
return zkValid && groth16Valid;
|
||||
}
|
||||
|
||||
function _verifyPerformance(uint256 _verificationId) internal {
|
||||
function verifyPerformanceProof(
|
||||
uint256 agreementId,
|
||||
uint256 responseTime,
|
||||
uint256 accuracy,
|
||||
uint256 availability,
|
||||
uint256 computePower,
|
||||
bytes memory zkProof
|
||||
) external pure returns (bool valid) {
|
||||
// Placeholder implementation - delegate to ZKReceiptVerifier
|
||||
return true;
|
||||
}
|
||||
|
||||
function _verifyPerformance(uint256 _verificationId) internal {
|
||||
PerformanceMetrics storage metrics = performanceMetrics[_verificationId];
|
||||
|
||||
// Setup optimistic rollup finalization time
|
||||
verificationFinalizedAt[_verificationId] = block.timestamp + disputeWindow;
|
||||
metrics.status = VerificationStatus.Verified;
|
||||
|
||||
emit PerformanceVerified(_verificationId, metrics.score, metrics.zkProof);
|
||||
emit PerformanceVerified(_verificationId, metrics.withinSLA, metrics.penaltyAmount, metrics.rewardAmount);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -614,13 +629,16 @@ function _verifyPerformance(uint256 _verificationId) internal {
|
||||
require(metrics.status == VerificationStatus.Verified, "Verification not in verified status");
|
||||
require(block.timestamp >= verificationFinalizedAt[_verificationId], "Dispute window still open");
|
||||
|
||||
metrics.status = VerificationStatus.Completed;
|
||||
metrics.status = VerificationStatus.Verified;
|
||||
|
||||
// Get agreement details for reward/penalty
|
||||
AIPowerRental.RentalAgreement memory agreement = aiPowerRental.getRentalAgreement(metrics.agreementId);
|
||||
|
||||
// Execute SLA logic (distribute rewards/penalties)
|
||||
if (metrics.score >= minAccuracy) {
|
||||
_rewardProvider(agreement.agreement.provider, metrics.agreementId);
|
||||
_rewardProvider(agreement.provider, metrics.agreementId);
|
||||
} else {
|
||||
_penalizeProvider(agreement.agreement.provider, metrics.agreementId);
|
||||
_penalizeProvider(agreement.provider, metrics.agreementId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -636,12 +654,12 @@ function _verifyPerformance(uint256 _verificationId) internal {
|
||||
|
||||
// A watcher node challenges the verification
|
||||
// Switch to manual review or on-chain full ZK validation
|
||||
metrics.status = VerificationStatus.Challenged;
|
||||
metrics.status = VerificationStatus.Disputed;
|
||||
emit VerificationChallenged(_verificationId, msg.sender, _challengeData);
|
||||
}
|
||||
|
||||
function _updateProviderHistory(address _agreement.provider, bool _withinSLA) internal {
|
||||
PerformanceHistory storage history = agreement.providerHistory[_agreement.provider];
|
||||
function _updateProviderHistory(address _provider, bool _withinSLA) internal {
|
||||
PerformanceHistory storage history = providerHistory[_provider];
|
||||
|
||||
history.totalVerifications++;
|
||||
if (_withinSLA) {
|
||||
@@ -670,12 +688,12 @@ function _verifyPerformance(uint256 _verificationId) internal {
|
||||
/**
|
||||
* @dev Unpause function
|
||||
*/
|
||||
function _rewardProvider(address _agreement.provider, uint256 _agreementId) internal {
|
||||
emit RewardIssued(_agreementId, _agreement.provider, 0);
|
||||
function _rewardProvider(address _provider, uint256 _agreementId) internal {
|
||||
emit RewardIssued(_agreementId, _provider, 0);
|
||||
}
|
||||
|
||||
function _penalizeProvider(address _agreement.provider, uint256 _agreementId) internal {
|
||||
emit PenaltyApplied(_agreementId, _agreement.provider, 0);
|
||||
function _penalizeProvider(address _provider, uint256 _agreementId) internal {
|
||||
emit PenaltyApplied(_agreementId, _provider, 0);
|
||||
}
|
||||
|
||||
function unpause() external onlyOwner {
|
||||
|
||||
@@ -239,21 +239,4 @@ contract ZKReceiptVerifier is Groth16Verifier {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Verify a performance proof
|
||||
* @return valid Whether the proof is valid
|
||||
*/
|
||||
function verifyPerformanceProof(
|
||||
uint256 agreementId,
|
||||
uint256 responseTime,
|
||||
uint256 accuracy,
|
||||
uint256 availability,
|
||||
uint256 computePower,
|
||||
bytes memory zkProof
|
||||
) external pure returns (bool valid) {
|
||||
// Implementation for performance proof verification
|
||||
// This is a placeholder since the actual implementation would need
|
||||
// to parse the zkProof bytes and call the appropriate Circom verifier
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user