tokamak-network / tokamak-thanos

MIT License
7 stars 3 forks source link

Improve gas cost by using transient storage #237

Closed nguyenzung closed 1 week ago

nguyenzung commented 2 weeks ago

Issue: The address of L2 native token is stored in the SystemConfig contract. The current flow of getting this address as below:

L1StandardBridge -> L1CrossDomainMessenger -> OptimismPortal -> SystemConfig

If L1StandardBridge query the address of L2 native token, the request goes throw L1CrossDomainMessenger and then OptimismPortal then SystemConfig. Later in the same transaction, if L1CrossDomainMessenger need the address L2 native token, it makes a call to OptimismPortal. It wastes some gas with this flow.

Suggestion We can save gas by using transition storage so that if a contract queries the address of L2 native token successfully, the address will be cached in transient storage.

https://soliditylang.org/blog/2024/01/26/transient-storage/

0x6e616d commented 2 weeks ago

We are using Solidity 0.8.15, but transient storage is introduced from 0.8.24. I think we will keep in mind and consider when we upgrade the Solidity version

DevUreak commented 2 weeks ago

If you don't upgrade the project version, the temporary storage will be difficult to use. This needs to be discussed.

nguyenzung commented 2 weeks ago

You are right. Let leave the issue here for the future discussion

suahnkim commented 1 week ago

DevUreak I think upgrading the solidity version is a good idea, but I don't think we have enough time and people to make sure that the upgrade is applied correctly.

Can we propose this idea directly to Optimism repo instead? and work on it separately outside of Thanos code for now?

If you are ok with that, please close the issue, and leave the reference issue here for record keeping?

DevUreak commented 1 week ago

@suahnkim That's a good idea. I will make a proposal regarding this to Optimism, and if the Core team allows, I will fork the project and test gas savings using tload.

nguyenzung commented 1 week ago

Let me close this issue https://github.com/tokamak-network/tokamak-thanos/issues/253#issuecomment-2336706112