MultiversX Tracker is Live!

Transient Storage: Temporary Space on a Permanent Blockchain

Etherum Reddit

More / Etherum Reddit 140 Views

Transient Storage: Temporary Space on a Permanent Blockchain

Introduction

Transient Storage creates a place in a block with temporary data for Ethereum transactions. The benefits are significant gas savings for users, for rollups, and in making certain aspects of smart contracts more secure. We often take for granted the permanence of data on the blockchain, but there is value in being able to store temporary data too.

https://preview.redd.it/ef9u81hz9vta1.png?577&format=png&auto=webp&s=5ef2f21af1777386f227897a52d1be4abebcdff6

Contract Storage on Ethereum

Whenever a smart contract is deployed to Ethereum, it receives an amount of storage that it can use to hold data. This storage contains everything a contract may need; whitelisted addresses, who the contract owner is, what the balances of token holders are, and so on.

When one of these pieces of data needs to be updated, like changing the owner of a contract for example, a transaction is submitted with the old owner’s address as well as the new owner’s. This rewrites the data held in contract storage, and a record of the old contract owner is maintained in the transaction history.

The problem is that this operation of writing or rewriting data to the blockchain is the most expensive operation that can be performed (it involves updating Ethereum’s state trie, which you can read about here). Despite the cost, this operation happens frequently out of necessity.

Memory Storage

If a contract’s storage is the hard drive, you can think of memory storage as the RAM. Memory storage is where a contract stores the data it actually uses when performing a transaction (retrieving the old contract owner’s name and updating it with the new one, for example). Once a transaction is finalized, any relevant new values in memory storage are posted or updated in contract storage, i.e. the expensive transaction. Everything that shouldn’t be posted to contract storage is deleted.

https://preview.redd.it/1bl3ma52avta1.png?500&format=png&auto=webp&s=a73ce3015408c14972412c2f9a0c90a25d762525

One might wonder if memory storage is sufficient to allow “transient storage,” a place for temporary data to exist for the duration of a transaction. This suspicion is somewhat correct, and there are some implementations of transient storage on Ethereum today that do things this way. There are however limitations to using memory storage as a temporary data source that necessitate transient storage as a new feature.

EIP-1153: Transient Storage

EIP-1153 creates a new space in blocks to hold data temporarily while a transaction is executed. This approach to transient storage delivers several benefits that are explained below, including cheaper deployment of some contracts, cheaper costs for rollups reporting their state to Ethereum, and protection from re-entrancy attacks.

https://preview.redd.it/ahk2ntu3avta1.png?636&format=png&auto=webp&s=2e232d718e72de6a140452252f44434a86db16bc

Cheaper Contract Deployment

Many contracts today allow users to create completely new contracts, as in Uniswap when creating a new liquidity pool to swap two assets, or when setting up a new NFT contract with Manifold. When users use Uniswap or Manifold for this purpose, the contract they interact with “initializes” the new contract with some basic parameters. To do this it’ll have some generic data like the structure of the liquidity pool, or code compliant to the standard of ERC-721. Alongside the generic data there’ll also be some individual data that describes the specific assets in a pool or the fee it charges for trades, or the name of an NFT smart contract.

EIP-1153 enables the generic data (init code) to always stay the same by instead passing the individual data (constructor arguments) into transient storage. This method saves gas costs on deployments of these types of contracts since individual data is not posted on-chain.

Rollup Storage

Rollups aggregate transactions and submit them together to Ethereum in batches. When rollups submit to Ethereum, they submit the proof (the result of all the transactions), as well as the data executed itself. The data is published so that the proof can be verified as valid.

Transient storage can allow rollups to generate their proofs more efficiently. This reduces gas costs for all rollup submissions, and by extension, all transactions on rollups.

https://preview.redd.it/6x9aw4d5avta1.png?521&format=png&auto=webp&s=84b804016e493034dc639b56877221bb60691f0b

Read more about rollups here.

Re-Entrancy Attacks

A re-entrancy attack happens when a transaction is able to withdraw assets from a contract multiple times before stopping, often draining a contract of its funds. This happens when a vulnerable contract sends assets out first, then updates its balance afterwards. A re-entrancy attack gets in the middle of those two actions, preventing the vulnerable contract from updating its balance and allowing the attacker to drain it of its funds.

Re-entrancy attacks can be prevented with properly planned code, but transient storage makes them even easier to mitigate. By storing information about a withdrawal in transient storage, withdrawals will happen only for pre-determined amounts.

In Conclusion

Transient storage can reduce gas costs across a variety of complex smart contracts. This enables using dApps more cost-effectively while also enabling novel applications on Ethereum. Someone has already developed a way to give someone a quick, instant loan while keeping custody of the funds.

While transient storage benefits users, the bigger benefit is to the protocols that use it. Uniswap and Optimism have pushed aggressively for transient storage to be included in the Shanghai upgrade instead of staking withdrawals. The controversy around that motivated me to start this newsletter to keep people informed on developments in Ethereum. My hope is this information enables people to understand where Ethereum is going, and to add your voice on where you think that should be.

This write-up is a summary of the full version from my free newsletter!

Visit below, and consider signing up! You'll receive a write-up on blockchain every other week ????

https://ramiwrites.substack.com/p/transient-storage-temporary-space?sd=pf

Stay kind. Stay curious.

submitted by /u/phillistine
[link] [comments]

Get BONUS $200 for FREE!

You can get bonuses upto $100 FREE BONUS when you:
💰 Install these recommended apps:
💲 SocialGood - 100% Crypto Back on Everyday Shopping
💲 xPortal - The DeFi For The Next Billion
💲 CryptoTab Browser - Lightweight, fast, and ready to mine!
💰 Register on these recommended exchanges:
🟡 Binance🟡 Bitfinex🟡 Bitmart🟡 Bittrex🟡 Bitget
🟡 CoinEx🟡 Crypto.com🟡 Gate.io🟡 Huobi🟡 Kucoin.



Comments