Skip to content

Commit

Permalink
Merge branch 'main' into feat/blobstorage-store-blob
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberhorsey authored Apr 3, 2024
2 parents bcad2d7 + 381f8b8 commit 442ab70
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 9 deletions.
6 changes: 4 additions & 2 deletions packages/protocol/contracts/L1/libs/LibUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ library LibUtils {
view
returns (bool)
{
uint256 deadline = _tsTimestamp.max(_lastUnpausedAt) + _windowMinutes * 60;
return block.timestamp >= deadline;
unchecked {
uint256 deadline = _tsTimestamp.max(_lastUnpausedAt) + _windowMinutes * 60;
return block.timestamp >= deadline;
}
}
}
19 changes: 17 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 @@ -190,7 +192,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 @@ -262,7 +264,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 @@ -646,4 +648,17 @@ contract Bridge is EssentialContract, IBridge {
return false;
}
}

function _isPostInvocationDelay(
uint256 _receivedAt,
uint256 _invocationDelay
)
private
view
returns (bool)
{
unchecked {
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 @@ -26,6 +26,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 @@ -81,6 +83,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
12 changes: 10 additions & 2 deletions packages/protocol/contracts/team/TimelockTokenPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,23 @@ contract TimelockTokenPool is EssentialContract, EIP712Upgradeable {
}

/// @notice Withdraws all withdrawable tokens.
function withdraw() external nonReentrant {
function withdraw() external whenNotPaused nonReentrant {
_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 _nonce The nonce to be used.
/// @param _sig Signature provided by the grant recipient.
function withdraw(address _to, uint256 _nonce, bytes memory _sig) external nonReentrant {
function withdraw(
address _to,
uint256 _nonce,
bytes calldata _sig
)
external
whenNotPaused
nonReentrant
{
if (_to == address(0)) revert INVALID_PARAM();

address account = ECDSA.recover(getWithdrawalHash(_to, _nonce), _sig);
Expand Down
7 changes: 6 additions & 1 deletion packages/protocol/contracts/team/airdrop/ERC20Airdrop2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ contract ERC20Airdrop2 is MerkleClaimable {
using LibMath for uint256;
using SafeERC20 for IERC20;

uint256 public constant WITHDRAWAL_GRACE_PERIOD = 30 days;

/// @notice The address of the token contract.
address public token;

Expand All @@ -39,7 +41,10 @@ contract ERC20Airdrop2 is MerkleClaimable {
error WITHDRAWALS_NOT_ONGOING();

modifier ongoingWithdrawals() {
if (claimEnd > block.timestamp || claimEnd + withdrawalWindow < block.timestamp) {
if (
claimEnd > block.timestamp
|| claimEnd + withdrawalWindow + WITHDRAWAL_GRACE_PERIOD < block.timestamp
) {
revert WITHDRAWALS_NOT_ONGOING();
}
_;
Expand Down
4 changes: 2 additions & 2 deletions packages/protocol/test/team/airdrop/ERC20Airdrop2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ contract TestERC20Airdrop2 is TaikoTest {
vm.expectRevert(ERC20Airdrop2.WITHDRAWALS_NOT_ONGOING.selector);
airdrop2.withdraw(Alice);

// Roll 11 day after
// Roll 31 day after
vm.roll(block.number + 200);
vm.warp(claimEnd + 11 days);
vm.warp(claimEnd + 10 days + 30 days + 1); // withdrawal window + grace period + 1sec

(uint256 balance, uint256 withdrawable) = airdrop2.getBalance(Alice);

Expand Down

0 comments on commit 442ab70

Please sign in to comment.