Calldata check can not be added for adjacent parameters #26
Labels
2 (Med Risk)
Assets not at direct risk, but function/availability of the protocol could be impacted or leak value
bug
Something isn't working
duplicate-17
🤖_primary
AI based primary recommendation
🤖_10_group
AI based duplicate group recommendation
satisfactory
satisfies C4 submission criteria; eligible for awards
sufficient quality report
This report is of sufficient quality
Lines of code
https://github.com/code-423n4/2024-10-kleidi/blob/c474b9480850d08514c100b415efcbc962608c62/src/Timelock.sol#L1028-L1155
https://github.com/code-423n4/2024-10-kleidi/blob/c474b9480850d08514c100b415efcbc962608c62/src/Timelock.sol#L1119-L1123
Vulnerability details
Explanation
The _addCalldataCheck function is used to enable certain addresses and selectors to be called by hot signers and run validation on their input data.
However, while checking the overlap of parameters, the validation is too restrictive, and results in making it impossible for two adjacent parameters to be added independently.
This happens because the
startIndex
is supposed to be inclusive, and theendIndex
is exclusive. As an example, if the two first inputs of a function are of typesaddress
, the start and end index of the first one should be [4, 24), and the next variables should be at indexes [24, 44) of the calldata. And since the start index of the second variable is equal to the end index of the first variable, the check fails.Impact
The comments in the code clearly mention that the separate checks should be possible. While this is still possible to do, the users need to merge all of the adjacent addresses they need together and add all of the accepted string separately. This will make the management of such calldata much harder than it should be.
As an example, for a function call
signature(dataType, dataType, dataType, dataType, dataType)
, if for each of the first 4 fields there are 5 accepted strings, user should enter4^5 = 1024
strings. And if at a later date they want to add a restriction on the 5th data type, they need to remove all the previous ones and add all the strings from the start. This problem increases exponentially with the number of inputs and their possible values, and can make it impossible for some situations to add the values. 10 parameters with 10 different values would take10^10
restrictions in total which can be quite impossible for users to add.Proof of Concept
The
testWhitelistingBatchCalldataSucceeds
test is slightly modified as below and can show that adjacent variables can not be added. The result fails withrevert: CalldataList: Partial check overlap
:Recommended Mitigation Steps
Change the code and use
<=
and>=
instead of>
and<
.Assessed type
Invalid Validation
The text was updated successfully, but these errors were encountered: