Try   HackMD

ERC20 - ERC777 bridge

Actors

  • Alice and Charlie are 2 users of a DApp and want to exchange value using an ERC20 token.
  • The MainBridge contract locks tokens on the mainnet.
  • The ForeignBridge contract manages the minting and burning of the equivalent tokens on the Foreign chain
  • A group of validators watches the ERC20 token events to trigger intra-chain
  • The list of validators (addresses) are stored in the MainBridge and ForeignBridge contracts
  • A threshold is set on how many signatures are required to execute the intra-chain transfers.
  • The validators sign-off on intra-chain token deposits or withdrawals.

Assumptions on trust

  • Alice and Charlie trust the majority of the validators to act in their interest
  • Alice and Charlie assume the minimum threshold of validators is always online to process their intra-chain conversions.

Setup

An administrator ( currently the owner of the contracts ) adds an existing ERC20 token from the Main net in the ForeignBridge. This function creates a new (ERC777) token on the Foreign net and links the Mainnet address to the newly generated token.
The validators watch these events , and start watching Transfer() events on both chains. These watches are filtered on

  • Transfers towards the MainBridge on the Main net
  • Transfers towards the Foreignbridge on the Foreign net

Scenario

  1. Alice has some 'Sample ERC20' tokens on the mainnet and goes from Main-net to Foreign-net.
  2. On the Foreign-net, she will send tokens to Charlie.
  3. Charlie then redeems his received Foreign-net tokens for Main-net tokens.
Created with Raphaël 2.2.0Transfer to Foreign-netAliceAliceSample ERC20Sample ERC20MainBridgeMainBridgeValidatorValidatorForeignBridgeForeignBridgeSample ERC777Sample ERC777'Send 10 token to MainBridge`transfers 10 tokenSees Transfer() event to MainBridgesign mint eventvalidator 2 signs toovalidator 3 signs toowhen sign threshold is reachedsign mint eventfinalize mint requestmints 10 token for Alice
Created with Raphaël 2.2.0Usage on Foreign chainAliceAliceSample ERC777Sample ERC777CharlieCharlie'Send 1 token to Charlie'transfers 1 token to Charlie
Created with Raphaël 2.2.0Redeem on Main-netCharlieCharlieSample ERC777Sample ERC777ForeignBridgeForeignBridgeValidatorValidatorMainBridgeMainBridge'Send 1 token to ForeignBridge'transfers 1 tokencreates withdraw requestSees Transfer() event to ForeignBridgesign Withdraw requestvalidator 2 signsvalidator 3 signswhen sign threshold is reachedsign Withdraw requestfinalize withdrawBurn 1 tokenwithdraw(1,charlie)transfer 1 Sample ERC20 token

notes

  • after this flow , Alice still has 9 tokens locked in the MainBridge contract
  • Alice can redeem her 9 tokens using the same flow as Charlie

Token incentive for withdrawal

Alice needs the final withdrawal of her token executed on the main net - which costs gas.
Alice has 2 options:

  • Alice executes the token withdrawal herself , using the validator signatures. She pays for the gas.
  • Alice can incentivize someone else to do the transaction for her.

There is an incentivation scheme buit into the bridge , whereby Alice can offer a reward in tokens for anyone doing the final withdrawal transaction.

This is by offering a number of tokens as a reward to whoever executes the transaction.

Created with Raphaël 2.2.0Redeem on Main-net with token rewardAliceAliceForeignBridgeForeignBridgeCharlieCharlieMainBridgeMainBridge'Send 10 token to ForeignBridge'validation procedure takes placevalidator signatures are stored'I offer a reward of 1 SWT for doing my withdrawal'alices reward signatures is storedcharlie sees rewardCharlie executes withdrawal... using validators signatures... and alice's reward signaturewithdraw(10,alice)bridge sends 9 tokens to alice , 1 to charlie