Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/swift-cooks-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@layerzerolabs/onft-evm": patch
---

The ONFT721MsgCodec library composeMsg function was ignoring the sender offset when decoding composed messages. Added a new SENDER_OFFSET constant variable and 2 new helper functions composeMsgFrom and composeMsgPayload to decode every member of the composed message separately and keep backwards compatibility.
19 changes: 19 additions & 0 deletions packages/onft-evm/contracts/onft721/libs/ONFT721MsgCodec.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pragma solidity ^0.8.22;
library ONFT721MsgCodec {
uint8 private constant SEND_TO_OFFSET = 32;
uint8 private constant TOKEN_ID_OFFSET = 64;
uint8 private constant SENDER_OFFSET = 96;

/**
* @dev Encodes an ONFT721 LayerZero message payload.
Expand Down Expand Up @@ -65,6 +66,24 @@ library ONFT721MsgCodec {
return _msg[TOKEN_ID_OFFSET:];
}

/**
* @dev Decodes the sender of the composed message from the composed message.
* @param _msg The message.
* @return The sender address of the composed message in bytes32 format.
*/
function composeMsgFrom(bytes calldata _msg) internal pure returns (bytes32) {
return bytes32(_msg[TOKEN_ID_OFFSET:SENDER_OFFSET]);
}

/**
* @dev Decodes the payload from the composed message.
* @param _msg The message.
* @return The composed message payload.
*/
function composeMsgPayload(bytes calldata _msg) internal pure returns (bytes memory) {
return _msg[SENDER_OFFSET:];
}

/**
* @dev Converts an address to bytes32.
* @param _addr The address to convert.
Expand Down