Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dantaik committed Apr 2, 2024
1 parent 643bd17 commit 24e8196
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
17 changes: 15 additions & 2 deletions packages/protocol/contracts/bridge/Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity 0.8.24;

import "../common/EssentialContract.sol";
import "../libs/LibAddress.sol";
import "../libs/LibMath.sol";
import "../signal/ISignalService.sol";
import "./IBridge.sol";

Expand All @@ -13,6 +14,7 @@ import "./IBridge.sol";
/// @custom:security-contact [email protected]
contract Bridge is EssentialContract, IBridge {
using Address for address;
using LibMath for uint256;
using LibAddress for address;
using LibAddress for address payable;

Expand Down Expand Up @@ -207,7 +209,7 @@ contract Bridge is EssentialContract, IBridge {
}
}

if (block.timestamp >= invocationDelay + receivedAt) {
if (_isPostInvocationDelay(receivedAt, invocationDelay)) {
delete proofReceipt[msgHash];
messageStatus[msgHash] = Status.RECALLED;

Expand Down Expand Up @@ -279,7 +281,7 @@ contract Bridge is EssentialContract, IBridge {
}
}

if (block.timestamp >= invocationDelay + receivedAt) {
if (_isPostInvocationDelay(receivedAt, invocationDelay)) {
// If the gas limit is set to zero, only the owner can process the message.
if (_message.gasLimit == 0 && msg.sender != _message.destOwner) {
revert B_PERMISSION_DENIED();
Expand Down Expand Up @@ -598,4 +600,15 @@ contract Bridge is EssentialContract, IBridge {
return false;
}
}

function _isPostInvocationDelay(
uint256 _receivedAt,
uint256 _invocationDelay
)
private
view
returns (bool)
{
return block.timestamp >= _receivedAt.max(lastUnpausedAt) + _invocationDelay;
}
}
3 changes: 3 additions & 0 deletions packages/protocol/contracts/common/EssentialContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ abstract contract EssentialContract is UUPSUpgradeable, Ownable2StepUpgradeable,

uint8 private __paused;

uint64 public lastUnpausedAt;

uint256[49] private __gap;

/// @notice Emitted when the contract is paused.
Expand Down Expand Up @@ -78,6 +80,7 @@ abstract contract EssentialContract is UUPSUpgradeable, Ownable2StepUpgradeable,
/// @notice Unpauses the contract.
function unpause() public virtual whenPaused {
__paused = _FALSE;
lastUnpausedAt = uint64(block.timestamp);
emit Unpaused(msg.sender);
// We call the authorize function here to avoid:
// Warning (5740): Unreachable code.
Expand Down
4 changes: 2 additions & 2 deletions packages/protocol/contracts/team/TimelockTokenPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,14 @@ contract TimelockTokenPool is EssentialContract, EIP712Upgradeable {
}

/// @notice Withdraws all withdrawable tokens.
function withdraw() external nonReentrant {
function withdraw() external nonReentrant whenNotPaused {
_withdraw(msg.sender, msg.sender);
}

/// @notice Withdraws all withdrawable tokens to a designated address.
/// @param _to The address where the granted and unlocked tokens shall be sent to.
/// @param _sig Signature provided by the grant recipient.
function withdraw(address _to, bytes memory _sig) external nonReentrant {
function withdraw(address _to, bytes memory _sig) external whenNotPaused nonReentrant {
if (_to == address(0)) revert INVALID_PARAM();
address recipient = ECDSA.recover(getWithdrawalHash(_to), _sig);
_withdraw(recipient, _to);
Expand Down

0 comments on commit 24e8196

Please sign in to comment.