Skip to content

Commit

Permalink
docs: updating gas token docs
Browse files Browse the repository at this point in the history
  • Loading branch information
praetoriansentry committed Mar 28, 2024
1 parent d96aa86 commit 07f5b90
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cdk_bridge_infra.star
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def start_bridge_ui(plan, args, bridge_service):
"ETHEREUM_FORCE_UPDATE_GLOBAL_EXIT_ROOT": "true",
"ETHEREUM_PROOF_OF_EFFICIENCY_CONTRACT_ADDRESS": zkevm_rollup_address,
"ETHEREUM_ROLLUP_MANAGER_ADDRESS": zkevm_rollup_manager_address,
"ETHEREUM_EXPLORER_URL": "",
"ETHEREUM_EXPLORER_URL": args["l1_explorer_url"],
"POLYGON_ZK_EVM_EXPLORER_URL": args["polygon_zkevm_explorer"],
"POLYGON_ZK_EVM_NETWORK_ID": "1",
"ENABLE_FIAT_EXCHANGE_RATES": "false",
Expand Down
Binary file added docs/gas-token-img/09_bridge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/gas-token-img/10_bridge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/gas-token-img/11_bridge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/gas-token-img/12_bridge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/gas-token-img/13_bridge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/gas-token-img/14_bridge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/gas-token-img/15_bridge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
103 changes: 98 additions & 5 deletions docs/gas-token.org
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@ For the rest of this guide I'll probably only be interested in three
of these mapped services: the bridge UI, the L1 RPC, and the L2 RPC.

To get started let's extract the generated files and take a look at
the ~gasTokenAddress~ (note: you'll need to have [[https://jqlang.github.io/jq/][jq]] installed):
the ~gasTokenAddress~:

#+begin_src bash
kurtosis files download cdk-v1 zkevm /tmp
cat /tmp/zkevm/create_rollup_parameters.json | jq '.gasTokenAddress'
kurtosis service exec cdk-v1 contracts-001 "cat /opt/zkevm/create_rollup_parameters.json"
#+end_src

Running this command will give us the address of our ERC20 token. In
Expand All @@ -55,10 +54,12 @@ this command, you'll also need to have the [[https://book.getfoundry.sh/getting-
installed.

#+begin_src bash
# this should be set to the gas token address that you saw in the previous command
gta="0xBDF337Ae0209B33285034c476f35733BFC890707"
cast send \
--mnemonic "code code code code code code code code code code code quality" \
--rpc-url "$(kurtosis port print cdk-v1 el-1-geth-lighthouse rpc)" \
"$(jq -r '.gasTokenAddress' /tmp/zkevm/create_rollup_parameters.json)" \
"$gta" \
'mint(address,uint256)' \
0x85dA99c8a7C2C95964c8EfD687E95E632Fc533D6 1000000000000000000000000000
#+end_src
Expand All @@ -67,7 +68,7 @@ Assuming that worked we can check our token balance as well:
#+begin_src bash
cast call \
--rpc-url "$(kurtosis port print cdk-v1 el-1-geth-lighthouse rpc)" \
"$(jq -r '.gasTokenAddress' /tmp/zkevm/create_rollup_parameters.json)" \
"$gta" \
'balanceOf(address)(uint256)' \
0x85dA99c8a7C2C95964c8EfD687E95E632Fc533D6
#+end_src
Expand Down Expand Up @@ -104,10 +105,13 @@ menu:

In the modal, you'll want to paste the ERC 20 Gas Token address that
we found earlier with this command:

#+begin_src bash
cat /tmp/zkevm/create_rollup_parameters.json | jq '.gasTokenAddress'
#+end_src

In my case, it's ~0xBDF337Ae0209B33285034c476f35733BFC890707~

[[file:gas-token-img/02_bridge.png]]

Confirm the details of your token and then click the add button.
Expand Down Expand Up @@ -146,3 +150,92 @@ see the bridge value as native value on L2.

[[file:gas-token-img/08_bridge.png]]

To complete the test here, lets transfer some of the value on L2 to
another address. In my case, I'll send some value to this address
~0x125fb391ba829e0865963d3b91711610049a9e78~:

[[file:gas-token-img/09_bridge.png]]

After importing the private key
~0903a9a721167e2abaa0a33553cbeb209dc9300d28e4e4d6d2fac2452f93e357~ for
this account, I can see the balance in metamask.

[[file:gas-token-img/10_bridge.png]]

Now let's try to withdraw it! After initiating the withdraw
transaction, we'll have to wait for our tx's data to be proven on L1.

[[file:gas-token-img/11_bridge.png]]

As of 2024-03-27, there might be a small bug in the bridge UI which
causes the transaction not to be claimable on L1 with the
UI. Essentially the bridge UI is selecting the wrong destination
network so the proof will not validate. That being said, it's possible
to claim directly using the smart contracts.

[[file:gas-token-img/12_bridge.png]]

We'll put together a more comprehensive script later, but if you
wanted to see how to use ~cast~ and the bridge service to do a bridge
claim, it would look something like this. If you want to run this
yourself, I'd recommend going line by line and tweaking as needed.

#+begin_src bash
# Setup some vars for use later on
skey="0903a9a721167e2abaa0a33553cbeb209dc9300d28e4e4d6d2fac2452f93e357"
destination_net="0"
destination_addr="0x125FB391bA829e0865963D3B91711610049a9e78"
bridge_addr="0xD71f8F956AD979Cc2988381B8A743a2fE280537D"
meta_bytes="0x"

# Grab the endpoints for l1 and the bridge service
rpc_url="http://$(kurtosis port print cdk-v1 el-1-geth-lighthouse rpc)"
bridge_api_url="$(kurtosis port print cdk-v1 zkevm-bridge-service-001 bridge-rpc)"

# the signature for claiming is long - just putting it into a var
claim_sig="claimAsset(bytes32[32],bytes32[32],uint256,bytes32,bytes32,uint32,address,uint32,address,uint256,bytes)"

# Get the list of deposits for the destination address
curl -s "$bridge_api_url/bridges/$destination_addr?limit=100&offset=0" | jq '.' > bridge-deposits.json

# Filter the list of deposits down to the first claimable tx that hasn't already been claimed and is destined for L1
jq '[.deposits[] | select(.ready_for_claim == true and .claim_tx_hash == "" and .dest_net == '$destination_net')] | .[0]' bridge-deposits.json > claimable-tx.json


# use the bridge service to get the merkle proof of our deposit
curr_deposit_cnt=$(jq -r '.deposit_cnt' claimable-tx.json)
curr_network_id=$(jq -r '.network_id' claimable-tx.json)
curl -s "$bridge_api_url/merkle-proof?deposit_cnt=$curr_deposit_cnt&net_id=$curr_network_id" | jq '.' > proof.json

# get our variables organized
in_merkle_proof="$(jq -r -c '.proof.merkle_proof' proof.json | tr -d '"')"
in_rollup_merkle_proof="$(jq -r -c '.proof.rollup_merkle_proof' proof.json | tr -d '"')"
in_global_index=$(jq -r '.global_index' claimable-tx.json)
in_main_exit_root=$(jq -r '.proof.main_exit_root' proof.json)
in_rollup_exit_root=$(jq -r '.proof.rollup_exit_root' proof.json)
in_orig_net=$(jq -r '.orig_net' claimable-tx.json)
in_orig_addr=$(jq -r '.orig_addr' claimable-tx.json)
in_dest_net=$(jq -r '.dest_net' claimable-tx.json)
in_dest_addr=$(jq -r '.dest_addr' claimable-tx.json)
in_amount=$(jq -r '.amount' claimable-tx.json)
in_metadata=$(jq -r '.metadata' claimable-tx.json)

# Generate the call data, this is useful just to examine what the call will look loke
cast calldata $claim_sig "$in_merkle_proof" "$in_rollup_merkle_proof" $in_global_index $in_main_exit_root $in_rollup_exit_root $in_orig_net $in_orig_addr $in_dest_net $in_dest_addr $in_amount $in_metadata

# Perform an eth_call to make sure the tx will work
cast call --rpc-url $rpc_url $bridge_addr $claim_sig "$in_merkle_proof" "$in_rollup_merkle_proof" $in_global_index $in_main_exit_root $in_rollup_exit_root $in_orig_net $in_orig_addr $in_dest_net $in_dest_addr $in_amount $in_metadata

# Publish the actual transaction!
cast send --rpc-url $rpc_url --private-key $skey $bridge_addr $claim_sig "$in_merkle_proof" "$in_rollup_merkle_proof" $in_global_index $in_main_exit_root $in_rollup_exit_root $in_orig_net $in_orig_addr $in_dest_net $in_dest_addr $in_amount $in_metadata
#+end_src

This worked!

[[file:gas-token-img/14_bridge.png]]

Now we can confirm the claim went through using Metamask and the
bridge UI. Even though the bridge UI didn't allow me to claim, it does
correctly show that a claim was executed!

[[file:gas-token-img/15_bridge.png]]
5 changes: 3 additions & 2 deletions params.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ zkevm_contracts_repo: https://github.com/0xPolygonHermez/zkevm-contracts.git

zkevm_agglayer_image: nulyjkdhthz/agglayer:v0.1.0
zkevm_bridge_service_image: hermeznetwork/zkevm-bridge-service:v0.4.2
zkevm_bridge_ui_image: hermeznetwork/zkevm-bridge-ui:latest # TODO: better tags for the bridge ui
zkevm_bridge_ui_image: hermeznetwork/zkevm-bridge-ui:multi-network

# Port configuration.
zkevm_hash_db_port: 50061
Expand Down Expand Up @@ -150,7 +150,8 @@ zkevm_rollup_fork_id: 8
# The consensus contract name of the new rollup.
zkevm_rollup_consensus: PolygonValidiumEtrog

polygon_zkevm_explorer: "https://sepolia.etherscan.io/"
polygon_zkevm_explorer: "https://explorer.private/"
l1_explorer_url: "https://sepolia.etherscan.io/"

# If this is true, we will automatically deploy an ERC20 contract on
# L1 to be used at the gasTokenAddress
Expand Down

0 comments on commit 07f5b90

Please sign in to comment.