Persistent Contract Call revert prevents finalizing a ballot
The DAO contract does not handle a revert from an external contract call when executing an approved ballot, so the ballot cannot be marked as finalized. This leaves the proposer with an active proposal, preventing them from creating new proposals.
vnavascues Follow with ether_sky, 0xRobocop and 1 other
Originally disclosed on Code4rena
Submitted by vnavascues, also found by ether_sky, 0xRobocop, and haxatron
https://github.com/code-423n4/2024-01-salty/blob/main/src/dao/DAO.sol#L180
https://github.com/code-423n4/2024-01-salty/blob/main/src/dao/DAO.sol#L219
https://github.com/code-423n4/2024-01-salty/blob/main/src/dao/DAO.sol#L219
The DAO._executeApproval function does not handle an external contract call error:
else if (ballot.ballotType == BallotType.CALL_CONTRACT) {
// @audit-issue unhandled revert
ICalledContract(ballot.address1).callFromDAO(ballot.number1);
emit ContractCalled(ballot.address1, ballot.number1);
}
Given an approved CALL_CONTRACT ballot that can be finalized, the ballot won’t be marked as finalized if the external contract call (from above) reverts.
function _finalizeApprovalBallot(uint256 ballotID) internal {
if (proposals.ballotIsApproved(ballotID)) {
Ballot memory ballot = proposals.ballotForID(ballotID);
_executeApproval(ballot);
}
// @audit-issue the line below won't be executed if `_executeApproval` reverts
proposals.markBallotAsFinalized(ballotID);
}
Impact
A permanent revert leaves the ballot unfinalized, and the user that posted it with an active proposal (in the _userHasActiveProposal mapping); a state that prevents the user account from creating a new proposal. At this point the user has two options to sort out the situation:
A. Unstake and transfer its SALT into a new account. B. Convince the other users to reach quorum on NO and finalize the ballot without calling the external contract.
Proof Of Concept
New contract to be created in /src/dao/tests:
// SPDX-License-Identifier: BUSL 1.1
pragma solidity =0.8.22;
import "../interfaces/ICalledContract.sol";
contract TestCallReceiverFaulty is ICalledContract {
uint256 public value;
function callFromDAO(uint256 n) external {
value = n;
revert("callFromDAO() unexpectedly reverted");
}
}
Add the following test in DAO.t.sol:
function testCallContractApproveReverted() public {
// Arrange
vm.startPrank(alice);
staking.stakeSALT(1000000 ether);
TestCallReceiverFaulty testReceiver = new TestCallReceiverFaulty();
uint256 ballotID = proposals.proposeCallContract(
address(testReceiver),
123,
"description"
);
assertEq(
proposals.ballotForID(ballotID).ballotIsLive,
true,
"Ballot not correctly created"
);
proposals.castVote(ballotID, Vote.YES);
vm.warp(block.timestamp + 11 days);
vm.expectRevert("callFromDAO() unexpectedly reverted");
// Act
dao.finalizeBallot(ballotID);
// Assert
assertEq(
proposals.ballotForID(ballotID).ballotIsLive,
true,
"Ballot not correctly finalized"
);
assertTrue(
testReceiver.value() != 123,
"Receiver shouldn't receive the call"
);
assertEq(
proposals.userHasActiveProposal(alice),
true,
"Alice proposal is not active"
);
}
Recommended Mitigation Steps
A trivial solution is to handle the reverted external contract call with a try..catch and allow to always mark the approved ballot as finalized. A new ballot can always be created if the desired effects of the call were not applied on the first call.
Amend the CALL_CONTRACT case in the DAO._executeApproval function:
else if (ballot.ballotType == BallotType.CALL_CONTRACT) {
try ICalledContract(ballot.address1).callFromDAO(ballot.number1) {
// NB: place the emission outside if it must be emitted no matter the external call outcome
emit ContractCalled(ballot.address1, ballot.number1);
} catch (bytes memory) {}
}
Add the following test in DAO.t.sol:
function testCallContractApproveRevertHandled() public {
// Arrange
vm.startPrank(alice);
staking.stakeSALT(1000000 ether);
TestCallReceiverFaulty testReceiver = new TestCallReceiverFaulty();
uint256 ballotID = proposals.proposeCallContract(
address(testReceiver),
123,
"description"
);
// Act
_voteForAndFinalizeBallot(ballotID, Vote.YES);
// Assert
assertTrue(
testReceiver.value() != 123,
"Receiver shouldn't receive the call"
);
assertEq(
proposals.userHasActiveProposal(alice),
false,
"Alice proposal is not active"
);
}
othernet-global (Salty.IO) confirmed and commented:
callFromDAO now wrapped in a try/catch
https://github.com/othernet-global/salty-io/commit/5f1a5206a04b0f3fe45ad88a311370ce12fb0135
Note: For full discussion, see here.
Status: Mitigation confirmed. Full details in reports from t0x1c, 0xpiken, and [zzebra83].
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
The external call is made without a try/catch, so a revert aborts the finalization logic before the ballot is marked as finalized.
Impact
A permanent revert leaves the ballot unfinalized and the proposer with an active proposal, preventing them from creating new proposals; they must unstake and move funds or convince others to vote NO.
What the attacker needed
A user with enough SALT to propose; a contract that reverts on call; a successful YES vote
The fix
The external call should be wrapped in a try/catch so the ballot is always marked as finalized.
How it was found
- Stake SALT and create a CALL_CONTRACT ballot pointing to a contract that reverts.
- Vote YES and wait for the voting period to end.
- Call finalizeBallot; the external call reverts and the ballot remains live.
- Observe that the proposer still has an active proposal.
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 lets people vote on actions, like calling another contract. If that call fails, the code stops before recording the vote as finished, so the person who proposed it is stuck and cannot propose again.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.