Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/policies/TimelockPolicy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ contract TimelockPolicy is PolicyBase, IStatelessValidator, IStatelessValidatorW
error ProposalNotPending();
error OnlyAccount();
error ProposalFromPreviousEpoch();
error ParametersTooLarge();

/**
* @notice Install the timelock policy
Expand All @@ -82,6 +83,10 @@ contract TimelockPolicy is PolicyBase, IStatelessValidator, IStatelessValidatorW

if (delay == 0) revert InvalidDelay();
if (expirationPeriod == 0) revert InvalidExpirationPeriod();
// Prevent uint48 overflow in createProposal: uint48(block.timestamp) + delay + expirationPeriod
if (uint256(delay) + uint256(expirationPeriod) > type(uint48).max - block.timestamp) {
revert ParametersTooLarge();
}

// Increment epoch to invalidate any proposals from previous installations
currentEpoch[id][msg.sender]++;
Expand Down
48 changes: 24 additions & 24 deletions test/btt/Timelock.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -522,18 +522,18 @@ contract TimelockTest is Test {
}

function test_GivenInitialized_WhenCallingCheckSignaturePolicy() external whenCallingCheckSignaturePolicy {
// it should return zero
// it should revert (TOB-KERNEL-20: signature validation not supported)
vm.prank(WALLET);
uint256 result = timelockPolicy.checkSignaturePolicy(POLICY_ID, address(0), bytes32(0), "");
assertEq(result, 0, "Should return 0 when initialized");
vm.expectRevert("TimelockPolicy: signature validation not supported");
timelockPolicy.checkSignaturePolicy(POLICY_ID, address(0), bytes32(0), "");
}

function test_GivenNotInitialized_WhenCallingCheckSignaturePolicy() external whenCallingCheckSignaturePolicy {
// it should return one
// it should revert (TOB-KERNEL-20: signature validation not supported)
address uninitWallet = address(0xcccc);
vm.prank(uninitWallet);
uint256 result = timelockPolicy.checkSignaturePolicy(POLICY_ID, address(0), bytes32(0), "");
assertEq(result, 1, "Should return 1 when not initialized");
vm.expectRevert("TimelockPolicy: signature validation not supported");
timelockPolicy.checkSignaturePolicy(POLICY_ID, address(0), bytes32(0), "");
}

// ============ validateSignatureWithData Tests ============
Expand All @@ -543,30 +543,30 @@ contract TimelockTest is Test {
}

function test_GivenDelayAndExpirationAreNonzero() external whenCallingValidateSignatureWithData {
// it should return true
// it should revert (TOB-KERNEL-20: stateless signature validation not supported)
bytes memory data = abi.encode(uint48(1 hours), uint48(1 days));
bool result = timelockPolicy.validateSignatureWithData(bytes32(0), "", data);
assertTrue(result, "Should return true for valid data");
vm.expectRevert("TimelockPolicy: stateless signature validation not supported");
timelockPolicy.validateSignatureWithData(bytes32(0), "", data);
}

function test_GivenDelayIsZero_WhenCallingValidateSignatureWithData()
external
whenCallingValidateSignatureWithData
{
// it should return false
// it should revert (TOB-KERNEL-20: stateless signature validation not supported)
bytes memory data = abi.encode(uint48(0), uint48(1 days));
bool result = timelockPolicy.validateSignatureWithData(bytes32(0), "", data);
assertFalse(result, "Should return false for zero delay");
vm.expectRevert("TimelockPolicy: stateless signature validation not supported");
timelockPolicy.validateSignatureWithData(bytes32(0), "", data);
}

function test_GivenExpirationIsZero_WhenCallingValidateSignatureWithData()
external
whenCallingValidateSignatureWithData
{
// it should return false
// it should revert (TOB-KERNEL-20: stateless signature validation not supported)
bytes memory data = abi.encode(uint48(1 hours), uint48(0));
bool result = timelockPolicy.validateSignatureWithData(bytes32(0), "", data);
assertFalse(result, "Should return false for zero expiration");
vm.expectRevert("TimelockPolicy: stateless signature validation not supported");
timelockPolicy.validateSignatureWithData(bytes32(0), "", data);
}

// ============ validateSignatureWithDataWithSender Tests ============
Expand All @@ -579,30 +579,30 @@ contract TimelockTest is Test {
external
whenCallingValidateSignatureWithDataWithSender
{
// it should return true
// it should revert (TOB-KERNEL-20: stateless signature validation not supported)
bytes memory data = abi.encode(uint48(1 hours), uint48(1 days));
bool result = timelockPolicy.validateSignatureWithDataWithSender(address(0), bytes32(0), "", data);
assertTrue(result, "Should return true for valid data");
vm.expectRevert("TimelockPolicy: stateless signature validation not supported");
timelockPolicy.validateSignatureWithDataWithSender(address(0), bytes32(0), "", data);
}

function test_GivenDelayIsZero_WhenCallingValidateSignatureWithDataWithSender()
external
whenCallingValidateSignatureWithDataWithSender
{
// it should return false
// it should revert (TOB-KERNEL-20: stateless signature validation not supported)
bytes memory data = abi.encode(uint48(0), uint48(1 days));
bool result = timelockPolicy.validateSignatureWithDataWithSender(address(0), bytes32(0), "", data);
assertFalse(result, "Should return false for zero delay");
vm.expectRevert("TimelockPolicy: stateless signature validation not supported");
timelockPolicy.validateSignatureWithDataWithSender(address(0), bytes32(0), "", data);
}

function test_GivenExpirationIsZero_WhenCallingValidateSignatureWithDataWithSender()
external
whenCallingValidateSignatureWithDataWithSender
{
// it should return false
// it should revert (TOB-KERNEL-20: stateless signature validation not supported)
bytes memory data = abi.encode(uint48(1 hours), uint48(0));
bool result = timelockPolicy.validateSignatureWithDataWithSender(address(0), bytes32(0), "", data);
assertFalse(result, "Should return false for zero expiration");
vm.expectRevert("TimelockPolicy: stateless signature validation not supported");
timelockPolicy.validateSignatureWithDataWithSender(address(0), bytes32(0), "", data);
}

// ============ getProposal Tests ============
Expand Down