Submitted by 0xAlix2, also found by DemoreX, DanielArmstrong, 0x37, jsonDoge, dhank, KlosMitSoss, stuart_the_minion, Allarious, and klau5
Cold signers can add call data checks as whitelisted checks that hot signers could execute without timelocks, the call data checks depend on the indices of the encoded call. However, the protocol invalidly handles these indices in 2 separate places:
Where length is computed as end indexstart index, which is usually wrong as index subtraction needs +1 to be translated to a length. For most of the scenario, this is okay; however, if a parameter that is being checked filled all of its bytes then this would be an issue (PoC is an example). For example, a uint256 filling all of its 32 bytes.
NB: This is not caught in the unit tests because there isnt any test that checks this edge case, where a parameter that fills all its bytes is being checked.
This forces the whitelisted call to revert.
The following PoC shows a scenario where an infinite approval call is being whitelisted, we dont want to allow fewer approvals (only uint256 max), so the encoding of the call:
results in the following bytes string:
To have an infinite approval call whitelisted we need to add conditions on both the spender and the amount:
For the spender part, its straightforward where we need to check from index 16 to 35 (1eff47bc3a10a45d4b230b5d10e37751fe6aa718 from the encoded bytes); however, passing 16 and 35 will cause the TX to revert with CalldataList: Data length mismatch, this is where the issue starts, we pass 16 to 36, but now 36 is the start of the unit max. And we pass 37 to 69, to have the whole 32 bytes included (unit max fills all 32 bytes), passing the end index less than 69 reverts.
Now, when the whitelisted call is triggered with the above params, the TX will revert with End index is greater than the length of the byte string, and this is because the amounts byte length is 68 while the end index is 69.
As a result: wrong index/length handling => forcing to pass incorrect params.
Coded POC:
Add the following test in test/integration/System.t.sol, and run it using forge test -vv --fork-url "https://mainnet.infura.io/v3/PROJECT_ID" --fork-block-number 20515328 --mt test_DaiTransfer_withoutPlus1:
In BytesHelper.sol:
In Timelock.sol:
ElliotFriedman (Kleidi) confirmed and commented:
Alex the Entreprenerd (judge) commented:
Alex the Entreprenerd (judge) commented:
Alex the Entreprenerd (judge) commented:
ElliotFriedman (Kleidi) commented:
