Skip to content

Latest commit

 

History

History
125 lines (93 loc) · 10 KB

File metadata and controls

125 lines (93 loc) · 10 KB
CIP No. 645
Title Align Conflux eSpace Behavior with EVM
Author Chenxing Li (@ChenxingLi)
Status Accepted
Type Spec Breaking
Created 2025-03-13

Simple Summary

This CIP proposes aligning Conflux eSpace's behavior with Ethereum's EVM to ensure compatibility with Ethereum development tools and provide a consistent experience for developers. It also addresses the impact of new EIPs on Conflux Core Space.

Summary

This CIP proposes updates to Conflux eSpace's gas pricing mechanisms to ensure compatibility with Ethereum's EVM, addressing discrepancies that impact developer experience and testing reliability. The following Ethereum Improvement Proposals (EIPs) are implemented or adapted:

Description Link
EIP-1108: Reduces gas costs for alt_bn128 precompile EIP-1108
EIP-1884: Reprices trie-size-dependent opcodes EIP-1884
EIP-2028: Reduces Calldata gas cost EIP-2028
EIP-2200: Rebalances net-metered SSTORE gas cost EIP-2200
EIP-2565: Reduces gas cost for modular exponentiation transactions EIP-2565
EIP-2929: Increases gas costs for opcode transactions to mitigate DDoS EIP-2929
EIP-3529: Removes gas refunds for SELFDESTRUCT and reduces SSTORE refunds EIP-3529
EIP-3651: Reduces gas fees for accessing COINBASE address EIP-3651
EIP-3860: Limits initcode size to 49152 EIP-3860

Additionally, this CIP addresses discrepancies found during Ethereum behavioral alignment tests, including:

  • Implementation of EIP-4844-related opcodes (BLOBHASH and BLOBBASEFEE) with consistent "zero" results.
  • Nonce alignment for failed CREATE2 operations (EIP-684 compliance).
  • Proper validation of fee-related conditions for transactions (EIP-1559 compliance).
  • Memory boundary handling in MCOPY (EIP-5656 compliance).
  • Transient storage lifecycle changes to conform to EIP-1153.

Refer to the Specification section for detailed implementation specifics.

Motivation

Ethereum development tools like Remix implement their own EVM engines. Inconsistent gas pricing in Conflux eSpace may cause developers to experience discrepancies between testing and deployment environments. Ensuring gas pricing alignment between Conflux eSpace and Ethereum is crucial for maintaining EVM compatibility and providing a seamless development experience.

Specification

Fixing Opcode Discrepancies

This CIP addresses opcode behavior inconsistencies to ensure alignment with Ethereum standards:

  1. Implementation of Placeholder Logic for BLOBHASH and BLOBBASEFEE:
    In compliance with EIP-4844, the opcodes BLOBHASH and BLOBBASEFEE are implemented with deterministic "zero" result behaviors:

    • BLOBHASH: Produces an all-zero hash as the output.
    • BLOBBASEFEE: Yields a base fee of "zero," adhering to the expected specification.
  2. Gas Cost Modifications for MCOPY and BASEFEE:

    • The base gas cost for MCOPY has been revised from 0 to 3.
    • The base gas cost for BASEFEE has been revised from 3 to 2.

EIP-684 Alignment

In cases where CREATE2 fails due to address conflicts, this CIP ensures that the sender's nonce is incremented, consistent with EIP-684. Previously, nonce incrementation was skipped for failed CREATE2 operations.

EIP-1559 Alignment

Misaligned fee validations are corrected to adhere to EIP-1559 rules:

  1. Priority Fee Compliance: Transactions where priority_fee > max_fee are no longer incorrectly accepted and are now rejected. (Considered invalid in consensus)
  2. Fee Calculation Adjustment: Validation of available user balances now uses the max_gas_price instead of effective_gas_price, aligning fee calculations with EIP-1559.

EIP-5656 Alignment: Memory Boundary in MCOPY

In the original Conflux implementation of MCOPY, when src + length exceeded memory boundaries, the overflow was filled with zero values, without expanding the memory. In contrast, EIP-5656 specifies that memory should be automatically expanded to accommodate the operation when exceeding boundaries. This CIP adjusts the behavior in eSpace to align with Ethereum's specification.

EIP-1153 Alignment: Transient Storage

EIP-1153 defines transient storage as being valid only for the duration of a single transaction, with values cleared after its execution. The original Conflux implementation extended the availability of transient storage to Core space's epochs and eSpace's blocks. This CIP adjusts the implementation to comply with EIP-1153.

Core Space Adjustments

The following adjustments are made to Core Space to accommodate Conflux's storage collateral mechanism and unique architecture:

1. Ignoring storage occupation and release in EIP-2200

Due to Conflux's use of storage collateral instead of gas fees for storage payment, both the original value and new value are treated as non-zero in Core Space when implementing EIP-2200 rules, ignoring storage entry occupancy and release effects when computing the gas cost of SSTORE.

2. Built-in Contract Handling

  • All built-in contracts are treated as warm addresses.
  • All storage entries of built-in contracts do not follow the warm and cold mechanism; they are consistently treated as cold.

Retained Inconsistencies

Due to Conflux's unique consensus mechanism and its forward compatibility with the existing ecosystem, certain inconsistencies will persist. This section highlights the specific adjustments and differences.

Modified Gas Price Constants

The following gas price constants in eSpace have been adjusted to better align with Ethereum standards:

  • G_sset: 20000 → 40000
  • G_newaccount: 25000 → 50000
  • G_codedeposit: 200 → 400
  • EIP-7702's PER_EMPTY_ACCOUNT_COUNT: 25000 → 50000

COINBASE Address Handling

In Conflux, the coinbase (which receives mining rewards and transaction fees) resides in the Core Space. When using the COINBASE opcode in eSpace, a hex20 address is retrieved; however, this hex20 address corresponds to the Core Space address rather than the eSpace address with the same hex20 value. As a result, the eSpace address with the same hex20 value is not considered "warm" as it is not the actual coinbase address (EIP-2929).

BLOCKHASH Gas Pricing

While Ethereum allows querying blocks in the range [n-256, n-1] for block height n, Conflux supports a larger range of [n-65535, n] (CIP-133). Corresponding gas prices for BLOCKHASH are adjusted as follows:

  • Ethereum: 20 gas (uniform for all cases)
  • Conflux: 2100 gas (for the range [n-65535, n-257]), 100 gas (for blocks in [n-256, n-1])

Insufficient Transaction Balance Handling

When the transaction balance cannot afford the maximum transaction cost (max gas price × gas limit + tx value):

  • In Ethereum, the transaction fails without incrementing the sender's nonce or deducting transaction fees.
  • In Conflux, due to differences in block packing mechanisms, the sender's nonce is incremented, and the maximum effective gas price multiplied by the gas limit is deducted — or the entire balance is deducted if insufficient.

EIP-7702 Refund Behavior

For EIP-7702, when an address updates its delegate (rather than creating a new delegation), Ethereum refunds PER_EMPTY_ACCOUNT_COUNT - PER_AUTH_ACCOUNT_COUNT = 12500 gas. However, due to differences in underlying storage mechanisms, Conflux does not issue a refund in this case.

EcRecover Input Constraints

Ethereum's EcRecover function strictly requires the v value (recovery ID) to be either 27 or 28. Conflux, in addition to supporting 27 and 28, also supports 0 and 1, which are interpreted equivalently to 27 and 28 respectively.

Rationale

Gas Price Constants

As a high-performance blockchain, Conflux's resource costs for CPU and storage differ from Ethereum's. While Conflux has a gas limit budget over 10 times larger than Ethereum's, it does not aim for a 10-fold increase in ledger space. In Core Space, storage collateral was introduced to distinguish between computational and storage resources. However, in eSpace, to maintain compatibility, gas is still used to measure storage costs.
So in CIP-90, an additional rule was adopted: all gas costs related to storage usage were set to twice those of Ethereum's EVM. This CIP continues this design to ensure consistency and alignment with the existing ecosystem.

The Number 645

During the drafting of this CIP, the next available PR number was 155. However, a guiding principle for CIPs is to avoid using numbers that coincide with well-known EIPs (e.g., EIP-20, EIP-721) discussing different topics. EIP-155 represents the most common transaction type in Ethereum prior to the introduction of EIP-1559.
Given the significance of this CIP, which implements nine EIPs in a single proposal, the CIP editors decided to assign it a distinctive number. The number 645 was chosen as it visually resembles the uppercase letters GAS, symbolizing the core focus of this proposal.

Backwards Compatibility

This CIP is spec-breaking.

Security Considerations

The adjustments to gas pricing and storage handling are designed to mitigate potential security risks while maintaining compatibility with Ethereum's EVM. Developers should review the changes to ensure their contracts function as expected under the new rules.