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

Fix EIP-7623 gas calculation and tests #217

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from

Conversation

2dvorak
Copy link
Contributor

@2dvorak 2dvorak commented Jan 21, 2025

Proposed changes

This PR fixes gas calculation logic for EIP-7623 changes introduced in #200
Also, this PR fixes gas calculation tests accordingly.
Added state transition test for EIP-7623.

Kaia-specific gas calculation logic

EIP-7623 states that the new formula for gas calculation as follows:

tx.gasUsed = (
    21000
    +
    max(
        STANDARD_TOKEN_COST * tokens_in_calldata
        + execution_gas_used
        + isContractCreation * (32000 + INITCODE_WORD_COST * words(calldata)),
        TOTAL_COST_FLOOR_PER_TOKEN * tokens_in_calldata
    )
)

Geth's implementation for above formula is:

max(total_gas_used, 21000 + floor_gas)

However Kaia has different TxGas for different tx types, for example fee delegated tx has 21000 + 10000.
That would make our implementation:

max(total_gas_used, tx_gas_per_tx_type + floor_gas)

Furthermore, we have additional gas for signature validation for fee delegated tx.
That would further complicate our implementation to:

max(total_gas_used, tx_gas_per_tx_type + sig_validation_gas + floor_gas)

Impact on our code

As a result, our code for intrinsic gas changed from:

func ValidatedGas() uint64 {
	return intrinsicGas + senderValidateGas + feePayerValidateGas
}

to:

type ValidatedGas struct {
	IntrinsicGas   uint64
	SigValidateGas uint64
}

func ValidatedGas() *ValidatedGas {
	return &ValidatedGas{
		IntrinsicGas: intrinsicGas,
		SigValidateGas: senderValidateGas + feePayerValidateGas
	}

because we need SigValidateGas for gas comparison max(total_gas_used, tx_gas_per_tx_type + sig_validation_gas + floor_gas)

Note that unrelated fields or variables are omitted for brevity.

Types of changes

Please put an x in the boxes related to your change.

  • Bugfix
  • New feature or enhancement
  • Others

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have read the CONTRIBUTING GUIDELINES doc
  • I have read the CLA and signed by comment I have read the CLA Document and I hereby sign the CLA in first time contribute
  • Lint and unit tests pass locally with my changes ($ make test)
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in downstream modules

Related issues

#200

@2dvorak 2dvorak self-assigned this Jan 21, 2025
blockchain/types/tx_internal_data.go Outdated Show resolved Hide resolved
blockchain/types/tx_internal_data.go Outdated Show resolved Hide resolved
blockchain/types/tx_internal_data.go Outdated Show resolved Hide resolved
blockchain/types/transaction.go Outdated Show resolved Hide resolved
@2dvorak 2dvorak marked this pull request as ready for review January 24, 2025 04:38
@hyeonLewis
Copy link
Contributor

Is WIP: Add EIP-7623 tests done with current testings?

@2dvorak
Copy link
Contributor Author

2dvorak commented Jan 24, 2025

@hyeonLewis Yes, I've updated the description. Thank you!

@2dvorak 2dvorak force-pushed the 2dvorak/add-eip7623-test branch from f5b3768 to 832b10a Compare January 24, 2025 10:48
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.

3 participants