Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unifies some method names with other threshold projects #183

Merged
merged 2 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contracts/contracts/Adjudicator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
address indexed stakingProvider
);

SignatureVerifier.HashAlgorithm public immutable hashAlgorithm;

Check warning on line 31 in contracts/contracts/Adjudicator.sol

View workflow job for this annotation

GitHub Actions / linting

Function order is incorrect, state variable declaration can not go after event definition (line 25)
uint256 public immutable basePenalty;
uint256 public immutable penaltyHistoryCoefficient;
uint256 public immutable percentagePenaltyCoefficient;
TACoApplication public immutable application;

mapping(address => uint256) public penaltyHistory;

Check warning on line 37 in contracts/contracts/Adjudicator.sol

View workflow job for this annotation

GitHub Actions / linting

Main key parameter in mapping penaltyHistory is not named

Check warning on line 37 in contracts/contracts/Adjudicator.sol

View workflow job for this annotation

GitHub Actions / linting

Value parameter in mapping penaltyHistory is not named
mapping(bytes32 => bool) public evaluatedCFrags;

Check warning on line 38 in contracts/contracts/Adjudicator.sol

View workflow job for this annotation

GitHub Actions / linting

Main key parameter in mapping evaluatedCFrags is not named

Check warning on line 38 in contracts/contracts/Adjudicator.sol

View workflow job for this annotation

GitHub Actions / linting

Value parameter in mapping evaluatedCFrags is not named

/**
* @param _hashAlgorithm Hashing algorithm
Expand All @@ -50,7 +50,7 @@
uint256 _penaltyHistoryCoefficient,
uint256 _percentagePenaltyCoefficient
) {
require(

Check warning on line 53 in contracts/contracts/Adjudicator.sol

View workflow job for this annotation

GitHub Actions / linting

Use Custom Errors instead of require statements
_percentagePenaltyCoefficient != 0 && address(_application.token()) != address(0),
"Wrong input parameters"
);
Expand Down Expand Up @@ -87,7 +87,7 @@
abi.encodePacked(_capsuleBytes, _cFragBytes),
hashAlgorithm
);
require(!evaluatedCFrags[evaluationHash], "This CFrag has already been evaluated.");

Check warning on line 90 in contracts/contracts/Adjudicator.sol

View workflow job for this annotation

GitHub Actions / linting

Use Custom Errors instead of require statements
evaluatedCFrags[evaluationHash] = true;

// 2. Verify correctness of re-encryption
Expand All @@ -99,11 +99,11 @@
emit CFragEvaluated(evaluationHash, msg.sender, cFragIsCorrect);

// 3. Verify associated public keys and signatures
require(

Check warning on line 102 in contracts/contracts/Adjudicator.sol

View workflow job for this annotation

GitHub Actions / linting

Use Custom Errors instead of require statements
ReEncryptionValidator.checkSerializedCoordinates(_operatorPublicKey),
"Staker's public key is invalid"
);
require(

Check warning on line 106 in contracts/contracts/Adjudicator.sol

View workflow job for this annotation

GitHub Actions / linting

Use Custom Errors instead of require statements
ReEncryptionValidator.checkSerializedCoordinates(_requesterPublicKey),
"Requester's public key is invalid"
);
Expand All @@ -111,7 +111,7 @@
UmbralDeserializer.PreComputedData memory precomp = _preComputedData.toPreComputedData();

// Verify operator's signature of CFrag
require(

Check warning on line 114 in contracts/contracts/Adjudicator.sol

View workflow job for this annotation

GitHub Actions / linting

Use Custom Errors instead of require statements
SignatureVerifier.verify(
_cFragBytes,
abi.encodePacked(_cFragSignature, precomp.lostBytes[1]),
Expand Down Expand Up @@ -162,7 +162,7 @@
SignatureVerifier.hashEIP191(stamp, bytes1(0x45)), // Currently, we use version E (0x45) of EIP191 signatures
_operatorIdentityEvidence
);
address stakingProvider = application.stakingProviderFromOperator(operator);
address stakingProvider = application.operatorToStakingProvider(operator);
require(stakingProvider != address(0), "Operator must be associated with a provider");

// 5. Check that staking provider can be slashed
Expand Down
37 changes: 27 additions & 10 deletions contracts/contracts/TACoApplication.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import "@openzeppelin/contracts/utils/math/SafeCast.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin-upgradeable/contracts/access/OwnableUpgradeable.sol";
import "@threshold/contracts/staking/IApplication.sol";
import "../threshold/IApplicationWithOperator.sol";
import "../threshold/IApplicationWithDecreaseDelay.sol";
import "@threshold/contracts/staking/IStaking.sol";
import "./coordination/ITACoRootToChild.sol";
import "./coordination/ITACoChildToRoot.sol";
Expand All @@ -16,7 +17,12 @@ import "./coordination/ITACoChildToRoot.sol";
* @title TACo Application
* @notice Contract distributes rewards for participating in app and slashes for violating rules
*/
contract TACoApplication is IApplication, ITACoChildToRoot, OwnableUpgradeable {
contract TACoApplication is
IApplicationWithDecreaseDelay,
IApplicationWithOperator,
ITACoChildToRoot,
OwnableUpgradeable
{
using SafeERC20 for IERC20;
using SafeCast for uint256;

Expand Down Expand Up @@ -312,6 +318,7 @@ contract TACoApplication is IApplication, ITACoChildToRoot, OwnableUpgradeable {
function authorizationParameters()
external
view
override
returns (
uint96 _minimumAuthorization,
uint64 authorizationDecreaseDelay,
Expand Down Expand Up @@ -535,7 +542,7 @@ contract TACoApplication is IApplication, ITACoChildToRoot, OwnableUpgradeable {
* @notice Approve request of decreasing authorization. Can be called by anyone
* @param _stakingProvider Address of staking provider
*/
function finishAuthorizationDecrease(
function approveAuthorizationDecrease(
address _stakingProvider
) external updateReward(_stakingProvider) {
StakingProviderInfo storage info = stakingProviderInfo[_stakingProvider];
Expand Down Expand Up @@ -618,16 +625,14 @@ contract TACoApplication is IApplication, ITACoChildToRoot, OwnableUpgradeable {
/**
* @notice Returns staking provider for specified operator
*/
function stakingProviderFromOperator(address _operator) external view returns (address) {
function operatorToStakingProvider(address _operator) external view returns (address) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will require changes to nucypher. Opened nucypher/nucypher#3350

return _stakingProviderFromOperator[_operator];
}

/**
* @notice Returns operator for specified staking provider
*/
function getOperatorFromStakingProvider(
address _stakingProvider
) external view returns (address) {
function stakingProviderToOperator(address _stakingProvider) external view returns (address) {
return stakingProviderInfo[_stakingProvider].operator;
}

Expand All @@ -650,7 +655,9 @@ contract TACoApplication is IApplication, ITACoChildToRoot, OwnableUpgradeable {
* decrease for the given staking provider. If no authorization
* decrease has been requested, returns zero.
*/
function pendingAuthorizationDecrease(address _stakingProvider) external view returns (uint96) {
function pendingAuthorizationDecrease(
address _stakingProvider
) external view override returns (uint96) {
return stakingProviderInfo[_stakingProvider].deauthorizing;
}

Expand All @@ -660,7 +667,7 @@ contract TACoApplication is IApplication, ITACoChildToRoot, OwnableUpgradeable {
*/
function remainingAuthorizationDecreaseDelay(
address _stakingProvider
) external view returns (uint64) {
) external view override returns (uint64) {
uint256 endDeauthorization = stakingProviderInfo[_stakingProvider].endDeauthorization;
if (endDeauthorization <= block.timestamp) {
return 0;
Expand Down Expand Up @@ -743,6 +750,16 @@ contract TACoApplication is IApplication, ITACoChildToRoot, OwnableUpgradeable {
return stakingProviders.length;
}

/**
* @notice Used by staking provider to set operator address that will
* operate a node. The operator address must be unique.
* Reverts if the operator is already set for the staking provider
* or if the operator address is already in use.
*/
function registerOperator(address _operator) external override {
bondOperator(msg.sender, _operator);
}

/**
* @notice Bond operator
* @param _stakingProvider Staking provider address
Expand All @@ -751,7 +768,7 @@ contract TACoApplication is IApplication, ITACoChildToRoot, OwnableUpgradeable {
function bondOperator(
address _stakingProvider,
address _operator
) external onlyOwnerOrStakingProvider(_stakingProvider) updateReward(_stakingProvider) {
) public onlyOwnerOrStakingProvider(_stakingProvider) updateReward(_stakingProvider) {
StakingProviderInfo storage info = stakingProviderInfo[_stakingProvider];
address previousOperator = info.operator;
require(
Expand Down
6 changes: 3 additions & 3 deletions contracts/contracts/coordination/Coordinator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ contract Coordinator is Initializable, AccessControlDefaultAdminRulesUpgradeable

function setProviderPublicKey(BLS12381.G2Point calldata _publicKey) external {
uint32 lastRitualId = uint32(rituals.length);
address stakingProvider = application.stakingProviderFromOperator(msg.sender);
address stakingProvider = application.operatorToStakingProvider(msg.sender);
require(stakingProvider != address(0), "Operator has no bond with staking provider");

ParticipantKey memory newRecord = ParticipantKey(lastRitualId, _publicKey);
Expand Down Expand Up @@ -314,7 +314,7 @@ contract Coordinator is Initializable, AccessControlDefaultAdminRulesUpgradeable
"Not waiting for transcripts"
);

address provider = application.stakingProviderFromOperator(msg.sender);
address provider = application.operatorToStakingProvider(msg.sender);
Participant storage participant = getParticipantFromProvider(ritual, provider);

require(application.authorizedStake(provider) > 0, "Not enough authorization");
Expand Down Expand Up @@ -353,7 +353,7 @@ contract Coordinator is Initializable, AccessControlDefaultAdminRulesUpgradeable
"Not waiting for aggregations"
);

address provider = application.stakingProviderFromOperator(msg.sender);
address provider = application.operatorToStakingProvider(msg.sender);
Participant storage participant = getParticipantFromProvider(ritual, provider);
require(application.authorizedStake(provider) > 0, "Not enough authorization");

Expand Down
8 changes: 4 additions & 4 deletions contracts/contracts/coordination/TACoChildApplication.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ contract TACoChildApplication is ITACoRootToChild, ITACoChildApplication, Initia

mapping(address => StakingProviderInfo) public stakingProviderInfo;
address[] public stakingProviders;
mapping(address => address) public stakingProviderFromOperator;
mapping(address => address) public operatorToStakingProvider;

/**
* @dev Checks caller is root application
Expand Down Expand Up @@ -95,9 +95,9 @@ contract TACoChildApplication is ITACoRootToChild, ITACoChildApplication, Initia

info.operator = operator;
// Update operator to provider mapping
stakingProviderFromOperator[oldOperator] = address(0);
operatorToStakingProvider[oldOperator] = address(0);
if (operator != address(0)) {
stakingProviderFromOperator[operator] = stakingProvider;
operatorToStakingProvider[operator] = stakingProvider;
}
info.operatorConfirmed = false;
// TODO placeholder to notify Coordinator
Expand All @@ -117,7 +117,7 @@ contract TACoChildApplication is ITACoRootToChild, ITACoChildApplication, Initia

function confirmOperatorAddress(address _operator) external override {
require(msg.sender == coordinator, "Only Coordinator allowed to confirm operator");
address stakingProvider = stakingProviderFromOperator[_operator];
address stakingProvider = operatorToStakingProvider[_operator];
StakingProviderInfo storage info = stakingProviderInfo[stakingProvider];
require(
info.authorized >= minimumAuthorization,
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/AdjudicatorTestSet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ contract TACoApplicationForAdjudicatorMock {
mapping(address => uint256) public rewardInfo;
mapping(address => address) internal _stakingProviderFromOperator;

function stakingProviderFromOperator(address _operator) public view returns (address) {
function operatorToStakingProvider(address _operator) public view returns (address) {
return _stakingProviderFromOperator[_operator];
}

Expand Down
6 changes: 3 additions & 3 deletions contracts/test/CoordinatorTestSet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ contract ChildApplicationForCoordinatorMock is ITACoChildApplication {

mapping(address => uint96) public authorizedStake;
mapping(address => address) public operatorFromStakingProvider;
mapping(address => address) public stakingProviderFromOperator;
mapping(address => address) public operatorToStakingProvider;
mapping(address => bool) public confirmations;

function updateOperator(address _stakingProvider, address _operator) external {
address oldOperator = operatorFromStakingProvider[_stakingProvider];
stakingProviderFromOperator[oldOperator] = address(0);
operatorToStakingProvider[oldOperator] = address(0);
operatorFromStakingProvider[_stakingProvider] = _operator;
stakingProviderFromOperator[_operator] = _stakingProvider;
operatorToStakingProvider[_operator] = _stakingProvider;
}

function updateAuthorization(address _stakingProvider, uint96 _amount) external {
Expand Down
6 changes: 3 additions & 3 deletions contracts/test/TACoApplicationTestSet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,17 @@ contract ChildApplicationForTACoApplicationMock {

mapping(address => uint96) public authorizedStake;
mapping(address => address) public operatorFromStakingProvider;
mapping(address => address) public stakingProviderFromOperator;
mapping(address => address) public operatorToStakingProvider;

constructor(TACoApplication _rootApplication) {
rootApplication = _rootApplication;
}

function updateOperator(address _stakingProvider, address _operator) external {
address oldOperator = operatorFromStakingProvider[_stakingProvider];
stakingProviderFromOperator[oldOperator] = address(0);
operatorToStakingProvider[oldOperator] = address(0);
operatorFromStakingProvider[_stakingProvider] = _operator;
stakingProviderFromOperator[_operator] = _stakingProvider;
operatorToStakingProvider[_operator] = _stakingProvider;
}

function updateAuthorization(address _stakingProvider, uint96 _amount) external {
Expand Down
64 changes: 64 additions & 0 deletions contracts/threshold/IApplicationWithDecreaseDelay.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// SPDX-License-Identifier: GPL-3.0-or-later

// ██████████████ ▐████▌ ██████████████
// ██████████████ ▐████▌ ██████████████
// ▐████▌ ▐████▌
// ▐████▌ ▐████▌
// ██████████████ ▐████▌ ██████████████
// ██████████████ ▐████▌ ██████████████
// ▐████▌ ▐████▌
// ▐████▌ ▐████▌
// ▐████▌ ▐████▌
// ▐████▌ ▐████▌
// ▐████▌ ▐████▌
// ▐████▌ ▐████▌

pragma solidity ^0.8.9;

import "@threshold/contracts/staking/IApplication.sol";

/// @title Interface for Threshold Network applications with delay after decrease request
interface IApplicationWithDecreaseDelay is IApplication {
/// @notice Returns authorization-related parameters of the application.
/// @dev The minimum authorization is also returned by `minimumAuthorization()`
/// function, as a requirement of `IApplication` interface.
/// @return _minimumAuthorization The minimum authorization amount required
/// so that operator can participate in the application.
/// @return authorizationDecreaseDelay Delay in seconds that needs to pass
/// between the time authorization decrease is requested and the
/// time that request gets approved. Protects against free-riders
/// earning rewards and not being active in the network.
/// @return authorizationDecreaseChangePeriod Authorization decrease change
/// period in seconds. It is the time, before authorization decrease
/// delay end, during which the pending authorization decrease
/// request can be overwritten.
/// If set to 0, pending authorization decrease request can not be
/// overwritten until the entire `authorizationDecreaseDelay` ends.
/// If set to value equal `authorizationDecreaseDelay`, request can
/// always be overwritten.
function authorizationParameters()
external
view
returns (
uint96 _minimumAuthorization,
uint64 authorizationDecreaseDelay,
uint64 authorizationDecreaseChangePeriod
);

/// @notice Returns the amount of stake that is pending authorization
/// decrease for the given staking provider. If no authorization
/// decrease has been requested, returns zero.
function pendingAuthorizationDecrease(address _stakingProvider) external view returns (uint96);

/// @notice Returns the remaining time in seconds that needs to pass before
/// the requested authorization decrease can be approved.
function remainingAuthorizationDecreaseDelay(
address stakingProvider
) external view returns (uint64);

/// @notice Approves the previously registered authorization decrease
/// request. Reverts if authorization decrease delay has not passed
/// yet or if the authorization decrease was not requested for the
/// given staking provider.
function approveAuthorizationDecrease(address stakingProvider) external;
}
42 changes: 42 additions & 0 deletions contracts/threshold/IApplicationWithOperator.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// SPDX-License-Identifier: GPL-3.0-or-later

// ██████████████ ▐████▌ ██████████████
// ██████████████ ▐████▌ ██████████████
// ▐████▌ ▐████▌
// ▐████▌ ▐████▌
// ██████████████ ▐████▌ ██████████████
// ██████████████ ▐████▌ ██████████████
// ▐████▌ ▐████▌
// ▐████▌ ▐████▌
// ▐████▌ ▐████▌
// ▐████▌ ▐████▌
// ▐████▌ ▐████▌
// ▐████▌ ▐████▌

pragma solidity ^0.8.9;

import "@threshold/contracts/staking/IApplication.sol";

/// @title Interface for Threshold Network applications with operator role
interface IApplicationWithOperator is IApplication {
/// @notice Returns operator registered for the given staking provider.
function stakingProviderToOperator(address stakingProvider) external view returns (address);

/// @notice Returns staking provider of the given operator.
function operatorToStakingProvider(address operator) external view returns (address);

/// @notice Used by staking provider to set operator address that will
/// operate a node. The operator addressmust be unique.
/// Reverts if the operator is already set for the staking provider
/// or if the operator address is already in use.
/// @dev Depending on application the given staking provider can set operator
/// address only one or multiple times. Besides that application can decide
/// if function reverts if there is a pending authorization decrease for
/// the staking provider.
function registerOperator(address operator) external;

// TODO consider that?
// /// @notice Used by additional role (owner for example) to set operator address that will
// /// operate a node for the specified staking provider.
// function registerOperator(address stakingProvider, address operator) external;
}
2 changes: 1 addition & 1 deletion contracts/threshold/ITACoChildApplication.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pragma solidity ^0.8.0;
import "../contracts/coordination/ITACoChildToRoot.sol";

interface ITACoChildApplication is ITACoChildToRoot {
function stakingProviderFromOperator(address _operator) external view returns (address);
function operatorToStakingProvider(address _operator) external view returns (address);

function authorizedStake(address _stakingProvider) external view returns (uint96);

Expand Down
Loading