From a04203d643cf5d5f9c0a957954dad113f280f39f Mon Sep 17 00:00:00 2001 From: Ameesha Agrawal Date: Tue, 16 May 2023 22:53:40 +0530 Subject: [PATCH] feat: add rescue funds in hasher and sig verifier --- contracts/utils/Hasher.sol | 27 ++++++++++++++++++++++++- contracts/utils/SignatureVerifier.sol | 29 ++++++++++++++++++++++++++- test/ExecutionManager.t.sol | 2 +- test/Setup.t.sol | 4 ++-- test/TransmitManager.t.sol | 4 ++-- 5 files changed, 59 insertions(+), 7 deletions(-) diff --git a/contracts/utils/Hasher.sol b/contracts/utils/Hasher.sol index fb056f25..02b1ee9e 100644 --- a/contracts/utils/Hasher.sol +++ b/contracts/utils/Hasher.sol @@ -2,6 +2,9 @@ pragma solidity 0.8.7; import "../interfaces/IHasher.sol"; +import "../libraries/RescueFundsLib.sol"; +import "../utils/AccessControl.sol"; +import {RESCUE_ROLE} from "../utils/AccessRoles.sol"; /** * @title Hasher @@ -9,7 +12,15 @@ import "../interfaces/IHasher.sol"; * @dev This contract is modular component in socket to support different message packing algorithms in case of blockchains * not supporting this type of packing. */ -contract Hasher is IHasher { +contract Hasher is IHasher, AccessControl { + /** + * @notice initialises and grants RESCUE_ROLE to owner. + * @param owner_ The address of the owner of the contract. + */ + constructor(address owner_) AccessControl(owner_) { + _grantRole(RESCUE_ROLE, owner_); + } + /// @inheritdoc IHasher function packMessage( uint32 srcChainSlug_, @@ -35,4 +46,18 @@ contract Hasher is IHasher { ) ); } + + /** + * @notice Rescues funds from a contract that has lost access to them. + * @param token_ The address of the token contract. + * @param userAddress_ The address of the user who lost access to the funds. + * @param amount_ The amount of tokens to be rescued. + */ + function rescueFunds( + address token_, + address userAddress_, + uint256 amount_ + ) external onlyRole(RESCUE_ROLE) { + RescueFundsLib.rescueFunds(token_, userAddress_, amount_); + } } diff --git a/contracts/utils/SignatureVerifier.sol b/contracts/utils/SignatureVerifier.sol index 74743c68..c5fcecac 100644 --- a/contracts/utils/SignatureVerifier.sol +++ b/contracts/utils/SignatureVerifier.sol @@ -2,14 +2,27 @@ pragma solidity 0.8.7; import "../interfaces/ISignatureVerifier.sol"; + +import "../libraries/RescueFundsLib.sol"; import "../libraries/SignatureVerifierLib.sol"; +import "../utils/AccessControl.sol"; +import {RESCUE_ROLE} from "../utils/AccessRoles.sol"; + /** * @title Signature Verifier * @notice Verifies the signatures and returns the address of signer recovered from the input signature or digest. * @dev This contract is modular component in socket to support different signing algorithms. */ -contract SignatureVerifier is ISignatureVerifier { +contract SignatureVerifier is ISignatureVerifier, AccessControl { + /** + * @notice initialises and grants RESCUE_ROLE to owner. + * @param owner_ The address of the owner of the contract. + */ + constructor(address owner_) AccessControl(owner_) { + _grantRole(RESCUE_ROLE, owner_); + } + /// @inheritdoc ISignatureVerifier function recoverSigner( uint32 dstChainSlug_, @@ -36,4 +49,18 @@ contract SignatureVerifier is ISignatureVerifier { return SignatureVerifierLib.recoverSignerFromDigest(digest_, signature_); } + + /** + * @notice Rescues funds from a contract that has lost access to them. + * @param token_ The address of the token contract. + * @param userAddress_ The address of the user who lost access to the funds. + * @param amount_ The amount of tokens to be rescued. + */ + function rescueFunds( + address token_, + address userAddress_, + uint256 amount_ + ) external onlyRole(RESCUE_ROLE) { + RescueFundsLib.rescueFunds(token_, userAddress_, amount_); + } } diff --git a/test/ExecutionManager.t.sol b/test/ExecutionManager.t.sol index a45fb1ac..553c87e5 100644 --- a/test/ExecutionManager.t.sol +++ b/test/ExecutionManager.t.sol @@ -56,7 +56,7 @@ contract ExecutionManagerTest is Setup { signatureVerifier ); - signatureVerifier = new SignatureVerifier(); + signatureVerifier = new SignatureVerifier(owner); transmitManager = new TransmitManager( signatureVerifier, owner, diff --git a/test/Setup.t.sol b/test/Setup.t.sol index c4913142..008e9a47 100644 --- a/test/Setup.t.sol +++ b/test/Setup.t.sol @@ -244,8 +244,8 @@ contract Setup is Test { ) internal { vm.startPrank(deployer_); - cc_.hasher__ = new Hasher(); - cc_.sigVerifier__ = new SignatureVerifier(); + cc_.hasher__ = new Hasher(deployer_); + cc_.sigVerifier__ = new SignatureVerifier(deployer_); cc_.capacitorFactory__ = new CapacitorFactory(deployer_); cc_.executionManager__ = new ExecutionManager( deployer_, diff --git a/test/TransmitManager.t.sol b/test/TransmitManager.t.sol index 75b72827..3b16bdde 100644 --- a/test/TransmitManager.t.sol +++ b/test/TransmitManager.t.sol @@ -49,7 +49,7 @@ contract TransmitManagerTest is Setup { feesPayer = vm.addr(feesPayerPrivateKey); feesWithdrawer = vm.addr(feesWithdrawerPrivateKey); - signatureVerifier = new SignatureVerifier(); + signatureVerifier = new SignatureVerifier(owner); transmitManager = new TransmitManager( signatureVerifier, owner, @@ -253,7 +253,7 @@ contract TransmitManagerTest is Setup { } function testSetSignatureVerifier() public { - SignatureVerifier signatureVerifierNew = new SignatureVerifier(); + SignatureVerifier signatureVerifierNew = new SignatureVerifier(owner); hoax(owner); vm.expectEmit(false, false, false, true);