Skip to content

Commit

Permalink
chore: update guides (#88)
Browse files Browse the repository at this point in the history
* chore: update guides

* chore: add sdk link
  • Loading branch information
BC-A authored Jul 20, 2024
1 parent ee4ed91 commit de1ae6d
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
101 changes: 101 additions & 0 deletions src/guides/trustless-bridge.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,55 @@ In the L2 bridge contract, it does:

4. If step 3 succeeds, Mint the L2 token to pk_l2 with `leaf.amount`; or deny the minting request.

**Detailed steps:**

1. The user calls [deposit](https://github.com/0xEigenLabs/eigen-sdk-js/blob/master/examples/zkevm/erc20/deposit.js) through the SDK.
2. The SDK calls the bridgeAsset function of the Bridge contract with the following parameters:
- destinationNetwork
- destinationAddress
- amount
- tokenAddress
3. The Bridge contract interacts with the GlobalExitRoot contract. If the L2 does not have the corresponding token, a wrapped token will be created, and the amount of the original tokens will be transferred to the Bridge contract. The deposit is executed, generating a new L1EMTRoot. The parameters for the deposit are as follows:
```
getLeafValue(
_LEAF_TYPE_ASSET,
originNetwork,
originTokenAddress,
destinationNetwork,
destinationAddress,
leafAmount,
keccak256(metadata)
)
metadata = abi.encode(
_safeName(token),
_safeSymbol(token),
_safeDecimals(token)
);
```
4. The bridge-service listens to the Bridge contract. After detecting a BridgeEvent, it retrieves the L1 EMT root from the GlobalExitRoot.
5. The bridge-service then updates the L2's GEMT (GlobalExitRootL2).
6. The user calls [deposit_claim](https://github.com/0xEigenLabs/eigen-sdk-js/blob/master/examples/zkevm/erc20/deposit_claim.js) through the SDK, requiring the transaction hash of the deposit.
7. The SDK obtains the merkle proof, L1 EMT root, and L2 EMT root from the bridge-service.
8. The SDK then calls the claimAsset function of the Bridge contract with the following parameters:
- smtProof
- index
- mainnetExitRoot, L1 EMT root
- rollupExitRoot, L2 EMT root
- originNetwork,
- originTokenAddress,
- destinationNetwork,
- destinationAddress,
- amount,
- metadata,
9. The GlobalExitRoot contract calls the Verifier contract to verify the merkle proof. Upon successful verification, it transfers the funds to the destination address on L2.
**L2 -> L1**
Expand Down Expand Up @@ -94,3 +143,55 @@ In the L1 bridge contract, it does:
3. Verify the Merkle proof with the leaf over the L2 EMT root;
4. If step 3 succeeds, Transfer the L1 token from Bridge.sol contract address to pk_l1 with `leaf.amount`; or deny the minting request.
**Detailed steps:**
1. The user calls [withdraw](https://github.com/0xEigenLabs/eigen-sdk-js/blob/master/examples/zkevm/erc20/withdraw.js) through the SDK.
2. The SDK calls the bridgeAsset function of the Bridge contract on L2 with the following parameters:
- destinationNetwork
- destinationAddress
- amount
- tokenAddress
3. The Bridge contract interacts with the GlobalExitRootL2 contract, destroys the user's tokens, and executes a deposit, generating a new L2EMTRoot.
4. The bridge-service listens to the Bridge contract on L2. After detecting a BridgeEvent, it retrieves the L2EMT root from the GlobalExitRootL2 and stores it in the database.
5. Eigen-Zeth retrieves the GEMT from the GlobalExitRoot contract on L1 for each transaction. After obtaining the GEMT
6. Eigen-Zeth calls the sequence_batches function of the ZkVM with an array of the following structure:
```
BatchData {
transactions: rlp_vec,
global_exit_root,
timestamp: block.timestamp.as_u64(),
};
```
7. Eigen-Zeth retrieves the L2 EMT root from the bridge-service.
8. Eigen-Zeth then calls the verify_batches function of the ZkVM with the following parameters, where proof_data.proof refers to the ZKP proof:
```
verify_batches(
0,
last_verified_block,
last_verified_block + 1,
zeth_last_rollup_exit_root,
proof_data.post_state_root,
proof_data.proof,
proof_data.public_input,
)
```
9. The ZkVM contract calls the Groth16Verifier contract to verify the ZKP proof. After successful verification
10. The ZkVM contract calls the GlobalExitRoot contract to update the GEMT.
11. The user calls [withdraw_exit](https://github.com/0xEigenLabs/eigen-sdk-js/blob/master/examples/zkevm/erc20/withdraw_exit.js) through the SDK and needs to provide the transaction hash of the withdraw.
12. The SDK obtains the merkle proof, L1 EMT root, and L2 EMT root from the bridge-service.
13. The SDK then calls the ClaimAsset function of the Bridge contract on L2.
Binary file modified static/img/zkvm/zkvm-bridge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit de1ae6d

Please sign in to comment.