Skip to content

Commit

Permalink
TACoApplication: proper rename provider<->operator getters
Browse files Browse the repository at this point in the history
  • Loading branch information
vzotova committed Nov 16, 2023
1 parent a2850ca commit 3e91320
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 66 deletions.
2 changes: 1 addition & 1 deletion contracts/contracts/Adjudicator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ contract Adjudicator {
SignatureVerifier.hashEIP191(stamp, bytes1(0x45)), // Currently, we use version E (0x45) of EIP191 signatures
_operatorIdentityEvidence
);
address stakingProvider = application.stakingProviderToOperator(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
6 changes: 2 additions & 4 deletions contracts/contracts/TACoApplication.sol
Original file line number Diff line number Diff line change
Expand Up @@ -618,16 +618,14 @@ contract TACoApplication is
/**
* @notice Returns staking provider for specified operator
*/
function stakingProviderToOperator(address _operator) external view returns (address) {
function operatorToStakingProvider(address _operator) external view returns (address) {
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 Down
6 changes: 3 additions & 3 deletions contracts/contracts/coordination/Coordinator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ contract Coordinator is Initializable, AccessControlDefaultAdminRulesUpgradeable

function setProviderPublicKey(BLS12381.G2Point calldata _publicKey) external {
uint32 lastRitualId = uint32(rituals.length);
address stakingProvider = application.stakingProviderToOperator(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 @@ -288,7 +288,7 @@ contract Coordinator is Initializable, AccessControlDefaultAdminRulesUpgradeable
"Not waiting for transcripts"
);

address provider = application.stakingProviderToOperator(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 @@ -327,7 +327,7 @@ contract Coordinator is Initializable, AccessControlDefaultAdminRulesUpgradeable
"Not waiting for aggregations"
);

address provider = application.stakingProviderToOperator(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 stakingProviderToOperator;
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
stakingProviderToOperator[oldOperator] = address(0);
operatorToStakingProvider[oldOperator] = address(0);
if (operator != address(0)) {
stakingProviderToOperator[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 = stakingProviderToOperator[_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 stakingProviderToOperator(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 @@ -10,14 +10,14 @@ import "../threshold/ITACoChildApplication.sol";
contract ChildApplicationForCoordinatorMock is ITACoChildApplication {
mapping(address => uint96) public authorizedStake;
mapping(address => address) public operatorFromStakingProvider;
mapping(address => address) public stakingProviderToOperator;
mapping(address => address) public operatorToStakingProvider;
mapping(address => bool) public confirmations;

function updateOperator(address _stakingProvider, address _operator) external {
address oldOperator = operatorFromStakingProvider[_stakingProvider];
stakingProviderToOperator[oldOperator] = address(0);
operatorToStakingProvider[oldOperator] = address(0);
operatorFromStakingProvider[_stakingProvider] = _operator;
stakingProviderToOperator[_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 stakingProviderToOperator;
mapping(address => address) public operatorToStakingProvider;

constructor(TACoApplication _rootApplication) {
rootApplication = _rootApplication;
}

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

function updateAuthorization(address _stakingProvider, uint96 _amount) external {
Expand Down
3 changes: 3 additions & 0 deletions contracts/threshold/IApplicationWithOperator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ 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
Expand Down
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 stakingProviderToOperator(address _operator) external view returns (address);
function operatorToStakingProvider(address _operator) external view returns (address);

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

Expand Down
18 changes: 9 additions & 9 deletions tests/application/test_authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ def test_involuntary_authorization_decrease(
assert child_application.authorizedStake(staking_provider) == 0
assert taco_application.isAuthorized(staking_provider)
assert taco_application.isOperatorConfirmed(staking_provider)
assert taco_application.getOperatorFromStakingProvider(staking_provider) == staking_provider
assert taco_application.stakingProviderToOperator(staking_provider) == staking_provider
assert taco_application.operatorToStakingProvider(staking_provider) == staking_provider
assert child_application.operatorFromStakingProvider(staking_provider) == staking_provider

events = taco_application.AuthorizationInvoluntaryDecreased.from_receipt(tx)
Expand All @@ -253,8 +253,8 @@ def test_involuntary_authorization_decrease(
assert not taco_application.isAuthorized(staking_provider)
assert not taco_application.isOperatorConfirmed(staking_provider)
assert not taco_application.stakingProviderInfo(staking_provider)[OPERATOR_CONFIRMED_SLOT]
assert taco_application.getOperatorFromStakingProvider(staking_provider) == ZERO_ADDRESS
assert taco_application.stakingProviderToOperator(staking_provider) == ZERO_ADDRESS
assert taco_application.operatorToStakingProvider(staking_provider) == ZERO_ADDRESS
assert child_application.operatorFromStakingProvider(staking_provider) == ZERO_ADDRESS

events = taco_application.AuthorizationInvoluntaryDecreased.from_receipt(tx)
Expand Down Expand Up @@ -293,7 +293,7 @@ def test_involuntary_authorization_decrease(
threshold_staking.involuntaryAuthorizationDecrease(
staking_provider, authorization, 0, sender=creator
)
assert taco_application.getOperatorFromStakingProvider(staking_provider) == ZERO_ADDRESS
assert taco_application.stakingProviderToOperator(staking_provider) == ZERO_ADDRESS
assert taco_application.stakingProviderInfo(staking_provider)[AUTHORIZATION_SLOT] == 0
assert taco_application.pendingAuthorizationDecrease(staking_provider) == 0
assert taco_application.stakingProviderInfo(staking_provider)[END_DEAUTHORIZATION_SLOT] == 0
Expand Down Expand Up @@ -507,8 +507,8 @@ def test_finish_authorization_decrease(
assert taco_application.pendingAuthorizationDecrease(staking_provider) == 0
assert taco_application.stakingProviderInfo(staking_provider)[END_DEAUTHORIZATION_SLOT] == 0
assert taco_application.stakingProviderInfo(staking_provider)[END_COMMITMENT_SLOT] != 0
assert taco_application.getOperatorFromStakingProvider(staking_provider) == staking_provider
assert taco_application.stakingProviderToOperator(staking_provider) == staking_provider
assert taco_application.operatorToStakingProvider(staking_provider) == staking_provider
assert taco_application.authorizedOverall() == new_value
assert taco_application.authorizedStake(staking_provider) == new_value
assert child_application.authorizedStake(staking_provider) == new_value
Expand Down Expand Up @@ -536,8 +536,8 @@ def test_finish_authorization_decrease(
assert taco_application.pendingAuthorizationDecrease(staking_provider) == 0
assert taco_application.stakingProviderInfo(staking_provider)[END_DEAUTHORIZATION_SLOT] == 0
assert taco_application.stakingProviderInfo(staking_provider)[END_COMMITMENT_SLOT] == 0
assert taco_application.getOperatorFromStakingProvider(staking_provider) == ZERO_ADDRESS
assert taco_application.stakingProviderToOperator(staking_provider) == ZERO_ADDRESS
assert taco_application.operatorToStakingProvider(staking_provider) == ZERO_ADDRESS
assert taco_application.authorizedOverall() == 0
assert taco_application.authorizedStake(staking_provider) == 0
assert child_application.authorizedStake(staking_provider) == 0
Expand Down Expand Up @@ -566,7 +566,7 @@ def test_finish_authorization_decrease(
threshold_staking.setDecreaseRequest(staking_provider, 0, sender=creator)
taco_application.approveAuthorizationDecrease(staking_provider, sender=creator)
assert taco_application.authorizedStake(staking_provider) == 0
assert taco_application.getOperatorFromStakingProvider(staking_provider) == ZERO_ADDRESS
assert taco_application.stakingProviderToOperator(staking_provider) == ZERO_ADDRESS


def test_resync(accounts, threshold_staking, taco_application, child_application, chain):
Expand Down Expand Up @@ -621,8 +621,8 @@ def test_resync(accounts, threshold_staking, taco_application, child_application
assert taco_application.pendingAuthorizationDecrease(staking_provider) == 0
assert taco_application.stakingProviderInfo(staking_provider)[END_COMMITMENT_SLOT] != 0
assert taco_application.authorizedOverall() == new_value
assert taco_application.getOperatorFromStakingProvider(staking_provider) == staking_provider
assert taco_application.stakingProviderToOperator(staking_provider) == staking_provider
assert taco_application.operatorToStakingProvider(staking_provider) == staking_provider
assert taco_application.authorizedOverall() == new_value
assert taco_application.authorizedStake(staking_provider) == new_value
assert child_application.authorizedStake(staking_provider) == new_value
Expand All @@ -647,8 +647,8 @@ def test_resync(accounts, threshold_staking, taco_application, child_application
assert taco_application.stakingProviderInfo(staking_provider)[AUTHORIZATION_SLOT] == new_value
assert taco_application.pendingAuthorizationDecrease(staking_provider) == new_value
assert taco_application.authorizedOverall() == new_value
assert taco_application.getOperatorFromStakingProvider(staking_provider) == staking_provider
assert taco_application.stakingProviderToOperator(staking_provider) == staking_provider
assert taco_application.operatorToStakingProvider(staking_provider) == staking_provider
assert taco_application.authorizedOverall() == new_value
assert taco_application.authorizedStake(staking_provider) == new_value
assert child_application.authorizedStake(staking_provider) == 0
Expand All @@ -672,8 +672,8 @@ def test_resync(accounts, threshold_staking, taco_application, child_application
assert taco_application.stakingProviderInfo(staking_provider)[END_DEAUTHORIZATION_SLOT] == 0
assert taco_application.stakingProviderInfo(staking_provider)[END_COMMITMENT_SLOT] == 0
assert taco_application.authorizedOverall() == 0
assert taco_application.getOperatorFromStakingProvider(staking_provider) == ZERO_ADDRESS
assert taco_application.stakingProviderToOperator(staking_provider) == ZERO_ADDRESS
assert taco_application.operatorToStakingProvider(staking_provider) == ZERO_ADDRESS
assert taco_application.authorizedOverall() == 0
assert taco_application.authorizedStake(staking_provider) == 0
assert child_application.authorizedStake(staking_provider) == 0
Expand Down
Loading

0 comments on commit 3e91320

Please sign in to comment.