concrete mul#43
Conversation
## Walkthrough
This change introduces a new `DecimalFloat` contract exposing the full set of decimal floating-point operations from the `LibDecimalFloat` library as external functions for offchain access. It also standardizes naming conventions by renaming multiplication, division, power, and power10 functions from `multiply`, `divide`, `power`, and `power10` to `mul`, `div`, `pow`, and `pow10` respectively, updating all internal calls, documentation, and tests accordingly. Additionally, deployment helper functions and related imports were adjusted.
## Changes
| File(s) | Change Summary |
|-------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------|
| src/concrete/DecimalFloat.sol | Added new `DecimalFloat` contract exposing `Float` operations externally, forwarding calls to `LibDecimalFloat` functions. |
| src/lib/LibDecimalFloat.sol | Renamed functions: `multiply`→`mul`, `divide`→`div`, `power10`→`pow10`, `power`→`pow`; updated parameter order for `pow10`; revised NatSpec comments; updated internal calls. |
| src/lib/implementation/LibDecimalFloatImplementation.sol | Renamed internal functions `multiply`→`mul`, `divide`→`div`, `power10`→`pow10`; updated all internal calls accordingly; replaced detailed docstring with brief comment. |
| test/lib/LibDecimalFloatSlow.sol | Renamed `multiplySlow`→`mulSlow`; updated internal call from `divide` to `div` in `invSlow`; no logic changes. |
| test/src/concrete/DecimalFloat.mul.t.sol | Added new test contract `DecimalFloatMulTest` verifying multiplication consistency between library and deployed contract. |
| test/src/lib/LibDecimalFloat.mixed.t.sol | Renamed test function and calls from `divide` to `div` and from `multiply` to `mul`. |
| test/src/lib/LibDecimalFloat.mul.t.sol | Renamed test contract and functions from `multiply*` to `mul*`; updated all related calls. |
| test/src/lib/implementation/LibDecimalFloatImplementation.mul.t.sol | Renamed test contract and all test functions from `Multiply*` to `Mul*`; updated all related calls. |
| test/src/lib/LibDecimalFloat.div.t.sol | Renamed test contract and functions from `divide*` to `div*`; updated all related calls. |
| test/src/lib/LibDecimalFloat.pow.t.sol | Renamed test contract and functions from `power*` to `pow*`; updated calls to division from `divide` to `div`. |
| test/src/lib/LibDecimalFloat.pow10.t.sol | Renamed test contract and functions from `power10*` to `pow10*`; updated calls to `power10`→`pow10` and argument order. |
| test/src/lib/implementation/LibDecimalFloatImplementation.div.t.sol | Renamed test contract and functions from `Divide*` to `Div*`; updated all related calls to `divide`→`div`. |
| test/src/lib/implementation/LibDecimalFloatImplementation.pow10.t.sol | Renamed test contract and functions from `Power10*` to `Pow10*`; updated calls to `power10`→`pow10`. |
| script/Deploy.sol | Updated import path for `LibDecimalFloatDeploy`; added call to `LibDecimalFloatDeploy.decimalFloatZoltu()` after `container.writeZoltu()`. |
| src/lib/deploy/LibDecimalFloatDeploy.sol | Changed import path; added constant `LOG_TABLES_ADDRESS`; added `decimalFloatZoltu()` function deploying `DecimalFloat` contract via low-level call; unchanged existing functions. |
| test/abstract/LogTest.sol | Updated import path for `LibDecimalFloatDeploy`. |
| test/src/concrete/DecimalFloat.add.t.sol | Added new test contract `DecimalFloatAddTest` verifying addition consistency between library and deployed contract. |
| test/src/concrete/DecimalFloat.abs.t.sol | Added new test contract `DecimalFloatAbsTest` verifying absolute value consistency between library and deployed contract. |
| test/src/concrete/DecimalFloat.div.t.sol | Added new test contract `DecimalFloatDivTest` verifying division consistency between library and deployed contract. |
| test/src/concrete/DecimalFloat.eq.t.sol | Added new test contract `DecimalFloatEqTest` verifying equality comparison consistency. |
| test/src/concrete/DecimalFloat.floor.t.sol | Added new test contract `DecimalFloatFloorTest` verifying floor function consistency. |
| test/src/concrete/DecimalFloat.format.t.sol | Added new test contract `DecimalFloatFormatTest` verifying formatting consistency. |
| test/src/concrete/DecimalFloat.frac.t.sol | Added new test contract `DecimalFloatFracTest` verifying fractional part function consistency. |
| test/src/concrete/DecimalFloat.gt.t.sol | Added new test contract `DecimalFloatGtTest` verifying greater-than comparison consistency. |
| test/src/concrete/DecimalFloat.inv.t.sol | Added new test contract `DecimalFloatInvTest` verifying inversion consistency. |
| test/src/concrete/DecimalFloat.isZero.t.sol | Added new test contract `DecimalFloatIsZeroTest` verifying zero-check consistency. |
| test/src/concrete/DecimalFloat.log10.t.sol | Added new test contract `DecimalFloatLog10Test` with external log10 function; test function commented out. |
| test/src/concrete/DecimalFloat.lt.t.sol | Added new test contract `DecimalFloatLtTest` verifying less-than comparison consistency. |
| test/src/concrete/DecimalFloat.max.t.sol | Added new test contract `DecimalFloatMaxTest` verifying maximum function consistency. |
| test/src/concrete/DecimalFloat.min.t.sol | Added new test contract `DecimalFloatMinTest` verifying minimum function consistency. |
| test/src/concrete/DecimalFloat.minus.t.sol | Added new test contract `DecimalFloatMinusTest` verifying negation consistency. |
| test/src/concrete/DecimalFloat.parse.t.sol | Added new test contract `DecimalFloatParseTest` verifying parsing consistency. |
| test/src/concrete/DecimalFloat.pow.t.sol | Added new test contract `DecimalFloatPowTest` with external pow function; test function commented out. |
| test/src/concrete/DecimalFloat.pow10.t.sol | Added new test contract `DecimalFloatPow10Test` with external pow10 function; test function commented out. |
| test/src/concrete/DecimalFloat.sub.t.sol | Added new test contract `DecimalFloatSubTest` verifying subtraction consistency. |
| test/src/lib/LibDecimalFloat.isZero.t.sol | Added new test contract `LibDecimalFloatIsZeroTest` verifying isZero function behavior with multiple test cases. |
## Sequence Diagram(s)
```mermaid
sequenceDiagram
participant User
participant DecimalFloat (Contract)
participant LibDecimalFloat (Library)
participant LibDecimalFloatImplementation (Library)
User->>DecimalFloat: mul(Float a, Float b)
DecimalFloat->>LibDecimalFloat: mul(Float a, Float b)
LibDecimalFloat->>LibDecimalFloatImplementation: mul(int256 coeffA, int256 expA, int256 coeffB, int256 expB)
LibDecimalFloatImplementation-->>LibDecimalFloat: returns (int256, int256)
LibDecimalFloat-->>DecimalFloat: returns Float
DecimalFloat-->>User: returns FloatPossibly related PRs
Suggested reviewers
|
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (8)
src/concrete/DecimalFloat.sol(1 hunks)src/lib/LibDecimalFloat.sol(2 hunks)src/lib/implementation/LibDecimalFloatImplementation.sol(3 hunks)test/lib/LibDecimalFloatSlow.sol(1 hunks)test/src/concrete/DecimalFloat.mul.t.sol(1 hunks)test/src/lib/LibDecimalFloat.mixed.t.sol(1 hunks)test/src/lib/LibDecimalFloat.mul.t.sol(1 hunks)test/src/lib/implementation/LibDecimalFloatImplementation.mul.t.sol(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: git-clean
- GitHub Check: rainix (ubuntu-latest, rainix-sol-test)
- GitHub Check: rainix (ubuntu-latest, rainix-sol-static)
🔇 Additional comments (22)
test/src/lib/LibDecimalFloat.mixed.t.sol (1)
21-21: Consistent function renaming applied.The function call has been updated from
multiplytomul, maintaining consistency with the standardized naming convention established across the codebase.src/concrete/DecimalFloat.sol (1)
1-12: Well-structured concrete contract implementation.This new contract provides a clean external interface to the
mulfunction in the LibDecimalFloat library. The implementation correctly uses the library, follows appropriate naming conventions, and properly implements the function asexternal pure.test/lib/LibDecimalFloatSlow.sol (1)
10-10: Consistent function renaming for slow implementation.The function name has been standardized from
multiplySlowtomulSlow, maintaining consistency with the other multiplication function renames in the codebase.src/lib/implementation/LibDecimalFloatImplementation.sol (3)
92-93: Function renamed with concise documentation.The function has been renamed from
multiplytomulwith a brief but clear comment indicating it's a stack-only implementation. This standardizes the naming convention across the codebase.
125-125: Updated internal reference to renamed function.The recursive call has been updated to refer to the renamed
mulfunction, maintaining consistency throughout the implementation.
836-836: Updated function reference in linear interpolation.The function call within the
unitLinearInterpolationmethod has been updated to use the renamedmulfunction, ensuring consistency across all internal references.test/src/lib/LibDecimalFloat.mul.t.sol (3)
9-9: Contract renamed to follow consistent naming conventionThe contract has been renamed from
LibDecimalFloatMultiplyTesttoLibDecimalFloatMulTestto align with the standardized naming convention for multiplication functions across the codebase.
12-22: Updated function name and implementation callThe function has been renamed from
multiplyExternaltomulExternaland now correctly callsLibDecimalFloatImplementation.mulinstead ofmultiply. This change maintains the same functionality while adhering to the new naming convention.
24-26: Updated method name and implementation callThe secondary helper function has been renamed and updated to use the new
mulmethod name instead ofmultiply. This change maintains consistency with the new naming convention.src/lib/LibDecimalFloat.sol (3)
421-438: Enhanced documentation for multiplication operationThe function documentation has been replaced with a more detailed excerpt from the decimal arithmetic specification, providing a comprehensive explanation of how the multiplication operation works, including coefficient handling, exponent combination, and rounding behavior.
This improved documentation makes the code more maintainable and easier to understand.
442-451: Renamed function frommultiplytomulThe function has been renamed from
multiplytomulto standardize the naming convention for multiplication operations across the library. The implementation correctly calls the updatedLibDecimalFloatImplementation.mulmethod.This change maintains the same functionality while providing a more concise and consistent API.
608-610: Updated implementation call in power functionThe internal call in the
powerfunction has been updated to use the renamedLibDecimalFloatImplementation.mulmethod instead ofmultiply. This ensures consistency with the new naming convention throughout the library.test/src/concrete/DecimalFloat.mul.t.sol (3)
1-7: New test file with appropriate importsThis new test file correctly imports the necessary dependencies, including the core
DecimalFloatcontract, theLibDecimalFloatlibrary, and the ForgeTestcontract.
8-13: Well-structured test contract with helper methodThe
DecimalFloatTestcontract is properly structured with the appropriate library usage and includes a helper methodmulExternalthat cleanly wraps the library's multiplication functionality.
15-26: Comprehensive test for deployed contract behaviorThe
testMulDeployedfunction effectively verifies that the deployedDecimalFloatcontract's multiplication behavior is consistent with the library implementation:
- It creates a new instance of the
DecimalFloatcontract- It tries to multiply two floats using the library's implementation
- If successful, it verifies that the deployed contract returns the same result
- If the library implementation reverts, it verifies that the deployed contract reverts with the same error
This ensures behavioral consistency between the library and contract implementations.
test/src/lib/implementation/LibDecimalFloatImplementation.mul.t.sol (7)
14-14: Contract renamed to follow consistent naming conventionThe test contract has been renamed from
LibDecimalFloatImplementationMultiplyTesttoLibDecimalFloatImplementationMulTestto align with the standardized naming convention for multiplication functions.
17-21: Updated test method name and implementation callThe test function has been renamed from
testMultiplyZero0ExponenttotestMulZero0Exponentand now correctly calls the renamed implementation methodLibDecimalFloatImplementation.mul.
25-29: Updated test method name and implementation callThe test function has been renamed from
testMultiplyZeroAnyExponenttotestMulZeroAnyExponentand now correctly calls the renamed implementation method.
33-37: Renamed test methods with consistent naming conventionMultiple test methods have been renamed from using "Multiply" to "Mul" in their names, maintaining a consistent naming convention throughout the test file and calling the renamed implementation methods.
Also applies to: 41-45, 49-53, 57-61, 76-80
65-73: Updated test method with exponentsThe test method for multiplication with exponents has been updated to use the renamed
mulmethod while maintaining the same test logic and assertions.
82-90: Renamed gas benchmark testsThe gas benchmark test methods have been renamed to use the "Mul" naming convention, contributing to the overall consistency of the codebase.
92-107: Updated property-based test with renamed methodsThe property-based test has been updated to call both the renamed implementation method
LibDecimalFloatImplementation.muland the renamed slow implementation methodLibDecimalFloatSlow.mulSlow. The test logic remains unchanged, ensuring comprehensive testing of the implementation.
There was a problem hiding this comment.
Actionable comments posted: 4
🔭 Outside diff range comments (1)
src/lib/implementation/LibDecimalFloatImplementation.sol (1)
1-852: 💡 Verification agent🧩 Analysis chain
Verify the consistency of function naming across the codebase.
All arithmetic function names have been standardized (
multiply→mul,divide→div,power10→pow10). This change enhances consistency and readability but requires verification that all references have been updated.
🏁 Script executed:
#!/bin/bash # Check for any remaining instances of the old function names to ensure complete renaming echo "Checking for remaining references to 'multiply'..." rg -i -l "multiply" --glob "*.sol" | grep -v "comment\|doc" echo "Checking for remaining references to 'divide'..." rg -i -l "divide" --glob "*.sol" | grep -v "comment\|doc" echo "Checking for remaining references to 'power10'..." rg -i -l "power10" --glob "*.sol" | grep -v "comment\|doc"Length of output: 1036
Update remaining references to standardized arithmetic function names
The grep run shows that occurrences of the old names still exist in both code and tests. Please replace:
multiply→muldivide→divpower10→pow10in the following files:
• test/src/lib/LibDecimalFloat.mul.t.sol
• test/src/lib/implementation/LibDecimalFloatImplementation.mul.t.sol
• src/lib/LibDecimalFloat.sol
• src/concrete/DecimalFloat.sol
• src/lib/implementation/LibDecimalFloatImplementation.sol• test/src/lib/LibDecimalFloat.pow.t.sol
• test/src/lib/implementation/LibDecimalFloatImplementation.pow.t.sol• test/src/lib/LibDecimalFloat.pow10.t.sol
After updating function calls and doc‐comments in those files, rerun the search to confirm no legacy names remain.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (13)
script/Deploy.sol(2 hunks)src/concrete/DecimalFloat.sol(1 hunks)src/lib/LibDecimalFloat.sol(5 hunks)src/lib/deploy/LibDecimalFloatDeploy.sol(2 hunks)src/lib/implementation/LibDecimalFloatImplementation.sol(6 hunks)test/abstract/LogTest.sol(1 hunks)test/lib/LibDecimalFloatSlow.sol(2 hunks)test/src/lib/LibDecimalFloat.div.t.sol(1 hunks)test/src/lib/LibDecimalFloat.mixed.t.sol(1 hunks)test/src/lib/LibDecimalFloat.pow.t.sol(5 hunks)test/src/lib/LibDecimalFloat.pow10.t.sol(1 hunks)test/src/lib/implementation/LibDecimalFloatImplementation.div.t.sol(3 hunks)test/src/lib/implementation/LibDecimalFloatImplementation.pow10.t.sol(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: rainix (ubuntu-latest, rainix-sol-test)
- GitHub Check: rainix (ubuntu-latest, rainix-sol-static)
- GitHub Check: git-clean
🔇 Additional comments (47)
test/abstract/LogTest.sol (1)
7-7: Import path update looks good.The change correctly reflects the reorganization of deployment-related code into a dedicated
deploysubdirectory, which improves code organization. The import is still used correctly in the file's logic.script/Deploy.sol (2)
6-6: Import path update looks good.The change correctly reflects the reorganization of deployment-related code into a dedicated
deploysubdirectory.
20-21: New deployment step for DecimalFloat contract properly integrated.This addition correctly integrates the deployment of the new
DecimalFloatcontract within the broadcast block, following the existing pattern withZoltusuffix for deployment methodology.test/src/lib/LibDecimalFloat.mixed.t.sol (3)
13-13: Function name standardization looks good.Renaming to
testDiv1Over3aligns with the standard Solidity naming conventions and matches the library function name change.
16-16: Method call renaming fromdividetodivlooks good.This change is part of the standardization of naming conventions throughout the codebase, aligning with common Solidity practices.
21-21: Method call renaming frommultiplytomullooks good.This change is part of the standardization of naming conventions throughout the codebase, aligning with common Solidity practices.
test/src/lib/implementation/LibDecimalFloatImplementation.pow10.t.sol (5)
9-9: Contract name standardization looks good.Renaming to
LibDecimalFloatImplementationPow10Testaligns with the library function name change and maintains consistency in the codebase.
12-12: Helper function rename fromcheckPower10tocheckPow10looks good.This change aligns with the standardization of naming conventions throughout the codebase.
20-20: Library function call rename topow10looks good.Updated to use the standardized function name in the implementation library.
25-25: Test function rename totestExactPowslooks good.This change maintains consistency with the renamed function being tested.
27-33: Helper function call updates look good.All calls to the helper function have been consistently updated to use the new name
checkPow10. This thorough approach ensures no references to the old name remain.Also applies to: 37-44, 54-59, 64-68, 82-82
src/lib/deploy/LibDecimalFloatDeploy.sol (1)
16-17: Unused constant & duplicated literal
LOG_TABLES_ADDRESSis declared but never referenced; the hard-coded address is duplicated inside the assembly block.
Replace the literal with the constant to reduce maintenance risk and ensure single-source-of-truth.[ suggest_nitpick ]
test/lib/LibDecimalFloatSlow.sol (2)
10-18: Rename looks good
mulSlowcleanly replaces the oldmultiplySlowname without altering behaviour.
No further action required.
42-44: Confirm denominator ordering after renameThe signature of
LibDecimalFloatImplementation.divis
div(int256 numCoeff, int256 numExp, int256 denCoeff, int256 denExp).Just double-check that
(1e37, -37)is intended to be the numerator here; previously the helper may have taken the reciprocal internally.test/src/lib/LibDecimalFloat.pow10.t.sol (5)
8-8: Contract name has been updated for consistency.The contract name has been updated from
LibDecimalFloatPower10TesttoLibDecimalFloatPow10Testto match the renamed function.
11-12: Function renamed and parameter order updated.The function name has been updated from
power10Externaltopow10Externalfor consistency, and the implementation call has been updated to match the renamed function in the library.
15-16: Function renamed and parameter order swapped.The function
pow10Externalhas been updated to callLibDecimalFloat.pow10(float, logTables())instead of the previousLibDecimalFloat.power10(logTables(), float), changing both the function name and the parameter order.
19-19: Test function renamed for consistency.The test function has been updated from
testPower10PackedtotestPow10Packedto align with the function naming convention changes.
21-21: All internal function calls updated consistently.All calls to
pow10Externalhave been updated from previouspower10Externalcalls, ensuring consistent naming throughout the test suite.Also applies to: 26-26, 28-28, 35-35
test/src/lib/LibDecimalFloat.div.t.sol (4)
9-9: Contract name has been updated for consistency.The contract name has been updated from
LibDecimalFloatDivideTesttoLibDecimalFloatDivTestto match the renamed function.
12-12: Function renamed to maintain consistency.The function has been renamed from
divideExternaltodivExternaland the internal call has been updated fromLibDecimalFloatImplementation.dividetoLibDecimalFloatImplementation.div.Also applies to: 18-18
24-25: External function name and implementation call updated.The function has been renamed from
divideExternaltodivExternaland the library call has been updated fromLibDecimalFloat.dividetoLibDecimalFloat.div.
28-28: Test function and call references updated consistently.The test function has been renamed from
testDividePackedtotestDivPackedwith all internal function calls updated accordingly to maintain consistency.Also applies to: 31-31, 33-33, 39-39
test/src/lib/implementation/LibDecimalFloatImplementation.div.t.sol (4)
12-12: Contract name updated for consistency.The contract name has been changed from
LibDecimalFloatImplementationDivideTesttoLibDecimalFloatImplementationDivTestto align with the renamed operation.
13-13: Helper function and implementation call renamed.The internal helper function has been renamed from
checkDivisiontocheckDivand the internal call updated fromLibDecimalFloatImplementation.dividetoLibDecimalFloatImplementation.div.Also applies to: 22-22
28-29: Test functions and implementation calls updated.All test functions have been renamed from
testDivide*totestDiv*and all calls to the implementation's division function have been updated to useLibDecimalFloatImplementation.divinstead ofLibDecimalFloatImplementation.divide.Also applies to: 30-38
42-43: All remaining test functions and references updated consistently.All remaining test function names have been updated from
testDivide*totestDiv*and their implementation calls have been updated to use thedivfunction instead ofdivide.Also applies to: 47-48, 52-53, 58-59, 63-64, 68-69, 73-74, 78-80, 85-86, 91-91, 97-97, 109-109
src/lib/implementation/LibDecimalFloatImplementation.sol (6)
92-93: Function documentation and name updated.The
multiplyfunction has been renamed tomuland its documentation has been simplified to indicate it's a stack-only implementation.
125-125: Internal recursive call updated for consistency.The internal recursive call has been updated from
multiplytomulto maintain consistency with the function renaming.
181-181: Division function renamed for consistency.The
dividefunction has been renamed todivfollowing the naming convention update. All the implementation logic remains unchanged.
471-471: Division call inside log10 function updated.The internal call to the division function has been updated from
dividetodivto reflect the renamed function.
489-489: power10 function renamed to pow10.The
power10function and its recursive internal call have been renamed topow10for consistency with the other renamed functions.Also applies to: 497-497
836-836: References to multiply and divide updated in interpolation function.The calls to
multiplyanddividewithin theunitLinearInterpolationfunction have been updated tomulanddivrespectively.Also applies to: 844-844
src/lib/LibDecimalFloat.sol (9)
421-437: Documentation improvement for multiplication operationThe documentation has been significantly improved with a detailed excerpt from the decimal arithmetic specification, which clearly explains how coefficients, exponents, and signs combine during multiplication and how rounding is applied.
442-442: Function rename: multiply → mulRenaming from
multiplyto the more concisemulfollows standard naming conventions in Solidity math libraries and improves consistency.
446-446: Internal call update for multiplication functionThe internal call to the implementation library has been correctly updated to match the renamed function.
460-460: Function rename: divide → divRenaming from
divideto the more concisedivaligns with standard naming conventions and is consistent with other function renames in this PR.
464-464: Internal call update for division functionThe internal call to the implementation library has been correctly updated to match the renamed function.
558-560: Parameter order change and function rename for power10 → pow10The function has been renamed from
power10topow10and the parameter order has been changed to accept theFloatstruct first and thetablesDataContractaddress second. The NatSpec comments have been updated accordingly.
563-563: Internal call update for pow10 functionThe internal call to the implementation library has been correctly updated to use the renamed function, while maintaining the original parameter order with the tables address first.
600-600: Function rename: power → powRenaming from
powerto the more concisepowfollows standard naming conventions in Solidity math libraries and improves consistency.
609-609: Internal call updates in pow functionThe internal calls to
mulandpow10have been correctly updated to match the renamed functions.Also applies to: 612-612
src/concrete/DecimalFloat.sol (5)
1-8: Well-structured imports and appropriate licenseThe imports are well-organized, bringing in the necessary libraries for floating-point math operations, along with proper licensing and specific solidity version.
9-11: New DecimalFloat contract with proper library importThis contract will serve as an external-facing wrapper around the
LibDecimalFloatlibrary, properly importing the library using theusingstatement.
18-21: Consistent function implementations with clear documentationAll functions consistently follow the same pattern of forwarding calls to the underlying library functions, with clear NatSpec documentation describing each function's purpose and parameters.
Also applies to: 26-28, 34-36, 42-44, 49-51, 57-58, 64-66, 72-74, 80-81, 88-89, 96-97, 105-106, 112-113, 119-120, 126-127, 133-134, 141-142, 149-150, 157-158, 164-165
125-127: Proper handling of logarithmic and exponential functionsThe logarithmic and exponential functions (
pow10,log10,pow) correctly pass theLOG_TABLES_ADDRESSconstant to the underlying library functions, simplifying the external interface by hiding the implementation detail of the tables data contract.Also applies to: 132-134, 140-142
1-166: Comprehensive external API for decimal floating-point operationsThis new contract successfully exposes the full set of decimal floating-point operations from the
LibDecimalFloatlibrary as external functions, enabling offchain access to all functionality. The contract is well-structured, consistently implemented, and properly documented.
There was a problem hiding this comment.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (21)
test/src/concrete/DecimalFloat.abs.t.sol(1 hunks)test/src/concrete/DecimalFloat.add.t.sol(1 hunks)test/src/concrete/DecimalFloat.div.t.sol(1 hunks)test/src/concrete/DecimalFloat.eq.t.sol(1 hunks)test/src/concrete/DecimalFloat.floor.t.sol(1 hunks)test/src/concrete/DecimalFloat.format.t.sol(1 hunks)test/src/concrete/DecimalFloat.frac.t.sol(1 hunks)test/src/concrete/DecimalFloat.gt.t.sol(1 hunks)test/src/concrete/DecimalFloat.inv.t.sol(1 hunks)test/src/concrete/DecimalFloat.isZero.t.sol(1 hunks)test/src/concrete/DecimalFloat.log10.t.sol(1 hunks)test/src/concrete/DecimalFloat.lt.t.sol(1 hunks)test/src/concrete/DecimalFloat.max.t.sol(1 hunks)test/src/concrete/DecimalFloat.min.t.sol(1 hunks)test/src/concrete/DecimalFloat.minus.t.sol(1 hunks)test/src/concrete/DecimalFloat.mul.t.sol(1 hunks)test/src/concrete/DecimalFloat.parse.t.sol(1 hunks)test/src/concrete/DecimalFloat.pow.t.sol(1 hunks)test/src/concrete/DecimalFloat.pow10.t.sol(1 hunks)test/src/concrete/DecimalFloat.sub.t.sol(1 hunks)test/src/lib/LibDecimalFloat.isZero.t.sol(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: rainix (ubuntu-latest, rainix-sol-test)
- GitHub Check: rainix (ubuntu-latest, rainix-sol-static)
- GitHub Check: git-clean
🔇 Additional comments (34)
test/src/concrete/DecimalFloat.log10.t.sol (2)
1-7: The imports and Solidity version look good.The file correctly imports all necessary components and specifies a recent Solidity version (0.8.25), which includes the latest security fixes.
8-14: Implementation of the log10External function looks correct.The external function properly wraps the library method call with the required logTables parameter. This follows the established pattern for testing library functions against concrete contract implementations.
test/src/concrete/DecimalFloat.pow10.t.sol (3)
1-7: The imports and Solidity version look good.The file correctly imports the necessary components with a recent Solidity version (0.8.25).
8-14: The pow10External function is implemented correctly.The external function properly wraps the library method call with the required logTables parameter from the inherited LogTest contract.
15-26: Consider uncommenting the testPow10Deployed function.Similar to the log10 test, this test function is commented out. If it's meant to be included in the test suite, it should be uncommented. The function itself is well-structured with proper assertions and error handling.
test/src/concrete/DecimalFloat.isZero.t.sol (3)
1-7: The imports and Solidity version look good.The file correctly imports the necessary components and uses a recent Solidity version (0.8.25).
8-14: The isZeroExternal function is implemented correctly.The external function properly wraps the library method call for checking if a Float value is zero.
15-26: The testIsZeroDeployed function looks good.This test function follows best practices by:
- Deploying a fresh contract instance
- Comparing results between the library function and contract implementation
- Properly handling reverts with expectRevert
- Using assertEq for result verification
test/src/concrete/DecimalFloat.lt.t.sol (3)
1-7: The imports and Solidity version look good.The file correctly imports the necessary components and uses a recent Solidity version (0.8.25).
8-14: The ltExternal function is implemented correctly.The external function properly wraps the library method call for the less-than comparison between two Float values.
15-26: The testLtDeployed function looks good.This test function is well-structured with:
- A new contract instance deployment
- Proper comparison between library and contract results
- Consistent error handling for reverts
- Clear assertions using assertEq
test/src/concrete/DecimalFloat.pow.t.sol (1)
1-27: Function and file structure looks goodThe test contract follows a good pattern of testing the
powfunctionality of theDecimalFloatcontract by comparing library usage with the deployed contract behavior. The structure is consistent with other test files and properly handles both success and error cases.test/src/concrete/DecimalFloat.eq.t.sol (1)
1-27: Test implementation looks goodThis test correctly verifies that the
eqfunction in the deployedDecimalFloatcontract behaves identically to the library function, including proper error propagation. The structure follows a consistent pattern with other tests and properly handles both success and revert cases.test/src/concrete/DecimalFloat.frac.t.sol (1)
1-27: Test implementation is well-structuredThe test for the
fracfunction properly verifies that the deployed contract behaves identically to the library function. The test correctly unwrapsFloatvalues for comparison and handles error cases appropriately.test/src/concrete/DecimalFloat.gt.t.sol (1)
1-27: Test implementation is correctThe test for the
gtfunction properly verifies that the deployed contract behaves identically to the library function. The test follows the consistent pattern established in other test files and correctly handles both success and error cases.test/src/concrete/DecimalFloat.floor.t.sol (1)
1-27: Well-structured test contract forfloorfunctionThis test contract effectively validates that the
DecimalFloatcontract'sfloormethod produces identical results to theLibDecimalFloatlibrary's implementation. The try-catch pattern ensures proper handling of both successful executions and reverts.A few observations:
- The test follows a good pattern of comparing the library implementation with the contract implementation
- Error handling is properly implemented with vm.expectRevert
- Unwrapping Float values for comparison is the correct approach
test/src/concrete/DecimalFloat.format.t.sol (1)
1-28: Well-implemented test for string formatting functionalityThis test validates that the
formatfunction in theDecimalFloatcontract correctly delegates to theLibFormatDecimalFloat.toDecimalStringmethod. The test structure is solid, with proper handling of both successful executions and reverts.Unlike the numeric tests that unwrap Float values, this test correctly uses string equality comparison since the return type is a string.
test/src/concrete/DecimalFloat.abs.t.sol (1)
1-27: Consistent test implementation for absolute value functionThis test for the
absfunction follows the same robust pattern as the other tests, comparing the results from the library implementation with the contract implementation. The error handling and assertion logic are correctly implemented.The test effectively verifies that the
DecimalFloatcontract'sabsmethod preserves the behavior of the underlying library function.test/src/concrete/DecimalFloat.add.t.sol (1)
1-27: Binary operation test follows established patternThis test for the
addfunction correctly validates a binary operation (addition), following the same solid test pattern used across all the other function tests. The test appropriately handles two input parameters and compares the results from both implementations.The consistent test structure across all these files demonstrates good testing practices and will make maintenance easier.
test/src/concrete/DecimalFloat.min.t.sol (1)
1-27: Well-structured test for DecimalFloat min functionThis test ensures the
minfunction in theDecimalFloatcontract behaves consistently with the library implementation. The test structure is robust, handling both successful cases and error conditions appropriately.Good use of fuzzing with the parameter types, which will test a wide range of input values. The test correctly compares unwrapped values and handles error propagation properly.
test/src/concrete/DecimalFloat.inv.t.sol (1)
1-27: Clean implementation of inv function testThis test effectively validates that the
inv(inverse) function in the concreteDecimalFloatcontract mirrors the behavior of the library implementation. The structure follows best practices by:
- Testing with fuzzed inputs
- Comparing unwrapped results for equality
- Properly handling error cases to ensure consistent revert behavior
The test will help ensure that the exposed external function behaves identically to the library method.
test/src/concrete/DecimalFloat.minus.t.sol (1)
1-27: Properly implemented test for minus functionThis test correctly validates the behavior of the
minusfunction (negation operation) onFloatvalues. The test follows the project's established pattern for testing concrete implementations against library behavior.The implementation properly handles both successful executions and error cases, ensuring the contract implementation matches the library functionality exactly.
test/src/concrete/DecimalFloat.sub.t.sol (1)
1-27: Effective test for subtraction operationThis test thoroughly validates the
subfunction, ensuring that the concrete implementation inDecimalFloatbehaves identically to the library implementation. The test:
- Properly fuzzes both input parameters
- Verifies result equality for successful operations
- Ensures consistent error propagation when operations fail
Good implementation that follows the project's consistent testing pattern for arithmetic operations.
test/src/concrete/DecimalFloat.max.t.sol (1)
1-27: Implementation looks robust and well-structured.This is a well-designed test contract for validating the
maxfunction of theDecimalFloatcontract. The test ensures that the external contract implementation matches the behavior of the library function, handling both successful executions and error cases appropriately.test/src/concrete/DecimalFloat.parse.t.sol (1)
1-29: Comprehensive test for parsing functionality.The test thoroughly validates that the
parsefunction in theDecimalFloatcontract behaves identically to the library implementation. I appreciate the validation of both error selectors and parsed values, which ensures complete behavior matching.test/src/concrete/DecimalFloat.div.t.sol (1)
1-27: Division function test properly validates behavior.This test correctly validates that the newly renamed
divfunction (previouslydivide) in theDecimalFloatcontract matches the behavior of the library implementation. The test structure handles both successful calculations and error propagation.test/src/concrete/DecimalFloat.mul.t.sol (1)
1-27: Multiplication function test is properly structured.This test thoroughly validates that the newly renamed
mulfunction (previouslymultiply) in theDecimalFloatcontract matches the behavior of the library implementation. The test structure follows a consistent pattern across all arithmetic operations, making the test suite maintainable.test/src/lib/LibDecimalFloat.isZero.t.sol (7)
1-6: Good choice of Solidity version and imports.The file uses the latest Solidity version (0.8.25) and correctly imports the necessary components from both the project and Forge Standard Library.
7-9: Clean contract definition with appropriate library usage.The contract properly extends the Forge Test contract and correctly applies the LibDecimalFloat library to the Float type.
10-12: Well-designed external helper function.This external function will be useful for testing external vs internal calls to the isZero function.
14-23: Well-implemented test for deployment consistency.This test appropriately verifies that both external and internal calls to
isZero()produce identical results and properly handles revert cases. The try-catch pattern is a good practice for testing expected reverts.
25-27: Good functional equivalence test.This test correctly verifies that
isZero()is functionally equivalent to comparing with zero usingeq(), which confirms consistent behavior across different comparison methods.
29-37: Comprehensive zero representation tests.This test effectively covers multiple zero representations with different exponents, ensuring the
isZero()function correctly identifies all variations of zero.
39-43: Thorough negative case testing.The function properly tests that non-zero values return false for
isZero(), using fuzzing with proper assumptions to ensure comprehensive coverage.
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
src/lib/deploy/LibDecimalFloatDeploy.sol (1)
16-16: 🧹 Nitpick (assertive)Avoid magic-address duplication – reference the declared constant
You have correctly introduced
LOG_TABLES_ADDRESS, but the literal0x7A0D...is still hard-coded further below in the inline assembly block.
Keeping the same value in two places invites drift and makes auditing harder. Because Solidity constants are accessible in Yul, you can safely reference the constant inside theassemblyblock.- bool success; + bool success;…and later:
- success := call(gas(), 0x7A0D94F55792C434d74a40883C6ed8545E406D12, 0, … + success := call(gas(), LOG_TABLES_ADDRESS, 0, …
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (1)
src/lib/deploy/LibDecimalFloatDeploy.sol(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: rainix (ubuntu-latest, rainix-sol-test)
- GitHub Check: rainix (ubuntu-latest, rainix-sol-static)
- GitHub Check: git-clean
Motivation
Solution
Checks
By submitting this for review, I'm confirming I've done the following:
Summary by CodeRabbit
New Features
Documentation
Refactor
Tests