github.com/ethereum-optimism/optimism@v1.7.2/packages/sdk/test/contracts/MessageEncodingHelper.sol (about)

     1  pragma solidity ^0.8.9;
     2  
     3  contract MessageEncodingHelper {
     4      // This function is copy/pasted from the Lib_CrossDomainUtils library. We have to do this
     5      // because the Lib_CrossDomainUtils library does not provide a function for hashing. Instead,
     6      // I'm duplicating the functionality of the library here and exposing an additional method that
     7      // does the required hashing. This is fragile and will break if we ever update the way that our
     8      // contracts hash the encoded data, but at least it works for now.
     9      // TODO: Next time we're planning to upgrade the contracts, make sure that the library also
    10      // contains a function for hashing.
    11      function encodeXDomainCalldata(
    12          address _target,
    13          address _sender,
    14          bytes memory _message,
    15          uint256 _messageNonce
    16      ) public pure returns (bytes memory) {
    17          return
    18              abi.encodeWithSignature(
    19                  "relayMessage(address,address,bytes,uint256)",
    20                  _target,
    21                  _sender,
    22                  _message,
    23                  _messageNonce
    24              );
    25      }
    26  
    27      function hashXDomainCalldata(
    28          address _target,
    29          address _sender,
    30          bytes memory _message,
    31          uint256 _messageNonce
    32      ) public pure returns (bytes32) {
    33          return keccak256(
    34              encodeXDomainCalldata(
    35                  _target,
    36                  _sender,
    37                  _message,
    38                  _messageNonce
    39              )
    40          );
    41      }
    42  }