The LibClipboard::decode
function decodes the input parameter clipboard
and returns the typeId
, etherValue
and returnPasteParams
. But the returned returnPasteParams
is not correct.
The LibClipboard::decode
function should decode the input clipboard
and return the typeId
, etherValue
and returnPasteParams
:
The LibClipboard::decode
function returns incorrect decoding returnPasteParams
.
Let's consider the following scenario:
The input parameter clipboard
is: 0x0100000000000000000000000000000000000000000000000000000000001234
(the Ether value is 0).
The expectected returnPasteParams
is: 0x0000000000000000000000000000000000000000000000000000000000001234
.
But the actual return value is: 0x0100000000000000000000000000000000000000000000000000000000001234
.
The LibClipboard::decode
function attempts to decode the entire clipboard
as a bytes32
, which is incorrect. This leads to improper extraction of the returnPasteParams
. The returned returnPasteParams
includes also typeId
and etherValue
.
The following test shows that the decode
function doesn't decode correctly the returnPasteParams
.
To simplify the test a new foundry setup is made with Decode
contract that contains the encode
and decode
functions:
And the test file Decode.t.sol
with test function testDecode
:
And the result from the test is:
The test shows that the function LibClipboasr::decode
doesn't return the correct returnPasteParams
.
Several functions rely on the result from the decode
function: LibClipboard::useClipboard
, Drafter::decodeClipboard
, LibFarm::_advancedFarm
and LibFarm::_advancedFarmMem
. These functions will receive wrong result for the returnPasteParams
parameter.
It is also worth noting that there is a mistake in the LibClipboard::encode
function too. The following test testEncode
shows that the function LibClipboard::encode
returns wrong clipboard
by large values for returnPasteParams
when the length is 1
:
The result is: [Return] 0x0100567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef
.
But the expected result is: 0x01001234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef
. This is because of the removing padding in the line uint240(uint256(returnPasteParams[0]))
. But I guess that this function will not be used with such a big values so the impact of the mistake in encode
function is low. The bigger problem is the issue in the decode
function, because it returns by every call wrong result for returnPasteParams
parameter and several functions in different contracts rely on this result.
Manual Review, Foundry
Modify the LibClipboard::decode
function to slice the clipboard
parameter and return only the expected returnPasteParams
.
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.