Missing disapproval check in LockManager.sol::approveUSDPrice allows simultaneous approval and disapproval of a price proposal
The approveUSDPrice function in LockManager.sol lacks a check to prevent a price feed from approving a price after it has already disapproved it. An attacker with a price feed role could vote both for and against the same proposal, potentially manipulating the voting outcome.
robertodf99 Follow with Rushkov_Boyan, EaglesSecurity and 48 others
Originally disclosed on Code4rena
Submitted by robertodf99, also found by Bauchibred (1, 2), Rushkov_Boyan, EaglesSecurity, twcctop, araj, Mahmud, typicalHuman, Topmark, Bbash, adam-idarrha, Bigsam, crypticdefense, 0xAadi, 0xdice91, Dots, xyz, iamandreiski, leegh, John_Femi, dhank, joaovwfreire, Eeyore, RotiTelur, Tychai0s, unique, avoloder, 0xleadwizard, AgileJune, swizz, djanerch, Sabit, Utsav, Evo, prapandey031, Stormreckson, mitko1111, Beosin, brevis, dd0x7e8, trachev, pfapostol, aslanbek, Sentryx, falconhoof, carrotsmuggler, ZdravkoHr, ZanyBonzy, bigtone, Walter, EPSec, 0xhacksmithh, MrPotatoMagic, pamprikrumplikas, brgltd, 0xAkira, and merlinboii
Impact
Due to the missing disapproval check, a price feed can both disapprove and subsequently approve a newly proposed price. Price feeds are intended to vote either for approval or disapproval, not both. Hence, this can be considered an unintended functionality.
Proof of Concept
Code
Place this in MunchablesTest.sol.
function test_priceFeedCanVoteBoth() public {
address priceFeed2 = makeAddr("priceFeed2");
address tokenUpdated = makeAddr("token");
address[] memory tokensUpdated = new address[](1);
tokensUpdated[0] = tokenUpdated;
deployContracts();
console.log("--------------- PoC ---------------");
cs.setRole(Role.PriceFeed_1, address(lm), address(this));
cs.setRole(Role.PriceFeed_2, address(lm), priceFeed2);
lm.proposeUSDPrice(1 ether, tokensUpdated);
vm.startPrank(priceFeed2);
lm.disapproveUSDPrice(1 ether);
lm.approveUSDPrice(1 ether);
vm.stopPrank();
}
Recommended Mitigation Steps
Add a check to see if the price feed has already disapproved the price proposal. If so, revert with a custom error.
function approveUSDPrice(
uint256 _price
)
external
onlyOneOfRoles(
[
Role.PriceFeed_1,
Role.PriceFeed_2,
Role.PriceFeed_3,
Role.PriceFeed_4,
Role.PriceFeed_5
]
)
{
if (usdUpdateProposal.proposer == address(0)) revert NoProposalError();
if (usdUpdateProposal.proposer == msg.sender)
revert ProposerCannotApproveError();
if (usdUpdateProposal.approvals[msg.sender] == _usdProposalId)
revert ProposalAlreadyApprovedError();
+ if (usdUpdateProposal.disapprovals[msg.sender] == _usdProposalId)
+ revert ProposalAlreadyDisapprovedError();
if (usdUpdateProposal.proposedPrice != _price)
revert ProposalPriceNotMatchedError();
usdUpdateProposal.approvals[msg.sender] = _usdProposalId;
usdUpdateProposal.approvalsCount++;
if (usdUpdateProposal.approvalsCount >= APPROVE_THRESHOLD) {
_execUSDPriceUpdate();
}
emit ApprovedUSDPrice(msg.sender);
}
0xinsanity (Munchables) confirmed and commented via duplicate issue #83:
Should be low-risk.
Fixed
0xsomeone (judge) confirmed and commented:
The Warden outlines a misbehavior in the
LockManagercode that permits an oracle to disapprove and then approve a particular price measurement. The current approval and disapproval thresholds are meant to indicate that no stalemate should be possible, as they are configured at3with the total price feed roles being 5.In reality, this will not lead to a quorum discrepancy as the only action permitted is disapproval and then approval. As such, a state with both approval and disapproval being enabled is impossible as either function reaching a quorum will cause the price measurement to be processed.
There is still an interesting edge case whereby 2
forand 2againstvotes will, under normal operations, result in the final role who has not cast their vote yet being the tie-breaker. In the current system, any of the individuals who voted against can place aforvote incorrectly regardless of what the final voter believes.Even though the price voters are privileged roles, their multitude does permit them to exploit this issue before they are removed if they are deemed malicious by the administrator team of the Munchables system, and in such a scenario the damage will already have been done. As such, I consider this to be a medium-risk rating due to the combination of a privileged action albeit not entirely trusted with an observable but not significant impact on the voting process.
Selecting the best submission out of this duplicate group was very hard as multiple submissions clearly demonstrated the vulnerability and went into depth as to its ramifications. This submission was selected as the best due to being concise, offering a very short and sweet PoC, and outlining the full details needed to grasp the vulnerability.
To note, any submission awarded with a 25% pie (i.e. a 75% reduction) was submitted via a QA report and thus cannot be eligible for the full reward.
Note: For full discussion, see here.
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 approveUSDPrice function does not check whether the caller has already disapproved the same proposal, allowing both actions.
Impact
A price feed could vote both for and against a proposal, potentially acting as a tie-breaker and manipulating the voting process, though the judge noted the impact is not significant.
What the attacker needed
A price feed role
How it was found
- Set up two price feed roles.
- Propose a new USD price.
- As the second price feed, disapprove the price.
- As the same price feed, approve the price.
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.
In a smart contract, a price feed is a trusted account that votes on price updates. The contract should stop a feed from voting both yes and no on the same proposal, but it does not, so a feed can change its vote after disapproving.
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.