From 8f999b065501e0cf25c2a9b273c6b5f62fea53bd Mon Sep 17 00:00:00 2001 From: Egor Lysenko Date: Thu, 7 Mar 2024 01:01:31 +0400 Subject: [PATCH] improve redirection --- contracts/sfc/SFC.sol | 16 ++++++++++++++-- contracts/sfc/SFCI.sol | 5 +++++ contracts/sfc/SFCState.sol | 2 ++ test/SFC.js | 2 +- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/contracts/sfc/SFC.sol b/contracts/sfc/SFC.sol index 64d53ff..5881d54 100644 --- a/contracts/sfc/SFC.sol +++ b/contracts/sfc/SFC.sol @@ -140,8 +140,20 @@ contract SFC is SFCBase, Version { _syncValidator(validatorID, true); } - function initiateRedirection(address from, address to) onlyOwner external { - require(getRedirection[from] != to, "already compelte"); + function setRedirectionAuthorizer(address v) onlyOwner external { + require(redirectionAuthorizer != v, "same"); + redirectionAuthorizer = v; + } + + event AnnouncedRedirection(address indexed from, address indexed to); + + function announceRedirection(address to) external { + emit AnnouncedRedirection(msg.sender, to); + } + + function initiateRedirection(address from, address to) external { + require(msg.sender == redirectionAuthorizer, "not authorized"); + require(getRedirection[from] != to, "already complete"); require(from != to, "same address"); getRedirectionRequest[from] = to; } diff --git a/contracts/sfc/SFCI.sol b/contracts/sfc/SFCI.sol index 8865362..dc75d73 100644 --- a/contracts/sfc/SFCI.sol +++ b/contracts/sfc/SFCI.sol @@ -15,6 +15,7 @@ interface SFCI { event DeactivatedValidator(uint256 indexed validatorID, uint256 deactivatedEpoch, uint256 deactivatedTime); event ChangedValidatorStatus(uint256 indexed validatorID, uint256 status); + event AnnouncedRedirection(address indexed from, address indexed to); function currentSealedEpoch() external view returns (uint256); @@ -154,6 +155,10 @@ interface SFCI { function migrateValidatorPubkeyUniquenessFlag(uint256 start, uint256 end) external; + function setRedirectionAuthorizer(address v) external; + + function announceRedirection(address to) external; + function initiateRedirection(address from, address to) external; function redirect(address to) external; diff --git a/contracts/sfc/SFCState.sol b/contracts/sfc/SFCState.sol index 7f49404..cfa1d8a 100644 --- a/contracts/sfc/SFCState.sol +++ b/contracts/sfc/SFCState.sol @@ -120,6 +120,8 @@ contract SFCState is Initializable, Ownable { mapping(bytes32 => uint256) internal pubkeyHashToValidatorID; + address public redirectionAuthorizer; + mapping(address => address) public getRedirectionRequest; mapping(address => address) public getRedirection; diff --git a/test/SFC.js b/test/SFC.js index f9f3e93..aa0308a 100644 --- a/test/SFC.js +++ b/test/SFC.js @@ -283,7 +283,7 @@ contract('SFC', async ([firstValidator, secondValidator, thirdValidator]) => { }); it('Returns the version of the current implementation', async () => { - expect((await this.sfc.version()).toString()).to.equals('0x333034'); + expect((await this.sfc.version()).toString()).to.equals('0x333035'); }); it('Reverts on transfers', async () => {