Skip to content

Feat: add compile-time evaluation for convert, slice and extract32 #4634

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

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

Conversation

lanceherman
Copy link

@lanceherman lanceherman commented May 8, 2025

Description

This PR implements compile-time evaluation for the convert, slice, and extract32 functions, improving gas efficiency and enabling optimizations. The implementation follows Vyper's pattern for compile-time evaluation while maintaining strict type safety and validation.

Changes

Convert Function

  • Added _try_fold method with comprehensive validation:
  • Integer range validation
  • Address length validation (20 bytes)
  • Bytes length validation
  • Decimal truncation checks
  • Proper hex prefix validation

Slice Function

  • Added _try_fold method with:
  • Bounds checking for start and length
  • Support for bytes, string, and hex inputs
  • Proper error messages for out-of-bounds access

Extract32 Function

  • Added _try_fold method with:
  • Proper handling of output_type kwarg
  • Support for BytesM_T, IntegerT, and AddressT outputs
  • Bounds checking for start index
  • Correct byte alignment for address outputs

Related Issues

Solves/Fixes #2498

@lanceherman lanceherman changed the title Issues 2498 3 Feat: add compile-time evaluation for convert, slice and extract32 May 8, 2025
@lanceherman
Copy link
Author

lanceherman commented May 17, 2025

Hi @charles-cooper can you please check and review the PR for the issue #2498 and let me know if it needs any changes.

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.

missing compile-time evaluation for convert, slice and extract32
1 participant