Shibarium
Search
K

Shibarium to Ethereum

The process of transferring data from Shibarium to Ethereum, involving Bone instead of Matic, and Puppynet 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 Shibarium to Ethereum

  1. 1.
    Transaction Creation on Shibarium:
    • Execute a transaction on the child contract deployed on Shibarium (formerly Polygon), emitting an event that includes the data intended for transfer to Ethereum.
    • The data is encoded in bytes and emitted in the event.
  2. 2.
    Checkpoints by Validators:
    • Validators on the Shibarium network pick up the transaction at specific intervals (typically 10-30 minutes), validate it, and add it to the checkpoint on Ethereum.
  3. 3.
    Checkpointing on Ethereum:
    • Validators create a checkpoint transaction on the RootChain contract in Ethereum, ensuring the inclusion of the Shibarium transaction hash.
    • The matic.js library can be used to check the checkpoint addition.
  4. 4.
    RootChainManager Contract:
    • After checkpointing, submit the hash of the Shibarium transaction to the RootChainManager contract on Ethereum as proof.
    • The RootChainManager contract validates the transaction, confirms its inclusion in the checkpoint, and decodes the event logs.
  5. 5.
    Predicate Contract Usage:
    • Utilize a Predicate contract, triggered only by the RootChainManager contract, to secure state changes on Ethereum.
    • The state changes on Ethereum occur only when the Shibarium transaction is checkpointed and verified by the RootChainManager contract.

Overview:

  • A transaction is executed on the child contract on Shibarium, emitting an event with the data to transfer.
  • Validators validate and checkpoint the transaction on Ethereum.
  • The matic.js library is used to trigger the exit function of the RootChainManager contract, ensuring secure state changes on Ethereum.

Implementation:

  1. 1.
    Child Contract (Shibarium):
    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);
    }
    }
  2. 2.
    Root Contract (Ethereum):
    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 Shibarium and Ethereum.
  • Use the PoS bridge to map these contracts to maintain a connection between them across chains.

Testing the Implementation:

  1. 1.
    Create a transaction on Shibarium by calling the setData function of the child contract.
  2. 2.
    Wait for the checkpoint to be completed.
  3. 3.
    Check the checkpoint inclusion.
  4. 4.
    Use the matic.js SDK to call the exit function of the RootChainManager.
The provided exit script can be used to verify the inclusion of the Shibarium transaction hash on the Ethereum chain and trigger the exitToken function of the Predicate contract. This ensures secure state changes on the root contract in Ethereum.