Skip to content
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

feat(contracts-communication): Interchain versioning library #2389

Merged
merged 17 commits into from
Apr 4, 2024

Conversation

ChiTimesChi
Copy link
Collaborator

@ChiTimesChi ChiTimesChi commented Mar 28, 2024

Description
Adds a new library to deal with generic versioned payloads. For starters, the AppConfig and Options structs are adjusted to take advantage of this library.

Versioning of InterchainBatch and InterchainTransaction is supposed to happen in the subsequent PRs.

Summary by CodeRabbit

  • New Features
    • Introduced versioning for batch and transaction payloads across various contracts and libraries to enhance compatibility and future-proofing.
    • Added new constants for database and client versions to ensure consistent version tracking.
    • Implemented new functions for encoding and decoding versioned batches and transactions, improving interoperability and data integrity.
  • Bug Fixes
    • Adjusted function parameter types and visibility to align with versioning requirements, ensuring accurate data handling and contract interactions.
  • Refactor
    • Updated existing functions to utilize versioned payload libraries, enhancing code efficiency and maintainability.
    • Refined test cases to cover versioned data handling, ensuring robustness and reliability of versioning features.
  • Documentation
    • Added error types related to invalid batch versions to improve error handling and user feedback.
  • Tests
    • Enhanced integration and unit tests to include versioning scenarios, ensuring comprehensive coverage and functionality validation.

@github-actions github-actions bot added go Pull requests that update Go code size/l labels Mar 28, 2024
Copy link
Contributor

coderabbitai bot commented Mar 28, 2024

Walkthrough

The recent updates across various contracts and tests in the packages/contracts-communication directory focus on introducing and implementing versioned payloads and batches. By incorporating VersionedPayloadLib and InterchainBatchLib, these changes enhance the system's ability to handle versioning for interchain communication, ensuring compatibility and validation of data across different blockchain networks. This evolution marks a significant step towards more robust and flexible interchain interactions.

Changes

Files Summary
.../contracts/libs/InterchainBatch.sol, .../contracts/libs/Options.sol, .../contracts/libs/AppConfig.sol, .../contracts/execution/SynapseExecutionServiceV1.sol Added VersionedPayloadLib import and updated functions for versioned payload handling.
.../contracts/InterchainDB.sol, .../contracts/InterchainClientV1.sol, .../interfaces/IInterchainDB.sol, .../mocks/InterchainDBMock.sol, .../mocks/InterchainModuleMock.sol Introduced version constants, modified functions to accept and handle versioned batches or options as bytes, and updated parameter types for better version management.
.../test/InterchainClientV1.Base.t.sol, .../test/InterchainClientV1.Dst.t.sol, .../test/InterchainClientV1.GenericViews.t.sol, .../test/InterchainDB.Dst.t.sol, .../test/InterchainDB.Src.t.sol, .../test/integration/ICIntegration.t.sol, .../test/integration/ICSetup.t.sol, .../test/libs/InterchainBatchLib.t.sol, .../test/libs/InterchainTransaction.t.sol, .../test/modules/SynapseModule.Destination.t.sol, .../test/modules/SynapseModule.Source.t.sol Enhanced tests with InterchainBatchLib and VersionedPayloadLib, added version constants, and updated function calls for versioned data handling.
.../test/harnesses/InterchainBatchLibHarness.sol, .../test/harnesses/InterchainTransactionLibHarness.sol Added functions to support encoding and decoding of versioned transactions and batches.
sin-executor/executor/executor_test.go Modified function call to align with updated batch verification logic.

A rabbit hopped through the code,
Leaving behind a versioned load.
With bits and bytes, it danced and twirled,
Linking chains across the world.
🌍🐇💻
In the glow of the moon's soft light,
It whispered, "To interoperability, goodnight."

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?

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>.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

codecov bot commented Mar 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 46.86012%. Comparing base (a01d39d) to head (e2a8942).
Report is 15 commits behind head on master.

Additional details and impacted files
@@                 Coverage Diff                 @@
##              master       #2389         +/-   ##
===================================================
- Coverage   46.93892%   46.86012%   -0.07881%     
===================================================
  Files            383         383                 
  Lines          29189       29189                 
  Branches          83          83                 
===================================================
- Hits           13701       13678         -23     
- Misses         14032       14051         +19     
- Partials        1456        1460          +4     
Flag Coverage Δ
committee 62.20028% <ø> (-1.55148%) ⬇️
sin-executor 61.57635% <ø> (-2.95568%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

cloudflare-workers-and-pages bot commented Mar 28, 2024

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: e2a8942
Status: ✅  Deploy successful!
Preview URL: https://62c79b0c.sanguine-fe.pages.dev
Branch Preview URL: https://feat-interchain-versioning-l.sanguine-fe.pages.dev

View logs

@ChiTimesChi
Copy link
Collaborator Author

@coderabbitai review

Copy link
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.

Review Status

Actionable comments generated: 0

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between a01d39d and bd2fd1a.
Files selected for processing (20)
  • packages/contracts-communication/contracts/InterchainClientV1.sol (1 hunks)
  • packages/contracts-communication/contracts/execution/SynapseExecutionServiceV1.sol (4 hunks)
  • packages/contracts-communication/contracts/interfaces/ISynapseExecutionServiceV1.sol (1 hunks)
  • packages/contracts-communication/contracts/libs/AppConfig.sol (2 hunks)
  • packages/contracts-communication/contracts/libs/Options.sol (2 hunks)
  • packages/contracts-communication/contracts/libs/VersionedPayload.sol (1 hunks)
  • packages/contracts-communication/test/InterchainClientV1.Dst.t.sol (2 hunks)
  • packages/contracts-communication/test/InterchainClientV1.Src.t.sol (2 hunks)
  • packages/contracts-communication/test/execution/SynapseExecutionServiceV1.Fees.t.sol (3 hunks)
  • packages/contracts-communication/test/harnesses/AppConfigLibHarness.sol (1 hunks)
  • packages/contracts-communication/test/harnesses/OptionsLibHarness.sol (1 hunks)
  • packages/contracts-communication/test/harnesses/VersionedPayloadLibHarness.sol (1 hunks)
  • packages/contracts-communication/test/libs/AppConfigLib.t.sol (3 hunks)
  • packages/contracts-communication/test/libs/OptionsLib.t.sol (3 hunks)
  • packages/contracts-communication/test/libs/VersionedPayloadLib.t.sol (1 hunks)
  • sin-executor/contracts/executionservice/executionservice.abigen.go (7 hunks)
  • sin-executor/contracts/interchainclient/interchainclient.abigen.go (12 hunks)
  • sin-executor/contracts/mocks/interchainapp/interchainapp.abigen.go (9 hunks)
  • sin-executor/contracts/mocks/optionslibexport/optionslibexport.abigen.go (4 hunks)
  • sin-executor/contracts/mocks/optionslibexport/optionslibexport.contractinfo.json (1 hunks)
Files not summarized due to errors (4)
  • sin-executor/contracts/executionservice/executionservice.abigen.go: Error: Message exceeds token limit
  • sin-executor/contracts/interchainclient/interchainclient.abigen.go: Error: Message exceeds token limit
  • sin-executor/contracts/mocks/interchainapp/interchainapp.abigen.go: Error: Message exceeds token limit
  • sin-executor/contracts/mocks/optionslibexport/optionslibexport.contractinfo.json: Error: Message exceeds token limit
Additional comments (65)
packages/contracts-communication/test/harnesses/OptionsLibHarness.sol (1)
  • 7-8: The modification to decodeOptionsV1 to return OptionsV1 memory directly is a positive change, enhancing type safety and aligning with the PR's objectives to utilize versioning capabilities more effectively.
packages/contracts-communication/test/harnesses/AppConfigLibHarness.sol (1)
  • 7-8: The update to decodeAppConfigV1 to return AppConfigV1 memory directly is a good improvement, enhancing type safety and clarity, and aligns well with the PR's versioning objectives.
packages/contracts-communication/test/harnesses/VersionedPayloadLibHarness.sol (1)
  • 8-26: The introduction of VersionedPayloadLibHarness and its functions for encoding and decoding versioned payloads, as well as retrieving version and payload information, aligns well with the PR's objectives for improved versioning capabilities. The use of VersionedPayloadLib methods throughout is consistent and appropriate.
packages/contracts-communication/contracts/interfaces/ISynapseExecutionServiceV1.sol (1)
  • 9-9: Changing the version parameter type in SynapseExecutionService__OptionsVersionNotSupported from uint256 to uint16 is a sensible and gas-efficient adjustment, aligning with the PR's versioning strategy.
packages/contracts-communication/contracts/libs/AppConfig.sol (1)
  • 11-38: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [4-36]

The updates to AppConfig.sol, including the addition of VersionedPayloadLib, changing APP_CONFIG_V1 to uint16, and the refactoring of encoding and decoding functions to use VersionedPayloadLib methods, are well-aligned with the PR's objectives for improved versioning. These changes enhance maintainability and are more gas-efficient.

packages/contracts-communication/test/libs/OptionsLib.t.sol (1)
  • 32-42: The updates to test functions in OptionsLib.t.sol to use VersionedPayloadLib for encoding versioned payloads are consistent with the PR's objectives and improve the tests' alignment with the new versioning capabilities. These changes ensure that the tests accurately reflect the new versioning approach.
packages/contracts-communication/contracts/libs/Options.sol (1)
  • 17-44: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [4-42]

The updates to Options.sol, including the addition of VersionedPayloadLib, changing OPTIONS_V1 to uint16, and the refactoring of encoding and decoding functions to use VersionedPayloadLib methods, are well-aligned with the PR's objectives for improved versioning. These changes enhance maintainability and are more gas-efficient.

packages/contracts-communication/test/libs/AppConfigLib.t.sol (1)
  • 33-42: The updates to test functions in AppConfigLib.t.sol to use VersionedPayloadLib for encoding versioned payloads are consistent with the PR's objectives and improve the tests' alignment with the new versioning capabilities. These changes ensure that the tests accurately reflect the new versioning approach.
packages/contracts-communication/test/libs/VersionedPayloadLib.t.sol (8)
  • 17-21: The expectRevertTooShort function is a good practice for testing expected reverts. However, it's important to ensure that the error message or selector used matches exactly what is implemented in the VersionedPayloadLib to avoid false positives/negatives in tests.
  • 23-26: The makeInvalid function cleverly manipulates the payload to create an invalid versioned payload by adjusting its length. This is a good approach for testing edge cases. Ensure that this method covers all possible "invalid" scenarios that the library is expected to handle.
  • 28-32: The roundtrip test for encodeVersionedPayload and its decoding functions (getVersion and getPayload) is comprehensive. It's important to include edge cases, such as empty payloads or maximum possible version numbers, to ensure robustness.
  • 34-38: Similar to the previous comment, this test ensures the library functions correctly when using memory references. Including tests for edge cases would enhance the test suite's coverage.
  • 40-44: This test verifies the library's behavior when attempting to extract the version from a too-short payload. It's crucial to have similar tests for all error conditions defined in the library to ensure comprehensive error handling.
  • 46-50: Testing the library's behavior for too-short payloads when extracting the payload itself is essential. Consider adding tests for other error conditions or invalid inputs to ensure the library's robustness.
  • 52-56: Repeating the test for getVersionFromMemory with too-short payloads ensures consistency between calldata and memory handling. It's good practice to ensure both scenarios are equally well-tested.
  • 58-62: The test for getPayloadFromMemory with too-short payloads complements the previous tests, ensuring the library handles memory references correctly. As with other tests, consider testing additional edge cases.
packages/contracts-communication/contracts/libs/VersionedPayload.sol (6)
  • 10-11: The custom error definitions VersionedPayload__TooShort and VersionedPayload__PrecompileFailed are clear and concise. Ensure that these errors are used consistently throughout the library to handle specific failure scenarios.
  • 16-18: The encodeVersionedPayload function correctly encodes the version and payload into a single bytes array. Consider adding input validation to ensure the version and payload meet any expected constraints or formats.
  • 22-30: The getVersion function extracts the version from the versioned payload. The use of inline assembly for efficiency is noted. Ensure that the assembly code is thoroughly reviewed and tested, as errors in assembly can be harder to detect and have significant consequences.
  • 35-40: The getPayload function for extracting the payload from calldata is straightforward and uses slicing. This approach is efficient but ensure it's consistently applied across similar functions for memory references.
  • 44-53: The getVersionFromMemory function mirrors getVersion but for memory references. The consistency between calldata and memory handling functions is good practice. Again, ensure the assembly code is thoroughly reviewed.
  • 59-80: The getPayloadFromMemory function uses the identity precompile for copying the payload, which is an interesting approach. Ensure that this method is compatible across all EVM chains and that the gas costs are acceptable. Additionally, consider handling the case where the payload's length is zero.
packages/contracts-communication/contracts/execution/SynapseExecutionServiceV1.sol (3)
  • 8-8: The addition of VersionedPayloadLib import is correctly done. This is necessary for the new functionality related to versioned payloads.
  • 74-74: Changing function parameters from bytes memory to bytes calldata in requestExecution is a good optimization for gas savings, as it avoids copying data from calldata to memory. Ensure that all calls to this function are updated accordingly.
  • 104-104: The introduction of VersionedPayloadLib.getVersion to handle options versioning is a significant improvement. It ensures that the contract can handle different versions of options more flexibly. Ensure that the versioning logic is thoroughly tested, especially for future versions of options.
packages/contracts-communication/test/execution/SynapseExecutionServiceV1.Fees.t.sol (3)
  • 4-5: The replacement of OptionsLib with VersionedPayloadLib in imports reflects the changes in the contract's implementation to use versioned payloads. Ensure that all tests are updated to use the new library functions correctly.
  • 102-103: The use of VersionedPayloadLib.getPayloadFromMemory and VersionedPayloadLib.encodeVersionedPayload to create mock options for testing is a good approach. It ensures that the tests are aligned with the new versioning functionality. Ensure that these tests cover various version and payload scenarios.
  • 156-158: Testing the behavior of the contract when handling unsupported options versions is crucial. This test ensures that the contract correctly rejects options with versions it does not support. Ensure that the contract's versioning logic is designed to be easily extendable for future versions.
packages/contracts-communication/contracts/InterchainClientV1.sol (1)
  • 202-205: The addition of a new decodeOptions function that is marked as view is an interesting change. This function allows external entities to decode options without modifying the state. Ensure that this function is used in contexts where state modification is not required, and consider the implications of marking it as view in terms of gas costs and usability.
packages/contracts-communication/test/InterchainClientV1.Src.t.sol (2)
  • 4-5: The addition of VersionedPayloadLib and the shift from OptionsLib to this new library for handling versioned payloads is a significant change. Ensure that all instances where OptionsLib was previously used are now correctly utilizing VersionedPayloadLib for encoding and decoding operations. This change should enhance maintainability and flexibility in handling versioned data structures.
  • 49-50: The encoding of options using VersionedPayloadLib introduces a more structured approach to handling versioned data. However, it's crucial to ensure that the version numbers used (0 for invalidOptionsV0 and 1 for invalidOptionsV1) align with the expected versions in the system. Misalignment could lead to decoding errors or unexpected behavior. Additionally, consider adding comments to clarify the purpose of these invalid options in testing scenarios.
sin-executor/contracts/mocks/optionslibexport/optionslibexport.abigen.go (4)
  • 40-41: The ABI and Bin values in OptionsLibMetaData have been updated. Ensure these changes accurately reflect the updated smart contract ABI and bytecode. This is crucial for the Go bindings to interact correctly with the smart contract.
  • 213-219: The ABI and Bin values in OptionsLibMocksMetaData have been updated to include new error types and functions. Verify that these updates are consistent with the intended changes in the smart contract's interface and logic. It's important to ensure that the ABI accurately represents the contract's functions and errors for correct interaction.
  • 489-489: The TypeCastsMetaData struct's Bin value has been updated. Confirm that this update correctly represents the compiled bytecode of the TypeCasts contract. Accurate bytecode is essential for deploying and interacting with the contract.
  • 660-663: New metadata for VersionedPayloadLib has been added, including ABI and Bin values. It's important to ensure that these values accurately represent the VersionedPayloadLib contract's interface and compiled bytecode. Incorrect ABI or bytecode can lead to failed contract interactions or deployments.
packages/contracts-communication/test/InterchainClientV1.Dst.t.sol (1)
  • 52-53: The usage of VersionedPayloadLib for encoding versioned payloads is a significant improvement in handling versioned data structures. However, it's crucial to ensure that the version numbers used (0 and 1 in this case) are correctly mapped to the expected versions of the OptionsV1 structure. Additionally, when encoding invalidOptionsV1, only the gasLimit is encoded, which might not fully represent the intended invalid state if other fields are expected in the versioned payload.

Consider adding comments or documentation to clarify the purpose and expected structure of these invalid options. If the intention is to test specific failure modes related to versioning, ensure that the test cases comprehensively cover the scenarios you aim to validate.

sin-executor/contracts/mocks/optionslibexport/optionslibexport.contractinfo.json (1)
  • 1-1: The JSON file structure appears well-formed and contains detailed contract information, including code, runtime code, and metadata for multiple contracts (OptionsLib, OptionsLibMocks, TypeCasts, and VersionedPayloadLib). This information is crucial for understanding the contracts' compilation and deployment details. Ensure that the metadata, including compiler version and optimization settings, matches the project's requirements for consistency and compatibility.
sin-executor/contracts/interchainclient/interchainclient.abigen.go (12)
  • 75-76: The update to AppConfigLibMetaData with the new ABI and Bin strings aligns with the PR's objectives to enhance version management. This inclusion of the AppConfigLib__IncorrectVersion error type in the ABI is a good practice for handling version mismatches.
  • 2279-2279: The update to InterchainBatchLibMetaData Bin string suggests changes in the contract bytecode. Given the ABI remains empty, ensure the contract's intended use is clear and verify its completeness or future plans for its development.
  • 2451-2451: The significant expansion of InterchainClientV1MetaData ABI, including various error types and functions, aligns well with the PR's objectives to enhance versioning capabilities and contract functionality.
  • 2473-2473: The updates to the Sigs map and Bin string in InterchainClientV1MetaData are consistent with the ABI changes, indicating enhancements to the contract's functionality.
  • 2680-2680: The addition of the DecodeOptions function binding in InterchainClientV1Caller supports the PR's objectives by enhancing the handling of versioned payloads.
  • 2697-2704: The addition of the DecodeOptions function bindings for both InterchainClientV1Session and InterchainClientV1CallerSession enhances the contract's usability by facilitating the decoding of options in different session contexts.
  • 4995-4995: The update to InterchainEntryLibMetaData Bin string suggests changes in the contract bytecode. Given the ABI remains empty, ensure the contract's intended use is clear and verify its completeness or future plans for its development.
  • 5168-5168: The update to InterchainTransactionLibMetaData Bin string suggests changes in the contract bytecode. As the ABI remains empty, ensure the contract's intended use is clear and verify its completeness or future plans for its development.
  • 5341-5341: The update to MathLibMetaData Bin string suggests changes in the contract bytecode. As the ABI remains empty, ensure the contract's intended use is clear and verify its completeness or future plans for its development.
  • 5513-5514: The update to OptionsLibMetaData with the new ABI and Bin strings aligns with the PR's objectives to enhance version management. This inclusion of the OptionsLib__IncorrectVersion error type in the ABI is a good practice for handling version mismatches.
  • 6073-6073: The update to TypeCastsMetaData Bin string suggests changes in the contract bytecode. As the ABI remains empty, ensure the contract's intended use is clear and verify its completeness or future plans for its development.
  • 6242-6414: The comprehensive update to VersionedPayloadLib, including ABI and Bin updates, deployment functions, and various bindings for contract interaction, aligns well with the PR's objectives of enhancing version management and handling of versioned payloads.
sin-executor/contracts/executionservice/executionservice.abigen.go (7)
  • 3071-3071: The ABI string for ISynapseExecutionServiceV1MetaData has been updated. Ensure that the ABI changes are consistent with the smart contract's latest version and that all necessary methods and errors are correctly defined.
  • 3729-3730: The ABI and Bin for OptionsLibMetaData have been updated. Verify that the ABI accurately reflects the contract's interface and that the binary data corresponds to the compiled contract code.
  • 4600-4600: The ABI for SynapseExecutionServiceV1MetaData has been updated. It's crucial to ensure that the ABI matches the contract's functions and errors accurately. Additionally, verify that the contract's versioning logic is correctly implemented in the ABI.
  • 4621-4621: The binary (Bin) data for SynapseExecutionServiceV1MetaData has been updated. Confirm that this binary data is the correct compiled version of the contract and that it has been thoroughly tested.
  • 6442-6442: The ABI for SynapseExecutionServiceV1HarnessMetaData has been updated. Ensure that this ABI accurately reflects the harness contract's interface, especially since harness contracts are used for testing.
  • 6463-6463: The binary (Bin) data for SynapseExecutionServiceV1HarnessMetaData has been updated. Verify that this binary data corresponds to the compiled version of the harness contract and that it has been tested for correctness.
  • 8281-8281: The introduction of VersionedPayloadLibMetaData and related functions, types, and sessions marks a significant update. Ensure that the ABI and Bin accurately represent the VersionedPayloadLib contract's functionality. Additionally, review the newly added functions and types for managing versioned payloads to ensure they follow best practices for Go and Ethereum smart contract bindings.
sin-executor/contracts/mocks/interchainapp/interchainapp.abigen.go (9)
  • 2966-2966: Ensure the ABI and binary data in AddressMetaData accurately reflect the latest version of the Address contract. It's crucial for maintaining the integrity of contract interactions.
  • 3138-3139: Verify that the ABI and binary data in AppConfigLibMetaData are up-to-date with the AppConfigLib contract's latest version. Accurate ABI and binary data are essential for correct contract interactions.
  • 3652-3652: Confirm that the EnumerableSet contract is intended to have an empty ABI. If the contract contains methods or events, the ABI should reflect those.
  • 3858-3858: The binary data introduced in this hunk lacks context regarding its associated contract. Ensure that this binary data is correctly linked to the intended contract and accurately reflects its latest version.
  • 13221-13221: Verify that the InterchainTransactionLib contract is intended to have an empty ABI. If the contract contains methods or events, the ABI should reflect those.
  • 13394-13394: Confirm that the MathLib contract is intended to have an empty ABI. If the contract contains methods or events, the ABI should reflect those.
  • 13566-13567: Ensure the ABI and binary data in OptionsLibMetaData accurately reflect the latest version of the OptionsLib contract. Accurate ABI and binary data are crucial for correct contract interactions.
  • 13740-13740: Verify that the TypeCasts contract is intended to have an empty ABI. If the contract contains methods or events, the ABI should reflect those.
  • 13910-14081: Review the use of deprecated fields VersionedPayloadLibABI and VersionedPayloadLibBin. Consider removing them if they are no longer needed, or ensure their usage is justified and documented.

Additionally, verify the correctness and completeness of the ABI and binary data for VersionedPayloadLib. Ensure that the Go bindings for interacting with the contract are implemented following best practices for maintainability and ease of use.

@ChiTimesChi ChiTimesChi marked this pull request as draft March 28, 2024 20:38
@ChiTimesChi
Copy link
Collaborator Author

Converting this to draft, as #2390 is targeting this branch.

Copy link
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: 0

Review Status

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between bd2fd1a and cb464d7.
Files selected for processing (2)
  • packages/contracts-communication/test/harnesses/VersionedPayloadLibHarness.sol (1 hunks)
  • packages/contracts-communication/test/libs/VersionedPayloadLib.t.sol (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • packages/contracts-communication/test/harnesses/VersionedPayloadLibHarness.sol
  • packages/contracts-communication/test/libs/VersionedPayloadLib.t.sol
Additional Context Used

* Implement Batch versioning

* Scaffold versioned batch verification

* Update tests with expected behavior for versioned batches

* Complete versioned batch verification
Copy link
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: 2

Review Status

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between cb464d7 and 3407aef.
Files selected for processing (18)
  • packages/contracts-communication/contracts/InterchainDB.sol (3 hunks)
  • packages/contracts-communication/contracts/interfaces/IInterchainDB.sol (2 hunks)
  • packages/contracts-communication/contracts/interfaces/IInterchainModule.sol (2 hunks)
  • packages/contracts-communication/contracts/libs/InterchainBatch.sol (3 hunks)
  • packages/contracts-communication/contracts/libs/ModuleBatch.sol (1 hunks)
  • packages/contracts-communication/contracts/modules/InterchainModule.sol (4 hunks)
  • packages/contracts-communication/test/InterchainDB.Dst.t.sol (10 hunks)
  • packages/contracts-communication/test/InterchainDB.Src.t.sol (19 hunks)
  • packages/contracts-communication/test/harnesses/InterchainBatchLibHarness.sol (1 hunks)
  • packages/contracts-communication/test/harnesses/ModuleBatchLibHarness.sol (1 hunks)
  • packages/contracts-communication/test/integration/ICIntegration.t.sol (2 hunks)
  • packages/contracts-communication/test/integration/ICSetup.t.sol (1 hunks)
  • packages/contracts-communication/test/libs/InterchainBatchLib.t.sol (1 hunks)
  • packages/contracts-communication/test/libs/ModuleBatchLib.t.sol (1 hunks)
  • packages/contracts-communication/test/mocks/InterchainDBMock.sol (1 hunks)
  • packages/contracts-communication/test/mocks/InterchainModuleMock.sol (1 hunks)
  • packages/contracts-communication/test/modules/SynapseModule.Destination.t.sol (6 hunks)
  • packages/contracts-communication/test/modules/SynapseModule.Source.t.sol (4 hunks)
Additional Context Used
Additional comments not posted (52)
packages/contracts-communication/test/mocks/InterchainModuleMock.sol (2)

4-5: The separation of import statements into individual lines improves readability and maintainability. Good practice.


10-10: Changing function parameters to bytes calldata for requestBatchVerification and mockVerifyRemoteBatch aligns with the PR's objectives. Ensure that corresponding encoding and decoding operations are properly implemented and tested across the system to handle these changes effectively.

Also applies to: 14-14

Verification successful

The search results indicate that both encodeVersionedBatch and decodeVersionedBatch operations are implemented and used across various files in the packages/contracts-communication directory. These operations are found within test harnesses, test cases, and the actual contract implementations, suggesting that the encoding and decoding of versionedBatch are properly integrated and likely tested within the system. This aligns with the PR's objectives of changing function parameters to bytes calldata for requestBatchVerification and ensuring that corresponding encoding and decoding operations are properly implemented and tested across the system.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify encoding and decoding operations for versionedBatch across the system
rg --type solidity "encodeVersionedBatch|decodeVersionedBatch"

Length of output: 97



Script:

#!/bin/bash
# Verify encoding and decoding operations for versionedBatch across the system by searching in Solidity files
rg "encodeVersionedBatch|decodeVersionedBatch" -g "*.sol"

Length of output: 4549

packages/contracts-communication/test/harnesses/ModuleBatchLibHarness.sol (2)

26-35: The addition of encodeVersionedModuleBatch function is a good step towards handling versioned module batches. Ensure the encoding logic aligns with the versioning strategy and that it's thoroughly tested.

Verification successful

The search revealed a test case named test_encodeVersionedModuleBatch_roundTrip in the file packages/contracts-communication/test/libs/ModuleBatchLib.t.sol, indicating that the encodeVersionedModuleBatch function is indeed being tested. This aligns with the emphasis on ensuring thorough testing for new functionalities. However, the depth and breadth of the testing cannot be fully assessed based on the search result alone.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify thorough testing of encodeVersionedModuleBatch function
rg --type solidity "test_encodeVersionedModuleBatch"

Length of output: 85



Script:

#!/bin/bash
# Adjusting the search to include Solidity files directly by specifying the .sol extension
rg "test_encodeVersionedModuleBatch" -g "*.sol"

Length of output: 229


37-43: The addition of decodeVersionedModuleBatch function complements the encoding functionality. Verify that the decoding logic correctly interprets the versioned data and that comprehensive tests cover various scenarios.

packages/contracts-communication/test/harnesses/InterchainBatchLibHarness.sol (3)

11-17: The addition of decodeVersionedBatchFromMemory is crucial for handling versioned batches. Ensure the decoding logic is accurately implemented and thoroughly tested, especially for handling different versions.


19-25: decodeVersionedBatch function is essential for decoding versioned batches. Verify that it correctly handles various versions and that comprehensive tests are in place.


27-36: Adding encodeVersionedBatch supports the system's versioning strategy. Ensure the encoding process is aligned with versioning requirements and that it's adequately tested.

Verification successful

The verification process has identified two test functions, test_encodeVersionedBatchFromMemory_roundTrip and test_encodeVersionedBatch_roundTrip, within packages/contracts-communication/test/libs/InterchainBatchLib.t.sol. These functions suggest that the encodeVersionedBatch method is indeed being tested, specifically focusing on round-trip encoding scenarios. This aligns with the review comment's requirement for thorough testing of the encodeVersionedBatch function to ensure it supports the system's versioning strategy effectively.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify thorough testing of encodeVersionedBatch function
rg --type solidity "test_encodeVersionedBatch"

Length of output: 79



Script:

#!/bin/bash
# Adjusting the search to include all files, focusing on Solidity by specifying the file extension
rg "test_encodeVersionedBatch" -g "*.sol"

Length of output: 399

packages/contracts-communication/test/libs/ModuleBatchLib.t.sol (1)

29-35: The addition of test_encodeVersionedModuleBatch_roundTrip is a good practice for validating the encoding and decoding of versioned module batches. Ensure this test covers a wide range of scenarios to guarantee robustness.

packages/contracts-communication/contracts/interfaces/IInterchainModule.sol (1)

19-21: Updating the requestBatchVerification function to accept a bytes parameter enhances flexibility in handling versioned data. Ensure all implementations of this interface are updated accordingly and that they correctly handle the bytes parameter.

Verification successful

The search results indicate that the requestBatchVerification function, accepting a uint256 and a bytes parameter, is implemented in various parts of the codebase, including the InterchainDB.sol, InterchainModule.sol, and a mock contract InterchainModuleMock.sol. This confirms that the change in the function signature to accept a bytes parameter for versioned batch data has been adopted in the implementations of the IInterchainModule interface. The presence of this method in both actual implementations and mock contracts used for testing suggests that the necessary updates to handle the bytes parameter have been made across the codebase.

Given this evidence, it can be concluded that the implementations of the IInterchainModule interface have been updated to accommodate the new bytes parameter in the requestBatchVerification function, enhancing flexibility in handling versioned data as intended by the PR.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify all implementations of IInterchainModule interface handle the new parameter correctly
rg --type solidity "requestBatchVerification" -C 5

Length of output: 83



Script:

#!/bin/bash
# Adjusted script to verify all implementations of IInterchainModule interface handle the new parameter correctly
# Searching for the method in Solidity files without relying on the unrecognized --type flag
rg "requestBatchVerification" -g "*.sol" -C 5

Length of output: 21357

packages/contracts-communication/test/mocks/InterchainDBMock.sol (1)

29-29: Changing the verifyRemoteBatch function's parameter to bytes calldata is consistent with the PR's versioning objectives. Ensure the system correctly handles these parameters, particularly regarding encoding and decoding operations.

Verification successful

The search results provide a comprehensive overview of how the verifyRemoteBatch function, with its parameter type changed to bytes calldata, is utilized across various parts of the system. The function is found in both the InterchainDBMock.sol and InterchainDB.sol files, indicating its mock implementation for testing and its actual implementation, respectively. Additionally, it's referenced in various test files and modules, such as SynapseModule.Destination.t.sol and SynapseModule.sol, which suggests that the system is designed to handle bytes calldata parameters in the context of verifying remote batches.

The usage contexts include testing scenarios that simulate the verification process, integration with the SynapseModule for processing batches, and direct calls within mock setups for testing purposes. This indicates a system-wide acknowledgment and handling of the bytes calldata parameter type for the verifyRemoteBatch function, aligning with the PR's objectives for enhanced versioning and flexible data handling.

Given the evidence from the search results, it can be concluded that the change to the verifyRemoteBatch function's parameter type to bytes calldata is consistently applied and utilized across the system, with proper handling in various contexts including testing, mock implementations, and actual module integrations. This supports the original review comment regarding the consistency of the change with the PR's versioning objectives and the importance of ensuring correct handling of these parameters.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify correct handling of bytes calldata parameters in verifyRemoteBatch across the system
rg --type solidity "verifyRemoteBatch" -C 5

Length of output: 76



Script:

#!/bin/bash
# Adjusted command to correctly search for verifyRemoteBatch in Solidity files
rg "verifyRemoteBatch" -g "*.sol" -C 5

Length of output: 59543

packages/contracts-communication/contracts/libs/ModuleBatch.sol (2)

33-46: The addition of encodeVersionedModuleBatch function supports the system's versioning strategy. Ensure the encoding logic is aligned with versioning requirements and that it's thoroughly tested.


48-58: The addition of decodeVersionedModuleBatch function complements the encoding functionality. Verify that the decoding logic correctly interprets the versioned data and that comprehensive tests cover various scenarios.

packages/contracts-communication/test/libs/InterchainBatchLib.t.sol (2)

51-56: The addition of test_encodeVersionedBatchFromMemory_roundTrip is a good practice for validating the encoding and decoding of versioned batches. Ensure this test covers a wide range of scenarios to guarantee robustness.


58-63: The addition of test_encodeVersionedBatch_roundTrip is crucial for ensuring the reliability of versioned batch encoding and decoding. Verify that this test comprehensively covers different versioning scenarios.

packages/contracts-communication/contracts/libs/InterchainBatch.sol (5)

4-4: The import statement for VersionedPayloadLib is correctly added to enable versioned payload handling within the InterchainBatch library.


22-22: Utilizing VersionedPayloadLib for the bytes type is a good practice for handling versioned data. This directive enables the use of versioning functions directly on bytes instances, which is essential for the added functionality.


39-51: The decodeVersionedBatchFromMemory function correctly decodes the versioned batch payload from memory into a version number and an InterchainBatch struct. It properly uses the VersionedPayloadLib to extract the version and payload, ensuring that the data is correctly interpreted. This function is crucial for handling versioned data received in memory.


53-64: The decodeVersionedBatch function is well-implemented for decoding versioned batch payloads from calldata. It makes effective use of VersionedPayloadLib to extract the version and payload, similar to the memory-based decoding function. This dual approach (memory and calldata) ensures flexibility in handling versioned data.


66-79: The encodeVersionedBatch function correctly encodes an InterchainBatch struct into a versioned batch payload. It uses VersionedPayloadLib to prepend the version to the encoded batch, facilitating version-aware data handling. This encoding function is essential for creating versioned payloads that can be understood by the system.

packages/contracts-communication/contracts/modules/InterchainModule.sol (3)

8-9: The update to imports, replacing ModuleBatchLib with InterchainBatchLib, aligns with the shift towards using versioned batch payloads. This change is necessary for the module to handle versioned data correctly.


19-29: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [22-38]

The modification of requestBatchVerification to accept a versionedBatch as bytes and the subsequent decoding logic to handle this versioned data are correctly implemented. This change ensures that the module can process versioned batches, enhancing the system's flexibility and maintainability.


51-61: The _verifyBatch function's adjustments to decode the versionedBatch and moduleData from the encoded module batch are correctly done. It ensures that the module can verify versioned batches by extracting the necessary information from the encoded data. This is crucial for maintaining the integrity and compatibility of the verification process.

packages/contracts-communication/test/integration/ICSetup.t.sol (1)

25-25: Adding the DB_VERSION constant is a good practice for maintaining version consistency across the system. This constant can be used to ensure that the test setup aligns with the expected database version, facilitating more accurate and relevant testing scenarios.

packages/contracts-communication/contracts/interfaces/IInterchainDB.sol (2)

22-22: Introducing the InterchainDB__InvalidBatchVersion error type is essential for robust error handling. It allows the system to provide more informative feedback when a batch version mismatch occurs, enhancing the system's reliability and user experience.


72-74: Modifying the verifyRemoteBatch function to accept a bytes parameter for versioned batch data is a necessary update for supporting versioning. This change ensures that the interface can handle versioned batches, aligning with the system's enhanced versioning capabilities.

packages/contracts-communication/test/modules/SynapseModule.Source.t.sol (4)

7-7: Importing InterchainBatchLib is correctly done to enable handling of versioned batches within the test. This library provides the necessary functionality for encoding and decoding versioned data, which is crucial for testing the module's compatibility with versioned payloads.


28-28: The introduction of the MOCK_DB_VERSION constant is a good practice for testing purposes. It allows for consistent versioning across test cases, ensuring that the tests accurately reflect the system's behavior with specific versioned data.


57-61: The modification to requestBatchVerification to encode the batch with a mock version before requesting verification is correctly implemented. This change ensures that the tests accurately simulate the handling of versioned batches, aligning with the system's versioning capabilities.


69-70: The encodeAndHashBatch function's update to encode the batch with a mock version before hashing is correctly done. This ensures that the tests accurately reflect the system's behavior when handling versioned batches, contributing to more reliable and relevant test outcomes.

packages/contracts-communication/contracts/InterchainDB.sol (3)

12-12: Adding the DB_VERSION constant to the InterchainDB contract is a crucial update for maintaining version consistency within the database. This constant facilitates version checks and ensures that the database operates with the correct version of the data, enhancing system integrity.


67-74: The modifications to the verifyRemoteBatch function to handle versioned batch data, including version checking and chain ID validation, are correctly implemented. These changes ensure that the database can accurately process and verify versioned batches, maintaining data integrity and compatibility.


220-222: Updating the requestBatchVerification function to encode the batch with the database version before requesting verification is a necessary enhancement. This ensures that the database interacts with versioned batches correctly, aligning with the system's versioning capabilities and enhancing interoperability.

packages/contracts-communication/test/integration/ICIntegration.t.sol (2)

12-12: The addition of InterchainBatchLib import is correctly done and necessary for the subsequent use of its functionality within the contract.


244-245: The use of InterchainBatchLib.encodeVersionedBatch for encoding a versioned batch is a significant enhancement. It ensures that batches are versioned, which can improve maintainability and flexibility in handling different batch formats in the future. Ensure that DB_VERSION is correctly defined and used throughout the system to maintain consistency in versioning.

packages/contracts-communication/test/modules/SynapseModule.Destination.t.sol (5)

7-7: The addition of InterchainBatchLib import is correctly done and necessary for the subsequent use of its functionality within the contract.


29-30: The introduction of MOCK_DB_VERSION is a good practice for testing, ensuring that versioned batch encoding can be properly tested with a consistent version number. Ensure that this mock version aligns with the expected versioning scheme of the system for accurate testing.


93-94: The modification to use InterchainBatchLib.encodeVersionedBatch in the encode function aligns with the goal of introducing versioning to batch processing. This change ensures that batches are encoded with a version, improving the system's flexibility and maintainability. Verify that MOCK_DB_VERSION is used consistently and correctly throughout the tests.


112-153: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [109-153]

The renaming of functions for clarity and consistency is a positive change, enhancing the readability and maintainability of the test suite. Ensure that all references to these functions are updated accordingly to avoid any broken references.


159-306: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [154-317]

Updating function names for clarity and consistency is beneficial for the maintainability and readability of the code. It's important to ensure that these changes are reflected across all test cases and that there are no lingering references to the old function names.

packages/contracts-communication/test/InterchainDB.Dst.t.sol (6)

7-7: The addition of InterchainBatchLib is crucial for encoding versioned batches. Ensure that the library is thoroughly tested, especially since it's being used to handle versioned data which is critical for maintaining data integrity across different versions.


26-27: Introducing a DB_VERSION constant is a good practice for version management. It's important to ensure that this version is updated accordingly with any structural changes to the data being stored or processed.


189-189: Renaming expectBatchVerifiedEvent to expectEventBatchVerified improves readability and consistency with naming conventions. Good refactor.


194-194: Renaming expectConflictingBatches to expectRevertConflictingBatches clarifies the function's purpose, which is to expect a revert due to conflicting batches. This is a positive change for code clarity.


211-213: Adding expectRevertInvalidBatchVersion function is a good practice for testing error handling related to version mismatches. Ensure comprehensive tests cover various invalid version scenarios.


315-321: The addition of test_verifyBatch_revert_wrongVersion is crucial for ensuring robustness in version handling. It's important to cover a wide range of invalid versions in the tests to ensure the system behaves as expected when encountering unexpected version numbers.

packages/contracts-communication/test/InterchainDB.Src.t.sol (7)

7-7: The inclusion of InterchainBatchLib and InterchainEntryLib is essential for handling versioned batches and entries. It's important to ensure these libraries are well-tested for their critical role in data integrity and version management.


27-28: Introducing a DB_VERSION constant in this context as well is consistent with the approach in the destination contract. This consistency is key for maintaining version compatibility across the system.


155-155: Renaming functions for event expectations and revert conditions, such as expectEventVerificationRequested, improves readability and clarity regarding the function's purpose. This is a positive change for code maintainability.


161-161: Renaming functions to more accurately describe their behavior, such as expectRevertBatchDoesNotExist, is a good practice. It helps in understanding the code's intent without needing to dive into the implementation details.


265-265: The addition of tests like test_requestVerification_writerF_oneModule_emitsEvent is important for ensuring the system behaves as expected under various scenarios. It's good to see comprehensive testing around the new versioning functionality.


364-364: Adding tests for revert scenarios, such as test_requestVerification_revert_batchNotFinalized_oneModule_nextNonce, is crucial for ensuring robust error handling. It's important to cover a wide range of error conditions in the tests.


624-624: The addition of test_getInterchainFee_noModules and similar tests for fee calculation is a good practice. It ensures that the fee logic behaves correctly under various conditions, which is critical for the system's economic aspects.

Comment on lines 54 to 57
bytes memory versionedBatch = InterchainBatchLib.encodeVersionedBatch(DB_VERSION, batch);
skip(1 minutes);
verifiedAt[address(module)][keccak256(abi.encode(batch))] = block.timestamp;
module.mockVerifyRemoteBatch(address(icDB), batch);
module.mockVerifyRemoteBatch(address(icDB), versionedBatch);
Copy link
Contributor

Choose a reason for hiding this comment

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

Encoding versioned batches using InterchainBatchLib.encodeVersionedBatch is a significant change. It's essential to validate the encoded data's structure and compatibility with the expected versioning format. Consider adding tests specifically for this encoding process to ensure its reliability.

Would you like me to help with creating additional tests for the encoding process?

Comment on lines 98 to 101
bytes memory versionedBatch = InterchainBatchLib.encodeVersionedBatch(
DB_VERSION, InterchainBatch({srcChainId: entry.srcChainId, dbNonce: entry.dbNonce, batchRoot: batchRoot})
);
return abi.encodeCall(IInterchainModule.requestBatchVerification, (DST_CHAIN_ID, versionedBatch));
Copy link
Contributor

Choose a reason for hiding this comment

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

Utilizing InterchainBatchLib.encodeVersionedBatch for creating versioned batch calldata is a significant change. It's crucial to validate the structure and compatibility of the encoded data with the expected versioning format, similar to the destination contract.

Would you like assistance in creating additional tests for the encoding process here as well?

…#2393)

* Implement Transaction versioning

* Implement tests for versioned txs

* Adjust integration tests

* Implement client/tx versioning

* Chore: cleanup deprecated functions

* Chore: remove unused imports

* Chore: `forge fmt`
Copy link
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: 0

Review Status

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 3407aef and 5525834.
Files selected for processing (14)
  • packages/contracts-communication/contracts/InterchainClientV1.sol (7 hunks)
  • packages/contracts-communication/contracts/interfaces/IInterchainClientV1.sol (1 hunks)
  • packages/contracts-communication/contracts/libs/InterchainTransaction.sol (3 hunks)
  • packages/contracts-communication/test/InterchainClientV1.Base.t.sol (5 hunks)
  • packages/contracts-communication/test/InterchainClientV1.Dst.t.sol (11 hunks)
  • packages/contracts-communication/test/InterchainClientV1.GenericViews.t.sol (2 hunks)
  • packages/contracts-communication/test/InterchainClientV1.Management.t.sol (1 hunks)
  • packages/contracts-communication/test/InterchainClientV1.Src.t.sol (5 hunks)
  • packages/contracts-communication/test/harnesses/InterchainTransactionLibHarness.sol (1 hunks)
  • packages/contracts-communication/test/integration/ICIntegration.t.sol (6 hunks)
  • packages/contracts-communication/test/integration/ICSetup.t.sol (1 hunks)
  • packages/contracts-communication/test/integration/PingPong.Dst.t.sol (2 hunks)
  • packages/contracts-communication/test/integration/PingPong.Src.t.sol (1 hunks)
  • packages/contracts-communication/test/libs/InterchainTransaction.t.sol (2 hunks)
Files skipped from review as they are similar to previous changes (5)
  • packages/contracts-communication/contracts/InterchainClientV1.sol
  • packages/contracts-communication/test/InterchainClientV1.Dst.t.sol
  • packages/contracts-communication/test/InterchainClientV1.Src.t.sol
  • packages/contracts-communication/test/integration/ICIntegration.t.sol
  • packages/contracts-communication/test/integration/ICSetup.t.sol
Additional Context Used
Additional comments not posted (22)
packages/contracts-communication/test/harnesses/InterchainTransactionLibHarness.sol (2)

25-33: The encodeVersionedTransaction function correctly delegates the encoding logic to InterchainTransactionLib.encodeVersionedTransaction, passing along the clientVersion and transaction. This encapsulation ensures that the encoding logic is centralized, which is good for maintainability.


36-41: The decodeVersionedTransaction function mirrors the encoding function by correctly delegating the decoding logic to InterchainTransactionLib.decodeVersionedTransaction. This approach maintains consistency and centralizes the versioned transaction handling logic.

packages/contracts-communication/test/InterchainClientV1.Management.t.sol (1)

4-4: The change to import InterchainClientV1BaseTest instead of InterchainClientV1 directly suggests a refactoring towards using a base test class for shared setup and utility functions. This is a good practice for reducing code duplication and improving test maintainability.

packages/contracts-communication/test/integration/PingPong.Src.t.sol (1)

34-34: The use of getEncodedTx for calculating txPayloadSize instead of directly using abi.encode is a positive change. It likely encapsulates the transaction encoding logic, including versioning, which improves code modularity and maintainability. Ensure that getEncodedTx correctly handles the encoding to reflect the actual payload size accurately.

packages/contracts-communication/test/InterchainClientV1.GenericViews.t.sol (3)

6-7: The import changes to include InterchainTransactionLibHarness and adjust other imports reflect a refactoring effort to better organize the test dependencies. This is a good practice for clarity and maintainability.


12-18: The addition of the libHarness variable of type InterchainTransactionLibHarness and its initialization in the setUp method is a good practice. It allows for reusing the harness across different test cases, improving test code modularity.


55-56: The modifications to the test_encodeTransaction function to use libHarness for decoding transactions and adding an assertion for the version are appropriate. It ensures that the versioning functionality is correctly integrated and tested.

packages/contracts-communication/contracts/libs/InterchainTransaction.sol (5)

6-6: The addition of the VersionedPayloadLib import is crucial for enabling versioned payload functionality within InterchainTransactionLib. This aligns with the PR's objective to enhance versioning capabilities.


29-29: The use of VersionedPayloadLib for bytes is a good practice, as it extends the functionality of byte arrays to include versioning capabilities. This is essential for the versioned transaction handling introduced in this PR.


56-64: The encodeVersionedTransaction function correctly encapsulates the logic for encoding transactions with versioning. It uses VersionedPayloadLib.encodeVersionedPayload, which is a good practice for maintaining consistency and reusability.


67-73: The decodeVersionedTransaction function complements the encoding function by providing the logic to decode versioned transactions. It correctly extracts the version and decodes the payload, ensuring that the versioning functionality is symmetric and reliable.


77-81: The update to the payloadSize calculation to account for the transaction version is necessary due to the introduction of versioning. It ensures that the payload size calculation remains accurate, considering the additional version bytes.

packages/contracts-communication/test/libs/InterchainTransaction.t.sol (2)

44-47: The renaming of the test function to test_encodeVersionedTransaction_roundTrip and its restructuring to include versioning support is a positive change. It ensures that the versioning functionality is thoroughly tested, which is crucial for the system's integrity.


60-60: The update to the test_payloadSize function to use the new encoding method for calculating the expected size is appropriate. It reflects the changes in the encoding logic due to versioning, ensuring that the payload size calculation tests remain accurate.

packages/contracts-communication/contracts/interfaces/IInterchainClientV1.sol (1)

10-10: The addition of the InterchainClientV1__InvalidTransactionVersion error is a necessary update to handle cases where an invalid transaction version is encountered. This enhances the robustness of the system by providing a clear error handling mechanism for versioning issues.

packages/contracts-communication/test/integration/PingPong.Dst.t.sol (2)

45-45: The replacement of abi.encode with getEncodedTx for encoding srcTx is a good practice. It likely encapsulates the transaction encoding logic, including versioning, which improves code modularity and maintainability.


59-59: Similarly, using getEncodedTx for encoding dstTx ensures consistency in how transactions are encoded across the test suite. This change aligns with the PR's objectives to enhance versioning capabilities.

packages/contracts-communication/test/InterchainClientV1.Base.t.sol (5)

6-8: The addition of InterchainTransactionLib in the import statements is appropriate for the functionalities introduced in this PR.


27-27: The addition of the CLIENT_VERSION constant aligns with the PR's objectives to enhance versioning capabilities.


82-86: The addition of the expectRevertInvalidTransactionVersion function enhances error handling for versioning.


218-218: The modification in the assertCorrectDescriptor function to use getEncodedTx for calculating transactionId aligns with the new versioning approach.


232-234: The addition of the getEncodedTx function is crucial for handling versioned transactions, utilizing InterchainTransactionLib.

* Bring back the vanilla encoding/decoding funcs

* Deduplicate Batch library

* Update DB and Module to use generic library

* Update tests

* Deduplicate Transaction library

* Update Client to use generic library

* Update tests
Copy link
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: 0

Review Status

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 5525834 and 269fcde.
Files selected for processing (18)
  • packages/contracts-communication/contracts/InterchainClientV1.sol (8 hunks)
  • packages/contracts-communication/contracts/InterchainDB.sol (3 hunks)
  • packages/contracts-communication/contracts/libs/InterchainBatch.sol (3 hunks)
  • packages/contracts-communication/contracts/libs/InterchainTransaction.sol (3 hunks)
  • packages/contracts-communication/contracts/modules/InterchainModule.sol (3 hunks)
  • packages/contracts-communication/test/InterchainClientV1.Base.t.sol (6 hunks)
  • packages/contracts-communication/test/InterchainClientV1.Dst.t.sol (15 hunks)
  • packages/contracts-communication/test/InterchainClientV1.GenericViews.t.sol (2 hunks)
  • packages/contracts-communication/test/InterchainDB.Dst.t.sol (8 hunks)
  • packages/contracts-communication/test/InterchainDB.Src.t.sol (20 hunks)
  • packages/contracts-communication/test/harnesses/InterchainBatchLibHarness.sol (1 hunks)
  • packages/contracts-communication/test/harnesses/InterchainTransactionLibHarness.sol (1 hunks)
  • packages/contracts-communication/test/integration/ICIntegration.t.sol (6 hunks)
  • packages/contracts-communication/test/integration/ICSetup.t.sol (4 hunks)
  • packages/contracts-communication/test/libs/InterchainBatchLib.t.sol (1 hunks)
  • packages/contracts-communication/test/libs/InterchainTransaction.t.sol (3 hunks)
  • packages/contracts-communication/test/modules/SynapseModule.Destination.t.sol (9 hunks)
  • packages/contracts-communication/test/modules/SynapseModule.Source.t.sol (5 hunks)
Files skipped from review as they are similar to previous changes (12)
  • packages/contracts-communication/contracts/InterchainClientV1.sol
  • packages/contracts-communication/contracts/InterchainDB.sol
  • packages/contracts-communication/contracts/libs/InterchainBatch.sol
  • packages/contracts-communication/contracts/libs/InterchainTransaction.sol
  • packages/contracts-communication/contracts/modules/InterchainModule.sol
  • packages/contracts-communication/test/InterchainClientV1.Base.t.sol
  • packages/contracts-communication/test/InterchainClientV1.Dst.t.sol
  • packages/contracts-communication/test/InterchainDB.Dst.t.sol
  • packages/contracts-communication/test/InterchainDB.Src.t.sol
  • packages/contracts-communication/test/integration/ICIntegration.t.sol
  • packages/contracts-communication/test/libs/InterchainBatchLib.t.sol
  • packages/contracts-communication/test/libs/InterchainTransaction.t.sol
Additional Context Used
Additional comments not posted (13)
packages/contracts-communication/test/harnesses/InterchainBatchLibHarness.sol (3)

11-13: Looks good. The encodeBatch function correctly utilizes InterchainBatchLib.encodeBatch for encoding an InterchainBatch.


15-17: The decodeBatch function is implemented correctly, making efficient use of calldata for its input bytes.


19-21: The decodeBatchFromMemory function provides a useful alternative for decoding batches stored in memory.

packages/contracts-communication/test/InterchainClientV1.GenericViews.t.sol (2)

6-8: The changes in imports align with the PR's objectives to enhance versioning capabilities by utilizing InterchainTransactionLibHarness and VersionedPayloadLibHarness.


53-55: The modifications in test_encodeTransaction to use txLibHarness and payloadLibHarness for decoding transactions and asserting the version are appropriate and align with the PR's objectives for versioning.

packages/contracts-communication/test/integration/ICSetup.t.sol (2)

27-28: The introduction of DB_VERSION and CLIENT_VERSION constants is a clear and straightforward way to manage versioning in tests.


39-41: The instantiation of InterchainBatchLibHarness and VersionedPayloadLibHarness enhances testing capabilities for versioned transactions and batches, aligning with the PR's objectives.

packages/contracts-communication/test/modules/SynapseModule.Source.t.sol (3)

7-7: The addition of InterchainBatchLib import is necessary for handling versioned batches, aligning with the PR's objectives.


33-33: The introduction of MOCK_DB_VERSION constant provides a clear reference for versioning in tests, which is useful for testing versioned batches.


64-66: Modifications to function calls to support versioned batch encoding, such as in getVersionedBatch, are consistent with the PR's objectives to enhance versioning capabilities.

packages/contracts-communication/test/modules/SynapseModule.Destination.t.sol (3)

7-12: The addition of InterchainBatchLib and VersionedPayloadLibHarness imports is necessary for handling versioned batches in tests, aligning with the PR's objectives.


35-35: The introduction of MOCK_DB_VERSION constant provides a mock version number for testing versioned batches, aligning with the PR's objectives.


124-126: Modifications to function names and implementations, such as getVersionedBatch, to accommodate versioned batches are appropriate and align with the PR's objectives to enhance versioning capabilities.

@ChiTimesChi ChiTimesChi marked this pull request as ready for review March 31, 2024 13:00
Copy link
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: 0

Review Status

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 269fcde and e2a8942.
Files selected for processing (8)
  • committee/contracts/interchaindb/interchaindb.abigen.go (13 hunks)
  • packages/contracts-communication/contracts/interfaces/IInterchainDB.sol (3 hunks)
  • packages/contracts-communication/test/mocks/InterchainDBMock.sol (2 hunks)
  • packages/contracts-communication/test/mocks/InterchainModuleMock.sol (1 hunks)
  • sin-executor/contracts/interchaindb/interchaindb.abigen.go (13 hunks)
  • sin-executor/contracts/mocks/interchainapp/interchainapp.abigen.go (10 hunks)
  • sin-executor/contracts/mocks/interchainmodulemock/interchainmodulemock.abigen.go (10 hunks)
  • sin-executor/executor/executor_test.go (1 hunks)
Files not summarized due to errors (4)
  • committee/contracts/interchaindb/interchaindb.abigen.go: Error: Message exceeds token limit
  • sin-executor/contracts/interchaindb/interchaindb.abigen.go: Error: Message exceeds token limit
  • sin-executor/contracts/mocks/interchainapp/interchainapp.abigen.go: Error: Message exceeds token limit
  • sin-executor/contracts/mocks/interchainmodulemock/interchainmodulemock.abigen.go: Error: Message exceeds token limit
Files skipped from review as they are similar to previous changes (2)
  • packages/contracts-communication/contracts/interfaces/IInterchainDB.sol
  • packages/contracts-communication/test/mocks/InterchainModuleMock.sol
Additional Context Used
Additional comments not posted (45)
packages/contracts-communication/test/mocks/InterchainDBMock.sol (2)

8-8: The addition of the DB_VERSION constant is appropriate and aligns with the PR's objectives to introduce versioning. Using uint16 is a good choice for version numbers as it offers a wide range while conserving storage space.


31-31: The change in the verifyRemoteBatch function's parameter to bytes calldata versionedBatch is suitable for handling versioned payloads efficiently. Ensure that the corresponding interface (IInterchainDB) has been updated to reflect this change.

sin-executor/executor/executor_test.go (1)

49-49: The update to use MockVerifyRemoteBatchStruct with the InterchainBatch struct parameter enhances type safety and clarity in handling versioned payloads. Ensure that the InterchainBatch struct is correctly defined and consistently used across related tests and contracts.

Verification successful

The verification process confirms the correct and consistent definition and usage of the InterchainBatch struct across tests and contracts within the project. This consistency supports the initial assessment that the update to use MockVerifyRemoteBatchStruct with the InterchainBatch struct parameter enhances type safety and clarity in handling versioned payloads.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify the correct definition and consistent usage of the InterchainBatch struct across tests and contracts.
ast-grep --lang go --pattern $'type InterchainBatch struct {
  $$$
}'

Length of output: 2275

sin-executor/contracts/mocks/interchainmodulemock/interchainmodulemock.abigen.go (10)

50-50: The ABI string is directly embedded within the Go code. While this is common for generated bindings, consider storing the ABI in a separate file or a configuration management system for larger projects. This approach enhances maintainability, especially when dealing with multiple contract versions or environments.


47-55: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [52-64]

The mapping of function signatures to their string representations (Sigs) is correctly defined. However, ensure that the contract ABI aligns with the expected functionalities and that all necessary functions are covered by the bindings.


220-235: The DBVERSION method binding is correctly implemented. It's good practice to follow the Go naming conventions, even in generated code. Consider renaming it to DBVersion to align with Go's camelCase naming convention for better readability.


237-249: Duplicate method bindings for DBVERSION are present for different session types (IInterchainDBSession and IInterchainDBCallerSession). This redundancy is expected in generated bindings to provide convenience methods for different types of contract interactions (read-only, transact, etc.). No action is needed, but it's good to be aware of this pattern when using or extending the generated code.


596-614: The VerifyRemoteBatch transaction method is correctly bound. Ensure that the input parameters, especially the versionedBatch byte slice, are correctly formatted and validated before invoking this method to avoid runtime errors or unexpected behavior.


661-664: The ABI for IInterchainModule is correctly defined. Regularly verify that the ABI matches the latest version of the smart contract to ensure compatibility and correct operation of the generated bindings.


849-867: The RequestBatchVerification method binding is implemented as expected. Given that it's a payable function, ensure that the transaction options (opts) include the correct value transfer if the smart contract function requires it. This is crucial for functions that alter the contract state and may require a fee.


873-873: The binary data (Bin) for InterchainBatchLib is embedded directly in the code. For maintainability and clarity, consider loading such data from external files or resources, especially if the contract bytecode is subject to frequent updates.


1430-1490: The mock methods (MockVerifyRemoteBatch and MockVerifyRemoteBatchStruct) are essential for testing and development. Ensure that these methods are used appropriately in test environments and that their usage is well-documented for developers. Additionally, verify that these methods do not get deployed or called in production environments inadvertently.


1666-1837: The VersionedPayloadLib contract and its bindings are correctly set up. Given that this library deals with versioned payloads, ensure thorough testing of payload encoding and decoding functionalities to prevent issues with data integrity and compatibility across different contract versions.

committee/contracts/interchaindb/interchaindb.abigen.go (11)

50-50: The ABI string is directly embedded within the Go code. For better maintainability and readability, consider loading the ABI from a separate JSON file. This approach makes it easier to update the ABI without modifying the Go code directly.


47-55: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [52-64]

The mapping of function signatures to their string representations (Sigs) is correctly defined. However, ensure that all contract functions are covered and correctly mapped. This is crucial for the correct operation of the generated bindings.


220-235: The DBVERSION method is correctly bound to the corresponding smart contract function. Ensure that the method name follows Go naming conventions, which might suggest using DBVersion instead for better readability.


598-614: The VerifyRemoteBatch transaction method is correctly bound. However, consider adding comments to document the purpose and usage of this method, especially since it involves state changes on the blockchain. Documentation can improve code maintainability and usability for developers.


661-664: The ABI for IInterchainModule is correctly defined. It's good practice to ensure that the ABI is kept up-to-date with any changes to the smart contract to maintain compatibility.


873-873: The binary data for InterchainBatchLib is embedded within the Go code. For contracts with large binaries, consider loading this data from an external file to improve code readability and maintainability.


1042-1050: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1045-1059]

The ABI and binary data for InterchainDB are correctly included. Regularly verify that these are in sync with the deployed smart contract version to avoid runtime errors due to ABI mismatches.


1237-1252: The method DBVERSION is correctly bound and follows the naming convention of the original smart contract function. Ensure consistency in naming conventions across all bound methods for clarity.


1613-1631: The VerifyRemoteBatch method is correctly implemented. Given its significance in verifying remote batches, thorough testing is recommended to ensure its correct operation under various conditions.


2995-2998: The ABI for VersionedPayloadLib includes error types, which are a newer feature in Solidity. Ensure that the Go bindings are capable of correctly interpreting these errors when they are returned by the smart contract.


2998-2998: The binary data for VersionedPayloadLib is embedded within the Go code. Consider the implications of this approach on the code size and readability, especially for larger contracts.

sin-executor/contracts/interchaindb/interchaindb.abigen.go (10)

50-50: The ABI string is directly embedded within the Go code. For maintainability and to avoid hardcoding, consider loading the ABI from a separate JSON file or a contract artifact generated by the Solidity compiler.


47-55: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [52-64]

The mapping of function signatures to their string representations (Sigs) is correctly defined. However, ensure that all contract functions are covered and correctly mapped to facilitate easy interaction with the contract.


220-235: The DBVERSION method is correctly bound to the corresponding smart contract function. Ensure that the method name follows Go naming conventions, which might suggest using DBVersion instead for better readability.


596-614: The VerifyRemoteBatch transaction method is correctly implemented. Ensure that all input parameters are validated before calling this method to prevent unexpected behavior or errors when interacting with the smart contract.


661-664: The ABI for IInterchainModule is correctly defined. Regularly verify that this ABI matches the latest version of the smart contract to ensure compatibility and correct operation of the binding.


849-867: The RequestBatchVerification method is correctly implemented for sending transactions. It's important to handle the transaction receipt and check for any events or errors that indicate the outcome of the transaction.


1042-1050: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1045-1059]

The ABI and binary data (Bin) for InterchainDB are correctly defined. Ensure that these are updated whenever the smart contract is redeployed or modified to maintain compatibility.


1237-1266: The DBVERSION method is correctly implemented. Consider adding error handling for the contract call to gracefully handle any issues that may arise during execution, such as connection errors or contract execution reverts.


1613-1631: The VerifyRemoteBatch method correctly sends a transaction to the smart contract. Ensure that the application checks the transaction receipt for success and handles any potential reverts or errors.


2995-2998: The VersionedPayloadLib contract's ABI and binary data are embedded directly in the Go code. For better maintainability, consider loading these from external files or contract artifacts.

sin-executor/contracts/mocks/interchainapp/interchainapp.abigen.go (11)

2966-2966: The AddressMetaData struct's Bin property contains the bytecode of the contract. Ensure that this bytecode corresponds to the latest compiled version of the Address contract to prevent discrepancies between the contract's code on the blockchain and the generated Go bindings.


3138-3139: The AppConfigLibMetaData struct's ABI and Bin properties are correctly defined. However, it's crucial to verify that the ABI matches the latest contract interface and that the Bin property contains the correct bytecode.


3652-3652: The EnumerableSetMetaData struct's ABI is an empty array, which suggests that the contract might not have any public functions or events. If this is intentional, ensure that the contract's logic does not require external interactions. Otherwise, review the contract to expose necessary functions or events.


3858-3858: The Bin property for the contract represented in this segment is provided. It's important to ensure that this bytecode is up-to-date with the latest contract compilation to maintain consistency between the contract deployed on the blockchain and the Go bindings.


11898-11898: The IInterchainClientV1MetaData struct's ABI includes a comprehensive list of errors and functions, indicating a well-defined interface for interchain operations. Verify that all necessary functions and error types are included and correctly defined according to the contract's intended functionality.


13221-13221: The InterchainTransactionLibMetaData struct's ABI is empty, similar to the EnumerableSetMetaData. Confirm that this is expected behavior and that the contract does not require any public interface for its intended use cases.


13394-13394: Similar to previous observations, the MathLibMetaData struct's ABI is empty. Ensure that this matches the contract's requirements and that no public interface is needed for the contract's functionality.


13566-13567: The OptionsLibMetaData struct includes an ABI definition focused on versioning errors. Confirm that the ABI accurately reflects all functionalities provided by the OptionsLib contract and that the bytecode is up-to-date.


13740-13740: The TypeCastsMetaData struct's ABI is empty, indicating no public functions or events. Verify that this is consistent with the contract's design and that no external interactions are required.


13909-13909: The VersionedPayloadLibMetaData struct introduces a new library for handling versioned payloads. Ensure that the ABI and Bin properties are correctly set to match the latest contract definitions. Additionally, review the provided functions and error types for completeness and accuracy.


13910-14081: The VersionedPayloadLib and its associated types (Caller, Transactor, Filterer, etc.) are well-structured to facilitate interaction with the Ethereum contract. It's important to ensure that all methods and sessions are correctly implemented and that they align with the contract's functionalities. Additionally, verify that the deployment function correctly initializes the contract with the intended logic.

@ChiTimesChi ChiTimesChi merged commit c21ec2f into master Apr 4, 2024
55 of 57 checks passed
@ChiTimesChi ChiTimesChi deleted the feat/interchain-versioning-library branch April 4, 2024 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go Pull requests that update Go code size/l
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants