In LlamaRelativeQuorum , the governance result might be incorrect as it counts the wrong approval/disapproval
The LlamaRelativeQuorum strategy counts approval and disapproval quantities instead of the number of role holders, while the quorum supply is set to the number of holders. This mismatch can let a single holder with a high quantity meet the approval threshold alone, even when the intended percentage of holders has not approved.
auditor0517 Follow with Toshii, kutugu and 2 others
Originally disclosed on Code4rena
Submitted by auditor0517, also found by Toshii, kutugu, 0xnev, and T1MOH
https://github.com/code-423n4/2023-06-llama/blob/9d641b32e3f4092cc81dbac7b1c451c695e78983/src/strategies/LlamaRelativeQuorum.sol#L223 https://github.com/code-423n4/2023-06-llama/blob/9d641b32e3f4092cc81dbac7b1c451c695e78983/src/strategies/LlamaRelativeQuorum.sol#L242
Proof of Concept
The LlamaRelativeQuorum uses approval/disapproval thresholds that are specified as percentages of total supply and the approval/disapproval supplies are set at validateActionCreation() during the action creation.
function validateActionCreation(ActionInfo calldata actionInfo) external {
LlamaPolicy llamaPolicy = policy; // Reduce SLOADs.
uint256 approvalPolicySupply = llamaPolicy.getRoleSupplyAsNumberOfHolders(approvalRole);
if (approvalPolicySupply == 0) revert RoleHasZeroSupply(approvalRole);
uint256 disapprovalPolicySupply = llamaPolicy.getRoleSupplyAsNumberOfHolders(disapprovalRole);
if (disapprovalPolicySupply == 0) revert RoleHasZeroSupply(disapprovalRole);
// Save off the supplies to use for checking quorum.
actionApprovalSupply[actionInfo.id] = approvalPolicySupply;
actionDisapprovalSupply[actionInfo.id] = disapprovalPolicySupply;
}
As we can see, actionApprovalSupply and actionDisapprovalSupply are set using getRoleSupplyAsNumberOfHolders which means the total number of role holders.
But while counting for totalApprovals/totalDisapprovals in getApprovalQuantityAt()/getDisapprovalQuantityAt(), it adds the quantity instead of role holders(1 for each holder).
function getApprovalQuantityAt(address policyholder, uint8 role, uint256 timestamp) external view returns (uint128) {
if (role != approvalRole && !forceApprovalRole[role]) return 0;
uint128 quantity = policy.getPastQuantity(policyholder, role, timestamp);
return quantity > 0 && forceApprovalRole[role] ? type(uint128).max : quantity; //@audit should return supply, not quantity
}
So the governance result would be wrong with the below example.
- There are 3 role holders(Alice, Bob, Charlie) and Alice has 2 quantities, others have 1.
- During the action creation with the
LlamaRelativeQuorumstrategy,actionApprovalSupply = 3and there should be 2 approved holders at least whenminApprovalPct = 51%. - But if Alice approves the action, the result of
getApprovalQuantityAt()will be 2 and the action will be approved with only one approval.
It’s because getApprovalQuantityAt() return the quantity although actionApprovalSupply equals NumberOfHolders.
Recommended Mitigation Steps
getApprovalQuantityAt() and getDisapprovalQuantityAt() should return 1 instead of quantity for the positive quantity.
I think we can modify these functions like below.
function getApprovalQuantityAt(address policyholder, uint8 role, uint256 timestamp) external view returns (uint128) {
if (role != approvalRole && !forceApprovalRole[role]) return 0;
uint128 quantity = policy.getPastQuantity(policyholder, role, timestamp);
if (quantity > 1) quantity = 1;
return quantity > 0 && forceApprovalRole[role] ? type(uint128).max : quantity;
}
function getDisapprovalQuantityAt(address policyholder, uint8 role, uint256 timestamp)
external
view
returns (uint128)
{
if (role != disapprovalRole && !forceDisapprovalRole[role]) return 0;
uint128 quantity = policy.getPastQuantity(policyholder, role, timestamp);
if (quantity > 1) quantity = 1;
return quantity > 0 && forceDisapprovalRole[role] ? type(uint128).max : quantity;
}
AustinGreen (Llama) disputed and commented:
This is actually how we intend this strategy to work but we’re open to feedback! Here’s an example:
- An instance has 10 role holders and a 50% min approval percentage. Each role holder’s quantity is 1, so 5 role holders can approve this action.
- 2 of the role holders have their quantity increased to 2.
- This means that if each of these role holders cast approvals, then their approval power will count as 4. That means just one other role holder is needed to cast approval to approve the action.
In this system quantity can be used to provide granular approval weights to role holders.
@AustinGreen- I don’t think this make sense. Sure, if each holder’s quantity is 1, then
getRoleSupplyis same asgetRoleSupplyAsNumberOfHoldersand what you said is valid. However, if you have 10 holders each with quantity 10 at snapshot, then youractionApprovalSupplyis set to 10 (number of holder) and any of their approval (10 quantity) would hit quorum.
AustinGreen (Llama) commented:
@gzeon- Yes that’s exactly how the design is intended to work!
@AustinGreen- This sounds weird, is this design documented anywhere? From what I can see in the code comments it seems to be hard for anyone (including potential user/dao) to understand such logic.
In the code, there is a comment
Minimum percentage of
totalApprovalQuantity / totalApprovalSupplyAtCreationTimerequired for the action to be queuedI think it is fair for one to assume
totalApprovalQuantityandtotalApprovalSupplyAtCreationTimewould be using the same metric, instead of one using the raw count and the other usingAsNumberOfHolders.
AustinGreen (Llama) commented:
Although this is the intended design for this strategy, we decided to create an additional strategy that Llama instances can adopt that follows the warden’s recommendations. It uses total (dis)approval quantity for the quorum calculation as specified.
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 strategy uses the number of role holders for the quorum supply but uses the raw quantity for approval/disapproval counting, creating a unit mismatch.
Impact
A single role holder with a high quantity could approve an action alone, bypassing the intended percentage of holders, though the project disputed this and later added a new strategy following the recommendation.
What the attacker needed
A Llama instance using LlamaRelativeQuorum; a role holder with quantity greater than 1; the holder approves the action
The fix
The project disputed the finding but later created an additional strategy that uses total approval quantity for quorum calculation as recommended.
How it was found
- Create a Llama instance with three role holders where one holder has quantity 2 and the others have quantity 1.
- Set the minimum approval percentage to 51%.
- Have the holder with quantity 2 approve the action.
- Observe that the action is approved with only one approval.
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 voting system, the total number of voters and the weight of each vote must use the same units. Here, the system sets the total supply as the number of people who can vote, but when counting votes it adds up their voting weights, which can be larger than one per person. So one person with a weight of two can count as two voters, potentially passing a proposal that should have needed more people.
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.