Closed code423n4 closed 1 year ago
downgrading to QA per https://github.com/code-423n4/org/issues/55
0xean changed the severity to QA (Quality Assurance)
tbrent marked the issue as sponsor confirmed
On further reflection, both _targetNames
and _newBasket
are not new in 3.0.0. 5 slots is correct.
tbrent marked the issue as sponsor disputed
Lines of code
https://github.com/reserve-protocol/protocol/blob/c4ec2473bbcb4831d62af55d275368e73e16b984/contracts/p1/BasketHandler.sol#L53-L78 https://github.com/reserve-protocol/protocol/blob/c4ec2473bbcb4831d62af55d275368e73e16b984/contracts/p1/BasketHandler.sol#L684
Vulnerability details
Impact
BasketHandlerP1 is not a subcontract of another contract, so this issue will not be raised in this upgrade. However, wrong slots calculation method may lead a contract not work after an upgrade in the future, it may be in a wrong state and can't be upgraded again, leaving all assets locked.
This is not the same as issues-55, it is not that the developer did not follow the best practice of 50-slots alignment, it is that the best practice was implemented with the wrong formula due to misunderstanding: The developer assume that struct always occupies 1 slot, a misconception that will likely lead to a future upgrade that will result in a completely broken contract that cannot be fixed with another upgrade.
Proof of Concept
According to the diff of 2.1.0-rc4...3.0.0,
BasketHandlerP1@v3.0.0
added the following new storages:And the
__gap
size is changed from 42 to 37 (means 5 slots are added):Just like the CHANGELOG said:
However, the number of slots calculated in the documentation and the code is wrong, the real number of slots occupied by the new variables is 9 instead of 5:
EnumerableSet.Bytes32Set private _targetNames;
, because Bytes32Set is a struct as follows:Basket private _newBasket;
, because Basket is a struct as follows:mapping(uint48 => Basket) private basketHistory;
EnumerableMap.Bytes32ToUintMap private _targetAmts;
, because Bytes32ToUintMap is a struct as follows:Tools Used
Manual Review
Recommended Mitigation Steps
It is recommended to fix the wrong gap value, and to provide a training for developers to understand the calculation of slots correctly
Assessed type
Other