header-langage
简体中文
繁體中文
English
Tiếng Việt
Scan to Download the APP
Partnered With:

How can developers reduce transaction costs on Ethereum Layer2?

Read this article in 9 Minutes
Blockchain developers need to be very careful about the amount of call data they require for their transactions, as this can have a significant impact on transaction fees for end users. This article Outlines some of the techniques you can use to reduce ca

Original title: Crunching the Calldata
Original article by David Mihal

Kxp, BlockBeats


Since 2020, Ethereum's expansion roadmap has been centered around a "Rollup" : an independent execution environment that inherits Ethereum's security using proofs (either zero-knowledge proofs or optimistic fraud proofs).


After years of development, Rollup has finally been deployed and is gaining adoption.Arbitrumoptimistic Rollup has been online for nearly a year, with more than $2.7 billion worth of assets deposited on the bridge, whileOptimismIt was a close second. Zero-knowledge rollups for specific applications such as Loopring and dydX are also widely used, and many competing generic zero-knowledge rollups will be launched in the coming months.


Although Rollup is fast now, some worry that its costs are too high.



In fact, Arbitrum and Optimism still have significantly higher transaction fees than "low fee" chains such as Solana and Polygon.


So, what's holding these rollups back?


Rollup economics


To understand transaction fees, we first need to break down the various costs incurred by blockchain exchanges:


· Execution

This is the cost to all nodes in a network to perform the transaction and verify that the result is valid (e.g., you actually own the ownership of the tokens you are transferring).


· Storage/status

This is the cost of updating the blockchain "database" with new values (e.g., the sender's balance decreases and the receiver's balance increases after the Token transfer).


· Data availability

In order for the blockchain to remain distrustable and verifiable by all, the blockchain must ensure that all relevant data about the transaction is publicly shared with all network participants. Essentially, it's about making sure everyone in the world can see your trade. Without this assurance, all kinds of attacks are possible (known as block attacks).


As we have seen, data availability is one of the key bottlenecks in today's blockchain.


Rollup: Transfers execution off-chain


Rollup's main advance is that it moves the execution and storage of the blockchain "off-chain", that is, on a limited set of nodes. Instead of having every Ethereum node in the network perform all transactions or store every update, we can delegate this task directly to the Rollup operator.


But does that mean we need to trust these operators? Isn't that centralization?


Rollup will inherit Ethereum's security using various proof types. Optimistic Rollup allows a single honest entity to submit a "proof of fraud" and win a reward for a misbehaving sequer, while ZK Rollup uses a proof of zero knowledge to prove that the Layer-2 chain has been properly updated.


Data availability tradeoffs


Moving execution off the main chain can greatly reduce the cost of execution and state storage, but rollups still need to publish their data to the Layer-1 chain to ensure data availability. Essentially, Rollup pays low Layer-2 execution and storage costs, but still needs to pay Layer-1 fees to publish their data.


This can be seen on the "Advanced TxInfo" TAB of any transaction in the ArbiScan block browser. Transaction costs are made up of the cost of the call data published to L1, the calculations used on L2, and L2 storage, and L1 call data is the primary source of costs in almost all transactions. That said, the biggest problem Rollup needs to solve is the cost of publishing data to Layer-1.


The future of data availability


While data availability is still a bottleneck for Rollup, it will ease over time.


Ethereum upgrades such asProto-DankshardingAnd finally completeDankshardingWill greatly reduce the cost of publishing data to Ethereum. Moreover, programs such as Celestia are designed to provide independent chains that are specifically set up to provide cheap data availability.


In the long run, systems like Danksharding and Celestia will reduce the cost of data availability and increase its richness, while throwing the problem back to the execution level. However, these solutions will take time to fully mature: Celestia is still a few months away from releasing its mainnet, and it could be more than a year before Ethereum can add data availability upgrades like Proto-Danksharding.


Call data compression


Data compression is a field older than computers themselves. Morse code, invented in 1838, is the earliest known application of data compression. Then, the use of computers accelerated research into data compression, and algorithms like Huffman coding were invented in the 1950s.


Since Rollup is cheap to implement but expensive to make available, these teams have been incorporating data compression algorithms into their protocols. Optimism has incorporated the Zlib compression algorithm into their Rollup, and Arbitrum's upcoming Nitro upgrade is usedbrotliCompression algorithm.


Note: This experiment may have been done hastily before Nitro was released in order to experiment on uncompressed Arbitrum call data.


Data compression algorithms are certainly useful tools to help reduce the cost of these calls to data. Compressing blockchain transactions, however, is a difficult task: What data compression does is look for the same patterns and shorten them. However, transactions are full of addresses, hashes, and signatures, which are essentially "random data" to these compression algorithms and have no similarity.


Only when developers start to care about reducing the call data in their applications will the cost of such data really come down. Sky-high Gas prices in 2020-2021 are forcing developers to optimize their code to minimize execution and state storage.



As we transition to the L2 world, call data goes from the cheapest resource to the most expensive resource, so developers have to learn these new optimizations all over again.


Experiment: How far can we compress a simple Token transmission


Now let's do an experiment on Arbitrum: How far can we compress the call data needed for a simple Token transfer? To what extent do these optimizations reduce transaction costs?


Experimental design and control group trading


To conduct our experiment, we will set up a simple smart contract that transfers a Token from the transaction sender to any given address.


The smart contract does require the user to send a approve() transaction before sending our actual test transaction. Because of this limitation, users may not want to use this system for Token transfer. However, the cost savings used in this experiment can also be applied to other contracts (e.g., optimized Uniswap routers).


At the beginning of the experiment, we will send a "control" transaction to get the benchmark cost, which calls a simple Solidity function for passing the Token address, the recipient address, and the number of tokens to be transferred.


Our test transaction used 576,051 ArbiGas at a total cost of $0.43.



Data reduction


The call data for the control group has a lot of unnecessary data that we can strip out. First, we need to remove all zeros, which are just for data padding. Although they are cheaper than non-zero bytes, they still incur a cost, so we need to remove them.


There is also a 4-byte function signature at the beginning, which is the identifier of which Solidity function we are trying to call. We can delete this data and let our code infer what action to take.


After this two-step optimization we have reduced the bytecode from 100 to 43. As a result, our test transaction used 494,485 ArbiGas (14% less) at a cost of $0.37.



The "assistant" contract


Most of our data is now made up of two addresses in the call data: one is the Token address we want to transfer, and the other is the receiver address of the transfer.


However, we can assume that most users are transferring the same few tokens (WETH, Dai, USDC). So, one way to remove the entire Token address from the call data is to deploy a special "helper" contract for that Token. If we could send the transaction to this helper, we would avoid the need to send the Token address altogether.


This reduced the data bytecode to 23 bytes, and the test transaction used 457,546 ArbiGas (21% less than the control) at a cost of $0.34.



Address query table


In the previous phase we used a "helper contract" to remove an address from the call data, but our call data still contains another address.


Can we find a more reliable way to "compress" addresses?


Fortunately, Arbitrum has a built-in contract called the Address Table Registry, which we can use to shorten our call data.


This contract is essentially a "phone book" that converts a 20-byte Ethereum address into a simple integer. Imagine that your friend has a traditional phone book: Instead of reading your entire phone number to them, just say "I'm number four on page 200 of the phone book" and ask them to look it up.


Therefore, we can make a contract and replace the full address with an "address index" and look it up internally.


This eliminates both the Token address and the receiving address, reducing the call data to 9 bytes. Thus, our test transaction used 428,347 ArbiGas (26% less than the control) at a cost of $0.32.



Method merging


Finally, let's put it all together:


· Remove data fill and function selector

· Use auxiliary contracts to remove common addresses

· Use the Arbitrum address table to shorten other addresses


All together, our call data size is now only 6 bytes. The final test transaction used 426,529 ArbiGas (also 26% less than the control group and slightly less than the previous test group) at a cost of $0.32.



Lossy compression


All of the compression methods we just talked about are "lossless compression," meaning that the compressed output contains all the same data as the original input.


But just as photo and video files often use "lossy compression" algorithms to remove unnecessary information, we can also delete unnecessary data in most cases.


We can eliminate unnecessary precision by shortening the number. For example, the ERC-20 tokens tend to have an accuracy of 18 decimal places, but most users typically only care about 4 decimal places. To do this, we could set up a contract that accepts numbers 8 decimal places by default and multiplies them by 10 to the power of 10, with ancillary features for users who need more precision.


Again, the date is usually expressed as "the number of seconds since January 1, 1970" (also known as Unix time). The contract can reduce the size of this integer by setting different units of time, such as minutes, hours, or days, and can set its own "epoch", for example, January 1, 2015.


Summary of experience


In short, call data has gone from being the cheapest resource on Ethereum L1 to the most expensive resource on Ethereum Rollup. Data availability technologies such as Proto-Danksharding and Celestia will eventually solve this problem, but neither is online yet, and it could be years before data availability becomes cheap and widespread.


Therefore, blockchain developers need to be very careful about the amount of call data they need for their transactions, as this can have a significant impact on transaction fees for end users.


This article Outlines some of the technical approaches that can be used to reduce call data, which I believe will become increasingly abundant as more of the "optimization army" turns its attention to Layer 2.


Original link


Welcome to join the official BlockBeats community:

Telegram Subscription Group: https://t.me/theblockbeats

Telegram Discussion Group: https://t.me/BlockBeats_App

Official Twitter Account: https://twitter.com/BlockBeatsAsia

举报 Correction/Report
Choose Library
Add Library
Cancel
Finish
Add Library
Visible to myself only
Public
Save
Correction/Report
Submit