Commit 82f27c29 authored by Maurelian's avatar Maurelian

refactor(ctb): Inline the _activateDelay logic

This change will enable forwarding zero length data
parent a4c66440
...@@ -6,6 +6,7 @@ import { ISemver } from "src/universal/ISemver.sol"; ...@@ -6,6 +6,7 @@ import { ISemver } from "src/universal/ISemver.sol";
/// @title DelayedVetoable /// @title DelayedVetoable
/// @notice This contract enables a delay before a call is forwarded to a target contract, and during the delay period /// @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. /// the call can be vetoed by the authorized vetoer.
/// This contract does not support value transfers, only data is forwarded.
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();
...@@ -128,11 +129,12 @@ contract DelayedVetoable is ISemver { ...@@ -128,11 +129,12 @@ contract DelayedVetoable is ISemver {
/// the need for additional layers of abi encoding. /// the need for additional layers of abi encoding.
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 && _delay == 0) {
if (msg.sender != INITIATOR && msg.sender != VETOER) { if (msg.sender != INITIATOR && msg.sender != VETOER) {
revert Unauthorized(INITIATOR, msg.sender); revert Unauthorized(INITIATOR, msg.sender);
} }
_activateDelay(); _delay = OPERATING_DELAY;
emit DelayActivated(_delay);
return; return;
} }
...@@ -190,11 +192,4 @@ contract DelayedVetoable is ISemver { ...@@ -190,11 +192,4 @@ contract DelayedVetoable is ISemver {
} }
} }
} }
/// @notice Sets the delay to the operating delay.
function _activateDelay() internal {
if (_delay != 0) revert AlreadyDelayed();
_delay = OPERATING_DELAY;
emit DelayActivated(_delay);
}
} }
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
pragma solidity 0.8.15; pragma solidity 0.8.15;
import { CommonTest } from "./CommonTest.t.sol"; import { CommonTest } from "./CommonTest.t.sol";
import { DelayedVetoable } from "../src/L1/DelayedVetoable.sol"; import { DelayedVetoable } from "src/L1/DelayedVetoable.sol";
contract DelayedVetoable_Init is CommonTest { contract DelayedVetoable_Init is CommonTest {
error Unauthorized(address expected, address actual); error Unauthorized(address expected, address actual);
...@@ -109,6 +109,11 @@ contract DelayedVetoable_HandleCall_Test is DelayedVetoable_Init { ...@@ -109,6 +109,11 @@ contract DelayedVetoable_HandleCall_Test is DelayedVetoable_Init {
vm.prank(initiator); vm.prank(initiator);
(bool success,) = address(delayedVetoable).call(data); (bool success,) = address(delayedVetoable).call(data);
// Check that the call is in the _queuedAt mapping
bytes32 callHash = keccak256(data);
vm.prank(address(0));
assertEq(delayedVetoable.queuedAt(callHash), block.timestamp);
vm.warp(block.timestamp + operatingDelay); vm.warp(block.timestamp + operatingDelay);
vm.expectEmit(true, false, false, true, address(delayedVetoable)); vm.expectEmit(true, false, false, true, address(delayedVetoable));
emit Forwarded(keccak256(data), data); emit Forwarded(keccak256(data), data);
...@@ -124,7 +129,6 @@ contract DelayedVetoable_HandleCall_TestFail is DelayedVetoable_Init { ...@@ -124,7 +129,6 @@ contract DelayedVetoable_HandleCall_TestFail is DelayedVetoable_Init {
function test_handleCall_unauthorizedInitiation_reverts() external { function test_handleCall_unauthorizedInitiation_reverts() external {
vm.expectRevert(abi.encodeWithSelector(Unauthorized.selector, initiator, address(this))); vm.expectRevert(abi.encodeWithSelector(Unauthorized.selector, initiator, address(this)));
(bool success,) = address(delayedVetoable).call(NON_ZERO_DATA); (bool success,) = address(delayedVetoable).call(NON_ZERO_DATA);
assertTrue(success);
} }
/// @dev The call cannot be forewarded until the delay has passed. /// @dev The call cannot be forewarded until the delay has passed.
...@@ -134,7 +138,6 @@ contract DelayedVetoable_HandleCall_TestFail is DelayedVetoable_Init { ...@@ -134,7 +138,6 @@ contract DelayedVetoable_HandleCall_TestFail is DelayedVetoable_Init {
vm.expectRevert(abi.encodeWithSelector(ForwardingEarly.selector)); vm.expectRevert(abi.encodeWithSelector(ForwardingEarly.selector));
(success,) = address(delayedVetoable).call(data); (success,) = address(delayedVetoable).call(data);
assertFalse(success);
} }
/// @dev The call cannot be forwarded a second time. /// @dev The call cannot be forwarded a second time.
......
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