Validating your statements

Once you’ve fetched the proof, you can now verify it using a contract on Chiado. The contract will use the HashiProver helper library to check the proof against the block header stored on Chiado.

Deploying the Verification Contract on Chiado

Here is the contract that you will deploy on Chiado to read and verify the Transfer event on Sepolia:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import { HashiProver } from "./HashiProver.sol";

contract MockERC20Prover {

    event TransferEventVerified(uint256 indexed chainID, bytes rlpEncodedEvent);

    HashiProver public hashiProver;
    address public erc20Contract;
    uint256 public chainID;

    constructor(address hashiProver_, address erc20Contract_, uint256 chainID_) {
        hashiProver = HashiProver(hashiProver_);
        erc20Contract = erc20Contract_;
        chainID = chainID_;
    }

    function verifyTransferEvent(HashiProver.ReceiptProof calldata proof, bytes memory expectedRlpEncodedEvent) external {
        require(proof.chainId == chainID, "Invalid chain id"); 

        bytes memory rlpEncodedEvent = hashiProver.verifyForeignEvent(proof);

        require(keccak256(rlpEncodedEvent) == keccak256(expectedRlpEncodedEvent), "invalid event");
        emit TransferEventVerified(proof.chainId , rlpEncodedEvent);

        // TODO: Define your logic here

    }
}

Deployment:

  • In this example, pass the Hashi Prover contract on Chiado, ERC20Contract address on Sepolia that the Transfer event is emitted from, and chain ID of the ERC20Contract (Sepolia: 11155111)

Explanation:

  • This contract uses HashiProver to verify the event proof fetched earlier from Sepolia.

  • It checks that the proof is from Sepolia (chain ID 11155111), and rlpEncodedEvent returns from HashiProver.verifyForeignEvent matches the expectedRlpEncodedEvent that we passed as the function argument. To create the expectedRlpEncodedEvent, check out the helper script from Hashi-template.

  • The verifyForeignEvent function validates the event proof against the block header stored on Chiado, which was relayed from Sepolia.

  • If the proof is valid, the contract emits the TransferEventVerified event. You may defie your own logic after the proof has been verified.

References

Last updated