UpdateExpirattionPeriod() cannot be executed when the newExpirationPeriod is less than currentExpirationPeriod
The timelock contract's execution check uses the newly set expiration period instead of the original one, causing a scheduled operation to revert if the new period is shorter and the operation is executed after the new expiry. An attacker cannot exploit this; it is a self-inflicted operational mistake by the owner.
dhank Follow with KlosMitSoss
Originally disclosed on Code4rena
Submitted by dhank, also found by KlosMitSoss
Safe cannot reduce expirationPeriod to a newExpirationPeriod when
currentTimeStamp < timestamp[id] + expirationPeriod and
currentTimeStamp >= timestamp[id] + newExpirationPeriod
where id is the hash of updateExpirationPeriod() and timestamp[id] is the timestamp when the id can be executed.
Safe should be able to update the expirationPeriod to any values >= MIN_DELAY by scheduling the updateExpirationPeriod() and later execute from timelock when the operation is ready (before the expiry).
require(newPeriod >= MIN_DELAY, "Timelock: delay out of bounds");
But the protocol has overlooked the situation and added an reduntant check inside _afterCall() which is executed at the end of _execute().
function _afterCall(bytes32 id) private {
/// unreachable state because removing the proposal id from the
/// _liveProposals set prevents this function from being called on the
/// same id twice
require(isOperationReady(id), "Timelock: operation is not ready"); //@audit
timestamps[id] = _DONE_TIMESTAMP;
}
Here the isOperationReady(id) will be executed with the newExpirationPeriod.
code
function isOperationReady(bytes32 id) public view returns (bool) {
/// cache timestamp, save up to 2 extra SLOADs
uint256 timestamp = timestamps[id];
return timestamp > _DONE_TIMESTAMP && timestamp <= block.timestamp
=> && timestamp + expirationPeriod > block.timestamp;
}
There it is checking whether the currentTimestamp is less than the timestamp + updated EpirationPeriod instead of the actual expirationPeriod.
Proof Of Concept
forge test —match-test testDUpdateExpirationPeriodRevert -vvv
function testDUpdateExpirationPeriodRevert() public {
// Prepare the scheduling parameters
// Call schedule() first time
uint256 newExpirationPeriod = EXPIRATION_PERIOD - 2 days; //newExpirationPeriod = 3 days since EXPIRATION_PERIOD = 5 days intially
_schedule({ //safe has scheduled updateExpirationPeriod() call
caller: address(safe),
timelock: address(timelock),
target: address(timelock),
value: 0,
data: abi.encodeWithSelector(
timelock.updateExpirationPeriod.selector,newExpirationPeriod
),
salt: bytes32(0),
delay: MINIMUM_DELAY
});
//delay time has passed
vm.warp(block.timestamp + MIN_DELAY + EXPIRATION_PERIOD - 1 days); //current timestamp is 1 day before the expiry period.
vm.expectRevert("Timelock: operation is not ready"); //it will revert with this msg
timelock.execute(address(timelock),0, abi.encodeWithSelector(
timelock.updateExpirationPeriod.selector,newExpirationPeriod
),bytes32(0));
}
Updating to the new expirationPeriod will revert in this case. This can affect the protocols core design features.
Recommended Mitigation Steps
function _afterCall(bytes32 id) private {
//no need to check
timestamps[id] = _DONE_TIMESTAMP;
}
ElliotFriedman (Kleidi) confirmed, but disagreed with severity and commented:
Seems like this is a valid issue, but it’s valid only if you execute the proposal more than min delay after the transaction becomes executable and you are lowering the expiration period.
The title is misleading because you can execute this operation, but you just have to execute it within the new expiration period.
Feels more like a low severity than a medium.
Alex the Entreprenerd (judge) commented:
I need to think about it a bit more, but fundamentally it seems to be something that the owner would cause to themselves.
Alex the Entreprenerd (judge) decreased severity to Low/Non-Critical and commented:
With a similar point to issue #21 this is an operative mistake that the user can make.
Because this is a gotcha, where under valid use no harm would be done, I think the finding is best categorized as QA.
Alex the Entreprenerd (judge) commented:
After running the test, and reviewing the code, I see the issue. The new expiration is being used to validate the executed function. I see that this is a valid bug and am leaning towards raising the severity to Medium.
ElliotFriedman (Kleidi) commented:
I agree that this is a valid finding, so now we’re just talking about impact and severity. The solution for the end user is just execute the transaction before the new expiration period takes place. We can warn on the UI about this.
@Alex the Entreprenerd - Will leave severity of finding to your judgement.
Alex the Entreprenerd (judge) increased severity to Medium and commented:
The finding is a bit of an edge case, when changing a proposal expiration to a smaller value, the OZ reentrancy guard will use the expiration that was newly set, causing the execution to revert.
Fundamentally given this specific scenario, a proposal will not be executable, this leads me to agree with Medium severity.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the _afterCall function calls isOperationReady which uses the updated expirationPeriod instead of the original one, causing a revert when the new period is shorter and the operation is executed after the new expiry.
Impact
The owner cannot execute the scheduled updateExpirationPeriod if they wait too long; the operation reverts, but this is a self-inflicted mistake and not an attack.
What the attacker needed
Owner schedules updateExpirationPeriod; new period shorter than current; execute after new expiry
The fix
The check in _afterCall should be removed or adjusted to not use the new expiration period.
How it was found
- Schedule an updateExpirationPeriod call with a new period shorter than the current one.
- Wait until the operation is ready but after the new expiration period has passed.
- Execute the scheduled call; it reverts with 'Timelock: operation is not ready'.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A timelock is a smart contract that delays actions for safety. This bug means that if you try to shorten the delay, the contract might reject your own scheduled action because it checks the new shorter delay too early. It is a usability problem, not a security hole.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.