Skip to content

Conversation

gballet
Copy link
Owner

@gballet gballet commented Apr 24, 2025

This is an experiment to look into charging the gas "atomically" instead of on a per-leaf basis.

Differences are:

  • if there isn't enough gas to pay for the proving of all the leaves in a "cluster", then none of the leaves are added to the witness.
  • it's simpler, albeit more verbose: all corner cases where there is enough gas for one leaf but not another one, is
  • the witness is smaller
  • it will make the geth team happy, and it might even get merged some day!
  • it will require a spec change

The principle is simple:

  • Decouple the gas computation from the "touching"
  • Only return the "wanted" part from the gas computation
  • If an overflow is detected, just return ErrOutOfGas, which will cause all the remaining gas to be consumed - this simplifies all the issues we had of knowing when there isn't enough gas
  • touching does it blindly

TODO

  • run execution spec tests and confirm that it only fails on the tests that correspond to partial gas charging
  • update the spec
  • check the len(ret) > 0 part
  • get TestProcessVerkle to pass
  • shadowfork holesky it seems that the fork itself has been broken due to lack of maintenance, if this is broken by it (it shouldn't) then it will be fixed during the rebase
  • benchmark how much is lost when passing variadic arguments, and if this is optimized out by using the stack this is no longer needed as the API was changed to use a range instead.

@gballet gballet force-pushed the atomic-gas-charging branch 2 times, most recently from 76d2964 to 7c123ee Compare April 25, 2025 19:25
@gballet gballet force-pushed the atomic-gas-charging branch 2 times, most recently from 35d09b7 to 912098d Compare April 27, 2025 09:36
Signed-off-by: Guillaume Ballet <[email protected]>
@gballet gballet force-pushed the atomic-gas-charging branch from 912098d to cb65ee0 Compare April 27, 2025 14:54
gas1, wanted1 := aw.touchAddressAndChargeGas(addr, zeroTreeIndex, utils.BasicDataLeafKey, true, availableGas)
gas2, wanted2 := aw.touchAddressAndChargeGas(addr, zeroTreeIndex, utils.CodeHashLeafKey, true, availableGas-gas1)
return gas1 + gas2, wanted1 + wanted2
func (aw *AccessWitness) TouchContractCreateInit(addr []byte, availableGas uint64) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

availableGas parameter is redundant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants