-
Notifications
You must be signed in to change notification settings - Fork 90
Description
Feature Request
Describe the solution you'd like
A provider function getL1MessageHash which receives an L2 tx hash, and returns the L1 message hash, if it is applicable.
Context
L1 message hashes are computed in the following way link to docs.
A snippet of solidity code to compute this:
pragma solidity >=0.8.2 <0.9.0;
contract Hasher {
function getL1ToL2MsgHash(
address fromAddress,
uint256 toAddress,
uint256 selector,
uint256[] calldata payload,
uint256 nonce
) external view returns (bytes32) {
return
keccak256(
abi.encodePacked(
uint256(uint160(fromAddress)),
toAddress,
nonce,
selector,
payload.length,
payload
)
);
}
}
The required information to compute this on L2 is available when querying getTransactionByHash
Example:
mainnet tx: 0x0075f4ad64b9eca93b4e1bb48fa3db4260e476fcf65e7ab97bf5f60a2a3022ce
The result of getTransactionbyHash
{
"jsonrpc": "2.0",
"id": 0,
"result": {
"calldata": [
"0xae0ee0a63a2ce6baeeffe56e7714fb4efe48d419",
"0x1d8ec38501c2fddf0b17fcd38df2029fb059b2016889e6962e5f19449735108",
"0x354a6ba7a180000",
"0x0"
],
"contract_address": "0x73314940630fd6dcda0d772d4c972c4e0a9946bef9dabf4ef84eda8ef542b82",
"entry_point_selector": "0x2d757788a8d8d6f21d1cd40bce38a8222d70654214e96ff95d8086e684fbee5",
"nonce": "0x15b1a",
"transaction_hash": "0x75f4ad64b9eca93b4e1bb48fa3db4260e476fcf65e7ab97bf5f60a2a3022ce",
"type": "L1_HANDLER",
"version": "0x0"
}
}
The first param of calldata == fromAddress.
contract_address == toAddress
nonce == nonce
entry_point_selector == selector
payload and payload.length can be derived from the calldata field.
In case the L2 tx is not a result of an l1->l2 interaction, the function can return null (or error)
This can be a good first issue