Skip to content

op expo growth#390

Merged
thedavidmeister merged 2 commits into
mainfrom
2025-08-04-exp-growth
Aug 4, 2025
Merged

op expo growth#390
thedavidmeister merged 2 commits into
mainfrom
2025-08-04-exp-growth

Conversation

@thedavidmeister
Copy link
Copy Markdown
Contributor

@thedavidmeister thedavidmeister commented Aug 4, 2025

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

    • Re-enabled the exponential-growth operation, making it available as a standard operation alongside existing options.
  • Refactor

    • Updated the exponential-growth operation to use decimal floating-point math for improved precision and flexibility.
    • Modernized function signatures and internal logic to align with newer operand and stack types.
  • Tests

    • Enhanced and expanded tests for the exponential-growth operation, including more precise floating-point input handling and improved test coverage.
    • Updated test environment setup to support configurable blockchain fork sources via environment variables.
  • Chores

    • Updated editor settings for improved file handling and editing experience, including auto-trim of trailing whitespace and changes to auto-save behavior.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Aug 4, 2025

Walkthrough

This change re-enables and refactors the exponential-growth opcode in the codebase. The opcode is now fully integrated into the standard operations, using a new decimal floating-point math library (Float/LibDecimalFloat) and updated operand types (OperandV2). Associated tests and documentation were updated accordingly, and editor settings were adjusted for improved consistency.

Changes

Cohort / File(s) Change Summary
VSCode Editor Settings
.vscode/settings.json
Updated editor settings: disabled quick suggestions, hover, and parameter hints; set auto-save on focus change; enabled trimming trailing whitespace. No language-specific changes.
Standard Ops Integration
src/lib/op/LibAllStandardOps.sol
Re-enabled and integrated LibOpExponentialGrowth as a standard opcode: uncommented import, incremented opcode count, added to opcode arrays/mappings, and included authoring metadata.
Exponential Growth Opcode Refactor
src/lib/op/math/growth/LibOpExponentialGrowth.sol
Refactored exponential growth opcode to use Float/LibDecimalFloat for decimal floating-point math instead of fixed-point. Updated function signatures to use OperandV2, rewrote calculation logic, and added a new referenceFn for testing.
Exponential Growth Opcode Tests
test/src/lib/op/math/growth/LibOpExponentialGrowth.t.sol
Uncommented and refactored tests to use Float, OperandV2, and StackItem. Enhanced input bounding, improved precision, updated expected results, and modernized test logic to match new opcode implementation.
Pow Opcode Test Fork Selection
test/src/lib/op/math/LibOpPow.t.sol
Changed test environment fork selection to use ETH_RPC_URL from environment variables instead of a hardcoded Arbitrum RPC URL.

Sequence Diagram(s)

sequenceDiagram
    participant Interpreter
    participant LibAllStandardOps
    participant LibOpExponentialGrowth
    participant LibDecimalFloat

    Interpreter->>LibAllStandardOps: Execute "exponential-growth" opcode
    LibAllStandardOps->>LibOpExponentialGrowth: run(state, operand, stackTop)
    LibOpExponentialGrowth->>LibDecimalFloat: Float math (mul, add, pow)
    LibDecimalFloat-->>LibOpExponentialGrowth: Result
    LibOpExponentialGrowth-->>LibAllStandardOps: Updated stackTop
    LibAllStandardOps-->>Interpreter: Execution continues
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~35 minutes

Possibly related PRs

  • 2025 07 09 div #351: Refactors and re-enables the div opcode using floating-point math, following a similar integration pattern as exponential-growth.
  • 2025 07 13 max #359: Updates and re-enables the max opcode with floating-point math and new operand types, modifying the same standard ops integration points.
  • linear growth #377: Refactors and re-enables the linear growth opcode using the Float library and OperandV2 updates, mirroring the changes made for exponential-growth.

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 2025-08-04-exp-growth

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.
  • 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.

Support

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

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 generate unit tests to generate unit tests for 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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

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 7212a7e and 39e4127.

⛔ 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)
  • .vscode/settings.json (1 hunks)
  • src/lib/op/LibAllStandardOps.sol (6 hunks)
  • src/lib/op/math/growth/LibOpExponentialGrowth.sol (1 hunks)
  • test/src/lib/op/math/LibOpPow.t.sol (1 hunks)
  • test/src/lib/op/math/growth/LibOpExponentialGrowth.t.sol (1 hunks)
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: thedavidmeister
PR: rainlanguage/rain.interpreter#360
File: src/lib/op/erc20/LibOpERC20Allowance.sol:0-0
Timestamp: 2025-07-15T11:31:28.010Z
Learning: In the rainlanguage/rain.interpreter project, forge (Foundry's formatting tool) handles code formatting automatically, so formatting-related suggestions are not actionable.
📚 Learning: in multiplication overflow detection tests like libopuint256multest, when performing sequential mult...
Learnt from: thedavidmeister
PR: rainlanguage/rain.interpreter#368
File: test/src/lib/op/math/uint256/LibOpUint256Mul.t.sol:56-69
Timestamp: 2025-07-17T14:15:14.886Z
Learning: In multiplication overflow detection tests like LibOpUint256MulTest, when performing sequential multiplication (a * b * c * d...), encountering a zero value means the final result will always be zero regardless of subsequent values. Since zero multiplied by any value (including MAX_UINT256) cannot overflow, it's safe and correct to break out of the overflow detection loop early when zero is encountered.

Applied to files:

  • test/src/lib/op/math/LibOpPow.t.sol
  • src/lib/op/math/growth/LibOpExponentialGrowth.sol
  • test/src/lib/op/math/growth/LibOpExponentialGrowth.t.sol
  • src/lib/op/LibAllStandardOps.sol
📚 Learning: for test utility contracts (like those in test_fixtures crate), input validation in constructors is ...
Learnt from: 0xgleb
PR: rainlanguage/rain.interpreter#333
File: test/utils/TestERC20.sol:10-15
Timestamp: 2025-06-09T07:44:13.280Z
Learning: For test utility contracts (like those in test_fixtures crate), input validation in constructors is not needed according to user 0xgleb's preference, as these are used in controlled testing environments.

Applied to files:

  • test/src/lib/op/math/LibOpPow.t.sol
📚 Learning: in rain interpreter stack operations like libopevery, when the output position (stacktop) is set to ...
Learnt from: thedavidmeister
PR: rainlanguage/rain.interpreter#381
File: src/lib/op/logic/LibOpEvery.sol:24-46
Timestamp: 2025-07-27T22:56:57.928Z
Learning: In Rain interpreter stack operations like LibOpEvery, when the output position (stackTop) is set to coincide with an input item's position on the stack, explicit writing may not be needed if the desired output value is already at that position. The function can return the pointer to that position directly, leveraging the existing stack layout.

Applied to files:

  • src/lib/op/math/growth/LibOpExponentialGrowth.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, test-wasm-build)
  • GitHub Check: git-clean
  • GitHub Check: rainix (ubuntu-latest, rainix-rs-artifacts)
  • GitHub Check: rainix (ubuntu-latest, rainix-rs-test)
  • GitHub Check: rainix (macos-latest, rainix-rs-artifacts)
  • GitHub Check: rainix (ubuntu-latest, rainix-sol-static)
  • GitHub Check: rainix (ubuntu-latest, rainix-sol-artifacts)
  • GitHub Check: rainix (ubuntu-latest, rainix-rs-static)
  • GitHub Check: rainix (ubuntu-latest, rainix-sol-test)
  • GitHub Check: rainix (macos-latest, rainix-rs-test)
🔇 Additional comments (12)
.vscode/settings.json (1)

8-9: Validate automatic save + whitespace trimming behaviour

Switching to "files.autoSave": "onFocusChange" and enabling files.trimTrailingWhitespace will cause VS Code to write the file as soon as focus leaves the editor and may introduce unexpected commits if the user is navigating quickly between tabs.
The whitespace trimming is generally helpful, but the auto-save policy can surprise developers during interactive debugging or partial edits.

Please confirm that the whole team is comfortable with this workspace-wide behaviour; if not, consider omitting files.autoSave and leaving it to individual preference.

test/src/lib/op/math/LibOpPow.t.sol (1)

13-13: Good practice: Using environment variable for RPC URL

The change from hardcoded RPC URL to environment variable improves test flexibility and follows best practices for configuration management.

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

62-62: LGTM: Import statement properly restored

The import for LibOpExponentialGrowth is correctly uncommented, enabling the exponential growth opcode.


115-115: Correct constant update

The ALL_STANDARD_OPS_LENGTH is properly incremented from 64 to 65 to account for the added exponential-growth opcode.


242-245: Complete and consistent opcode integration

The exponential-growth opcode is properly integrated with:

  • Clear and accurate metadata description
  • Appropriate operand handler (handleOperandDisallowed)
  • All required function pointers (integrity and run)
  • Correct alphabetical ordering within the growth operations section

Also applies to: 447-448, 593-593, 704-704

src/lib/op/math/growth/LibOpExponentialGrowth.sol (3)

16-19: Correct integrity constraints

The integrity function properly enforces 3 inputs (base, rate, t) and 1 output for the exponential growth calculation.


21-38: Well-implemented exponential growth calculation

The run function correctly:

  • Loads three Float values from the stack
  • Implements the exponential growth formula: base * (1 + rate)^t
  • Uses proper stack pointer management
  • Changed from pure to view to access LOG_TABLES_ADDRESS for power calculations

40-54: Useful reference implementation for testing

The reference function provides a gas-intensive but clear implementation that mirrors the optimized run function, facilitating comprehensive testing.

test/src/lib/op/math/growth/LibOpExponentialGrowth.t.sol (4)

11-13: Consistent test environment setup

Uses environment variable for RPC URL, maintaining consistency with other test files in the codebase.


23-61: Comprehensive fuzz testing with appropriate bounds

The test properly:

  • Bounds inputs to reasonable ranges to avoid overflow
  • Uses Float type with signed coefficients and exponents
  • Leverages opReferenceCheck for thorough validation against the reference implementation

64-91: Thorough evaluation test coverage

Excellent test cases covering:

  • Edge cases (zero values)
  • Normal operation with various inputs
  • Fractional and negative exponents
  • Precise expected values using packed Float representation

93-121: Complete input/output validation

All error cases are properly tested:

  • Various invalid input counts (0, 1, 2, 4)
  • Invalid output counts (0, 2)
  • Operand disallowance

Comment thread .vscode/settings.json Outdated
@thedavidmeister thedavidmeister merged commit 55e2dc0 into main Aug 4, 2025
11 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Aug 12, 2025
4 tasks
@coderabbitai coderabbitai Bot mentioned this pull request Oct 6, 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