Closed YamenMerhi closed 2 years ago
As abi.encodePacked
is cheaper and can easily be sliced into its different pieces, as the last part is only dynamic its the preferred way for LSP7 and LSP8.
Closing this as its now documented on the spec: https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-7-DigitalAsset.md#_notifytokensender
What is this issue about?
Currently, we use
abi.encodePacked
to send the token transfer data to theuniversalReceiver(..)
function on the sender and receiver profiles to inform them about the transfer.Code Snippet:
A developer from the community asked the following:
After testing
Turns out that using
abi.encode
instead ofabi.encodePacked
will be more expensive by a minimum of 771 gas units (Could increase significantly if optional data was sent during the transfer). Since we will inform the sender and the receiver, it will increase with a minimum of 1,542 gas units.Slicing parameter:
While using
abi.encodePacked
, it's easy to get the parameters using any slicing library, as the data sent is:(address, address, uint256, bytes)
:(fixedLength, fixedLength, fixedLength, dynamicLength)
.Since the first three parameters are fixed length we can get all the parameters: Slicing Method: Slicing(starting from, length)
Slicing(0,20)
Slicing(20,20)
Slicing(40,32)
Slicing(72, packedData.length - 72 )
Decoding
While using
abi.encode
, we should useabi.decode
which is more expensive by ~1.5-2k gas units than Slicing.The combination of
abi.encode
andabi.decode
will make the transfer gas cost much higher. We should enforce usingabi.encodePacked
in the specs of LSP7 & LSP8 contracts.