-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
V2 #100
Conversation
Warning Rate Limit Exceeded@RnkSngh has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 10 minutes and 47 seconds before requesting another review. How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. WalkthroughThe update enhances the vIBC Core Smart Contracts project by improving documentation clarity and refining the codebase. It includes interface segregation, Solidity version updates, and detailed contract descriptions for better IBC packet handling and interactions. Changes
Possibly related issues
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
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 as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 22
Out of diff range and nitpick comments (14)
contracts/examples/Earth.sol (1)
9-14
: Ensure documentation clarity and accuracy.The documentation comment for the
Earth
contract could be enhanced to provide more details about the specific functionalities and use cases of the contract.contracts/interfaces/IProofVerifier.sol (1)
41-46
: Ensure error messages are clear and informative.The error messages defined in the
IProofVerifier
interface could be more descriptive to aid in debugging and understanding the nature of the errors. Consider adding more context to each error message.test/Ibc.t.sol (1)
5-5
: Ensure consistency in import statements.The import statements in
Ibc.t.sol
are inconsistent in their formatting. Consider standardizing the format for clarity and maintainability.README.md (1)
3-3
: Ensure the spelling of "dapp devs" is consistent with the intended terminology; consider "DApp developers" for clarity.contracts/interfaces/IbcDispatcher.sol (1)
75-79
: Consider documenting the purpose of each event to enhance code readability and maintainability.contracts/interfaces/IDispatcher.sol (1)
36-39
: Consider adding documentation for thesetClientForConnection
andremoveConnection
functions to clarify their purpose and usage.contracts/core/OptimisticLightClient.sol (1)
26-26
: Ensure the constructor parameters are correctly documented to enhance code readability and maintainability.test/Dispatcher/Dispatcher.multiclient.sol (1)
4-12
: Consider organizing imports to improve readability.Grouping related imports together and separating different types (like contracts, libraries, and interfaces) can make the code easier to navigate.
test/Dispatcher/Dispatcher.proof.t.sol (1)
37-37
: Consider adding documentation for theDispatcherIbcWithRealProofsSuite
abstract contract to explain its purpose and usage.test/utils/Dispatcher.base.t.sol (1)
36-44
: Clarify the purpose of constants and their usage in the contract to improve maintainability.contracts/examples/Mars.sol (1)
144-144
: Empty functiononChanCloseInit
should include a comment explaining why no operation is needed or if future implementation is intended.contracts/core/Dispatcher.sol (3)
80-82
: The functionsetPortPrefix
correctly checks for an empty string, which is a basic validation. Consider adding more comprehensive checks if the port prefix has specific format or length requirements.
260-271
: The functionchannelOpenAck
includes multiple external calls and state changes. Review the transaction gas usage to ensure it stays within reasonable limits, especially considering the nested calls and state updates.
[!TIP]
Codebase VerificationThe extracted content from the
_connectChannel
function in thecontracts/core/Dispatcher.sol
file reveals that the function does indeed register a channel mapping. However, there are two "TODO" comments that are particularly relevant to the review comment:
- Check for duplicated channel registration: This indicates that the current implementation does not yet include logic to prevent duplicate channel registrations, which is a critical oversight in ensuring the integrity of channel connections.
- Version handling in channel connection: There is a note about potentially incorrect version handling, suggesting that the version used should be the self version rather than the counterparty's. This could lead to incorrect data associations if not addressed.
These findings confirm the concerns raised in the review comment about the need to review the channel registration logic for potential issues with duplicates and incorrect data associations.
Final Response:
The review of the
_connectChannel
function in thecontracts/core/Dispatcher.sol
file confirms the presence of potential issues with duplicate channel registrations and incorrect data associations as indicated by the "TODO" comments within the function. It is recommended to address these issues to ensure the robustness and correctness of the channel connection logic.
- TODO comments indicate missing checks for duplicate registrations.
- Incorrect version handling might lead to wrong data associations.
Analysis chain
Line range hint
670-721
: The function_connectChannel
is a critical internal function that handles the connection of channels. Review the channel registration logic to ensure it does not allow for duplicate registrations or incorrect data associations.
The output from the script indicates that the search for the
_connectChannel
function in thecontracts/core/Dispatcher.sol
file was successful, but it only confirmed the existence of the function without providing the necessary details about the implementation of channel registration logic. This is insufficient to verify whether the function handles duplicate registrations or incorrect data associations as mentioned in the review comment.To properly verify the implementation details, we need to extract the full content of the
_connectChannel
function. Let's run another script to get the complete function definition.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify channel registration logic in `_connectChannel`. # Test: Search for channel registration patterns in the function. Expect: Checks against duplicates and incorrect data. ast-grep --lang solidity --pattern $'function _connectChannel($_) { $$$ _portChannelMap[$$$] = $$$; $$$ }'Length of output: 224
Script:
#!/bin/bash # Description: Verify channel registration logic in `_connectChannel`. # Test: Search for channel registration patterns in the function. Expect: Checks against duplicates and incorrect data. rg --multiline 'function _connectChannel\(' contracts/core/Dispatcher.solLength of output: 105
Script:
#!/bin/bash # Description: Extract the full content of the `_connectChannel` function to verify channel registration logic. # Test: Extract the function definition and check for logic handling duplicates and incorrect data. rg --multiline 'function _connectChannel\(' -A 20 contracts/core/Dispatcher.solLength of output: 991
Please split the channel close: update api commit such that we end up with a single commit that adds the ch-close related changes and another commit that fixes/tweaks timeouts Also, please squash reoder Channel struct to be storage compatible into the first and only ch-close related commit. Again, one feature fix per commit. Please squash these three commits into "add multiclient support"
Finally, the "+ get existing test suite working" related changes must not be a separate commit but rather be part of those commits that broke the tests. I suggest running |
One last note, please do not "squash and merge" when finished but rather "rebase and merge" or all the comments above won't make any difference :D |
90c6bc6
to
596f2fd
Compare
Done! Should be split into a ch close commit and a sperate timeout timestamp commit
This is a great suggestion, now the storage gap should be fixed in the ch-close commit as per your request
Done!
For context - I always rebase with -x "forge test && yarn lint && forge build --sizes" so I think the "+ get existing test suite working" should have already been working with the test suite. But I agree this commit was admittedly poorly named , so I renamed it to "multi client support" to be clearer. Now (as before) all commits always should pass the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 11
Out of diff range and nitpick comments (10)
README.md (2)
3-3
: Ensure the project description is clear and concise.Consider refining the project description for clarity and conciseness to enhance understanding for new contributors.
17-27
: Ensure consistency in documentation formatting.Add blank lines around headings for better readability and to adhere to Markdown best practices.
contracts/base/GeneralMiddleware.sol (2)
16-21
: Enhance contract documentation for better clarity.Consider expanding the contract documentation to include more details about its functionality and use cases.
Line range hint
64-64
: Ensure all public functions override an interface definition.Confirm that
onRecvUniversalPacket
is properly overriding an interface method or declare it in an interface if missing.contracts/core/UniversalChannelHandler.sol (2)
20-26
: Enhance contract documentation for better clarity.Consider expanding the contract documentation to include more details about its functionality and use cases.
62-68
: Ensure clarity in function documentation.Refine the function documentation to clearly describe the parameters and their roles.
contracts/libs/Ibc.sol (1)
Line range hint
171-203
: Ensure the documentation is clear and concise.Consider refining the documentation for the
channelProofKey
andchannelProofValue
functions to enhance clarity and understanding.contracts/core/Dispatcher.sol (3)
11-11
: Consider organizing imports for better readability. Grouping related imports together (e.g., all OpenZeppelin imports) can improve the maintainability of the code.
464-486
: Theacknowledgement
function properly handles packet acknowledgements with sequence checks for ordered channels. Consider adding more detailed comments explaining the sequence check logic for maintainability.
Line range hint
547-574
: TherecvPacket
function effectively handles packet receipts with proper state checks and proof verification. The early return pattern used for timed-out packets is a good practice. Consider adding more inline comments for clarity.
Review Details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (1)
diagrams/vibcContractsOverview.jpg
is excluded by!**/*.jpg
Files selected for processing (42)
- .gitignore (1 hunks)
- README.md (2 hunks)
- contracts/base/GeneralMiddleware.sol (2 hunks)
- contracts/core/Dispatcher.sol (20 hunks)
- contracts/core/OptimisticLightClient.sol (3 hunks)
- contracts/core/OptimisticProofVerifier.sol (6 hunks)
- contracts/core/UniversalChannelHandler.sol (9 hunks)
- contracts/examples/Earth.sol (1 hunks)
- contracts/examples/Mars.sol (4 hunks)
- contracts/interfaces/IDispatcher.sol (4 hunks)
- contracts/interfaces/ILightClient.sol (1 hunks)
- contracts/interfaces/IProofVerifier.sol (2 hunks)
- contracts/interfaces/IUniversalChannelHandler.sol (1 hunks)
- contracts/interfaces/IbcDispatcher.sol (2 hunks)
- contracts/interfaces/IbcReceiver.sol (5 hunks)
- contracts/libs/Ibc.sol (9 hunks)
- contracts/libs/IbcErrors.sol (1 hunks)
- contracts/libs/IbcUtils.sol (1 hunks)
- contracts/utils/DummyLightClient.sol (1 hunks)
- contracts/utils/DummyProofVerifier.sol (1 hunks)
- script/Deploy.s.sol (3 hunks)
- test/Dispatcher.gasGriefing.t.sol (2 hunks)
- test/Dispatcher/Dispatcher.ack.sol (1 hunks)
- test/Dispatcher/Dispatcher.client.t.sol (1 hunks)
- test/Dispatcher/Dispatcher.closeChannel.t.sol (1 hunks)
- test/Dispatcher/Dispatcher.dappHandlerRevert.t.sol (1 hunks)
- test/Dispatcher/Dispatcher.multiclient.sol (1 hunks)
- test/Dispatcher/Dispatcher.proof.t.sol (4 hunks)
- test/Dispatcher/Dispatcher.t.sol (7 hunks)
- test/Dispatcher/Dispatcher.timeout.t.sol (1 hunks)
- test/Ibc.t.sol (1 hunks)
- test/OpConsensusStateManager.t.sol (1 hunks)
- test/Verifier.t.sol (7 hunks)
- test/VirtualChain.sol (4 hunks)
- test/universal.channel.t.sol (4 hunks)
- test/upgradeableProxy/Dispatcher.upgrade.t.sol (3 hunks)
- test/upgradeableProxy/DispatcherUUPS.accessControl.t.sol (2 hunks)
- test/upgradeableProxy/upgrades/DispatcherV2.sol (3 hunks)
- test/upgradeableProxy/upgrades/DispatcherV2Initializable.sol (2 hunks)
- test/utils/Dispatcher.base.t.sol (3 hunks)
- test/utils/Proof.base.t.sol (2 hunks)
- test/utils/TestUtils.t.sol (3 hunks)
Files skipped from review as they are similar to previous changes (36)
- .gitignore
- contracts/core/OptimisticLightClient.sol
- contracts/core/OptimisticProofVerifier.sol
- contracts/examples/Earth.sol
- contracts/examples/Mars.sol
- contracts/interfaces/IDispatcher.sol
- contracts/interfaces/ILightClient.sol
- contracts/interfaces/IProofVerifier.sol
- contracts/interfaces/IUniversalChannelHandler.sol
- contracts/interfaces/IbcDispatcher.sol
- contracts/interfaces/IbcReceiver.sol
- contracts/libs/IbcErrors.sol
- contracts/libs/IbcUtils.sol
- contracts/utils/DummyLightClient.sol
- contracts/utils/DummyProofVerifier.sol
- script/Deploy.s.sol
- test/Dispatcher.gasGriefing.t.sol
- test/Dispatcher/Dispatcher.ack.sol
- test/Dispatcher/Dispatcher.client.t.sol
- test/Dispatcher/Dispatcher.closeChannel.t.sol
- test/Dispatcher/Dispatcher.dappHandlerRevert.t.sol
- test/Dispatcher/Dispatcher.multiclient.sol
- test/Dispatcher/Dispatcher.proof.t.sol
- test/Dispatcher/Dispatcher.timeout.t.sol
- test/Ibc.t.sol
- test/OpConsensusStateManager.t.sol
- test/Verifier.t.sol
- test/VirtualChain.sol
- test/universal.channel.t.sol
- test/upgradeableProxy/Dispatcher.upgrade.t.sol
- test/upgradeableProxy/DispatcherUUPS.accessControl.t.sol
- test/upgradeableProxy/upgrades/DispatcherV2.sol
- test/upgradeableProxy/upgrades/DispatcherV2Initializable.sol
- test/utils/Dispatcher.base.t.sol
- test/utils/Proof.base.t.sol
- test/utils/TestUtils.t.sol
Additional Context Used
LanguageTool (1)
README.md (1)
Near line 12: Loose punctuation mark.
Context: ...and used in production. -interfaces/
: Interfaces for core and testing contrac...
GitHub Check Runs (1)
lint success (11)
contracts/base/GeneralMiddleware.sol: [warning] 5-5:
imported name Ibc is not used
contracts/base/GeneralMiddleware.sol: [warning] 32-32:
Variable name must be in mixedCase
contracts/base/GeneralMiddleware.sol: [warning] 50-50:
Named parameters missing. MIN unnamed argumenst is 4
contracts/base/GeneralMiddleware.sol: [warning] 61-61:
Named parameters missing. MIN unnamed argumenst is 4
contracts/base/GeneralMiddleware.sol: [warning] 64-64:
All public or external methods in a contract must override a definition from an interface
contracts/base/GeneralMiddleware.sol: [warning] 80-80:
Named parameters missing. MIN unnamed argumenst is 4
contracts/base/GeneralMiddleware.sol: [warning] 109-109:
Named parameters missing. MIN unnamed argumenst is 4
contracts/base/GeneralMiddleware.sol: [warning] 126-126:
Named parameters missing. MIN unnamed argumenst is 4
contracts/base/GeneralMiddleware.sol: [warning] 139-139:
Named parameters missing. MIN unnamed argumenst is 4
contracts/base/GeneralMiddleware.sol: [warning] 159-159:
Code contains empty blocks
Additional comments not posted (8)
contracts/libs/Ibc.sol (1)
8-9
: Ensure all imports are necessary.Verification successful
The
Address
import from the OpenZeppelin library is indeed used within theIbc.sol
file. The usage is found in the function_hexStrToAddress
, which converts a hexadecimal string to an Ethereum address, utilizing theAddress
library for this conversion. This confirms that the import is necessary and correctly utilized in the code.
- The import statement is correctly placed and used in the function
_hexStrToAddress
.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that the `Address` import is used within the Ibc.sol file. # Test: Search for the `Address` usage. Expect: At least one occurrence. rg --type solidity $'Address' -- contracts/libs/Ibc.solLength of output: 87
Script:
#!/bin/bash # Description: Verify that the `Address` import is used within the Ibc.sol file. # Test: Search for the `Address` usage. Expect: At least one occurrence. rg 'Address' contracts/libs/Ibc.solLength of output: 193
test/Dispatcher/Dispatcher.t.sol (2)
255-255
: Update error message for better clarity.Refer to the existing comment for enhancing the error message.
352-352
: Update error message for better clarity.Refer to the existing comment for enhancing the error message.
contracts/core/Dispatcher.sol (5)
15-15
: Good use ofReentrancyGuard
to prevent reentrancy attacks. This is crucial for contracts that perform state-changing operations.
30-30
: The use of multiple inheritance is correctly implemented. Ensure that the order of inheritance follows the solidity best practices to avoid the diamond problem or any other inheritance issues.Verification successful
The inheritance order in
Dispatcher.sol
has been verified and follows Solidity best practices. The contracts are ordered in a way that minimizes the risk of inheritance conflicts and the diamond problem. The use of interfaces and well-designed OpenZeppelin contracts further supports this proper implementation.
- File:
contracts/core/Dispatcher.sol
- Inheritance Order:
OwnableUpgradeable, UUPSUpgradeable, ReentrancyGuard, IDispatcher
Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check the inheritance order in Dispatcher.sol to ensure it follows best practices. # Test: Search for the contract definition and inheritance list. Expect: Correct order following Solidity best practices. rg --type solidity 'contract Dispatcher is' contracts/core/Dispatcher.solLength of output: 108
Script:
#!/bin/bash # Description: Corrected script to check the inheritance order in Dispatcher.sol to ensure it follows best practices. # Test: Search for the contract definition and inheritance list. Expect: Correct order following Solidity best practices. rg 'contract Dispatcher is' contracts/core/Dispatcher.solLength of output: 150
152-152
: ThenonReentrant
modifier is used appropriately inchannelOpenInit
to prevent reentrancy attacks. This is crucial for functions that can alter contract state in a way that could be exploited.
Line range hint
602-623
: ThewriteTimeoutPacket
function is well-implemented with appropriate checks for packet receipt and timeout conditions. The function's logic is clear and follows best practices for error handling.
643-650
: ThegetOptimisticConsensusState
function provides necessary state information with clear and concise logic. Ensure that the light client retrieval is robust against potential errors in the connection string.Verification successful
The script output shows that the
lightClient
is retrieved using a mapping_connectionToLightClient
withconnection
as the key. However, the output does not provide any information about error handling mechanisms in case theconnection
key does not exist in the mapping or leads to an invalid light client. This is crucial for ensuring robustness in the function as mentioned in the review comment.To further verify the robustness of error handling, we need to check if there are any checks or error handling mechanisms after the
lightClient
is retrieved. This could include checking if the retrievedlightClient
is valid or handling cases where theconnection
might not lead to a valid light client.
The script output confirms that after retrieving the
lightClient
using the_connectionToLightClient
mapping, there is a check to ensure that the retrievedlightClient
is not a zero address. If it is, the function reverts with anIBCErrors.lightClientNotFound
error, which includes theconnection
as part of the error message. This indicates that there is robust error handling in place to manage cases where theconnection
does not correspond to a valid light client.This effectively addresses the concern raised in the review comment about ensuring that the light client retrieval is robust against potential errors in the connection string.
Conclusion:
ThegetOptimisticConsensusState
function in theDispatcher.sol
file includes robust error handling for the retrieval of the light client based on the connection string. If the light client cannot be found (i.e., the address is zero), the function will revert with a specific error, preventing any further execution with an invalid state.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify robust error handling for light client retrieval in `getOptimisticConsensusState`. # Test: Search for error handling related to light client retrieval. Expect: Robust error handling mechanisms. rg --type solidity 'lightClient =' contracts/core/Dispatcher.solLength of output: 99
Script:
#!/bin/bash # Description: Verify robust error handling for light client retrieval in `getOptimisticConsensusState`. # Test: Search for error handling related to light client retrieval. Expect: Robust error handling mechanisms. rg 'lightClient =' contracts/core/Dispatcher.solLength of output: 110
Script:
#!/bin/bash # Description: Verify error handling after light client retrieval in `getOptimisticConsensusState`. # Test: Search for error handling or validation checks after light client retrieval. rg 'lightClient =' -A 10 contracts/core/Dispatcher.solLength of output: 436
596f2fd
to
02837cc
Compare
add address 0 checks to dispatcher contract
- add docs to core contracts - fix contract naming - organize contract files
Previously our process was to only merge commits into main which have been deployed. Now we are updating our process to start merging things into main which have been reviewed, but not necessarily deployed into production or staging.
This PR reconsiles these two processes, so that once this PR is merged, the main branch will have the canonical code that represents our vibc contracts, which contains a mix of code we had from our previous audit, and code we have added to main and deployed into production since our audit.
Note : all changes in this PR should have already been reviewed, either from a PR to v2 directly (i.e. for the audit) or rebased from main (i.e. changes to main after the audit) .
The features added in this PR (which were already included in the past audit) are:
The only additional changes to these features which differed from the code in our previous audit were the changes required to rebase the new changes we've committed to our main branch since our previous audit. These changes in main include:
Summary by CodeRabbit
Documentation
README.md
for clearer overview of vIBC Core Smart Contracts project.Dispatcher
,OptimisticLightClient
,OptimisticProofVerifier
, andUniversalChannelHandler
.New Features
Bug Fixes
Refactor
Dispatcher.sol
for security enhancements.Chores
.gitignore
to include coverage report files and directories.