VirtualGenesisDAO.sol:earlyExecute() proposals can be executed two times
The earlyExecute function runs a proposal's actions through an internal helper that does not mark the proposal as executed, so the public execute function can later run the same proposal a second time. An attacker could therefore cause an approved proposal's actions to be carried out twice.
Submitted by Fitro
Finding description and impact
earlyExecute() allows a proposal to be executed earlier but can only be called by an account with the EXECUTOR_ROLE.
function earlyExecute(uint256 proposalId) public payable onlyRole(EXECUTOR_ROLE) returns (uint256) {
(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) = proposalDetails(proposalId);
require(
state(proposalId) == ProposalState.Active &&
_voteSucceeded(proposalId) &&
_quorumReached(proposalId) &&
!_earlyExecutions[proposalId],
"Proposal not ready for early execution"
);
// avoid reentrancy
_earlyExecutions[proposalId] = true;
_executeOperations(proposalId, targets, values, calldatas, descriptionHash);
emit ProposalExecuted(proposalId);
return proposalId;
}
As you can see, it uses the _earlyExecutions mapping to prevent the proposal from being executed a second time. The problem is that _executeOperations() does not set the executed flag to true, as can be seen in the comments of the function.
/**
* NOTE: Calling this function directly will NOT check the current state of the proposal, set the executed flag to
* true or emit the `ProposalExecuted` event. Executing a proposal should be done using {execute} or {_execute}.
*/
function _executeOperations(
uint256 /* proposalId */,
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 /*descriptionHash*/
) internal virtual {
for (uint256 i = 0; i < targets.length; ++i) {
(bool success, bytes memory returndata) = targets[i].call{value: values[i]}(calldatas[i]);
Address.verifyCallResult(success, returndata);
}
}
This is problematic because a user can call execute() from the Governor.sol abstract contract to execute the proposal again, since _proposals[proposalId].executed is not set to true, as shown in the execute().
function execute(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) public payable virtual returns (uint256) {
uint256 proposalId = hashProposal(targets, values, calldatas, descriptionHash);
_validateStateBitmap(
proposalId,
_encodeStateBitmap(ProposalState.Succeeded) | _encodeStateBitmap(ProposalState.Queued)
);
// mark as executed before calls to avoid reentrancy
@> _proposals[proposalId].executed = true;
///code...
As shown, executed is set to true to prevent a proposal from being executed more than once. However, when _executeOperations() is used directly, this flag is not set. Since the execute() function is public and not overridden to include access control, any user can call it, allowing the proposal to be executed a second time.
Recommended mitigation steps
To resolve the issue, replace the call to _executeOperations() with a call to execute().
function earlyExecute(uint256 proposalId) public payable onlyRole(EXECUTOR_ROLE) returns (uint256) {
(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) = proposalDetails(proposalId);
require(
state(proposalId) == ProposalState.Active &&
_voteSucceeded(proposalId) &&
_quorumReached(proposalId) &&
!_earlyExecutions[proposalId],
"Proposal not ready for early execution"
);
// avoid reentrancy
_earlyExecutions[proposalId] = true;
- _executeOperations(proposalId, targets, values, calldatas, descriptionHash);
+ execute(targets, values, calldatas, descriptionHash);
emit ProposalExecuted(proposalId);
return proposalId;
}
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 early-execution path calls the internal _executeOperations helper, which does not set the proposal's executed flag, instead of the public execute function that does.
Impact
A passed proposal's actions could be executed twice, since the public execute function is not overridden with access control.
What the attacker needed
EXECUTOR_ROLE triggers early execution; proposal has succeeded and reached quorum
The fix
The early-execution path should call the public execute function instead of the internal helper so the executed flag is set.
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 DAO is a group that votes on actions, and once a vote passes the action should run exactly once. Here the shortcut that runs a proposal early forgot to record that it had run, so the normal public run function still thought it was pending and would run it again. Anyone could trigger that second run.
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.