PoS Bridge
Please check the latest Matic.js documentation on PoS to get started.
A bridge is basically a set of contracts that help in moving assets from the root chain to the child chain. There are primarily two bridges to move assets between Ethereum and Polygon. The first one is the Plasma bridge and the second one is called the PoS Bridge or Proof of Stake bridge. Plasma bridge provides an increased security guarantee due to the Plasma exit mechanism.
However, there are certain restrictions on the child token and there is a 7-day withdrawal period associated with all exits/withdraws from Polygon to Ethereum on the Plasma bridge.
This is quite painful for those DApps/users who need some flexibility and faster withdrawals, and are happy with the level of security provided by the Polygon Proof-of-Stake bridge, secured by a robust set of external validators.
Proof of stake based assets provides PoS security and faster exit with one checkpoint interval.
Steps to use the PoS Bridge
Before we enter into this section of the docs, it may help to have a thorough understanding of some terms as you'll interact with them while trying to use the bridge: Mapping and the State Sync Mechanism.
Then, the first step to using the PoS bridge is mapping the Root Token and Child Token. It means that the token contract on the root chain and the token contract on the child chain have to maintain a connection (called mapping) to transfer assets between themselves. If you're interested in submitting a mapping request, please do that using this guide.
At a lower level and with more detail, this is what happens:
Deposit
- Owner of the asset (ERC20/ERC721/ERC1155) token has to approve a specific contract on the PoS bridge to spend the amount of tokens to be transferred. This specific contract is called the Predicate Contract (deployed on the Ethereum network) which actually locks the amount of tokens to be deposited.
- Once the approval is given, the next step is to deposit the asset. A function call has to be made on the
RootChainManager
contract which in turn triggers theChildChainManager
contract on the Polygon chain. - This happens through a state sync mechanism which can be understood in detail from here.
- The
ChildChainManager
internally calls thedeposit
function of the child token contract and the corresponding amount of asset tokens are minted to the user's account. It is important to note that only theChildChainManager
can access thedeposit
function on the child token contract. - Once the user gets the tokens, they can be transfered almost instantly with negligible fees on the Polygon chain.
Withdrawals
- Withdrawing assets back to Ethereum is a 2-step process in which the asset token has to be first burnt on the Polygon chain and then the proof of this burn transaction has to be submitted on the Ethereum chain.
- It takes about 20 mins to 3 hours for the burn transaction to be checkpointed into the Ethereum chain. This is done by the Proof of Stake validators.
- Once the transaction has been added to the checkpoint, proof of the burn transaction can be submitted on the
RootChainManager
contract on Ethereum by calling theexit
function. - This function call verifies the checkpoint inclusion and then triggers the Predicate contract which had locked the asset tokens when the assets were deposited initially.
- As the final step, the predicate contract releases the locked tokens and refunds them to the users account on Ethereum.
Once mapping is done, you can either use the matic.js SDK to interact with the contracts or you can do the same without the SDK. However, the matic.js SDK is designed in a very user friendly way to make the asset transfer mechanism very easy to integrate with any application.