The policy contract enforces an invariant that "sum of all user quantities for a role == that role's total quantity". However, when casting approval, the quantity used is returned from the strategy. A strategy might not respect this invariant.
The fix here is to make _newCastCount more robust.
Modifications:
To make _newCastCount more robust it now behaves as follows:
Both inputs are uint96, meaning when we add them, solidity overflows if the sum is greater than type(uint96).max. As a result, we must upcast one input to uint256 so solidity treats the addition as if we're adding to uint256 values.
If the uint256 sum of the two inputs is greater than type(uint96).max, return type(uint96).max.
Otherwise, return the sum.
Result:
LlamaCore can handle strategies that don't respect the expected behavior of quantities
Motivation:
Closes https://github.com/llamaxyz/llama/issues/448
The policy contract enforces an invariant that "sum of all user quantities for a role == that role's total quantity". However, when casting approval, the quantity used is returned from the strategy. A strategy might not respect this invariant.
With such a strategy, it's possible for casts to be blocked by reverting on overflow in the
currentCount + quantity
line as discussed in https://github.com/spearbit-audits/review-llama2/issues/16The fix here is to make
_newCastCount
more robust.Modifications:
To make
_newCastCount
more robust it now behaves as follows:type(uint96).max
. As a result, we must upcast one input to uint256 so solidity treats the addition as if we're adding to uint256 values.type(uint96).max
, returntype(uint96).max
.Result:
LlamaCore can handle strategies that don't respect the expected behavior of quantities