-
Notifications
You must be signed in to change notification settings - Fork 32
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
Fix: chi-01 (agent root passing) #1526
Conversation
WalkthroughThe primary change revolves around the Changes
Validation with GitHub issue(Beta)Assessment of the PR changes against GitHub Issue
TipsChat with CodeRabbit Bot (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1526 +/- ##
===================================================
- Coverage 50.81212% 50.81006% -0.00207%
===================================================
Files 357 357
Lines 23888 23887 -1
Branches 280 279 -1
===================================================
- Hits 12138 12137 -1
Misses 10596 10596
Partials 1154 1154
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 UI
Files selected for processing (5)
- packages/contracts-core/contracts/Destination.sol (3 hunks)
- packages/contracts-core/contracts/interfaces/InterfaceDestination.sol (1 hunks)
- packages/contracts-core/test/mocks/DestinationMock.t.sol (1 hunks)
- packages/contracts-core/test/suite/Destination.t.sol (10 hunks)
- packages/contracts-core/test/suite/DestinationSynapse.t.sol (1 hunks)
Additional comments: 16
packages/contracts-core/contracts/interfaces/InterfaceDestination.sol (1)
- 7-12: The function signature and documentation have been updated to reflect the new behavior. Ensure that all calls to this function throughout the codebase have been updated to handle the new return value.
packages/contracts-core/test/mocks/DestinationMock.t.sol (1)
- 13-13: The function signature has been updated to reflect the changes in the return values. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.
- function passAgentRoot() external returns (bool rootPassed, bool rootPending) {} + function passAgentRoot() external returns (bool rootPending) {}packages/contracts-core/test/suite/DestinationSynapse.t.sol (1)
- 33-38: The test
test_setupCorrectly
has been updated to reflect the changes in thepassAgentRoot
function. The function now returns a boolean indicating whether there is a pending agent root. The assertionassertFalse(rootPending)
checks that there is no pending agent root at the time of setup.packages/contracts-core/contracts/Destination.sol (3)
98-103: The check for passing the current agent merkle root before accepting an attestation has been removed. This change simplifies the logic and reduces gas costs, but it also means that the function will now accept attestations even if the current agent merkle root has not been passed. Ensure that this change does not introduce any security vulnerabilities or inconsistencies in the contract's state.
108-114: The return values of the
passAgentRoot()
function have been modified to only return a boolean indicating whether there is a pending root or not. This change simplifies the function's interface and makes it easier to use, but it also removes the ability to check whether the current agent merkle root was passed to the LightManager. Ensure that this change does not break any code that relies on the old return values.- _saveAttestation(att, notaryIndex, sigIndex); - _storedAttestations.push(StoredAttData({agentRoot: agentRoot, dataHash: att.dataHash()})); - // Save Agent Root if required, and update the Destination's Status - bool rootPending = passAgentRoot(); - destStatus = _saveAgentRoot(rootPending, agentRoot, notaryIndex); - _saveGasData(snapGas, notaryIndex); - return true; + _saveAttestation(att, notaryIndex, sigIndex); + _storedAttestations.push(StoredAttData({agentRoot: agentRoot, dataHash: att.dataHash()})); + // Save Agent Root if required, and update the Destination's Status + bool rootPending = passAgentRoot(); + destStatus = _saveAgentRoot(rootPending, agentRoot, notaryIndex); + _saveGasData(snapGas, notaryIndex); + return true;
- 117-150: The logic in the
passAgentRoot()
function has been updated to reflect the changes in its return values. The function now only checks whether there is a pending agent root, and does not check whether the current agent merkle root was passed to the LightManager. This change simplifies the function's logic and reduces gas costs, but it also removes the ability to check whether the current agent merkle root was passed to the LightManager. Ensure that this change does not introduce any security vulnerabilities or inconsistencies in the contract's state.- function passAgentRoot() public returns (bool rootPending) { - // Agent root is not passed on Synapse Chain, as it could be accessed via BondingManager - if (localDomain == synapseDomain) return false; - bytes32 oldRoot = IAgentManager(agentManager).agentRoot(); - bytes32 newRoot = _nextAgentRoot; - // Check if agent root differs from the current one in LightManager - if (oldRoot == newRoot) return false; - DestinationStatus memory status = destStatus; - // Invariant: Notary who supplied `newRoot` was registered as active against `oldRoot` - // So we just need to check the Dispute status of the Notary - if (_notaryDisputeExists(status.notaryIndex)) { - // Remove the pending agent merkle root, as its signer is in dispute - _nextAgentRoot = oldRoot; - return false; - } - // If Notary recently won a Dispute, we can optimistically assume that their passed root is valid. - // However, we need to wait until the Dispute timeout is over, before passing the new root to LightManager. - if (_notaryDisputeTimeout(status.notaryIndex)) { - // We didn't pass anything, but there is a pending root - return true; - } - // Check if agent root optimistic period is over - if (status.agentRootTime + AGENT_ROOT_OPTIMISTIC_PERIOD > block.timestamp) { - // We didn't pass anything, but there is a pending root - return true; - } - // `newRoot` signer was not disputed, and the root optimistic period is over. - // Finally, pass the Agent Merkle Root to LightManager - InterfaceLightManager(address(agentManager)).setAgentRoot(newRoot); - return false; - } + function passAgentRoot() public returns (bool rootPending) { + // Agent root is not passed on Synapse Chain, as it could be accessed via BondingManager + if (localDomain == synapseDomain) return false; + bytes32 oldRoot = IAgentManager(agentManager).agentRoot(); + bytes32 newRoot = _nextAgentRoot; + // Check if agent root differs from the current one in LightManager + if (oldRoot == newRoot) return false; + DestinationStatus memory status = destStatus; + // Invariant: Notary who supplied `newRoot` was registered as active against `oldRoot` + // So we just need to check the Dispute status of the Notary + if (_notaryDisputeExists(status.notaryIndex)) { + // Remove the pending agent merkle </blockquote></details> <details><summary>packages/contracts-core/test/suite/Destination.t.sol (10)</summary><blockquote> * 44-45: The return value of `passAgentRoot` is now directly assigned to `bool rootPending`. This change is consistent with the PR summary. * 264-294: The function `test_acceptAttestation_passesAgentRoot` has been significantly updated. It now includes logic to form and submit a second attestation, checks for updated agent root and index values in the `destStatus` function, and checks the pending agent root in the `nextAgentRoot` function. Ensure that these changes are consistent with the intended behavior. * 332-338: The return value of `passAgentRoot` is now directly assigned to `bool rootPending`. This change is consistent with the PR summary. * 341-347: The return value of `passAgentRoot` is now directly assigned to `bool rootPending`. This change is consistent with the PR summary. * 375-382: The return value of `passAgentRoot` is now directly assigned to `bool rootPending`. This change is consistent with the PR summary. * 387-394: The return value of `passAgentRoot` is now directly assigned to `bool rootPending`. This change is consistent with the PR summary. * 403-410: The return value of `passAgentRoot` is now directly assigned to `bool rootPending`. This change is consistent with the PR summary. * 419-426: The return value of `passAgentRoot` is now directly assigned to `bool rootPending`. This change is consistent with the PR summary. * 435-442: The return value of `passAgentRoot` is now directly assigned to `bool rootPending`. This change is consistent with the PR summary. * 450-457: The return value of `passAgentRoot` is now directly assigned to `bool rootPending`. This change is consistent with the PR summary. </blockquote></details></blockquote></details> </details>
Description
Replaces #1331. The merge conflicts there were a bit annoying to solve, so given the low diff size decided to redo the PR.
List of old commits and their new counterparts
Summary by CodeRabbit
Refactor:
passAgentRoot
function in theDestination
contract and its interfaceInterfaceDestination
. It now only returns a boolean indicating if there is a pending agent root, enhancing the function's clarity and focus.Tests:
DestinationTest
andDestinationSynapseTest
contracts to reflect the changes in thepassAgentRoot
function. This ensures our tests remain accurate and reliable.test_acceptAttestation_passesAgentRoot
function in theDestinationTest
contract to include logic for forming and submitting a second attestation, improving the test's comprehensiveness.