Skip to content

Conversation

lorenzogentile404
Copy link
Contributor

@lorenzogentile404 lorenzogentile404 commented Sep 26, 2025

Note

Refactors BLS MSM precompile pricing/gas checks, raises MSM CT_MAX to 7, widens OUTGOING_INST/PRC_NAME to i16, marks OOB add/mod lookups as unchecked, and adjusts constancy condition logic.

  • BLS MSM precompile flow (oob/*/precompiles/common/bls/bls_msm.lisp):
    • Introduces reference-table-discount; computes discount conditionally on num-inputs <= 128.
    • Splits cost computation into a dedicated DIV step (EVM_INST_DIV, MOD_FLAG=1, WCP_FLAG=0); derives precompile-cost at shift 6 and moves insufficient-gas to shift 7.
    • Compares call gas vs computed precompile-cost in a separate LT step; simplifies return-gas to callee-gas - precompile-cost (removes pair-size/multiplier scaling).
  • Type/schema updates:
    • Widen OUTGOING_INST to :i16 in oob/*/columns.lisp.
    • Widen PRC_NAME to :i16 in reftables/prague/bls_reftable.lisp.
  • Limits:
    • Increase CT_MAX_BLS_G1_MSM/CT_MAX_BLS_G2_MSM from 6 to 7 in oob/*/constants.lisp.
  • Lookups:
    • Mark oob-into-add and oob-into-mod clookups as :unchecked in oob/*/lookups/.
  • Constancy condition (blsdata/*/generalities/constancy_conditions.lisp):
    • Replace will-remain-constant! ACC_INPUTS check with if-zero (- (next ACC_INPUTS) ACC_INPUTS) before enforcing NONTRIVIAL_POP_BIT constancy.

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

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

This comment was marked as outdated.

Copy link
Collaborator

@OlivierBBB OlivierBBB left a comment

Choose a reason for hiding this comment

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

LGTM

(defconstraint pair-of-inputs-constancy ()
(if-not-zero ACC_INPUTS
(if (will-remain-constant! ACC_INPUTS)
(if-zero (- (next ACC_INPUTS) ACC_INPUTS)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this rejected by go-corset ? The original version looked ok to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, they are probably equivalent, but I believe this way is more clear

(vanishes! (shift [OUTGOING_DATA 1] 7))
(eq! (shift [OUTGOING_DATA 2] 7) (prc---callee-gas))
(vanishes! (shift [OUTGOING_DATA 3] 7))
(eq! (shift [OUTGOING_DATA 4] 7) (prc-g1msm-prc-g2msm---precompile-cost)))))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we replace all the (shift [OUTGOING_DATA X] Y) with meaningful shorthand names ?

Copy link
Contributor Author

@lorenzogentile404 lorenzogentile404 Oct 1, 2025

Choose a reason for hiding this comment

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

yes, but I would prefer in a separated PR.

(eq! (shift OUTGOING_INST 6) EVM_INST_DIV)
(vanishes! (shift [OUTGOING_DATA 1] 6))
(eq! (shift [OUTGOING_DATA 2] 6) (prc---callee-gas))
(eq! (* (shift [OUTGOING_DATA 2] 6) (msm-pair-size)) (prc-g1msm-prc-g2msm---msm-cost-numerator_msm-pair-size))
Copy link

Choose a reason for hiding this comment

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

Bug: EVM Division Precompile Constraint Error

The compute-precompile-cost-integer-division constraint misconfigures the EVM_INST_DIV operation. OUTGOING_DATA 2 is incorrectly constrained as a value related to the quotient, but it should be the dividend (numerator). The actual division result (the precompile cost) should come from OUTGOING_RES_LO.

Fix in Cursor Fix in Web

(vanishes! (shift [OUTGOING_DATA 3] 6))
(eq! (* (shift [OUTGOING_DATA 4] 6) (msm-pair-size) PRC_BLS_MULTIPLICATION_MULTIPLIER)
(prc-g1msm-prc-g2msm---precompile-cost_msm-pair-size_PRC_BLS_MULTIPLICATION_MULTIPLIER)))))
(eq! (shift [OUTGOING_DATA 4] 6) PRC_BLS_MULTIPLICATION_MULTIPLIER))))
Copy link

Choose a reason for hiding this comment

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

Bug: Cost Calculation Error in Precompile Constraint

The prc-g1msm-prc-g2msm---compute-precompile-cost-integer-division constraint performs a division but doesn't store the result into (shift OUTGOING_RES_LO 6). As a result, prc-g1msm-prc-g2msm---precompile-cost will not reflect the computed value, leading to an incorrect precompile cost.

Fix in Cursor Fix in Web

@lorenzogentile404 lorenzogentile404 merged commit 77b5e2d into master Oct 6, 2025
6 checks passed
@lorenzogentile404 lorenzogentile404 deleted the 772-debug-bls branch October 6, 2025 18:25
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.

Debug BLS
2 participants