-
Notifications
You must be signed in to change notification settings - Fork 30
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: synapse module cleanup #2118
Conversation
Important Auto Review SkippedAuto reviews are disabled on base/target branches other than the default branch. Please add the base/target branch pattern to the list of additional branches to be reviewed in the settings. Please check the settings in the CodeRabbit UI or the To trigger a single review, invoke the WalkthroughThe recent updates focus on enhancing the Changes
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 (
|
@coderabbitai review |
@ChiTimesChi: I will review the PR. Actions performedReview triggered.
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## feat/communication #2118 +/- ##
============================================================
- Coverage 46.57615% 46.57023% -0.00592%
============================================================
Files 230 230
Lines 16867 16867
Branches 83 83
============================================================
- Hits 7856 7855 -1
Misses 8170 8170
- Partials 841 842 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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.
Review Status
Actionable comments generated: 0
Configuration used: .coderabbit.yaml
Files selected for processing (7)
- packages/contracts-communication/contracts/events/SynapseModuleEvents.sol (1 hunks)
- packages/contracts-communication/contracts/interfaces/ISynapseModule.sol (5 hunks)
- packages/contracts-communication/contracts/modules/InterchainModule.sol (2 hunks)
- packages/contracts-communication/contracts/modules/SynapseModule.sol (6 hunks)
- packages/contracts-communication/test/modules/SynapseModule.Destination.t.sol (1 hunks)
- packages/contracts-communication/test/modules/SynapseModule.Management.t.sol (5 hunks)
- packages/contracts-communication/test/modules/SynapseModule.Source.t.sol (4 hunks)
Additional comments: 42
packages/contracts-communication/contracts/events/SynapseModuleEvents.sol (2)
- 11-11: The
VerifyGasLimitChanged
event is well-defined and aligns with the PR's objective to introduce a configurable gas limit for theverifyEntry()
function. It correctly logs the chain ID and the new gas limit.- 13-13: The
ClaimFeeFractionChanged
event is correctly defined to log changes in the claim fee fraction. This supports the PR's goal of overhauling the fee collection workflow and incentivizing the claiming process.packages/contracts-communication/contracts/modules/InterchainModule.sol (1)
- 60-61: The addition of an empty
_requestVerification
function (marked withsolhint-disable-next-line no-empty-blocks
) is a placeholder for future implementations or overrides in derived contracts. While it's currently empty, ensure that derived contracts properly implement this function as needed.packages/contracts-communication/contracts/interfaces/ISynapseModule.sol (6)
- 7-10: The new error types introduced (
SynapseModule__ClaimFeeFractionExceedsMax
,SynapseModule__FeeCollectorNotSet
,SynapseModule__GasOracleNotContract
,SynapseModule__NoFeesToClaim
) are well-defined and provide clear error messages for specific failure conditions. This enhances the contract's readability and error handling.- 19-22: The
addVerifiers
function allows for adding multiple verifiers in a single transaction, improving efficiency. Ensure that the implementation checks for duplicates and already added verifiers to prevent unnecessary state changes or gas wastage.- 29-32: Similarly, the
removeVerifiers
function streamlines the process of removing multiple verifiers. It's important to ensure that the implementation handles cases where one or more verifiers are not currently added, to avoid reverting the entire transaction unnecessarily.- 44-48: The
setClaimFeeFraction
function introduces a mechanism to set the fraction of fees claimable by the caller ofclaimFees
. It's crucial to validate that the claim fee fraction does not exceed the maximum allowed value (MAX_CLAIM_FEE_FRACTION
) to maintain system integrity and prevent excessive claiming.- 55-59: The
setVerifyGasLimit
function allows for setting a custom gas limit for verifying entries on specific chains. This is a significant feature that adds flexibility to the gas limit configuration. Ensure that the gas limit values are validated to prevent setting excessively high or low limits that could impact the contract's functionality or economics.- 63-68: The
claimFees
function is a key part of the fee collection workflow overhaul. It should correctly calculate the claimer's fee based on the_claimFeeFraction
and transfer the remaining fees to thefeeCollector
. Proper error handling for unsetfeeCollector
and no fees to claim conditions is essential.packages/contracts-communication/contracts/modules/SynapseModule.sol (10)
- 17-18: The
DEFAULT_VERIFY_GAS_LIMIT
constant is set to a reasonable default of 100,000 gas units. This aligns with the PR's objective to introduce a configurable gas limit for theverifyEntry()
function. Ensure this default value is appropriate for the expected operations withinverifyEntry
.- 20-28: The introduction of
MAX_CLAIM_FEE_FRACTION
andFEE_PRECISION
constants, alongside the_claimFeeFraction
and_verifyGasLimit
internal variables, is well-structured. These changes support the new functionalities for managing claim fee fractions and gas limits. Ensure that the use of these variables adheres to the intended logic, especially in calculations involving percentages and gas limits.- 43-51: The implementation of
addVerifiers
using a loop to add each verifier individually is efficient. However, ensure that the_addVerifier
internal function properly handles cases where a verifier is already added to prevent unnecessary state changes.- 56-64: Similarly, the
removeVerifiers
function's loop implementation for removing verifiers is straightforward. It's important to ensure that the_removeVerifier
internal function gracefully handles cases where a verifier is not currently added, to avoid transaction failures.- 79-85: The
setClaimFeeFraction
function correctly checks if the providedclaimFeeFraction
exceeds theMAX_CLAIM_FEE_FRACTION
. This validation is crucial for maintaining the integrity of the fee claiming process. The emission of theClaimFeeFractionChanged
event upon successful update is a good practice for transparency.- 97-101: The
setVerifyGasLimit
function allows for flexible gas limit configuration per chain ID. The use of a mapping to store gas limits for different chain IDs is appropriate. Ensure that the gas limits set are validated against reasonable bounds to prevent misuse.- 105-118: The
claimFees
function's implementation, including error checks for an unsetfeeCollector
and no fees to claim, is in line with the PR's objectives. The calculation of the claimer's fee and the distribution of fees are crucial aspects. Ensure that the fee calculation and transfers are secure and accurate.- 129-132: The
getClaimFeeFraction
function provides a simple and direct way to retrieve the current claim fee fraction. This supports the enhanced fee collection workflow by allowing external entities to query the claim fee fraction.- 144-147: The
getClaimFeeAmount
function calculates the claim fee amount based on the contract's balance and the claim fee fraction. Ensure that the calculation is secure against rounding errors and that the division byFEE_PRECISION
is handled correctly.- 154-159: The
getVerifyGasLimit
function correctly returns a custom gas limit if set, or the default gas limit otherwise. This implementation supports the configurable gas limit feature. Validate that the default gas limit is used appropriately when no custom limit is set.packages/contracts-communication/test/modules/SynapseModule.Source.t.sol (14)
- 7-8: The reordering of imports and the addition of necessary contracts and libraries for testing are appropriate. This ensures that all dependencies are correctly included for comprehensive testing of the
SynapseModule
.- 23-23: The addition of the
claimer
address variable is a good practice for testing fee claiming functionalities. This allows for simulating different actors interacting with the contract in a testing environment.- 28-28: Renaming
EXPECTED_GAS_LIMIT
toDEFAULT_GAS_LIMIT
aligns with the introduction of configurable gas limits in theSynapseModule
. This change clarifies the purpose of the constant in the context of the tests.- 88-91: The
test_requestVerification_accumulatesFee
function correctly tests the accumulation of fees upon request verification. This test is essential for validating the fee collection mechanism's correctness.- 101-104: The
test_requestVerification_feeAboveRequired_accumulatesFee
function ensures that fees above the required amount are correctly accumulated. This test case is important for verifying the contract's behavior when excess fees are provided.- 114-120: The
test_claimFees_zeroClaimFee_emitsEvent
function tests the emission of theFeesClaimed
event with a zero claim fee. This test is crucial for ensuring that the event is emitted correctly under different fee claiming scenarios.- 122-128: The
test_claimFees_zeroClaimFee_distributesFees
function validates the distribution of fees when the claim fee is zero. This test ensures that all fees are transferred to thefeeCollector
as expected.- 130-136: The
test_claimFees_zeroClaimFee_revert_feeCollectorNotSet
function correctly tests the revert condition when thefeeCollector
is not set. This test is important for ensuring robust error handling in the fee claiming process.- 138-142: The
test_claimFees_zeroClaimFee_revert_noFeesToClaim
function tests the revert condition when there are no fees to claim. This test case is essential for validating the contract's behavior in scenarios where fee claiming is attempted without any accumulated fees.- 144-153: The
test_claimFees_nonZeroClaimFee_emitsEvent
function tests the emission of theFeesClaimed
event with a non-zero claim fee. This test is crucial for verifying the event's correctness when a portion of the fees is claimed by the caller.- 155-163: The
test_claimFees_nonZeroClaimFee_distributesFees
function validates the fee distribution when a non-zero claim fee is set. This test ensures that both thefeeCollector
and the claimer receive their respective portions of the fees correctly.- 187-208: The
test_getClaimFeeAmount
functions (for both zero and non-zero claim fees) correctly test the calculation of the claim fee amount under various conditions. These tests are important for ensuring the accuracy of the claim fee calculation logic.- 215-259: The
test_getModuleFee
functions test thegetModuleFee
logic under various conditions, including default and custom gas limits, as well as different numbers of signers. These tests are essential for validating the module fee calculation and the interaction with theGasOracleMock
.- 261-263: The
test_getVerifyGasLimit_default
function correctly tests the retrieval of the default gas limit when no custom limit is set. This test is important for verifying the fallback to the default gas limit in the absence of a custom configuration.packages/contracts-communication/test/modules/SynapseModule.Management.t.sol (6)
- 28-35: The addition of the
allVerifiers
array and its initialization in thesetUp
function is a good practice for setting up test conditions. This approach allows for easier management of test verifiers and supports the new functionality for adding and removing multiple verifiers.- 65-97: The tests for adding a single verifier (
test_addVerifier_addsVerifier
,test_addVerifier_emitsEvent
,test_addVerifier_revert_alreadyAdded
,test_addVerifier_revert_notOwner
) and multiple verifiers (test_addVerifiers_addsVerifiers
,test_addVerifiers_emitsEvents
,test_addVerifiers_revert_alreadyAdded
,test_addVerifiers_revert_notOwner
) are well-structured and cover important scenarios including success cases, event emissions, and revert conditions for already added verifiers and unauthorized access. These tests ensure the verifier addition functionality works as expected and is secure against unauthorized modifications.- 126-160: Similar to the addition tests, the removal tests for both single (
test_removeVerifier_removesVerifier
,test_removeVerifier_emitsEvent
,test_removeVerifier_revert_notAdded
,test_removeVerifier_revert_notOwner
) and multiple verifiers (test_removeVerifiers_removesVerifiers
,test_removeVerifiers_emitsEvents
,test_removeVerifiers_revert_notAdded
,test_removeVerifiers_revert_notOwner
) are comprehensive. They effectively validate the functionality for removing verifiers, ensuring the module behaves correctly in various scenarios including successful removals, event emissions, and handling unauthorized access and attempts to remove non-existent verifiers.- 236-272: The tests for setting the fee fraction (
test_setFeeFraction_setsFeeFraction
,test_setFeeFraction_emitsEvent
,test_setFeeFraction_exactlyMax
,test_setFeeFraction_revert_exceedsMax
,test_setFeeFraction_revert_notOwner
) are thorough and cover a wide range of scenarios including setting to a valid value, emitting the correct event, handling maximum allowed value, reverting on exceeding the maximum, and ensuring only the owner can make changes. These tests are crucial for ensuring the fee fraction functionality is robust, secure, and adheres to specified constraints.- 305-322: The addition of tests for setting the verify gas limit (
test_setVerifyGasLimit_setsVerifyGasLimit
,test_setVerifyGasLimit_emitsEvent
,test_setVerifyGasLimit_revert_notOwner
) is a valuable enhancement. These tests ensure that the gas limit for verification can be configured correctly, that the appropriate event is emitted upon change, and that only the owner has the authority to make this change. This functionality is essential for managing gas costs effectively in the verification process.- 297-297: The test
test_setGasOracle_revert_notContract
includes a sanity check to ensure that the address provided for the gas oracle is indeed a contract. This is a good security practice to prevent setting a non-contract address as the gas oracle, which could lead to unexpected behavior or vulnerabilities. However, it's important to ensure that this check is also performed in the main contract code, not just in the test, to enforce this validation outside of testing environments.Verification successful
The verification process has confirmed that the
setGasOracle
function in theSynapseModule.sol
file includes a check to ensure that the provided address is indeed a contract. This validation is performed by checking ifgasOracle_.code.length == 0
and reverting with a custom error if the condition is met, thereby enforcing the security practice outside of testing environments as well.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for the setGasOracle function implementation in the SynapseModule contract to verify contract address validation. rg "function setGasOracle" packages/contracts-communication/contracts/modules/SynapseModule.solLength of output: 164
Script:
#!/bin/bash # Extract the full implementation of the setGasOracle function to check for contract address validation rg -A 10 "function setGasOracle" packages/contracts-communication/contracts/modules/SynapseModule.solLength of output: 540
packages/contracts-communication/test/modules/SynapseModule.Destination.t.sol (3)
- 7-7: The direct import of
InterchainEntry
in this file, following the removal of its import from theSynapseModule
declarations, is a necessary adjustment to maintain access toInterchainEntry
functionalities within the tests. This change ensures that the tests remain functional and can directly utilizeInterchainEntry
for constructing test cases.- 16-17: Disabling the solhint directives
func-name-mixedcase
andordering
at the beginning of the contract is a common practice in test files to accommodate the naming conventions and structure preferred in test scenarios. However, it's important to use these directives judiciously and ensure that the overall code quality and readability are not compromised. In this context, the usage seems appropriate given the conventions in Solidity testing frameworks.- 4-20: > 📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [1-1]
The overall structure and logic of the tests in this file appear to be well-designed, covering a range of scenarios for verifying entries with different signature conditions. The tests are crucial for ensuring the integrity and security of the entry verification process. It's important to continue maintaining and expanding these tests as the SynapseModule evolves to cover new functionalities and edge cases.
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.
Review Status
Actionable comments generated: 5
Configuration used: .coderabbit.yaml
Files selected for processing (7)
- packages/contracts-communication/contracts/events/SynapseModuleEvents.sol (1 hunks)
- packages/contracts-communication/contracts/interfaces/ISynapseModule.sol (5 hunks)
- packages/contracts-communication/contracts/modules/InterchainModule.sol (2 hunks)
- packages/contracts-communication/contracts/modules/SynapseModule.sol (6 hunks)
- packages/contracts-communication/test/modules/SynapseModule.Destination.t.sol (1 hunks)
- packages/contracts-communication/test/modules/SynapseModule.Management.t.sol (5 hunks)
- packages/contracts-communication/test/modules/SynapseModule.Source.t.sol (4 hunks)
Files skipped from review as they are similar to previous changes (4)
- packages/contracts-communication/contracts/events/SynapseModuleEvents.sol
- packages/contracts-communication/contracts/interfaces/ISynapseModule.sol
- packages/contracts-communication/contracts/modules/InterchainModule.sol
- packages/contracts-communication/test/modules/SynapseModule.Destination.t.sol
Additional comments: 10
packages/contracts-communication/contracts/modules/SynapseModule.sol (10)
- 17-18: The default gas limit of 100,000 for
verifyEntry()
is introduced. Ensure this value has been benchmarked against typical use cases to avoid setting a limit that's too low or unnecessarily high, potentially leading to failed transactions or wasted gas.- 20-21: Constants
MAX_CLAIM_FEE_FRACTION
andFEE_PRECISION
are well-defined. It's good practice to define such constants for clarity and maintainability. Ensure the maximum claim fee fraction of 1% is appropriate for the system's economic model.- 25-28: The introduction of internal variables for claim fee fraction and gas limits is a positive change for flexibility and configurability. Ensure that access to these variables is properly restricted and validated where applicable.
- 81-85: The validation to ensure
claimFeeFraction
does not exceedMAX_CLAIM_FEE_FRACTION
is crucial for maintaining system integrity. This check prevents setting an excessively high fee fraction. Good implementation.- 97-100: Configurability of the
verifyEntry
function's gas limit per chain is a significant enhancement for flexibility. Ensure that there's a mechanism to prevent setting excessively low gas limits that could cause transactions to fail.- 105-118: The
claimFees
function's implementation, including the calculation ofclaimFee
and transferring fees to both thefeeCollector
and the caller, is well thought out. Ensure that the contract has a mechanism to receive and hold ETH for this functionality to work as expected.- 129-132: Exposing the claim fee fraction through a public getter is a good practice for transparency. This allows external parties to easily retrieve the current fee fraction.
- 145-147: The calculation of the claim fee amount using the contract's balance and the claim fee fraction is correct. Ensure that rounding errors are considered and have a negligible impact on the system's economics.
- 155-159: The fallback to
DEFAULT_VERIFY_GAS_LIMIT
when a specific chain's gas limit is not set is a sensible default behavior. This ensures that the system remains operational even if specific configurations are missing.- 188-188: The
_getModuleFee
function's implementation for estimating transaction costs on remote chains is a complex but necessary feature. Ensure that the gas oracle and calldata size calculations are accurate to prevent overestimating or underestimating fees.
Description
verifyEntry()
is not configurable, with a default value of 100k gas units.SynapseModule
claimFees()
to transfer the accumulated fees tofeeCollector
(assuming it's been set)claimFees()
function to incentivize claiming by the third parties.Summary by CodeRabbit
SynapseModule
contract for improved management of verifiers and fees.decodeEntry
function for efficiency.