logo

Verify

Cross Chain Transaction Verification#

This section provides guidance on verifying transactions across different blockchain chains, assuming that a side chain has already been deployed and indexed by the main chain.

Sending a Transaction#

Any transaction with the status "Mined" can be verified, provided that the transaction has been indexed.

Verifying the Transaction#

There are two scenarios for verification:

  • Verifying a transaction on the main chain.
  • Verifying a transaction on a side chain.
  • 1
    rpc VerifyTransaction (VerifyTransactionInput) returns (google.protobuf.BoolValue) {
    2
    option (aelf.is_view) = true;
    3
    }
    4
    5
    message VerifyTransactionInput {
    6
    aelf.Hash transaction_id = 1;
    7
    aelf.MerklePath path = 2;
    8
    int64 parent_chain_height = 3;
    9
    int32 verified_chain_id = 4;
    10
    }

    The VerifyTransaction method is used for verification and returns whether the transaction was mined and indexed by the destination chain. The method is the same for both scenarios; only the input values differ.

    Verifying a Main Chain Transaction#

    To verify a main chain transaction on a side chain, use the VerifyTransaction method on the side chain with the following input values:

  • parent_chain_height: The height of the block on the main chain where the transaction was packed.
  • transaction_id: The ID of the transaction to verify.
  • path: The Merkle path obtained from the main chain's API using GetMerklePathByTransactionIdAsync with the transaction ID.
  • verified_chain_id: The chain ID of the main chain.
  • You can retrieve the Merkle path of a transaction in a block by using the chain's API method GetMerklePathByTransactionIdAsync.

    Verifying a Side Chain Transaction#

    For verifying a side chain transaction:

  • Obtain the Merkle path using GetMerklePathByTransactionIdAsync, similar to main chain verification.
  • Retrieve the CrossChainMerkleProofContext of the transaction from the source chain using GetBoundParentChainHeightAndMerklePathByHeight.
  • 1
    rpc GetBoundParentChainHeightAndMerklePathByHeight (google.protobuf.Int64Value) returns (CrossChainMerkleProofContext) {
    2
    option (aelf.is_view) = true;
    3
    }
    4
    5
    message CrossChainMerkleProofContext {
    6
    int64 bound_parent_chain_height = 1;
    7
    aelf.MerklePath merkle_path_from_parent_chain = 2;
    8
    }

    Using the result from the above API, call VerifyTransaction on the target chain with:

  • transaction_id: The ID of the transaction to verify.
  • parent_chain_height: Use the bound_parent_chain_height field from CrossChainMerkleProofContext.
  • path: Concatenate the two Merkle paths in order:
  • verified_chain_id: The chain ID of the side chain where the transaction was mined.
  • Edited on: 18 July 2024 04:28:53 GMT+0