Commit 0a1ffdc4 authored by Maurelian's avatar Maurelian

fix(ctb): Immutables scream like a snake

parent 1d099302
...@@ -3,6 +3,9 @@ pragma solidity 0.8.15; ...@@ -3,6 +3,9 @@ pragma solidity 0.8.15;
import { ISemver } from "src/universal/ISemver.sol"; import { ISemver } from "src/universal/ISemver.sol";
/// @title DelayedVetoable
/// @notice This contract enables a delay before a call is forwarded to a target contract, and during the delay period
/// the call can be vetoed by the authorized vetoer.
contract DelayedVetoable is ISemver { contract DelayedVetoable is ISemver {
/// @notice Error for when the delay has already been set. /// @notice Error for when the delay has already been set.
error AlreadyDelayed(); error AlreadyDelayed();
...@@ -36,19 +39,19 @@ contract DelayedVetoable is ISemver { ...@@ -36,19 +39,19 @@ contract DelayedVetoable is ISemver {
event Vetoed(bytes32 indexed callHash, bytes data); event Vetoed(bytes32 indexed callHash, bytes data);
/// @notice The address that all calls are forwarded to after the delay. /// @notice The address that all calls are forwarded to after the delay.
address internal immutable _target; address internal immutable TARGET;
/// @notice The address that can veto a call. /// @notice The address that can veto a call.
address internal immutable _vetoer; address internal immutable VETOER;
/// @notice The address that can initiate a call. /// @notice The address that can initiate a call.
address internal immutable _initiator; address internal immutable INITIATOR;
/// @notice The current amount of time to wait before forwarding a call. /// @notice The current amount of time to wait before forwarding a call.
uint256 internal _delay; uint256 internal _delay;
/// @notice The delay which will be set after the initial system deployment is completed. /// @notice The delay which will be set after the initial system deployment is completed.
uint256 internal immutable _operatingDelay; uint256 internal immutable OPERATING_DELAY;
/// @notice The time that a call was initiated. /// @notice The time that a call was initiated.
mapping(bytes32 => uint256) internal _queuedAt; mapping(bytes32 => uint256) internal _queuedAt;
...@@ -76,29 +79,30 @@ contract DelayedVetoable is ISemver { ...@@ -76,29 +79,30 @@ contract DelayedVetoable is ISemver {
/// @param target_ Address of the target. /// @param target_ Address of the target.
/// @param operatingDelay_ Time to delay when the system is operational. /// @param operatingDelay_ Time to delay when the system is operational.
constructor(address vetoer_, address initiator_, address target_, uint256 operatingDelay_) { constructor(address vetoer_, address initiator_, address target_, uint256 operatingDelay_) {
_vetoer = vetoer_; // Note that the _delay value is not set here. Having an initial delay of 0 is helpful
_initiator = initiator_; // during the deployment of a new system.
_target = target_; VETOER = vetoer_;
_delay = 0; INITIATOR = initiator_;
_operatingDelay = operatingDelay_; TARGET = target_;
OPERATING_DELAY = operatingDelay_;
} }
/// @notice Gets the initiator /// @notice Gets the initiator
/// @return initiator_ Initiator address. /// @return initiator_ Initiator address.
function initiator() external virtual readOrHandle returns (address initiator_) { function initiator() external virtual readOrHandle returns (address initiator_) {
initiator_ = _initiator; initiator_ = INITIATOR;
} }
//// @notice Queries the vetoer address. //// @notice Queries the vetoer address.
/// @return vetoer_ Vetoer address. /// @return vetoer_ Vetoer address.
function vetoer() external virtual readOrHandle returns (address vetoer_) { function vetoer() external virtual readOrHandle returns (address vetoer_) {
vetoer_ = _vetoer; vetoer_ = VETOER;
} }
//// @notice Queries the target address. //// @notice Queries the target address.
/// @return target_ Target address. /// @return target_ Target address.
function target() external readOrHandle returns (address target_) { function target() external readOrHandle returns (address target_) {
target_ = _target; target_ = TARGET;
} }
/// @notice Gets the delay /// @notice Gets the delay
...@@ -125,9 +129,9 @@ contract DelayedVetoable is ISemver { ...@@ -125,9 +129,9 @@ contract DelayedVetoable is ISemver {
function _handleCall() internal { function _handleCall() internal {
// The initiator and vetoer activate the delay by passing in null data. // The initiator and vetoer activate the delay by passing in null data.
if (msg.data.length == 0) { if (msg.data.length == 0) {
if (msg.sender != _initiator && msg.sender != _vetoer) { if (msg.sender != INITIATOR && msg.sender != VETOER) {
// todo(maurelian): make this error have an expected array. // todo(maurelian): make this error have an expected array.
revert Unauthorized(_initiator, msg.sender); revert Unauthorized(INITIATOR, msg.sender);
} }
_activateDelay(); _activateDelay();
return; return;
...@@ -136,7 +140,7 @@ contract DelayedVetoable is ISemver { ...@@ -136,7 +140,7 @@ contract DelayedVetoable is ISemver {
bytes32 callHash = keccak256(msg.data); bytes32 callHash = keccak256(msg.data);
// Case 1: The initiator is calling the contract to initiate a call. // Case 1: The initiator is calling the contract to initiate a call.
if (msg.sender == _initiator && _queuedAt[callHash] == 0) { if (msg.sender == INITIATOR && _queuedAt[callHash] == 0) {
if (_delay == 0) { if (_delay == 0) {
// This forward function will halt the call frame on completion. // This forward function will halt the call frame on completion.
_forwardAndHalt(callHash); _forwardAndHalt(callHash);
...@@ -149,7 +153,7 @@ contract DelayedVetoable is ISemver { ...@@ -149,7 +153,7 @@ contract DelayedVetoable is ISemver {
// Case 2: The vetoer is calling the contract to veto a call. // Case 2: The vetoer is calling the contract to veto a call.
// Note: The vetoer retains the ability to veto even after the delay has passed. This makes censoring the vetoer // Note: The vetoer retains the ability to veto even after the delay has passed. This makes censoring the vetoer
// more costly, as there is no time limit after which their transaction can be included. // more costly, as there is no time limit after which their transaction can be included.
if (msg.sender == _vetoer && _queuedAt[callHash] != 0) { if (msg.sender == VETOER && _queuedAt[callHash] != 0) {
delete _queuedAt[callHash]; delete _queuedAt[callHash];
emit Vetoed(callHash, msg.data); emit Vetoed(callHash, msg.data);
return; return;
...@@ -159,7 +163,7 @@ contract DelayedVetoable is ISemver { ...@@ -159,7 +163,7 @@ contract DelayedVetoable is ISemver {
// passed. // passed.
if (_queuedAt[callHash] == 0) { if (_queuedAt[callHash] == 0) {
// The call has not been initiated, so we'll treat this is an unauthorized initiation attempt. // The call has not been initiated, so we'll treat this is an unauthorized initiation attempt.
revert Unauthorized(_initiator, msg.sender); revert Unauthorized(INITIATOR, msg.sender);
} }
if (_queuedAt[callHash] + _delay < block.timestamp) { if (_queuedAt[callHash] + _delay < block.timestamp) {
...@@ -176,7 +180,7 @@ contract DelayedVetoable is ISemver { ...@@ -176,7 +180,7 @@ contract DelayedVetoable is ISemver {
function _forwardAndHalt(bytes32 callHash) internal { function _forwardAndHalt(bytes32 callHash) internal {
// Forward the call // Forward the call
emit Forwarded(callHash, msg.data); emit Forwarded(callHash, msg.data);
(bool success,) = _target.call(msg.data); (bool success,) = TARGET.call(msg.data);
assembly { assembly {
// Success == 0 means a revert. We'll revert too and pass the data up. // Success == 0 means a revert. We'll revert too and pass the data up.
if iszero(success) { revert(0x0, returndatasize()) } if iszero(success) { revert(0x0, returndatasize()) }
...@@ -189,7 +193,7 @@ contract DelayedVetoable is ISemver { ...@@ -189,7 +193,7 @@ contract DelayedVetoable is ISemver {
/// @notice Sets the delay to the operating delay. /// @notice Sets the delay to the operating delay.
function _activateDelay() internal { function _activateDelay() internal {
if (_delay != 0) revert AlreadyDelayed(); if (_delay != 0) revert AlreadyDelayed();
_delay = _operatingDelay; _delay = OPERATING_DELAY;
emit DelayActivated(_delay); emit DelayActivated(_delay);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment