The packing function takes the array and packs it, and the unpacking function takes the packed array and inputted length of the original array and checks if it's valid with this require
but this doesn't ensure it is valid
assume there is a packed array with original length of 8 after the packing length is 4
going to unpacking function with array length = 4 and targetArrayLength = 7
| packed array | [0] | [1] | [2] | [3] |
|---|---|---|---|---|
| The value packed | 0,1 | 2,3 | 4,5 | 6,7 |
require successfully pass as 8 >= 7 and function execute ignoring the value stored at (lastindex-1)
| packed array | [0] | [1] | [2] | [3] |
|---|---|---|---|---|
| The value retrieved | 0,1 | 2,3 | 4,5 | 7 |
the same applies with odd length array assuming original array length of 7 then after packing = 4
| packed array | [0] | [1] | [2] | [3] |
|---|---|---|---|---|
| The value packed | 0,1 | 2,3 | 4,5 | 6 |
going to the unpacking function with targetArrayLength = 8 an extra empty value will be in (lastindex -1)
| packed array | [0] | [1] | [2] | [3] |
|---|---|---|---|---|
| The value retrieved | 0,1 | 2,3 | 4,5 | (0),7 |
Add this test in QuantAMMStorageTest contract
broken function leads to wrong values packed and retrieved
manual review
one solution is storing the length of the original array while packing at the last index
ex: original array length of 8 then after packing the length is 5 with the first 4 being the packed values and 5th index for the length and in unpacking function just read the last index this way it would be impossible for such collisions to happen in packing and unpacking
in _quantAMMPack128Array function at the end
in _quantAMMUnpack128Array instead of requiring
Please read the CodeHawks documentation to know which submissions are valid. If you disagree, provide a coded PoC and explain the real likelyhood and the detailed impact on the mainnet without any supposition (if, it could, etc) to prove your point.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.