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

EIP-4844: Implement gas accounting #1421

Closed
jangko opened this issue Jan 11, 2023 · 0 comments · Fixed by #1440
Closed

EIP-4844: Implement gas accounting #1421

jangko opened this issue Jan 11, 2023 · 0 comments · Fixed by #1440
Labels

Comments

@jangko
Copy link
Contributor

jangko commented Jan 11, 2023

Gas accounting

We introduce data gas as a new type of gas. It is independent of normal gas and follows its own targeting rule, similar to EIP-1559. We use the excess_data_gas header field to store persistent data needed to compute the data gas price. For now, only blobs are priced in data gas.

DATA_GAS_PER_BLOB: 2 ** 17
MIN_DATA_GASPRICE: 1
DATA_GASPRICE_UPDATE_FRACTION: 2225652

def calc_data_fee(tx: SignedBlobTransaction, parent: Header) -> int:
    return get_total_data_gas(tx) * get_data_gasprice(header)

def get_total_data_gas(tx: SignedBlobTransaction) -> int:
    return DATA_GAS_PER_BLOB * len(tx.message.blob_versioned_hashes)

def get_data_gasprice(header: Header) -> int:
    return fake_exponential(
        MIN_DATA_GASPRICE,
        header.excess_data_gas,
        DATA_GASPRICE_UPDATE_FRACTION
    )

def fake_exponential(factor: int, numerator: int, denominator: int) -> int:
    i = 1
    output = 0
    numerator_accum = factor * denominator
    while numerator_accum > 0:
        output += numerator_accum
        numerator_accum = (numerator_accum * numerator) // (denominator * i)
        i += 1
    return output // denominator
def validate_block(block: Block) -> None:
    ...

    for tx in block.transactions:
        ...

        # the signer must be able to afford the transaction
        assert signer(tx).balance >= tx.message.gas * tx.message.max_fee_per_gas + get_total_data_gas(tx) * tx.message.max_fee_per_data_gas

        # ensure that the user was willing to at least pay the current data gasprice
        assert tx.message.max_fee_per_data_gas >= get_data_gasprice(parent(block).header)

The actual data_fee as calculated via calc_data_fee is deducted from the sender balance before transaction execution and burned, and is not refunded in case of transaction failure. (meaning: calc_data_fee will be subtracted from sender near intrinsicGas)

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

Successfully merging a pull request may close this issue.

1 participant