diff --git a/.changeset/swift-cooks-serve.md b/.changeset/swift-cooks-serve.md new file mode 100644 index 000000000..15863f54b --- /dev/null +++ b/.changeset/swift-cooks-serve.md @@ -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. diff --git a/packages/onft-evm/contracts/onft721/libs/ONFT721MsgCodec.sol b/packages/onft-evm/contracts/onft721/libs/ONFT721MsgCodec.sol index 52491ba04..3cc029c55 100644 --- a/packages/onft-evm/contracts/onft721/libs/ONFT721MsgCodec.sol +++ b/packages/onft-evm/contracts/onft721/libs/ONFT721MsgCodec.sol @@ -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. @@ -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.