在 Starknet 中检查 L1 -> L2 message/invoke 的结果

Checking result of an L1 -> L2 message/invoke in Starknet

我已经为 L1 (Ethereum) 和 L2 (Starknet) 写了几个合约并让它们进行通信 here

我可以看到 L1 发送了我期待的消息,请参阅 this TX on etherscan。然而,其中的最后一条消息从未在我的 L2 合约上执行过。我试图弄清楚 L2 Sequencer 是否调用了我的合约的处理函数,如果是,whether/how 它失败了。

这里有人知道如何找到处理 L2 调用的 TX 吗?或者任何其他 ideas/tools 可以帮助弄清楚为什么 l1_handler 从来没有 executed/failed?

首先,来自 L1 的交易是常规交易,因此可以使用与调用交易相同的方式计算它们的哈希值。要获得这方面的更多信息,您可以查看文档 here。现在这有助于理解理论,但对实际计算 tx 哈希没有多大帮助。

这是向 StarkNet 发送消息的 L1 事件,这是我获取计算哈希值所需信息的地方

Address 0xde29d060d45901fb19ed6c6e959eb22d8626708e
Name LogMessageToL2 (index_topic_1 address fromAddress, index_topic_2 uint256 toAddress, index_topic_3 uint256 selector, uint256[] payload, uint256 nonce)View Source

Topics
0 0x7d3450d4f5138e54dcb21a322312d50846ead7856426fb38778f8ef33aeccc01
1  0x779b989d7358acd6ce64237f16bbef09f35f6ecc
2  1524569076953457512425355396075576585145183562308719695739798372277154230742
3  1285101517810983806491589552491143496277809242732141897358598292095611420389
Data
payload :
1393428179030720295440092695193628168230707649901849797435563042612822742693
11819812303435348947619
0
nonce :
69106

这是我在您的交易中使用的脚本(将来可能会更改)

from starkware.cairo.lang.vm.crypto import pedersen_hash
from starkware.cairo.common.hash_state import compute_hash_on_elements
from starkware.crypto.signature.fast_pedersen_hash import pedersen_hash
from typing import List


def calculate_transaction_hash_common(
    tx_hash_prefix,
    version,
    contract_address,
    entry_point_selector,
    calldata,
    max_fee,
    chain_id,
    additional_data,
    hash_function=pedersen_hash,
) -> int:
    calldata_hash = compute_hash_on_elements(data=calldata, hash_func=hash_function)
    data_to_hash = [
        tx_hash_prefix,
        version,
        contract_address,
        entry_point_selector,
        calldata_hash,
        max_fee,
        chain_id,
        *additional_data,
    ]

    return compute_hash_on_elements(
        data=data_to_hash,
        hash_func=hash_function,
    )


def tx_hash_from_message(
    from_address: str, to_address: int, selector: int, nonce: int, payload: List[int]
) -> str:
    int_hash = calculate_transaction_hash_common(
        tx_hash_prefix=510926345461491391292786,    # int.from_bytes(b"l1_handler", "big")
        version=0,
        contract_address=to_address,
        entry_point_selector=selector,
        calldata=[int(from_address, 16), *payload],
        max_fee=0,
        chain_id=1536727068981429685321,  # StarknetChainId.TESTNET.value
        additional_data=[nonce],
    )
    return hex(int_hash)


print(
    tx_hash_from_message(
        from_address="0x779b989d7358acd6ce64237f16bbef09f35f6ecc",
        to_address=1524569076953457512425355396075576585145183562308719695739798372277154230742,
        selector=1285101517810983806491589552491143496277809242732141897358598292095611420389,
        nonce=69106,
        payload=[
            1393428179030720295440092695193628168230707649901849797435563042612822742693,
            11819812303435348947619,
            0,
        ],
    )
)

这输出 0x4433250847579c56b12822a16205e12410f6ad35d8cfc2d6ab011a250eae77f 我们可以找到 here 正确执行。