Skip to content

Conversation

@lorenzogentile404
Copy link
Contributor

@lorenzogentile404 lorenzogentile404 commented Oct 27, 2025

Note

Adds secp256r1 P256_VERIFY precompile for Osaka and updates MODEXP per EIP-7823 (1024-byte bound, pricing), wiring changes across constants, hub/OOB/MMU/EC modules, plus new blake2fmodexpdata for Osaka and misc fixes.

  • Osaka fork — P256_VERIFY precompile
    • Introduces P256_VERIFY across constants/constants.lisp (gas, sizes, phases, OOB opcode).
    • Adds EC secp256r1 support in ecdata/osaka (columns, constants, constraints, circuit selector) and integrates in hub/OOB scenario handling.
    • Wires precompile through Hub (hub/osaka/... NSRs/flag sums, generalities, success/FKTR flows) and OOB (oob/osaka/...), including return data sizing and phases.
  • MODEXP (EIP-7823) overhaul
    • Adds upper byte-size bound EIP_7823_MODEXP_UPPER_BYTE_SIZE_BOUND (1024) and new pricing (min cost 500) with refactored OOB pricing/xbs logic and bound checks.
    • Restructures Hub MODEXP processing into granular files (common/__0x__*.lisp), updates success path to use the 1024 bound, and justifies success/return gas under bounds.
    • Updates MMU MODEXP micro-row counts to 64 and adjusts modexp_data/zero preprocessing and padding math accordingly.
  • Blake2f/Modexp data for Osaka
    • Adds blake2fmodexpdata/osaka/* (columns, constants, constraints, WCP lookup) and includes in Makefile for Osaka.
  • Build/Modules
    • Makefile: per-fork MMU and BLAKE2f_MODEXP_DATA variables; wires Osaka/London modules; adds RLP_TXN_RCPT_OSAKA and TRM_OSAKA.
  • EC constraints tweaks
    • Switches some ECRECOVER checks to ISZERO and adjusts success-bit logic; replaces several circuit selector constraints with defcomputedcolumn.
  • Misc
    • Adds automatic-vanishing constraints for misc sub-perspectives; renames/cleans up various shorthands and comparisons; fixes OOB heartbeat to ct-max-sum.

Written by Cursor Bugbot for commit 15aa249. This will update automatically on new commits. Configure here.

@lorenzogentile404 lorenzogentile404 linked an issue Oct 27, 2025 that may be closed by this pull request
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

;; 3.4.5 R1 membership ;;
;; utilities ;;
;;;;;;;;;;;;;;;;;;;;;;;;;
(defun (callToR1Membership k P_x_hi P_x_lo P_y_hi P_y_lo)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only non trivial part of this PR.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

PHASE_ECPAIRING_DATA 0x080A
PHASE_ECPAIRING_RESULT 0x080B
PHASE_P256_VERIFY_DATA 0x100A
PHASE_P256_VERIFY_RESULT 0x100B
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Phase IDs collide for precompile operations

Phase constant collision: PHASE_P256_VERIFY_DATA is set to 0x100A, which is identical to the existing PHASE_BLS_MAP_FP_TO_G1_DATA constant (also 0x100A). These phase identifiers must be unique to correctly distinguish between different precompile operations. This collision will cause the system to confuse P256_VERIFY operations with BLS_MAP_FP_TO_G1 operations.

Fix in Cursor Fix in Web

)))

(defun (precompile-processing---MODEXP---lead-log) (shift [misc/EXP_DATA 5] precompile-processing---MODEXP---misc-row-offset---leading-word-analysis)) ;; ""
(defun (precompile-processing---MODEXP---modexp-full-log) (+ (precompile-processing---MODEXP---lead-log) (* 16 (precompile-processing---MODEXP---sub-ebs-32))))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Incorrect MODEXP Gas Pricing

The modexp-full-log calculation multiplies sub-ebs-32 by 16 instead of 8. Since sub-ebs-32 represents bytes and the exponent log is measured in bits, the conversion factor should be 8 bits per byte, not 16. This will cause incorrect gas pricing calculations for MODEXP operations where the exponent size exceeds 32 bytes.

Fix in Cursor Fix in Web

)))

(defun (precompile-processing---MODEXP---lead-log) (shift [misc/EXP_DATA 5] precompile-processing---MODEXP---misc-row-offset---leading-word-analysis)) ;; ""
(defun (precompile-processing---MODEXP---modexp-full-log) (+ (precompile-processing---MODEXP---lead-log) (* 16 (precompile-processing---MODEXP---sub-ebs-32))))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: MODEXP Gas Pricing: Incorrect Calculation Inflates Costs

The precompile-processing---MODEXP---modexp-full-log calculation uses multiplier 16 instead of 8 to convert sub-ebs-32 (bytes) to bits. This doubles the exponent log value, causing incorrect MODEXP gas pricing. All other forks (London, Shanghai, Cancun, Prague) use multiplier 8, which correctly converts bytes to bits.

Fix in Cursor Fix in Web

(defconstraint g2-membership-circuit-selector ()
(eq! CS_G2_MEMBERSHIP G2MTR))
(defcomputedcolumn (CIRCUIT_SELECTOR_G2_MEMBERSHIP :binary@prove)
G2MTR)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: P256_VERIFY: Circuit Selector Integrity Compromised

The circuit-selectors-sum-binary constraint is missing CS_P256_VERIFY in the sum. This fails to verify that only one circuit selector is active at a time when P256_VERIFY is used, potentially allowing multiple circuit selectors to be active simultaneously.

Fix in Cursor Fix in Web

(* CALL___first_half_nsr___prc_success_wont_revert scenario/PRC_SUCCESS_CALLER_WONT_REVERT)
))

;; TODO add P256_VERIFY
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Precompile Processing Ignores P256_VERIFY

The precompile-processing---2nd-half-NSR and precompile-processing---2nd-half-flag-sum functions don't include P256_VERIFY handling. P256_VERIFY is not part of scenario-shorthand---PRC---common-BLS-address-bit-sum, so when P256_VERIFY is invoked, the NSR and flag sum calculations will be zero instead of the correct values, causing constraint violations.

Fix in Cursor Fix in Web

INDEX_MAX_ECADD_RESULT 3
INDEX_MAX_ECMUL_RESULT 3
INDEX_MAX_ECPAIRING_RESULT 1
INDEX_MAX_P256_VERIFY_DATA 10
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Data Index Error Impacts Verification

The INDEX_MAX_P256_VERIFY_DATA constant is set to 10, but P256_VERIFY data has 10 limbs with indices 0-9, making the maximum index 9. This off-by-one error causes internal_checks_passed to be read from the wrong HURDLE offset in the justify-success-bit-256-verify constraint.

Fix in Cursor Fix in Web

(defconstraint g2-membership-circuit-selector ()
(eq! CS_G2_MEMBERSHIP G2MTR))
(defcomputedcolumn (CIRCUIT_SELECTOR_G2_MEMBERSHIP :binary@prove)
G2MTR)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Circuit Selectors: Mutual Exclusivity Broken

The circuit-selectors-sum-binary constraint is missing CS_P256_VERIFY in the sum that validates at most one circuit selector is active at a time. This allows CIRCUIT_SELECTOR_P256_VERIFY to be active simultaneously with other circuit selectors, violating the mutual exclusivity requirement.

Fix in Cursor Fix in Web


;; P256_VERIFY flag sum
(defun (precompile-processing---2nd-half-flag-sum-for-P256-VERIFY)
(+ (* scenario/PRC_FAILURE_KNOWN_TO_HUB)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Verification Flag Sum Calculation Error

The first term in precompile-processing---2nd-half-flag-sum-for-P256-VERIFY is missing the flag sum function call. It multiplies scenario/PRC_FAILURE_KNOWN_TO_HUB by nothing instead of by (precompile-processing---flag-sum-P256-VERIFY-FKTH), causing incorrect flag sum calculation for the P256_VERIFY failure case.

Fix in Cursor Fix in Web

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.

EIP-7951: Precompile for secp256r1 Curve Support

4 participants