Skip to content

Conversation

@harkal
Copy link
Collaborator

@harkal harkal commented Jan 21, 2026

What I did

Add a new Venom optimization pass that combines adjacent assert iszero(x) sequences into a single assert using or, reducing bytecode size and gas cost.

How I did it

The implementation is split into two phases per reviewer request:

  • Analysis phase (_AssertCombineAnalysis): identifies pairs of asserts that can be merged based on compatible error messages and no side-effecting instructions between them
  • Transformation phase (AssertCombinerPass): applies the merges, combining predicates with or and removing redundant asserts

Key features:

  • Preserves error message matching (only merges asserts with same error_msg)
  • Respects side-effect barriers (mstore, sstore, mload, sload break chains)
  • Handles chained merges (3+ consecutive asserts merge into one)
  • Follows assign chains to find underlying iszero operations
  • Removes duplicate asserts on the same predicate

How to verify it

Run the unit tests:

pytest tests/unit/compiler/venom/test_assert_combiner.py -v

Commit message

feat[venom]: add assert combiner optimization pass

This pass combines adjacent `assert iszero(x)` sequences into a single
assert using `or`, reducing bytecode size and gas cost.

The implementation is split into two phases:
- Analysis phase (`_AssertCombineAnalysis`): identifies pairs of asserts
  that can be merged based on compatible error messages and no side-
  effecting instructions between them
- Transformation phase (`AssertCombinerPass`): applies the merges,
  combining predicates with `or` and removing redundant asserts

Key features:
- Preserves error message matching (only merges asserts with same
  error_msg)
- Respects side-effect barriers (mstore, sstore, mload, sload break
  chains)
- Handles chained merges (3+ consecutive asserts merge into one)
- Follows assign chains to find underlying iszero operations
- Removes duplicate asserts on the same predicate

Description for the changelog

Add AssertCombinerPass optimization that combines adjacent assert conditions using bitwise OR.

Cute Animal Picture

capybara

@harkal harkal marked this pull request as ready for review January 21, 2026 22:25
@codecov
Copy link

codecov bot commented Jan 21, 2026

Codecov Report

❌ Patch coverage is 88.18182% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.32%. Comparing base (688aa54) to head (9e4e44b).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
vyper/venom/passes/assert_combiner.py 88.07% 6 Missing and 7 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4818      +/-   ##
==========================================
- Coverage   93.35%   93.32%   -0.03%     
==========================================
  Files         148      149       +1     
  Lines       20588    20698     +110     
  Branches     3574     3599      +25     
==========================================
+ Hits        19220    19317      +97     
- Misses        917      923       +6     
- Partials      451      458       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@harkal harkal requested a review from charles-cooper January 21, 2026 23:06
Copy link
Member

@charles-cooper charles-cooper left a comment

Choose a reason for hiding this comment

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

please split this into an analysis pass (can be a local _AssertCombineAnalysis) and code modification pass

@charles-cooper
Copy link
Member

@codex do you work yet

@chatgpt-codex-connector
Copy link

Codex couldn't complete this request. Try again later.

Address review comment to separate analysis from code modification.
Now has:
- _MergeCandidate: dataclass for merge candidates
- _AssertCombineAnalysis: identifies pairs of asserts that can be merged
- AssertCombinerPass: applies the transformations
@vyperteam-bot vyperteam-bot bot force-pushed the feat/venom/assert_combiner branch from 3f31223 to 2d5b6ed Compare January 26, 2026 15:15
Copy link

@vyperteam-bot vyperteam-bot bot left a comment

Choose a reason for hiding this comment

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

Addressed review comment: split into analysis phase (_AssertCombineAnalysis) and transformation phase. All tests pass.

@vyperteam-bot vyperteam-bot bot changed the title feat[venom]: optimization pass assert combiner feat[venom]: add assert combiner optimization pass Jan 27, 2026
@charles-cooper charles-cooper enabled auto-merge (squash) January 27, 2026 19:46
@charles-cooper charles-cooper merged commit 5e8f16d into vyperlang:master Jan 27, 2026
169 checks passed
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.

2 participants