Skip to content

2025 07 13 lt - #357

Merged
thedavidmeister merged 4 commits into
mainfrom
2025-07-13-lt
Jul 13, 2025
Merged

2025 07 13 lt#357
thedavidmeister merged 4 commits into
mainfrom
2025-07-13-lt

Conversation

@thedavidmeister

@thedavidmeister thedavidmeister commented Jul 13, 2025

Copy link
Copy Markdown
Contributor

Motivation

Solution

Checks

By submitting this for review, I'm confirming I've done the following:

  • made this PR as small as possible
  • unit-tested any new functionality
  • linked any relevant issues or PRs
  • included screenshots (if this involves a front-end change)

Summary by CodeRabbit

  • New Features

    • Introduced a new floating-point "less-than" operation, enabling comparison of decimal values.
    • Updated metadata to display boolean results ("true"/"false") for the less-than operation.
  • Bug Fixes

    • Improved input validation and error handling for the less-than operation, ensuring correct input/output counts.
  • Tests

    • Added comprehensive tests for the new floating-point less-than operation, covering integrity, runtime correctness, and edge cases.
    • Removed legacy tests for the previous integer-based less-than operation.
  • Chores

    • Minor style improvement in multiplication operation tests for consistency.

@coderabbitai

coderabbitai Bot commented Jul 13, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes replace the integer-based less-than operation (LibOpLessThanNP) with a new floating-point aware implementation (LibOpLessThan). This includes updating function pointers, metadata, and tests to use the new logic. The test suite for the previous implementation is removed and replaced with tests for the new floating-point less-than operation.

Changes

File(s) Change Summary
src/lib/op/LibAllStandardOps.sol Switched less-than from LibOpLessThanNP to LibOpLessThan, updated metadata, incremented op count, adjusted function pointers.
src/lib/op/logic/LibOpLessThan.sol Renamed library, changed logic to use floating-point comparison, updated function signatures and types.
test/src/lib/op/logic/LibOpLessThan.t.sol Added new test contract for floating-point less-than, covering integrity, runtime, parsing, and error cases.
test/src/lib/op/logic/LibOpLessThanNP.t.sol Removed old test contract for integer-based less-than operation.
test/src/lib/op/math/LibOpMul.t.sol Replaced assert with assertTrue in error handling for multiplication overflow tests.

Sequence Diagram(s)

sequenceDiagram
    participant Interpreter
    participant LibOpLessThan
    participant LibDecimalFloat

    Interpreter->>LibOpLessThan: run(stack, operand)
    LibOpLessThan->>LibDecimalFloat: lt(a, b)
    LibDecimalFloat-->>LibOpLessThan: bool result
    LibOpLessThan-->>Interpreter: push uint256(1/0) to stack
Loading

Possibly related PRs

  • 2025 07 09 div #351: Refactors and updates the "div" operation implementation and related metadata/function pointers, similar to this PR's changes for the "less-than" operation.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bd7a6af and 38e5e8d.

⛔ Files ignored due to path filters (3)
  • src/generated/Rainterpreter.pointers.sol is excluded by !**/generated/**
  • src/generated/RainterpreterExpressionDeployer.pointers.sol is excluded by !**/generated/**
  • src/generated/RainterpreterParser.pointers.sol is excluded by !**/generated/**
📒 Files selected for processing (5)
  • src/lib/op/LibAllStandardOps.sol (6 hunks)
  • src/lib/op/logic/LibOpLessThan.sol (1 hunks)
  • test/src/lib/op/logic/LibOpLessThan.t.sol (1 hunks)
  • test/src/lib/op/logic/LibOpLessThanNP.t.sol (0 hunks)
  • test/src/lib/op/math/LibOpMul.t.sol (1 hunks)
💤 Files with no reviewable changes (1)
  • test/src/lib/op/logic/LibOpLessThanNP.t.sol
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: rainix (ubuntu-latest, rainix-sol-test)
  • GitHub Check: rainix (ubuntu-latest, rainix-sol-static)
  • GitHub Check: rainix (macos-latest, rainix-rs-artifacts)
  • GitHub Check: rainix (ubuntu-latest, rainix-sol-artifacts)
  • GitHub Check: rainix (ubuntu-latest, test-wasm-build)
  • GitHub Check: rainix (ubuntu-latest, rainix-rs-static)
  • GitHub Check: rainix (macos-latest, rainix-rs-test)
  • GitHub Check: rainix (ubuntu-latest, rainix-rs-test)
  • GitHub Check: rainix (ubuntu-latest, rainix-rs-artifacts)
  • GitHub Check: git-clean
🔇 Additional comments (15)
test/src/lib/op/math/LibOpMul.t.sol (1)

59-59: Good practice: Using assertTrue instead of assert in tests.

This change correctly uses the testing framework's assertion method instead of Solidity's assert, which is more appropriate for test validation.

src/lib/op/LibAllStandardOps.sol (6)

58-58: LGTM: Import updated to new less-than implementation.

The import correctly references the new floating-point based LibOpLessThan replacing the integer-based LibOpLessThanNP.


224-224: Improved clarity: Using boolean terminology in metadata.

The description now correctly uses "true"/"false" instead of numeric "1"/"0", which better reflects the boolean nature of the comparison operation.


434-435: Operation enabled: Less-than operand handler uncommented.

The less-than operation is now properly enabled in the operand handler array by uncommenting the LibParseOperand.handleOperandDisallowed assignment.


581-581: Function pointer updated: Integrity check reference.

The integrity function pointer correctly references LibOpLessThan.integrity instead of the previous LibOpLessThanNP.integrity.


693-693: Function pointer updated: Runtime execution reference.

The runtime function pointer correctly references LibOpLessThan.run instead of the previous LibOpLessThanNP.run.


108-108: ALL_STANDARD_OPS_LENGTH increment is correct
Verified that each of the three function‐pointer arrays (operandHandlerFunctionPointers, integrityFunctionPointers, and opcodeFunctionPointers) contains exactly 32 active entries (excluding commented‐out slots), matching the updated ALL_STANDARD_OPS_LENGTH = 32. No further changes needed.

src/lib/op/logic/LibOpLessThan.sol (4)

8-9: Appropriate imports for floating-point operations.

The addition of StackItem and Float/LibDecimalFloat imports enables proper floating-point less-than comparisons.


11-14: Library renamed and documentation updated.

The library name change from LibOpLessThanNP to LibOpLessThan aligns with the new floating-point implementation.


22-34: Floating-point comparison implementation looks correct.

The implementation properly:

  • Loads two Float values from the stack
  • Uses LibDecimalFloat.lt for accurate floating-point comparison
  • Stores the boolean result back on the stack
  • Maintains the expected stack pointer manipulation

37-47: Reference function correctly implements floating-point logic.

The reference function properly:

  • Converts StackItem inputs to Float values
  • Performs the same floating-point comparison as the runtime function
  • Returns the boolean result as a StackItem array
test/src/lib/op/logic/LibOpLessThan.t.sol (4)

20-38: Comprehensive integrity testing.

The integrity tests properly verify that the less-than operation always requires exactly 2 inputs and produces 1 output, regardless of operand values.


40-48: Effective fuzz testing for runtime correctness.

The runtime test uses randomized StackItem inputs and validates against the reference function, providing robust coverage of the floating-point comparison logic.


52-92: Thorough evaluation test coverage.

The tests cover important scenarios including:

  • Zero comparisons
  • Integer comparisons
  • Decimal comparisons (1.1 vs 1.2)
  • Negative number comparisons
  • Mixed integer/decimal comparisons

95-121: Complete error handling validation.

The tests properly validate error conditions for incorrect input/output counts, ensuring the integrity checks work as expected.

Comment on lines +64 to +91
function testOpLessThanNPEval2InputsFirstOneSecondZero() external view {
checkHappy("_: less-than(1 0);", bytes32(uint256(0)), "");
}

/// Test the eval of less than opcode parsed from a string. Tests 2 inputs.
/// Both inputs are 1.
function testOpLessThanNPEval2InputsBothOne() external view {
checkHappy("_: less-than(1 1);", bytes32(uint256(0)), "");
}

// Test 1.1 lt 1.2, which should return 1.
function testOpLessThanNP1_1Lt1_2() external view {
checkHappy("_: less-than(1.1 1.2);", bytes32(uint256(1)), "");
}

/// Test 1.0 lt 1 which should return 0.
function testOpLessThanNP1_0Lt1() external view {
checkHappy("_: less-than(1.0 1);", bytes32(uint256(0)), "");
}

// Test -1.1 lt -1.2, which should return 0.
function testOpLessThanNPMinus1_1LtMinus1_2() external view {
checkHappy("_: less-than(-1.1 -1.2);", bytes32(uint256(0)), "");
}

/// Test -1 lt 0, which should return 1.
function testOpLessThanNPMinus1Lt0() external view {
checkHappy("_: less-than(-1 0);", bytes32(uint256(1)), "");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Fix inconsistent function naming in test comments.

Several test function names still contain the "NP" suffix from the old implementation (lines 64, 70, 75, 80, 85, 90), which should be removed for consistency.

-    function testOpLessThanNPEval2InputsFirstOneSecondZero() external view {
+    function testOpLessThanEval2InputsFirstOneSecondZero() external view {

-    function testOpLessThanNPEval2InputsBothOne() external view {
+    function testOpLessThanEval2InputsBothOne() external view {

-    function testOpLessThanNP1_1Lt1_2() external view {
+    function testOpLessThan1_1Lt1_2() external view {

-    function testOpLessThanNP1_0Lt1() external view {
+    function testOpLessThan1_0Lt1() external view {

-    function testOpLessThanNPMinus1_1LtMinus1_2() external view {
+    function testOpLessThanMinus1_1LtMinus1_2() external view {

-    function testOpLessThanNPMinus1Lt0() external view {
+    function testOpLessThanMinus1Lt0() external view {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function testOpLessThanNPEval2InputsFirstOneSecondZero() external view {
checkHappy("_: less-than(1 0);", bytes32(uint256(0)), "");
}
/// Test the eval of less than opcode parsed from a string. Tests 2 inputs.
/// Both inputs are 1.
function testOpLessThanNPEval2InputsBothOne() external view {
checkHappy("_: less-than(1 1);", bytes32(uint256(0)), "");
}
// Test 1.1 lt 1.2, which should return 1.
function testOpLessThanNP1_1Lt1_2() external view {
checkHappy("_: less-than(1.1 1.2);", bytes32(uint256(1)), "");
}
/// Test 1.0 lt 1 which should return 0.
function testOpLessThanNP1_0Lt1() external view {
checkHappy("_: less-than(1.0 1);", bytes32(uint256(0)), "");
}
// Test -1.1 lt -1.2, which should return 0.
function testOpLessThanNPMinus1_1LtMinus1_2() external view {
checkHappy("_: less-than(-1.1 -1.2);", bytes32(uint256(0)), "");
}
/// Test -1 lt 0, which should return 1.
function testOpLessThanNPMinus1Lt0() external view {
checkHappy("_: less-than(-1 0);", bytes32(uint256(1)), "");
function testOpLessThanEval2InputsFirstOneSecondZero() external view {
checkHappy("_: less-than(1 0);", bytes32(uint256(0)), "");
}
/// Test the eval of less than opcode parsed from a string. Tests 2 inputs.
/// Both inputs are 1.
function testOpLessThanEval2InputsBothOne() external view {
checkHappy("_: less-than(1 1);", bytes32(uint256(0)), "");
}
// Test 1.1 lt 1.2, which should return 1.
function testOpLessThan1_1Lt1_2() external view {
checkHappy("_: less-than(1.1 1.2);", bytes32(uint256(1)), "");
}
/// Test 1.0 lt 1 which should return 0.
function testOpLessThan1_0Lt1() external view {
checkHappy("_: less-than(1.0 1);", bytes32(uint256(0)), "");
}
// Test -1.1 lt -1.2, which should return 0.
function testOpLessThanMinus1_1LtMinus1_2() external view {
checkHappy("_: less-than(-1.1 -1.2);", bytes32(uint256(0)), "");
}
/// Test -1 lt 0, which should return 1.
function testOpLessThanMinus1Lt0() external view {
checkHappy("_: less-than(-1 0);", bytes32(uint256(1)), "");
}
🤖 Prompt for AI Agents
In test/src/lib/op/logic/LibOpLessThan.t.sol between lines 64 and 91, the test
function names include the outdated "NP" suffix. Rename these functions to
remove the "NP" suffix for consistency with the current naming convention,
ensuring the function names accurately reflect their purpose without the old
suffix.

@thedavidmeister
thedavidmeister merged commit e8d94fb into main Jul 13, 2025
11 checks passed
This was referenced Jul 13, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Jul 28, 2025
4 tasks
@coderabbitai coderabbitai Bot mentioned this pull request Aug 11, 2025
4 tasks
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