Skip to content

sqrt#94

Merged
thedavidmeister merged 3 commits intomainfrom
2025-08-04-sqrt
Aug 6, 2025
Merged

sqrt#94
thedavidmeister merged 3 commits intomainfrom
2025-08-04-sqrt

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

    • Added a square root function for decimal float values, now accessible externally.
    • Introduced new constants representing 0.5 and 2 for decimal float operations.
  • Tests

    • Added comprehensive tests for the new square root function, covering edge cases, error handling, and round-trip accuracy.
    • Introduced tests for new constants to ensure correctness.
    • Expanded test coverage for power operations with deployment comparisons and improved error handling validation.
    • Updated gas snapshot to reflect new and adjusted tests.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Aug 4, 2025

Walkthrough

This update introduces square root functionality for decimal floats by adding a new sqrt method to both the core library (LibDecimalFloat) and the DecimalFloat contract. Associated constants (FLOAT_HALF, FLOAT_TWO) are added, and comprehensive tests are implemented to verify correctness, error handling, and gas usage. Existing tests are updated to use new constants and to cover the new functionality.

Changes

Cohort / File(s) Change Summary
Gas Snapshot Update
.gas-snapshot
Updated gas snapshot reflecting new and existing tests, minor run count changes, and added coverage for power and square root operations.
Library: Square Root & Constants
src/lib/LibDecimalFloat.sol
Added FLOAT_HALF, FLOAT_TWO constants; implemented sqrt function for floats using existing power logic.
Contract: Exposing Square Root
src/concrete/DecimalFloat.sol
Added external view sqrt function that exposes library square root capability.
Test: DecimalFloat Power
test/src/concrete/DecimalFloat.pow.t.sol
Updated powExternal to view; added testPowDeployed for deployed contract power operation consistency.
Test: DecimalFloat Square Root
test/src/concrete/DecimalFloat.sqrt.t.sol
Added new test contract for square root, verifying deployed contract and external call consistency.
Test: LibDecimalFloat Constants
test/src/lib/LibDecimalFloat.constants.t.sol
Added tests for new constants FLOAT_HALF and FLOAT_TWO.
Test: LibDecimalFloat Power
test/src/lib/LibDecimalFloat.pow.t.sol
Refactored to use FLOAT_ONE constant instead of explicit construction in round-trip checks.
Test: LibDecimalFloat Square Root
test/src/lib/LibDecimalFloat.sqrt.t.sol
Added new test contract for library square root: correctness, negative input handling, round-trip, and fuzz tests.

Sequence Diagram(s)

Square Root Functionality: Contract and Library

sequenceDiagram
    participant User
    participant DecimalFloat (Contract)
    participant LibDecimalFloat (Library)
    participant LogTables (Tables Data)

    User->>DecimalFloat: sqrt(Float a)
    DecimalFloat->>LibDecimalFloat: sqrt(a, LOG_TABLES_ADDRESS)
    LibDecimalFloat->>LogTables: (fetch log/power data as needed)
    LibDecimalFloat-->>DecimalFloat: Float sqrtResult
    DecimalFloat-->>User: Float sqrtResult
Loading

Test: Square Root Consistency

sequenceDiagram
    participant TestContract
    participant DeployedDecimalFloat
    participant LibDecimalFloat

    TestContract->>LibDecimalFloat: sqrtExternal(Float a, LOG_TABLES_ADDRESS)
    LibDecimalFloat-->>TestContract: Float result1

    TestContract->>DeployedDecimalFloat: sqrt(Float a)
    DeployedDecimalFloat->>LibDecimalFloat: sqrt(a, LOG_TABLES_ADDRESS)
    LibDecimalFloat-->>DeployedDecimalFloat: Float result2
    DeployedDecimalFloat-->>TestContract: Float result2

    TestContract->>TestContract: assert result1 == result2
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15–20 minutes

Note

⚡️ Unit Test Generation is now available in beta!

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


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 33a5cba and fa2a8db.

📒 Files selected for processing (1)
  • test/src/concrete/DecimalFloat.sqrt.t.sol (1 hunks)
🧰 Additional context used
🧠 Learnings (7)
📓 Common learnings
Learnt from: 0xgleb
PR: rainlanguage/rain.math.float#58
File: src/concrete/DecimalFloat.sol:175-182
Timestamp: 2025-06-16T13:17:28.513Z
Learning: In the rainlanguage/rain.math.float codebase, there's an established naming convention where functions accepting a `Float` type parameter consistently use `float` as the parameter name, even though it shadows the type name. This pattern is used throughout `LibDecimalFloat.sol` and should be maintained for consistency in related contracts like `DecimalFloat.sol`.
Learnt from: rouzwelt
PR: rainlanguage/rain.math.float#83
File: src/concrete/DecimalFloat.sol:248-251
Timestamp: 2025-07-24T04:32:14.171Z
Learning: In the rainlanguage/rain.math.float project, functions in DecimalFloat.sol that return tuples from LibDecimalFloat calls must unpack the tuple into local variables before returning them (rather than returning directly) to maintain compatibility with Slither static analysis checks.
📚 Learning: in the rainlanguage/rain.math.float codebase, there's an established naming convention where functio...
Learnt from: 0xgleb
PR: rainlanguage/rain.math.float#58
File: src/concrete/DecimalFloat.sol:175-182
Timestamp: 2025-06-16T13:17:28.513Z
Learning: In the rainlanguage/rain.math.float codebase, there's an established naming convention where functions accepting a `Float` type parameter consistently use `float` as the parameter name, even though it shadows the type name. This pattern is used throughout `LibDecimalFloat.sol` and should be maintained for consistency in related contracts like `DecimalFloat.sol`.

Applied to files:

  • test/src/concrete/DecimalFloat.sqrt.t.sol
📚 Learning: in the rainlanguage/rain.math.float project, functions in decimalfloat.sol that return tuples from l...
Learnt from: rouzwelt
PR: rainlanguage/rain.math.float#83
File: src/concrete/DecimalFloat.sol:248-251
Timestamp: 2025-07-24T04:32:14.171Z
Learning: In the rainlanguage/rain.math.float project, functions in DecimalFloat.sol that return tuples from LibDecimalFloat calls must unpack the tuple into local variables before returning them (rather than returning directly) to maintain compatibility with Slither static analysis checks.

Applied to files:

  • test/src/concrete/DecimalFloat.sqrt.t.sol
📚 Learning: in the rain.math.float library, all values of `float` (which is a type alias for bytes32) are consid...
Learnt from: thedavidmeister
PR: rainlanguage/rain.math.float#30
File: test/src/lib/LibDecimalFloat.gt.t.sol:33-36
Timestamp: 2025-04-25T03:58:01.307Z
Learning: In the rain.math.float library, all values of `Float` (which is a type alias for bytes32) are considered valid and can be safely used with methods like gt(), lt(), or eq() without causing reverts.

Applied to files:

  • test/src/concrete/DecimalFloat.sqrt.t.sol
📚 Learning: in the rainlanguage/rain.math.float codebase, variable shadowing in property tests like test_lt_eq_g...
Learnt from: 0xgleb
PR: rainlanguage/rain.math.float#58
File: crates/float/src/lib.rs:382-401
Timestamp: 2025-06-16T13:19:32.009Z
Learning: In the rainlanguage/rain.math.float codebase, variable shadowing in property tests like test_lt_eq_gt_with_add is acceptable when it represents a logical progression of the same conceptual value being tested through different states.

Applied to files:

  • test/src/concrete/DecimalFloat.sqrt.t.sol
📚 Learning: the file `crates/float/proptest-regressions/lib.txt` is automatically generated by proptest and shou...
Learnt from: 0xgleb
PR: rainlanguage/rain.math.float#46
File: crates/float/proptest-regressions/lib.txt:1-3
Timestamp: 2025-06-11T09:03:20.771Z
Learning: The file `crates/float/proptest-regressions/lib.txt` is automatically generated by proptest and should not be manually edited.

Applied to files:

  • test/src/concrete/DecimalFloat.sqrt.t.sol
📚 Learning: in the rainlanguage/rain.math.float repository, the user rouzwelt accepts non-null assertions in tes...
Learnt from: rouzwelt
PR: rainlanguage/rain.math.float#76
File: test_js/float.test.ts:9-32
Timestamp: 2025-07-17T02:38:44.698Z
Learning: In the rainlanguage/rain.math.float repository, the user rouzwelt accepts non-null assertions in test files because tests should throw and fail immediately when something goes wrong, making it clear where the issue occurred.

Applied to files:

  • test/src/concrete/DecimalFloat.sqrt.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). (7)
  • GitHub Check: rainix (ubuntu-latest, rainix-rs-test)
  • GitHub Check: git-clean
  • GitHub Check: rainix (ubuntu-latest, test-wasm-build)
  • GitHub Check: rainix (macos-latest, rainix-rs-test)
  • GitHub Check: rainix (ubuntu-latest, rainix-sol-test)
  • GitHub Check: rainix (ubuntu-latest, rainix-sol-static)
  • GitHub Check: rainix (ubuntu-latest, rainix-rs-static)
🔇 Additional comments (5)
test/src/concrete/DecimalFloat.sqrt.t.sol (5)

1-2: LGTM!

Standard license header and pragma declaration are correctly specified.


4-6: LGTM!

All necessary imports are present and correctly structured for testing sqrt functionality.


8-9: LGTM!

Contract name correctly reflects sqrt testing functionality, and the using statement follows established codebase patterns.


11-13: LGTM!

Helper function correctly implements sqrt call with required LOG_TABLES_ADDRESS parameter, following established naming conventions.


15-26: LGTM!

Comprehensive test that validates consistency between library and deployed contract sqrt implementations. The try/catch pattern effectively tests both success and error cases, ensuring consistent behavior across implementations.

✨ 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-sqrt

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 d06054a and 7c3e7c8.

📒 Files selected for processing (8)
  • .gas-snapshot (3 hunks)
  • src/concrete/DecimalFloat.sol (1 hunks)
  • src/lib/LibDecimalFloat.sol (2 hunks)
  • test/src/concrete/DecimalFloat.pow.t.sol (1 hunks)
  • test/src/concrete/DecimalFloat.sqrt.t.sol (1 hunks)
  • test/src/lib/LibDecimalFloat.constants.t.sol (1 hunks)
  • test/src/lib/LibDecimalFloat.pow.t.sol (1 hunks)
  • test/src/lib/LibDecimalFloat.sqrt.t.sol (1 hunks)
🧰 Additional context used
🧠 Learnings (11)
📓 Common learnings
Learnt from: 0xgleb
PR: rainlanguage/rain.math.float#59
File: crates/float/src/lib.rs:233-242
Timestamp: 2025-06-17T10:17:56.205Z
Learning: In the rainlanguage/rain.math.float repository, the maintainer 0xgleb prefers to handle documentation additions and improvements in separate issues rather than inline with feature PRs.
Learnt from: 0xgleb
PR: rainlanguage/rain.math.float#70
File: crates/float/src/evm.rs:38-43
Timestamp: 2025-07-03T11:20:50.456Z
Learning: In the rainlanguage/rain.math.float codebase, the user 0xgleb prefers not to add explanatory comments for well-established Rust idioms like the double `?` pattern, as these are self-explanatory to experienced Rust developers and don't need over-commenting.
Learnt from: rouzwelt
PR: rainlanguage/rain.math.float#76
File: test_js/float.test.ts:9-32
Timestamp: 2025-07-17T02:38:44.698Z
Learning: In the rainlanguage/rain.math.float repository, the user rouzwelt accepts non-null assertions in test files because tests should throw and fail immediately when something goes wrong, making it clear where the issue occurred.
Learnt from: 0xgleb
PR: rainlanguage/rain.math.float#58
File: src/concrete/DecimalFloat.sol:175-182
Timestamp: 2025-06-16T13:17:28.513Z
Learning: In the rainlanguage/rain.math.float codebase, there's an established naming convention where functions accepting a `Float` type parameter consistently use `float` as the parameter name, even though it shadows the type name. This pattern is used throughout `LibDecimalFloat.sol` and should be maintained for consistency in related contracts like `DecimalFloat.sol`.
Learnt from: rouzwelt
PR: rainlanguage/rain.math.float#83
File: src/concrete/DecimalFloat.sol:248-251
Timestamp: 2025-07-24T04:32:14.171Z
Learning: In the rainlanguage/rain.math.float project, functions in DecimalFloat.sol that return tuples from LibDecimalFloat calls must unpack the tuple into local variables before returning them (rather than returning directly) to maintain compatibility with Slither static analysis checks.
📚 Learning: in the rainlanguage/rain.math.float codebase, there's an established naming convention where functio...
Learnt from: 0xgleb
PR: rainlanguage/rain.math.float#58
File: src/concrete/DecimalFloat.sol:175-182
Timestamp: 2025-06-16T13:17:28.513Z
Learning: In the rainlanguage/rain.math.float codebase, there's an established naming convention where functions accepting a `Float` type parameter consistently use `float` as the parameter name, even though it shadows the type name. This pattern is used throughout `LibDecimalFloat.sol` and should be maintained for consistency in related contracts like `DecimalFloat.sol`.

Applied to files:

  • src/concrete/DecimalFloat.sol
  • test/src/lib/LibDecimalFloat.pow.t.sol
  • test/src/lib/LibDecimalFloat.constants.t.sol
  • src/lib/LibDecimalFloat.sol
  • test/src/concrete/DecimalFloat.pow.t.sol
  • .gas-snapshot
  • test/src/concrete/DecimalFloat.sqrt.t.sol
  • test/src/lib/LibDecimalFloat.sqrt.t.sol
📚 Learning: in the rainlanguage/rain.math.float project, functions in decimalfloat.sol that return tuples from l...
Learnt from: rouzwelt
PR: rainlanguage/rain.math.float#83
File: src/concrete/DecimalFloat.sol:248-251
Timestamp: 2025-07-24T04:32:14.171Z
Learning: In the rainlanguage/rain.math.float project, functions in DecimalFloat.sol that return tuples from LibDecimalFloat calls must unpack the tuple into local variables before returning them (rather than returning directly) to maintain compatibility with Slither static analysis checks.

Applied to files:

  • src/concrete/DecimalFloat.sol
  • test/src/lib/LibDecimalFloat.pow.t.sol
  • test/src/lib/LibDecimalFloat.constants.t.sol
  • src/lib/LibDecimalFloat.sol
  • test/src/concrete/DecimalFloat.pow.t.sol
  • .gas-snapshot
  • test/src/concrete/DecimalFloat.sqrt.t.sol
  • test/src/lib/LibDecimalFloat.sqrt.t.sol
📚 Learning: in the rain.math.float library, all values of `float` (which is a type alias for bytes32) are consid...
Learnt from: thedavidmeister
PR: rainlanguage/rain.math.float#30
File: test/src/lib/LibDecimalFloat.gt.t.sol:33-36
Timestamp: 2025-04-25T03:58:01.307Z
Learning: In the rain.math.float library, all values of `Float` (which is a type alias for bytes32) are considered valid and can be safely used with methods like gt(), lt(), or eq() without causing reverts.

Applied to files:

  • src/concrete/DecimalFloat.sol
  • test/src/lib/LibDecimalFloat.constants.t.sol
  • src/lib/LibDecimalFloat.sol
  • test/src/concrete/DecimalFloat.pow.t.sol
  • .gas-snapshot
  • test/src/concrete/DecimalFloat.sqrt.t.sol
  • test/src/lib/LibDecimalFloat.sqrt.t.sol
📚 Learning: in the rain.math.float project, the float type is designed with a specific bit layout: 224-bit signe...
Learnt from: 0xgleb
PR: rainlanguage/rain.math.float#64
File: src/concrete/DecimalFloat.sol:0-0
Timestamp: 2025-06-17T10:02:01.394Z
Learning: In the rain.math.float project, the Float type is designed with a specific bit layout: 224-bit signed coefficient and 32-bit signed exponent, represented as 32 bytes total. The LibDecimalFloat.unpack function returns values that are guaranteed to fit within int224 and int32 ranges due to this internal representation, making explicit range checks before casting unnecessary.

Applied to files:

  • test/src/lib/LibDecimalFloat.pow.t.sol
  • test/src/lib/LibDecimalFloat.constants.t.sol
  • src/lib/LibDecimalFloat.sol
  • .gas-snapshot
  • test/src/concrete/DecimalFloat.sqrt.t.sol
📚 Learning: in the rainlanguage/rain.math.float codebase, variable shadowing in property tests like test_lt_eq_g...
Learnt from: 0xgleb
PR: rainlanguage/rain.math.float#58
File: crates/float/src/lib.rs:382-401
Timestamp: 2025-06-16T13:19:32.009Z
Learning: In the rainlanguage/rain.math.float codebase, variable shadowing in property tests like test_lt_eq_gt_with_add is acceptable when it represents a logical progression of the same conceptual value being tested through different states.

Applied to files:

  • test/src/lib/LibDecimalFloat.pow.t.sol
  • test/src/lib/LibDecimalFloat.constants.t.sol
  • .gas-snapshot
  • test/src/concrete/DecimalFloat.sqrt.t.sol
  • test/src/lib/LibDecimalFloat.sqrt.t.sol
📚 Learning: the file `crates/float/proptest-regressions/lib.txt` is automatically generated by proptest and shou...
Learnt from: 0xgleb
PR: rainlanguage/rain.math.float#46
File: crates/float/proptest-regressions/lib.txt:1-3
Timestamp: 2025-06-11T09:03:20.771Z
Learning: The file `crates/float/proptest-regressions/lib.txt` is automatically generated by proptest and should not be manually edited.

Applied to files:

  • test/src/lib/LibDecimalFloat.pow.t.sol
  • test/src/lib/LibDecimalFloat.constants.t.sol
  • .gas-snapshot
  • test/src/concrete/DecimalFloat.sqrt.t.sol
  • test/src/lib/LibDecimalFloat.sqrt.t.sol
📚 Learning: in the rainlanguage/rain.math.float repository, the user rouzwelt accepts non-null assertions in tes...
Learnt from: rouzwelt
PR: rainlanguage/rain.math.float#76
File: test_js/float.test.ts:9-32
Timestamp: 2025-07-17T02:38:44.698Z
Learning: In the rainlanguage/rain.math.float repository, the user rouzwelt accepts non-null assertions in test files because tests should throw and fail immediately when something goes wrong, making it clear where the issue occurred.

Applied to files:

  • test/src/lib/LibDecimalFloat.constants.t.sol
  • test/src/concrete/DecimalFloat.sqrt.t.sol
  • test/src/lib/LibDecimalFloat.sqrt.t.sol
📚 Learning: in the rain.math.float codebase, the user prefers implementing standard rust traits (like neg) rathe...
Learnt from: 0xgleb
PR: rainlanguage/rain.math.float#57
File: crates/float/src/lib.rs:316-328
Timestamp: 2025-06-18T09:10:41.740Z
Learning: In the rain.math.float codebase, the user prefers implementing standard Rust traits (like Neg) rather than creating redundant public methods when the trait already provides the needed functionality. Float implements Copy, so reference usage with operators is not a concern.

Applied to files:

  • test/src/lib/LibDecimalFloat.constants.t.sol
  • src/lib/LibDecimalFloat.sol
📚 Learning: in the rainlanguage/rain.math.float repository, the maintainer 0xgleb prefers to handle documentatio...
Learnt from: 0xgleb
PR: rainlanguage/rain.math.float#59
File: crates/float/src/lib.rs:233-242
Timestamp: 2025-06-17T10:17:56.205Z
Learning: In the rainlanguage/rain.math.float repository, the maintainer 0xgleb prefers to handle documentation additions and improvements in separate issues rather than inline with feature PRs.

Applied to files:

  • src/lib/LibDecimalFloat.sol
📚 Learning: in the rain.math.float rust crate, the `execute_call` function already provides sufficient abstracti...
Learnt from: 0xgleb
PR: rainlanguage/rain.math.float#58
File: crates/float/src/lib.rs:201-232
Timestamp: 2025-06-16T13:14:38.431Z
Learning: In the rain.math.float Rust crate, the `execute_call` function already provides sufficient abstraction for EVM contract calls by handling execution boilerplate, error handling, and result processing. Individual methods like `lt`, `eq`, `gt` only need to handle their specific call encoding and result decoding, making further abstraction unnecessary.

Applied to files:

  • test/src/concrete/DecimalFloat.pow.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). (7)
  • GitHub Check: rainix (ubuntu-latest, rainix-rs-static)
  • GitHub Check: rainix (ubuntu-latest, rainix-sol-static)
  • GitHub Check: rainix (ubuntu-latest, rainix-rs-test)
  • GitHub Check: rainix (ubuntu-latest, rainix-sol-test)
  • GitHub Check: rainix (ubuntu-latest, test-wasm-build)
  • GitHub Check: rainix (macos-latest, rainix-rs-test)
  • GitHub Check: git-clean
🔇 Additional comments (15)
src/lib/LibDecimalFloat.sol (2)

99-105: LGTM! Constants are correctly defined.

The hex encodings properly represent 0.5 and 2.0 in the Float format, which will be essential for the sqrt implementation.


701-715: LGTM! Square root implementation is mathematically sound.

The implementation correctly calculates sqrt(a) = a^0.5 by delegating to the existing pow function. The documentation appropriately warns users about approximation inaccuracies inherent in the logarithmic tables.

src/concrete/DecimalFloat.sol (1)

191-196: LGTM! Function properly exposes sqrt functionality.

The implementation follows established patterns in the contract, correctly delegates to LibDecimalFloat.sqrt, and maintains consistency with other mathematical operations.

test/src/lib/LibDecimalFloat.pow.t.sol (1)

105-105: LGTM! Good refactoring to use predefined constant.

Using FLOAT_ONE instead of manual packing improves readability and consistency with the newly introduced constants.

test/src/lib/LibDecimalFloat.constants.t.sol (1)

80-90: LGTM! Proper validation of new constants.

The tests correctly verify that FLOAT_HALF represents 0.5 and FLOAT_TWO represents 2.0, which are essential for the sqrt functionality.

test/src/concrete/DecimalFloat.pow.t.sol (2)

11-13: LGTM! Function signature improvements.

Making the function view is appropriate since power operations don't modify state, and using LOG_TABLES_ADDRESS directly is consistent with other implementations.


15-26: LGTM! Comprehensive deployment testing.

The test properly validates consistency between internal and external implementations, handling both success and revert cases appropriately.

test/src/concrete/DecimalFloat.sqrt.t.sol (2)

11-13: LGTM!

The external sqrt function correctly wraps the library call and follows established testing patterns.


15-26: LGTM!

The test function correctly ensures behavioral consistency between the external library call and the deployed contract's sqrt method. The try-catch pattern properly validates both success and error cases.

test/src/lib/LibDecimalFloat.sqrt.t.sol (5)

1-13: LGTM!

The imports are comprehensive and appropriate for the sqrt testing requirements. The contract setup follows established patterns.


14-50: LGTM!

The helper functions are well-designed for comprehensive sqrt testing. The diffLimit tolerance, gas logging, and round-trip validation provide thorough test coverage. Parameter naming follows established conventions.


59-74: LGTM!

The negative input testing correctly validates that sqrt of negative numbers reverts with the appropriate Log10Negative error. The logic to ensure negative inputs and normalize coefficients for error matching is sound.


76-91: LGTM!

The round-trip testing approach is comprehensive, covering both specific test cases and fuzz testing. The parameter bounds ensure valid sqrt inputs while testing a wide range of values. This validates numerical accuracy of the sqrt implementation.


52-57: No changes needed: sqrt(16) test is correct as written

The computed value of
399950000000000000000000000000000000000000 × 10^(–41)
is ~3.9995, which matches the implementation’s precision and rounding behavior. The test’s expected coefficient/exponent pair therefore correctly reflects the actual output of LibDecimalFloat.sqrt(16).

✅ Approving as-is.

.gas-snapshot (1)

1-291: Gas snapshot update reflects new sqrt functionality.

The gas snapshot correctly includes new sqrt-related tests and shows minor gas usage variations. This is an automatically generated file that reflects the expected changes from the sqrt implementation.

Comment thread test/src/concrete/DecimalFloat.sqrt.t.sol Outdated
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@thedavidmeister thedavidmeister merged commit 44a8b39 into main Aug 6, 2025
8 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Sep 2, 2025
4 tasks
This was referenced Sep 30, 2025
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