Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read IntrinsicGas from FeeCurrencyDirectory #178

Merged
merged 8 commits into from
Aug 5, 2024

Conversation

ezdac
Copy link

@ezdac ezdac commented Jul 18, 2024

Closes #125

Implements:

  • refactor: now uses one combined object FeeCurrencyContext in block context for fee-currency related context info, storing both the exchange rates as well as the intrinsic fee currency gas costs
  • refactor: evm.Context.GasUsedForDebit removed from Context (which should be read only after initialization) and now passed as argument directly. The value is now stored in the state-transition's feeCurrencyGasUsed
  • read the fee-currency intrinsic gas cost from the FeeCurrencyDirectory on a per block context basis
  • introduce e2e test for intrinsic fee currency over-usage

@ezdac ezdac force-pushed the ezdac/intrinsic-gas-directory branch from 916de30 to 720d2d8 Compare July 18, 2024 15:10
@ezdac ezdac force-pushed the ezdac/intrinsic-gas-directory branch from 720d2d8 to 9b1d9fa Compare July 30, 2024 13:30
@ezdac ezdac force-pushed the ezdac/intrinsic-gas-directory branch 2 times, most recently from 36ce29a to 71082e6 Compare July 31, 2024 15:20
@ezdac ezdac marked this pull request as ready for review July 31, 2024 15:47
@ezdac ezdac force-pushed the ezdac/intrinsic-gas-directory branch from 71082e6 to ba82b0d Compare August 1, 2024 13:08
@ezdac ezdac requested a review from palango August 1, 2024 13:11
Copy link

@palango palango left a comment

Choose a reason for hiding this comment

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

Looks great, and nice independent commits.

Comments are mostly nits :)

cmd/evm/internal/t8ntool/execution.go Show resolved Hide resolved
common/celo_types.go Show resolved Hide resolved
contracts/fee_currencies.go Outdated Show resolved Hide resolved
contracts/fee_currencies.go Outdated Show resolved Hide resolved
return contracts.TryDebitFees(tx, from, pool.celoBackend)
//NOTE: we only test the `debitFees` call here.
// If the `creditFees` reverts (or runs out of gas), the transaction will
// not be invalidated here and will be included in the block.
Copy link

Choose a reason for hiding this comment

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

Will it be included in the block? Or just stay in the txpool?

Copy link
Author

Choose a reason for hiding this comment

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

It will be included in the block, since the txpool validation is successful here. (also see the discussion in #177 )

core/bench_test.go Outdated Show resolved Hide resolved
tests/transaction_test_util.go Outdated Show resolved Hide resolved
Comment on lines +29 to +36
if feeCurrency == nil {
return 0, true
}
Copy link

Choose a reason for hiding this comment

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

I had to look up why feeCurrency cannot be nil here. I think a comment would be helpful. Or maybe we can even panic.

Copy link
Author

@ezdac ezdac Aug 5, 2024

Choose a reason for hiding this comment

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

The reason it is there is to guard the pointer deref just below and because I thought it would make sense that the additional intrinsic gas cost of a nil currency is 0.
This also translates to an additional fee-currency specific max gas allowance for EVM calls as used by the MaxAllowedIntrinsicGasCost for the credit/debit EVM calls.
This then will be 0 and will cause the EVM calls to revert with out of gas, if ever called with a nil currency.

However this is all theoretical and currently there is no code-path where it comes to this, since the CreditFees and DebitFees are only called in non-nil fee-currency code-branches.

I will put the above in a comment.

contracts/fee_currencies.go Outdated Show resolved Hide resolved
@ezdac ezdac force-pushed the ezdac/intrinsic-gas-directory branch 2 times, most recently from 9c84c83 to bec64ac Compare August 5, 2024 10:07
ezdac and others added 8 commits August 5, 2024 12:08
This replaces the `BlockContext.ExchangeRates` with a wrapper object
`BlockContext.FeeCurrencyContext`.

This enables easier addition of fee-currency related information
to the block context and passing around that information.
The exchange-rates are now part of the `FeeCurrencyContext`
@ezdac ezdac force-pushed the ezdac/intrinsic-gas-directory branch from bec64ac to 111be39 Compare August 5, 2024 10:09
@ezdac ezdac requested a review from palango August 5, 2024 14:08
@ezdac ezdac merged commit a3cfee1 into celo7 Aug 5, 2024
7 checks passed
@ezdac ezdac deleted the ezdac/intrinsic-gas-directory branch August 5, 2024 15:56
karlb pushed a commit that referenced this pull request Aug 20, 2024
* Add FeeCurrencyContext object to BlockContext

This replaces the `BlockContext.ExchangeRates` with a wrapper object
`BlockContext.FeeCurrencyContext`.

This enables easier addition of fee-currency related information
to the block context and passing around that information.
The exchange-rates are now part of the `FeeCurrencyContext`

* Add intrinsic gas retrieval from FeeCurrencyDirectory

* Use intrinsic gas from FeeCurrencyDirectory in STF

* Add test for intrinsic gas too high in fee currency

* Add empty fee-currency context to tools and tests

* Add minor code improvements

Co-authored-by: Paul Lange <[email protected]>

* Add comment for nil fee-currency code path

* Add fee-currency-context to CeloBackend.NewEVM constructor

---------

Co-authored-by: Paul Lange <[email protected]>
karlb pushed a commit that referenced this pull request Aug 26, 2024
* Add FeeCurrencyContext object to BlockContext

This replaces the `BlockContext.ExchangeRates` with a wrapper object
`BlockContext.FeeCurrencyContext`.

This enables easier addition of fee-currency related information
to the block context and passing around that information.
The exchange-rates are now part of the `FeeCurrencyContext`

* Add intrinsic gas retrieval from FeeCurrencyDirectory

* Use intrinsic gas from FeeCurrencyDirectory in STF

* Add test for intrinsic gas too high in fee currency

* Add empty fee-currency context to tools and tests

* Add minor code improvements

Co-authored-by: Paul Lange <[email protected]>

* Add comment for nil fee-currency code path

* Add fee-currency-context to CeloBackend.NewEVM constructor

---------

Co-authored-by: Paul Lange <[email protected]>
karlb pushed a commit that referenced this pull request Aug 30, 2024
* Add FeeCurrencyContext object to BlockContext

This replaces the `BlockContext.ExchangeRates` with a wrapper object
`BlockContext.FeeCurrencyContext`.

This enables easier addition of fee-currency related information
to the block context and passing around that information.
The exchange-rates are now part of the `FeeCurrencyContext`

* Add intrinsic gas retrieval from FeeCurrencyDirectory

* Use intrinsic gas from FeeCurrencyDirectory in STF

* Add test for intrinsic gas too high in fee currency

* Add empty fee-currency context to tools and tests

* Add minor code improvements

Co-authored-by: Paul Lange <[email protected]>

* Add comment for nil fee-currency code path

* Add fee-currency-context to CeloBackend.NewEVM constructor

---------

Co-authored-by: Paul Lange <[email protected]>
karlb pushed a commit that referenced this pull request Oct 11, 2024
* Add FeeCurrencyContext object to BlockContext

This replaces the `BlockContext.ExchangeRates` with a wrapper object
`BlockContext.FeeCurrencyContext`.

This enables easier addition of fee-currency related information
to the block context and passing around that information.
The exchange-rates are now part of the `FeeCurrencyContext`

* Add intrinsic gas retrieval from FeeCurrencyDirectory

* Use intrinsic gas from FeeCurrencyDirectory in STF

* Add test for intrinsic gas too high in fee currency

* Add empty fee-currency context to tools and tests

* Add minor code improvements

Co-authored-by: Paul Lange <[email protected]>

* Add comment for nil fee-currency code path

* Add fee-currency-context to CeloBackend.NewEVM constructor

---------

Co-authored-by: Paul Lange <[email protected]>
piersy pushed a commit that referenced this pull request Oct 15, 2024
* Add FeeCurrencyContext object to BlockContext

This replaces the `BlockContext.ExchangeRates` with a wrapper object
`BlockContext.FeeCurrencyContext`.

This enables easier addition of fee-currency related information
to the block context and passing around that information.
The exchange-rates are now part of the `FeeCurrencyContext`

* Add intrinsic gas retrieval from FeeCurrencyDirectory

* Use intrinsic gas from FeeCurrencyDirectory in STF

* Add test for intrinsic gas too high in fee currency

* Add empty fee-currency context to tools and tests

* Add minor code improvements

Co-authored-by: Paul Lange <[email protected]>

* Add comment for nil fee-currency code path

* Add fee-currency-context to CeloBackend.NewEVM constructor

---------

Co-authored-by: Paul Lange <[email protected]>
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.

Read IntrinsicGas from FeeCurrencyDirectory
2 participants