paste32Bytes
in LibBytes.sol
doesn't work correctly
paste32Bytes
is used to copy 32 Bytes from copyFromData
at copyIndex
and paste into pasteToData
at pasteIndex
. However bytes memory variables in Solidity have an additional 32 bytes of overhead for storing the array length. Adding 0x20 (which is 32 in decimal) ensures that the pointer point to the actual data within the byte array, skipping this overhead. This is crucial for accurate byte manipulation, as directly accessing memory locations without considering the overhead could lead to incorrect data or out-of-bounds exceptions.
Test code below in remix:
Input:
copyFromData: "0x1111111111111111111111111111111111111111111111111111111111111111"
pasteToData: "0x2222222222222222222222222222222222222222222222222222222222222222"
copyIndex: 0
pasteIndex: 0
Output:
paste32Bytes: 0x1111111111111111111111111111111111111111111111111111111111111111
paste32BytesV2: 0x2222222222222222222222222222222222222222222222222222222222222222
Conclusion:
paste32Bytes
is working correctly and paste32BytesV2
not
pasteBytesTractor
and pasteBytesClipboard
don't work correctly
manual and remix
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.