Ramestta To Polygon

The process of transferring data from Ramestta to Polygon, involving RAMA instead of MATIC, and Ramestta Testnet in place of Mumbai, follows a specific mechanism facilitated by checkpoint transactions and validation by Validators. Here is a detailed explanation of the process:

Data Transfer Mechanism from Ramestta to Polygon

  1. Transaction Creation on Ramestta:

    • Execute a transaction on the child contract deployed on Ramestta, emitting an event that includes the data intended for transfer to Polygon.

    • The data is encoded in bytes and emitted in the event.

  2. Checkpoints by Validators:

    • Validators on the Ramestta network pick up the transaction at specific intervals (typically 10-30 minutes), validate it, and add it to the checkpoint on Polygon.

  3. Checkpointing on Polygon:

    • Validators create a checkpoint transaction on the RootChain contract in Polygon, ensuring the inclusion of the Ramestta transaction hash.

    • The rama.js(coming soon) library can be used to check the checkpoint addition.

  4. RootChainManager Contract:

    • After checkpointing, submit the hash of the Ramestta transaction to the RootChainManager contract on Polygon as proof.

    • The RootChainManager contract validates the transaction, confirms its inclusion in the checkpoint, and decodes the event logs.

  5. Predicate Contract Usage:

    • Utilize a Predicate contract, triggered only by the RootChainManager contract, to secure state changes on Polygon.

    • The state changes on Polygon occur only when the Ramestta transaction is checkpointed and verified by the RootChainManager contract.

Overview:

  • A transaction is executed on the child contract on Ramestta, emitting an event with the data to transfer.

  • Validators validate and checkpoint the transaction on Polygon.

  • The rama.js library is used to trigger the exit function of the RootChainManager contract, ensuring secure state changes on Polygon.

Implementation:

  1. Child Contract (Ramestta):

contract Child {
    event Data(address indexed from, bytes bytes_data);
    uint256 public data;

    function setData(bytes memory bytes_data) public {
        data = abi.decode(bytes_data, (uint256));
        emit Data(msg.sender, bytes_data);
    }
}
  1. Root Contract (Polygon):

contract Root {
    address public predicate;

    constructor(address _predicate) public {
        predicate = _predicate;
    }

    modifier onlyPredicate() {
        require(msg.sender == predicate);
        _;
    }

    uint256 public data;

    function setData(bytes memory bytes_data) public onlyPredicate {
        data = abi.decode(bytes_data, (uint256));
    }
}

Mapping Contracts:

  • Deploy these contracts on Ramestta and Polygon.

  • Use the PoS bridge to map these contracts to maintain a connection between them across chains.

Testing the Implementation:

  1. Create a transaction on Ramessta by calling the setData function of the child contract.

  2. Wait for the checkpoint to be completed.

  3. Check the checkpoint inclusion.

  4. Use the rama.js SDK to call the exit function of the RootChainManager.

The provided exit script can be used to verify the inclusion of the Ramestta transaction hash on the Polygon chain and trigger the exitToken function of the Predicate contract. This ensures secure state changes on the root contract in Polygon.

Last updated