User may force fail the action from the DAO:execute
A caller of the DAO execute function can choose a gas amount such that an inner call fails due to the 63/64 gas forwarding rule, while the remaining gas is enough to finish the execute function. This allows a malicious voter to force a permitted-to-fail action to fail, and also causes normal gas estimation to accidentally fail the call.
Submitted by V_B, also found by 0xWeiss
DAO.sol#L186 MajorityVotingBase.sol#L286 MajorityVotingBase.sol#L459
The execute function from the DAO.sol contract allow to execution of any call to any address if the caller has appropriate permission. Some calls are expected to be always successfully executed, and some may revert and execute will continue the execution.
The following code may call and handle call status.
address to = _actions[i].to;
(bool success, bytes memory response) = to.call{value: _actions[i].value}(
_actions[i].data
);
if (!success) {
// If the call failed and wasn't allowed in allowFailureMap, revert.
if (!hasBit(_allowFailureMap, uint8(i))) {
revert ActionFailed(i);
}
// If the call failed, but was allowed in allowFailureMap, store that
// this specific action has actually failed.
failureMap = flipBit(failureMap, uint8(i));
}
Also, the function is expected to be used in a different scenario, where the caller may be a user, voter, etc. (See MajorityVotingBase). So the caller is not a trusted entity and that means any manipulation of the DAO call should be avoided.
The problem is that caller may choose the gas with which the code is executed. If the child call execution spends enough gas then the user may choose that amount of gas, that child call frame fails, but the left gas is enough to successfully finish DAO:execute function.
Please note, even though the execute pass all gas to the child call, actually only 63/64 gas is passed and 1/64 of gas is left on the parent call (EIP-150).
Attack scenario
The DAO starts majority voting, and users who have DAO tokens may vote for the proposal. The proposal is to call one target protocol, which may fail in case of an inner reason. So the DAO set that the call may fail. The approximate gas that is needed to finish the call to the target contract is 700k. A malicious voter call execute function with 711.1k of gas. Since 63/64 * 711.1 < 700, the requested call will fail. And the remaining gas is still sufficient to end the execute function logic.
Impact
The user may forcefully fail the inner call from the execute function. Also, anyone who will use the usual eth_estimateGas for the gas estimation for the execute function will accidentally calculate the amount of gas that will fail the call.
Since majority voting is hard to process with many users involved, creating another proposal may create a lot of pain.
Recommended Mitigation Steps
Add the require that gas after the call is bigger than gas before / 64.
uint256 gasBefore;
// Do call...
require(gasleft() > gasBefore/64);
novaknole20 (Aragon) confirmed
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 execute function does not check that enough gas remains after the inner call to ensure the call was not starved by the 63/64 rule.
Impact
A malicious voter can force a permitted-to-fail inner call to fail, and normal gas estimation may also accidentally cause the call to fail, potentially requiring a new proposal.
What the attacker needed
A DAO with majority voting; a proposal with an action allowed to fail; the attacker can call execute
The fix
The execute function should require that the gas remaining after the call is greater than one sixty-fourth of the gas before the call.
How it was found
- A DAO proposal is created to call a target contract, and the call is marked as allowed to fail.
- A malicious voter calls the execute function with a gas amount slightly above 64/63 of the gas needed for the inner call.
- The inner call fails because only 63/64 of the gas is forwarded, but the remaining gas is enough to complete the execute function.
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.
When a smart contract calls another contract, it does not pass all its remaining gas; it keeps a small fraction (1/64) for itself. If someone sends a transaction with just enough gas, the inner call can run out of gas and fail, but the outer function still has enough gas to finish. This means a voter can deliberately make an action fail even though it was allowed to fail, which can disrupt governance.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.