Skip to content

Commit

Permalink
feat: add rescue funds in hasher and sig verifier
Browse files Browse the repository at this point in the history
  • Loading branch information
ameeshaagrawal committed May 16, 2023
1 parent 250ef7d commit a04203d
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 7 deletions.
27 changes: 26 additions & 1 deletion contracts/utils/Hasher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,25 @@
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
* @notice contract for hasher contract that calculates the packed message
* @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_,
Expand All @@ -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_);
}
}
29 changes: 28 additions & 1 deletion contracts/utils/SignatureVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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_,
Expand All @@ -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_);
}
}
2 changes: 1 addition & 1 deletion test/ExecutionManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ contract ExecutionManagerTest is Setup {
signatureVerifier
);

signatureVerifier = new SignatureVerifier();
signatureVerifier = new SignatureVerifier(owner);
transmitManager = new TransmitManager(
signatureVerifier,
owner,
Expand Down
4 changes: 2 additions & 2 deletions test/Setup.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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_,
Expand Down
4 changes: 2 additions & 2 deletions test/TransmitManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit a04203d

Please sign in to comment.