Skip to content

Commit

Permalink
feat(avs):Implement on-chain aggregation signature (imua-xyz#167)
Browse files Browse the repository at this point in the history
* feat:Add task ID auto increment 1 method

* convert the assetID to lowercase format when set oracle parameter

* feat:add task end epoch process logic

* Implement task result statistics in epoch end

* replace evm.origin with sender address

* fix apphash mismatch caused by unordered grouping of maps

* fix task ID call failure occupying sequence number

* fix query blsKey issuse and add sig verify

* fix division by votingpower zero

* fix remove submit task param response-hash

* fix the prompt information returned

---------

Co-authored-by: TimmyExogenous <144751317+TimmyExogenous@users.noreply.github.com>
Co-authored-by: Max <82761650+MaxMustermann2@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 24, 2024
1 parent a8ce2bf commit 36cd238
Show file tree
Hide file tree
Showing 47 changed files with 6,844 additions and 1,288 deletions.
1 change: 1 addition & 0 deletions precompiles/assets/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ func (p Precompile) UpdateTokenFromInputs(
if !ok || assetAddr == nil {
return 0, "", "", fmt.Errorf(exocmn.ErrContractInputParaOrType, 1, "[]byte", args[1])
}
// #nosec G115
if uint32(len(assetAddr)) < clientChainAddrLength {
return 0, "", "", fmt.Errorf(exocmn.ErrInvalidAddrLength, len(assetAddr), clientChainAddrLength)
}
Expand Down
178 changes: 44 additions & 134 deletions precompiles/avs/avs.sol → precompiles/avs/IAVSManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ IAVSManager constant AVSMANAGER_CONTRACT = IAVSManager(
/// @custom:address 0x0000000000000000000000000000000000000901
interface IAVSManager {
/// @dev Register AVS contract to EXO.
/// @param sender The external address for calling this method.
/// @param avsName The name of AVS.
/// @param minStakeAmount The minimum amount of funds staked by each operator.
/// @param taskAddr The task address of AVS.
Expand All @@ -29,6 +30,7 @@ interface IAVSManager {
///3.avsReward The proportion of reward for AVS.
///4.avsSlash The proportion of slash for AVS.
function registerAVS(
address sender,
string memory avsName,
uint64 minStakeAmount,
address taskAddr,
Expand All @@ -43,6 +45,7 @@ interface IAVSManager {
) external returns (bool success);

/// @dev Update AVS info to EXO.
/// @param sender The external address for calling this method.
/// @param avsName The name of AVS.
/// @param minStakeAmount The minimum amount of funds staked by each operator.
/// @param taskAddr The task address of AVS.
Expand All @@ -58,6 +61,7 @@ interface IAVSManager {
///3.avsReward The proportion of reward for AVS.
///4.avsSlash The proportion of slash for AVS.
function updateAVS(
address sender,
string memory avsName,
uint64 minStakeAmount,
address taskAddr,
Expand All @@ -72,36 +76,60 @@ interface IAVSManager {
) external returns (bool success);

/// @dev Deregister avs from exo
/// @param sender The external address for calling this method.
/// @param avsName The name of AVS.
function deregisterAVS(
address sender,
string memory avsName
) external returns (bool success);

/// @dev RegisterOperatorToAVS operator opt in current avs
/// @param sender The external address for calling this method.
function registerOperatorToAVS(
address sender
) external returns (bool success);

/// @dev DeregisterOperatorFromAVS operator opt out current avs
/// @param sender The external address for calling this method.
function deregisterOperatorFromAVS(
address sender
) external returns (bool success);


/// @dev CreateTask , avs owner create a new task
/// @param sender The external address for calling this method.
/// @param name The name of the task.
/// @param data The data supplied by the contract, usually ABI-encoded.
/// @param taskId The task ID of the task.
/// @param hash The data supplied by the contract, usually ABI-encoded.
/// @param taskResponsePeriod The deadline for task response.
/// @param taskChallengePeriod The challenge period for the task.
/// @param thresholdPercentage The signature threshold percentage.
/// @param taskStatisticalPeriod The statistical period for the task.
function createTask(
address sender,
string memory name,
bytes calldata data,
string memory taskId,
bytes calldata hash,
uint64 taskResponsePeriod,
uint64 taskChallengePeriod,
uint64 thresholdPercentage
uint64 thresholdPercentage,
uint64 taskStatisticalPeriod
) external returns (bool success);

/// @dev challenge , this function enables a challenger to raise and resolve a challenge.
/// @param sender The external address for calling this method.
/// @param taskHash The data supplied by the contract, usually ABI-encoded.
/// @param taskID The id of task.
/// @param taskResponseHash The hash of task response.
/// @param operatorAddress operator address.
function challenge(
address sender,
bytes calldata taskHash,
uint64 taskID,
bytes calldata taskResponseHash,
string memory operatorAddress
) external returns (bool success);



/// @dev SubmitProof ,After processing the task contract, aggregate the signature and submit the processed proof
/// @param taskId The task ID of the task.
/// @param taskContractAddress The contract address of AVSTask.
Expand All @@ -118,13 +146,13 @@ interface IAVSManager {


/// @dev Called by the avs manager service register an operator as the owner of a BLS public key.
/// @param operator is the operator for whom the key is being registered
/// @param sender The external address for calling this method.
/// @param name the name of public keys
/// @param pubKey the public keys of the operator
/// @param pubkeyRegistrationSignature the public keys of the operator
/// @param pubkeyRegistrationMessageHash the public keys of the operator
function registerBLSPublicKey(
string memory operator,
address sender,
string calldata name,
bytes calldata pubKey,
bytes calldata pubkeyRegistrationSignature,
Expand All @@ -135,11 +163,11 @@ interface IAVSManager {

/// @dev Returns the pubkey and pubkey hash of an operator
/// @param operator is the operator for whom the key is being registered
function getRegisteredPubkey(string memory operator) external returns (bytes calldata pubkey);
function getRegisteredPubkey(string memory operator) external pure returns (bytes memory pubkey);

/// @dev Returns the operators of all opt-in in the current avs
/// @param avsAddress avs address
function getOptInOperators(address avsAddress) external returns (string[] calldata operators);
function getOptInOperators(address avsAddress) external returns (string[] memory operators);

/// @dev getAVSUSDValue is a function to retrieve the USD share of specified Avs.
/// @param avsAddr The address of the avs
Expand All @@ -157,132 +185,14 @@ interface IAVSManager {
string memory operatorAddr
) external view returns (uint256 amount);

/// @dev RegisterBLSPublicKey Emitted when `operator` registers with the public keys `pubKey`.
/// @param operator the address of the delegator
/// @param pubKey the address of the validator
event RegisterBLSPublicKey(
string indexed operator,
string name,
bytes pubKey,
bytes pubkeyRegistrationSignature,
bytes pubkeyRegistrationMessageHash
);

/// @dev RegisterAVS Emitted when `avs` register to exocore.
/// @dev Register AVS contract to EXO.
/// @param avsAddress The address of AVS.
/// @param avsName The name of AVS.
/// @param minStakeAmount The minimum amount of funds staked by each operator.
/// @param taskAddr The task address of AVS.
/// @param slashAddr The slash address of AVS.
/// @param rewardAddr The reward address of AVS.
/// @param avsOwnerAddress The owners who have permission for AVS.
/// @param assetIds The basic asset information of AVS.
/// @param avsUnbondingPeriod The unbonding duration of AVS.
/// @param minSelfDelegation The minimum delegation amount for an operator.
/// @param epochIdentifier The AVS epoch identifier.
/// @param params 1.miniOptInOperators The minimum number of opt-in operators.
///2.minTotalStakeAmount The minimum total amount of stake by all operators.
///3.avsReward The proportion of reward for AVS.
///4.avsSlash The proportion of slash for AVS.
event RegisterAVS(
string indexed avsAddress,
string avsName,
uint64 minStakeAmount,
address taskAddr,
address slashAddr,
address rewardAddr,
address[] avsOwnerAddress,
string[] assetIds,
uint64 avsUnbondingPeriod,
uint64 minSelfDelegation,
string epochIdentifier,
uint64[] params
);

/// @dev UpdateAVS Emitted when `avs` update to exocore.
/// @param avsAddress The address of AVS.
/// @param avsName The name of AVS.
/// @param minStakeAmount The minimum amount of funds staked by each operator.
/// @param taskAddr The task address of AVS.
/// @param slashAddr The slash address of AVS.
/// @param rewardAddr The reward address of AVS.
/// @param avsOwnerAddress The owners who have permission for AVS.
/// @param assetIds The basic asset information of AVS.
/// @param avsUnbondingPeriod The unbonding duration of AVS.
/// @param minSelfDelegation The minimum delegation amount for an operator.
/// @param epochIdentifier The AVS epoch identifier.
/// @param params 1.miniOptInOperators The minimum number of opt-in operators.
///2.minTotalStakeAmount The minimum total amount of stake by all operators.
///3.avsReward The proportion of reward for AVS.
///4.avsSlash The proportion of slash for AVS.
event UpdateAVS(
string indexed avsAddress,
string avsName,
uint64 minStakeAmount,
address taskAddr,
address slashAddr,
address rewardAddr,
address[] avsOwnerAddress,
string[] assetIds,
uint64 avsUnbondingPeriod,
uint64 minSelfDelegation,
string epochIdentifier,
uint64[] params
);

/// @dev DeregisterAVS Emitted when `avs` Deregister to exocore.
/// @param avsAddress The address of AVS.
/// @param avsName The name of AVS.
event DeregisterAVS(
string indexed avsAddress,
string avsName
);

/// @dev RegisterOperatorToAVS Emitted when `operator` opt-in to avs.
/// @param operator address.
/// @param avsAddress The address of AVS.
event RegisterOperatorToAVS(
string indexed operator,
string indexed avsAddress
);

/// @dev DeregisterOperatorFromAVS Emitted when `operator` opt-out to avs.
/// @param operator address.
/// @param avsAddress The address of AVS.
event DeregisterOperatorFromAVS(
string indexed operator,
string indexed avsAddress
);

/// @dev CreateTask Emitted when `avs` CreateTask.
/// @param taskContractAddress The contract address of AVSTask.
/// @param taskId The task ID of the task.
/// @param name The name of the task.
/// @param data The data supplied by the contract, usually ABI-encoded.
/// @param taskResponsePeriod The deadline for task response.
/// @param taskChallengePeriod The challenge period for the task.
/// @param thresholdPercentage The signature threshold percentage.
event CreateTask(
string indexed taskContractAddress,
string indexed taskId,
event TaskCreated(
uint64 taskId,
string taskContractAddress,
string name,
bytes data,
bytes hash,
uint64 taskResponsePeriod,
uint64 taskChallengePeriod,
uint64 thresholdPercentage
);
/// @dev SubmitProof Emitted when task contract submit proof.
/// @param taskContractAddress The contract address of AVSTask.
/// @param taskId The task ID of the task.
/// @param aggregator The aggregator address.
/// @param avsAddress The address of AVS.
/// @param operatorStatuses The status and proof of operators.
event SubmitProof(
string indexed taskContractAddress,
string indexed taskId,
string aggregator,
string avsAddress,
bytes operatorStatuses
uint64 thresholdPercentage,
uint64 taskStatisticalPeriod
);
}
}
Loading

0 comments on commit 36cd238

Please sign in to comment.