This guide is intended for developers who want to understand the technical implementation of the bridge mechanism. For user-friendly instructions, see Withdraw Tokens.
The process of transferring data from Shibarium to Ethereum follows a specific mechanism facilitated by checkpoint transactions and validation by validators. This ensures secure and verifiable cross-chain transfers.

Data Transfer Mechanism

The transfer process involves several key steps that ensure data integrity and security across the bridge:
1

Transaction Creation on Shibarium

Execute a transaction on the child contract deployed on Shibarium, emitting an event that includes the data intended for transfer to Ethereum.
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);
    }
}
The data is encoded in bytes and emitted in the event for transfer to Ethereum.
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.
Checkpoint intervals ensure efficient batch processing while maintaining security.
3

Checkpointing on Ethereum

Validators create a checkpoint transaction on the RootChain contract in Ethereum, ensuring the inclusion of the Shibarium transaction hash.
const shib = require('@shibaswap/shib');

async function checkCheckpoint(txHash) {
    try {
        const checkpoint = await shib.checkpointInclusion(txHash);
        console.log('Checkpoint status:', checkpoint);
        return checkpoint;
    } catch (error) {
        console.error('Error checking checkpoint:', error);
    }
}
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

Predicate Contract Usage

Utilize a Predicate contract, triggered only by the RootChainManager contract, to secure state changes on 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));
    }
}

Implementation Overview

The complete flow ensures secure state changes on Ethereum:
  1. A transaction is executed on the child contract on Shibarium, emitting an event with the data to transfer
  2. Validators validate and checkpoint the transaction on Ethereum
  3. The shib.js library is used to trigger the exit function of the RootChainManager contract
  4. State changes on Ethereum occur only when the Shibarium transaction is checkpointed and verified

Contract Mapping

To establish the connection between Shibarium and Ethereum contracts:
1

Deploy Contracts

Deploy the Child contract on Shibarium and the Root contract on Ethereum using the provided contract code.
2

Map Contracts

Use the PoS bridge to map these contracts to maintain a connection between them across chains.
Ensure both contracts are deployed on the correct networks before mapping.
3

Verify Mapping

Confirm that the mapping is successful and both contracts can communicate through the bridge.

Testing the Implementation

1

Create Transaction

Create a transaction on Shibarium by calling the setData function of the child contract.
const Web3 = require('web3');

// Connect to Shibarium
const web3 = new Web3('YOUR_SHIBARIUM_RPC_URL');

const childABI = [/* Your Child contract ABI */];
const childAddress = 'YOUR_CHILD_CONTRACT_ADDRESS';

const childContract = new web3.eth.Contract(childABI, childAddress);

async function setData() {
    const data = web3.utils.toHex('123'); // Example data
    
    try {
        const result = await childContract.methods.setData(data).send({
            from: 'YOUR_WALLET_ADDRESS',
            gas: 200000
        });
        console.log('Transaction hash:', result.transactionHash);
        return result.transactionHash;
    } catch (error) {
        console.error('Error setting data:', error);
    }
}
2

Wait for Checkpoint

Wait for the checkpoint to be completed (typically 10-30 minutes).
You can monitor checkpoint status using the shib.js library.
3

Check Inclusion

Verify that your transaction hash is included in the checkpoint on Ethereum.
4

Trigger Exit

Use the shib.js SDK to call the exit function of the RootChainManager.
const shib = require('@shibaswap/shib');

async function exitToken(txHash) {
    try {
        const exitResult = await shib.exitERC20({
            burnTransactionHash: txHash,
            logEventSignature: '0x...', // Your event signature
            from: 'YOUR_WALLET_ADDRESS'
        });
        console.log('Exit initiated:', exitResult);
    } catch (error) {
        console.error('Exit error:', error);
    }
}

Security Features

The Shibarium to Ethereum bridge includes several security mechanisms:
  • Validator Verification: Multiple validators must approve checkpoint transactions
  • Predicate Contracts: State changes on Ethereum are restricted to authorized contracts
  • Event Verification: All transfers are verified through event logs
  • Checkpoint Inclusion: Transactions must be included in official checkpoints
This multi-layered security approach ensures that only valid and verified transactions can trigger state changes on Ethereum.

Timeframes

OperationTypical Duration
Transaction on ShibariumImmediate
Checkpoint Creation10-30 minutes
Exit Process30 minutes - 1 hours
Total Transfer Time40 minutes - 6.5 hours
Actual times may vary based on network congestion and validator activity.

Troubleshooting

Next Steps