Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@ This workshop follows through sending transactions on Arbitrum, inspecting their
## Useful links
* Arbitrum One RPC - https://arb-mainnet.g.alchemy.com/v2/cAVH7BTBvbzIucuwkjbltCH-RxNkFCe1
* Ethereum RPC - https://mainnet.infura.io/v3/6faa1b9b8d274a7f96192e868a65f6d4
* Follow along tx id if not sending your own- `0xb6f34cb1a7ef3d6d2e062815df80b47a151cd10026227a7f5326912a257602bb`
* L1/L2 gas -https://developer.arbitrum.io/arbos/gas
* Follow along tx id if not sending your own - `0xb6f34cb1a7ef3d6d2e062815df80b47a151cd10026227a7f5326912a257602bb`
* L1/L2 gas - https://developer.arbitrum.io/arbos/gas
* Transaction lifecycle - https://developer.arbitrum.io/tx-lifecycle
* ArbOS precompiles - https://developer.arbitrum.io/arbos/precompiles
* RLP encoding - https://ethereum.org/en/developers/docs/data-structures-and-encoding/rlp/

## Prerequisites
Please install the following, if you don't have them already
* An ethereum wallet (eg metamasdk browser extension)
* An ethereum wallet (eg metamask browser extension)
* [git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) - version control system
* [curl](https://curl.se/) - A http request util, probably installed by default
* [curl](https://curl.se/) - An HTTP request util, probably installed by default
* [Foundry](https://github.com/foundry-rs/foundry) - tools for, amongst other things, making ethereum JSON-RPC requests
- run: `curl -L https://foundry.paradigm.xyz | bash`
- followed by `foundryup`
* [jq](https://stedolan.github.io/jq/) - might be installed by default
- Mac OS - `brew install jq`
- Ubuntu - `apt get install jq`
- Ubuntu - `apt-get install jq`
* [brotli](https://github.com/google/brotli) - compression algorithm
- Mac OS - `brew install brotli`
- Ubuntu - `apt get install brotli`
- Ubuntu - `apt-get install brotli`

You may need to open a new shell after installing these

Expand All @@ -34,7 +34,7 @@ In a new shell do the following:
```
git clone git@github.com:yahgwai/devcon-workshop.git
```
1. Test foundry exists - if it doesn't foundry installed properly.
1. Test foundry exists - if it doesn't, foundry didn't install properly.
```
cast --version
```
Expand Down Expand Up @@ -64,7 +64,7 @@ Once you've chosen a transaction hash to use, set it as an environment variable
TX_ID=<tx id>
```

## Step 2 - Inpect the transaction receipt
## Step 2 - Inspect the transaction receipt
1. Get the transaction receipt by calling the ARB_ONE rpc, and prettify with jq.
```
curl -s -X POST -H "Content-Type: application/json" \
Expand All @@ -84,18 +84,18 @@ TX_ID=<tx id>
```
echo $GAS_USED_L1
```
Is the value what you expected? You might have expected this value to be much lower as all we need L1 gas for is to pay for call data. Call data is only 16 gas per byte, and standard token transfer only has around 190 bytes when [RLP](https://ethereum.org/en/developers/docs/data-structures-and-encoding/rlp/) encoded. A quick calculation shows that we should have expected to use around 16 * 180 = 2880 units of l1 gas which probably isn't the same order of magnitude as the value you have for `gasUsedForL1`. But remember that although `gasUsedForL1` pays for L1 costs, it is in units of L2 gas. We'll explore that concept more in the nexts stepts.
Is the value what you expected? You might have expected this value to be much lower as all we need L1 gas for is to pay for call data. Call data is only 16 gas per byte, and standard token transfer only has around 190 bytes when [RLP](https://ethereum.org/en/developers/docs/data-structures-and-encoding/rlp/) encoded. A quick calculation shows that we should have expected to use around 16 * 180 = 2880 units of l1 gas which probably isn't the same order of magnitude as the value you have for `gasUsedForL1`. But remember that although `gasUsedForL1` pays for L1 costs, it is in units of L2 gas. We'll explore that concept more in the next steps.
4. Also store the value of blockhash and block number for later use:
```
L2_BLOCKHASH=<tx.blockHash>
L2_BLOCKNUM=<tx.blockNumber>
```

### Step 3 - Getting the L1 base fee estimate as seen on L2
1. Lets try to convert `gasUsedForL1` from units of L2 gas to L1 gas to see if the amount matches up with our rought estimate above. To do that we need to find out:
1. Let's try to convert `gasUsedForL1` from units of L2 gas to L1 gas to see if the amount matches up with our rough estimate above. To do that we need to find out:
- What the L1 base fee was at the time, as seen by the L2
- What the L2 base fee was at the time
2. The L2 periodically receives information about the L1 base fee and updates it's local view. It also adjusts it based on how the accuracy of previous estimates. You can read more about this process [here]( https://developer.arbitrum.io/arbos/l1-pricing#adjusting-the-l1-gas-basefee).
2. The L2 periodically receives information about the L1 base fee and updates its local view. It also adjusts it based on how the accuracy of previous estimates. You can read more about this process [here]( https://developer.arbitrum.io/arbos/l1-pricing#adjusting-the-l1-gas-basefee).
3. In order to find out what the L1 base fee estimate was at the time we can query the [getL1BaseFeeEstimate](https://github.com/OffchainLabs/nitro/blob/v2.0.7/contracts/src/precompiles/ArbGasInfo.sol#L93) function on the ArbGasInfo precompile which can be found at address `0x000000000000000000000000000000000000006c`. We can use `cast` to make this call, taking care to specify that we want the value as it was at the time the transaction was sent using the `L2_BLOCKHASH` var.
```
cast call --rpc-url $ARB_RPC -b $L2_BLOCKHASH 0x000000000000000000000000000000000000006c 'function getL1BaseFeeEstimate() external view returns (uint256)'
Expand Down Expand Up @@ -127,7 +127,7 @@ TX_ID=<tx id>

### Step 5 - comparison to actual bytes
1. We can now [RLP](https://ethereum.org/en/developers/docs/data-structures-and-encoding/rlp/) encode the transaction and measure the number of bytes. Note that we don't expect this to be exactly the same due to a number of reasons:
- The gas used for L1 includes some compression factor - this isn't as high as when we the transaction is included in a batch, but it is a factor
- The gas used for L1 includes some compression factor - this isn't as high as when the transaction is included in a batch, but it is a factor
- There is also a small amount L1 gas that must be paid for batch overheads
2. RLP encode the transaction:
```
Expand Down Expand Up @@ -156,7 +156,7 @@ TX_ID=<tx id>

echo $BATCH_TX_ID
```
4. The sequencer submits the batch via the [addSequencerL2BatchFromOrigin](https://github.com/OffchainLabs/nitro/blob/v2.0.0/contracts/src/bridge/SequencerInbox.sol#L143) function on the SequencerInbox. The batch is the data field in the call data. Given the fixed size of the other arguments we can be sure that the data field starts at position 458 in the call data. Let's download the data, then save everything after position 458 to file.
4. The sequencer submits the batch via the [addSequencerL2BatchFromOrigin](https://github.com/OffchainLabs/nitro/blob/v2.0.0/contracts/src/bridge/SequencerInbox.sol#L143) function on the SequencerInbox. The batch is the data field in the call data. Given the fixed size of the other arguments we can be sure that the data field starts at position 458 in the call data. Let's download the data, then save everything after position 458 to a file.
```
BATCH_TX_DATA=$(cast tx --rpc-url $ETH_RPC $BATCH_TX_ID input)
echo ${BATCH_TX_DATA:458} > txDataField.br
Expand All @@ -174,4 +174,4 @@ TX_ID=<tx id>
ls -l
```
Now compare the size of `batchData.txt` with `compressedBatchData.br`
7. Finally, open `batchData.txt` in a text editor. Can find your RLP encoded transaction - $TX_RLP - in the data?
7. Finally, open `batchData.txt` in a text editor. Can you find your RLP encoded transaction - $TX_RLP - in the data?