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

feat: Enhance power operation gas estimation #4522

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tal7aouy
Copy link

Description

Improves gas estimation accuracy for power operations by implementing precise byte length calculations and optimizing gas costs.

Changes

def estimate_pow_gas(x, y, typ):
    """
    Estimate gas cost for power operation with optimized byte length calculation.
    
    Args:
        x: Base value IRnode
        y: Exponent value IRnode
        typ: Type information
    
    Returns:
        int: Estimated gas cost (base_cost + byte_length * 50)
    """
    base_gas = 10

    # Optimize gas calculation based on literal/non-literal values
    if y.is_literal:
        # For literal values, use exact bit length
        byte_length = max(1, (y.value.bit_length() + 7) // 8)
    else:
        # For non-literal values, use minimum required bytes based on type
        byte_length = max(1, (typ.bits + 7) // 8)

    return base_gas + (50 * byte_length)

Impact

  • More accurate gas estimation for power operations
  • Better optimization for literal values
  • No breaking changes to existing functionality

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.

1 participant