MessageEncodingHelper.sol 1.44 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
pragma solidity ^0.8.9;

contract MessageEncodingHelper {
    // This function is copy/pasted from the Lib_CrossDomainUtils library. We have to do this
    // because the Lib_CrossDomainUtils library does not provide a function for hashing. Instead,
    // I'm duplicating the functionality of the library here and exposing an additional method that
    // does the required hashing. This is fragile and will break if we ever update the way that our
    // contracts hash the encoded data, but at least it works for now.
    // TODO: Next time we're planning to upgrade the contracts, make sure that the library also
    // contains a function for hashing.
    function encodeXDomainCalldata(
        address _target,
        address _sender,
        bytes memory _message,
        uint256 _messageNonce
    ) public pure returns (bytes memory) {
        return
            abi.encodeWithSignature(
                "relayMessage(address,address,bytes,uint256)",
                _target,
                _sender,
                _message,
                _messageNonce
            );
    }

    function hashXDomainCalldata(
        address _target,
        address _sender,
        bytes memory _message,
        uint256 _messageNonce
    ) public pure returns (bytes32) {
        return keccak256(
            encodeXDomainCalldata(
                _target,
                _sender,
                _message,
                _messageNonce
            )
        );
    }
}