[Ongoing] Bridge Contract Gas Optimization with CHI Gastoken

Motivation

In the Ethereum blockchain, the value of Ether and Gas has always been determined by the market - the cap of which saw a 10x change over the past year. With the ETH/USD at its all-time high and tons of extremely active DeFi projects, the transaction fees we pay in Gas proves to be both unpredictable and high for the near future. While the Ethereum Community’s proposed solutions like EIP-1559 are still in the works, the best mitigation for high gas fees in the meantime is using CHI Gastoken.

Concept

Since the EVM now gives a gas refund when freeing contract storage or destroying child contracts, one can “bank” their gas by e.g. creating many dummy child contracts, then destroying them when making their desired expensive message call. Gastokens are a class of ERC20 tokens that encapsulate that action inside their token mint and token burn functions. The fact that minting can take place at any time - preferably during the network’s downtime with low overall gas price & overall transaction count - and does not need to be confirmed quickly further enables the developer to mitigate the impact of gas fee fluctuation through good planning.
CHI Token by 1Inch exchange is currently the most efficient actively-used Gastoken.
gastokens
Learn more about CHI Gastoken in their original post.

Objective

  • Update the Bridge Vault contract to use CHI token to reduce gas cost for expensive functions

ETH/Token Unshielding is the most gas-intensive action in Incognito’s Bridge right now, costing upwards of 50$ each Unshield call. If necessary, the deployment of our future contracts can be made cheaper using CHI token as well.

  • Devise a CHI minting strategy
  • Keep all contract functions agnostic to the CHI token usage

The update should not make core functions dependent on CHI. Functions should proceed as before in the case no CHI is available; plus it should be easy for a future upgrade to move away from this gas token in favor of a better gas solution, if one arises.

Timeline

  • Feb 2021
    • Code working prototype for the contract update
    • Create unit tests for relevant app flows in local & test environments
    • Prepare scripts for upgrading & minting CHI
  • Mar 2021
    • Review contract and tests
    • Deploy to test network; measure & extrapolate the gas saving with CHI token
    • Deploy the upgrade to mainnet environment
16 Likes

Would it make sense to utilize the CHI token in concert with one of the other gas tokens that offer refunds?

UNDG ENOL GASG

3 Likes

This proposal has already been proposed to the core team by @Matt6412 , here.

They replied and stated they would need time to research it. No further updates have been given.

3 Likes

Yes I had this idea and proposed to team to implement (for them to do)

What is the point in making a proposal like this? As far as I have seen these are core team initiatives so is op core team member?

3 Likes

Probably you are correct.

Btw, I had a project idea in my mind. Now, I can drop it. Relaxed :slight_smile:

3 Likes

Glad to see them implement my idea, it hopefully will make a difference! Layer2 imo should also be explored . @cusdt.eth is all over that one!

5 Likes

Progress Update, as of Feb 26:

  • Solidity coding complete.
  • CHI Minting Script coding complete.
  • Unshield-with-CHI unit tests complete. Local network & forked mainnet environments ready.

Next steps in the development :

  • Analyze the gas saving in our test simulations
  • Prepare for testnet deployment

See https://github.com/incognitochain/bridge-eth/tree/gastoken

6 Likes

:grimacing:

2 Likes

Refunds are currently only applied after transaction execution, so they cannot affect how much gas is available to any particular call frame during execution. Hence, removing them will not break the ability of any code to execute, though it will render some applications economically nonviable.

GasToken in particular will become valueless. DeFi arbitrage bots, which today frequently use either established GasToken schemes or a custom alternative to reduce on-chain costs, would benefit from rewriting their code to remove calls to these no-longer-functional gas storage mechanisms.

[source]

… and millions hundreds of tens of thousands of GT and CHI users cried out in pain …

1 Like

Any updates to this topic since the proposed or planned removal of gas refunds?

Hi. Thanks for the tip. We’re aware of the new EIP-3298’s planned changes to remove gas refunds from the EVM code, and are currently weighing the options.
It does seem like this EIP-3298 could go live in July alongside EIP-1559. This will go a long way to address the gas spike problem, which is the ultimate goal anyway.

2 Likes

Gas tokens are gone… Unfortunately!

Not yet. Did you read the post above your post?

1 Like

I think 1559 will pass , has to pass miners have to be smart!

Will pass but implementation/testing requires time.

1 Like