From 0aed51124168ceb488153d384c8b8db47946c6b8 Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Fri, 14 Nov 2025 16:20:03 +0100 Subject: [PATCH 1/2] Dealocate unused memory when queuing transactions Added memory management for transaction queuing in GovernorTimelockCompound. --- contracts/governance/extensions/GovernorTimelockCompound.sol | 3 +++ 1 file changed, 3 insertions(+) diff --git a/contracts/governance/extensions/GovernorTimelockCompound.sol b/contracts/governance/extensions/GovernorTimelockCompound.sol index 8f6183e8b89..12a00302869 100644 --- a/contracts/governance/extensions/GovernorTimelockCompound.sol +++ b/contracts/governance/extensions/GovernorTimelockCompound.sol @@ -6,6 +6,7 @@ pragma solidity ^0.8.24; import {IGovernor, Governor} from "../Governor.sol"; import {ICompoundTimelock} from "../../vendor/compound/ICompoundTimelock.sol"; import {Address} from "../../utils/Address.sol"; +import {Memory} from "../../utils/Memory.sol"; import {SafeCast} from "../../utils/math/SafeCast.sol"; /** @@ -70,12 +71,14 @@ abstract contract GovernorTimelockCompound is Governor { ) internal virtual override returns (uint48) { uint48 etaSeconds = SafeCast.toUint48(block.timestamp + _timelock.delay()); + Memory.Pointer ptr = Memory.getFreeMemoryPointer(); for (uint256 i = 0; i < targets.length; ++i) { if ( _timelock.queuedTransactions(keccak256(abi.encode(targets[i], values[i], "", calldatas[i], etaSeconds))) ) { revert GovernorAlreadyQueuedProposal(proposalId); } + Memory.setFreeMemoryPointer(ptr); // dealocate the memory that was reserved by "abi.encode". _timelock.queueTransaction(targets[i], values[i], "", calldatas[i], etaSeconds); } From 03336380e24cafb34df8bc6b25c737827dc80445 Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Fri, 14 Nov 2025 16:21:31 +0100 Subject: [PATCH 2/2] Apply suggestions from code review --- contracts/governance/extensions/GovernorTimelockCompound.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/governance/extensions/GovernorTimelockCompound.sol b/contracts/governance/extensions/GovernorTimelockCompound.sol index 12a00302869..4351c291bc9 100644 --- a/contracts/governance/extensions/GovernorTimelockCompound.sol +++ b/contracts/governance/extensions/GovernorTimelockCompound.sol @@ -78,7 +78,7 @@ abstract contract GovernorTimelockCompound is Governor { ) { revert GovernorAlreadyQueuedProposal(proposalId); } - Memory.setFreeMemoryPointer(ptr); // dealocate the memory that was reserved by "abi.encode". + Memory.setFreeMemoryPointer(ptr); // deallocate the memory that was reserved by "abi.encode". _timelock.queueTransaction(targets[i], values[i], "", calldatas[i], etaSeconds); }