-
Notifications
You must be signed in to change notification settings - Fork 5
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
refactor(storage): common inbound nonce #40
Conversation
WalkthroughThe changes involve updating nonce handling mechanisms across various contracts, particularly by replacing the Changes
Sequence Diagram(s)sequenceDiagram
participant Sender
participant GatewayStorage
participant BootstrapLzReceiver
participant ClientGatewayLzReceiver
Sender ->> BootstrapLzReceiver: Send message with nonce
BootstrapLzReceiver ->> GatewayStorage: Verify and update nonce
GatewayStorage ->> GatewayStorage: Validate nonce
GatewayStorage ->> BootstrapLzReceiver: Acknowledge update
BootstrapLzReceiver ->> Sender: Confirmation
Sender ->> ClientGatewayLzReceiver: Send message with nonce
ClientGatewayLzReceiver ->> GatewayStorage: Verify and update nonce
GatewayStorage ->> GatewayStorage: Validate nonce
GatewayStorage ->> ClientGatewayLzReceiver: Acknowledge update
ClientGatewayLzReceiver ->> Sender: Confirmation
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (2)
docs/architecture.svg
is excluded by!**/*.svg
docs/lst-flow.svg
is excluded by!**/*.svg
Files selected for processing (8)
- src/core/BootstrapLzReceiver.sol (2 hunks)
- src/core/ClientGatewayLzReceiver.sol (2 hunks)
- src/core/ExocoreGateway.sol (2 hunks)
- src/storage/BootstrapStorage.sol (1 hunks)
- src/storage/ClientChainGatewayStorage.sol (1 hunks)
- src/storage/ExocoreGatewayStorage.sol (1 hunks)
- src/storage/GatewayStorage.sol (2 hunks)
- test/mocks/ExocoreGatewayMock.sol (2 hunks)
Files skipped from review due to trivial changes (2)
- src/storage/BootstrapStorage.sol
- src/storage/ClientChainGatewayStorage.sol
Additional comments not posted (6)
src/storage/GatewayStorage.sol (2)
20-21
: Introduction of public mappinginboundNonce
.This mapping tracks nonces for specific sources, which is crucial for ensuring the integrity and non-repudiation of messages across different chains. This change aligns with the PR's goal to centralize nonce management.
30-36
: Implementation of_verifyAndUpdateNonce
function.This function correctly implements nonce verification and updates the nonce if it matches the expected value. The use of
revert
with a custom error message is a best practice for handling unexpected nonces, providing clear feedback on the error.src/core/BootstrapLzReceiver.sol (1)
21-21
: Integration of_verifyAndUpdateNonce
in_lzReceive
.The integration of
_verifyAndUpdateNonce
within_lzReceive
ensures that every incoming message is verified for nonce correctness before processing. This is a critical security feature that prevents replay attacks.src/core/ClientGatewayLzReceiver.sol (1)
29-29
: Integration of_verifyAndUpdateNonce
in_lzReceive
.The use of
_verifyAndUpdateNonce
here ensures that each message processed by the client gateway has its nonce verified, which is essential for maintaining the integrity and sequence of cross-chain messages.
[APROVED]test/mocks/ExocoreGatewayMock.sol (1)
170-170
: Integration of_verifyAndUpdateNonce
in_lzReceive
for mock testing.Correctly integrating
_verifyAndUpdateNonce
in the mock contract's_lzReceive
function ensures that the nonce verification logic is consistently tested across different implementations, maintaining the integrity of the testing process.src/core/ExocoreGateway.sol (1)
149-149
: Refactored Nonce Verification and Update ApprovedThe replacement of
_consumeInboundNonce
with_verifyAndUpdateNonce
aligns with the PR's objectives to centralize and improve nonce management. Ensure that the new function_verifyAndUpdateNonce
is thoroughly tested and audited to prevent security vulnerabilities such as replay attacks.Verification successful
Refactored Nonce Verification and Update Approved
The replacement of
_consumeInboundNonce
with_verifyAndUpdateNonce
aligns with the PR's objectives to centralize and improve nonce management. The implementation of_verifyAndUpdateNonce
insrc/storage/GatewayStorage.sol
correctly verifies and updates the nonce, ensuring it prevents replay attacks. Its usage in other files (src/core/BootstrapLzReceiver.sol
,src/core/ClientGatewayLzReceiver.sol
,src/core/ExocoreGateway.sol
, andtest/mocks/ExocoreGatewayMock.sol
) is consistent and appropriate.
- Implementation Location:
src/storage/GatewayStorage.sol
- Usage Locations:
src/core/BootstrapLzReceiver.sol
src/core/ClientGatewayLzReceiver.sol
src/core/ExocoreGateway.sol
test/mocks/ExocoreGatewayMock.sol
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the implementation and usage of `_verifyAndUpdateNonce`. # Test: Search for the function implementation and usage. Expect: Secure and correct implementation. rg --type solidity $'_verifyAndUpdateNonce'Length of output: 75
Script:
#!/bin/bash # Description: Verify the implementation and usage of `_verifyAndUpdateNonce`. # Step 1: Find all Solidity files in the repository. SOL_FILES=$(fd --extension sol) # Step 2: Search for the `_verifyAndUpdateNonce` function definition and usage within these files. for file in $SOL_FILES; do echo "Searching in $file" rg '_verifyAndUpdateNonce' "$file" doneLength of output: 18923
Script:
#!/bin/bash # Description: Extract the implementation of `_verifyAndUpdateNonce` and review its usage. # Step 1: Extract the implementation of `_verifyAndUpdateNonce` from `src/storage/GatewayStorage.sol`. echo "Implementation of _verifyAndUpdateNonce in src/storage/GatewayStorage.sol:" rg --context 10 'function _verifyAndUpdateNonce' src/storage/GatewayStorage.sol # Step 2: Review the usage of `_verifyAndUpdateNonce` in other files. echo "Usage of _verifyAndUpdateNonce in other files:" rg '_verifyAndUpdateNonce' src/core/BootstrapLzReceiver.sol src/core/ClientGatewayLzReceiver.sol src/core/ExocoreGateway.sol test/mocks/ExocoreGatewayMock.solLength of output: 1694
while the overrides still need to be present to inform the compiler about the base class whose function should be called, the implementation can still be made common in the base class.
The last commit a40ff77 moves the implementation of |
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.
LGTM. I add a simple comment explaining my thought about outboundNonce
This reverts commit a40ff77.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- src/storage/ClientChainGatewayStorage.sol (2 hunks)
Files skipped from review as they are similar to previous changes (1)
- src/storage/ClientChainGatewayStorage.sol
The mapping of
eid
->sender
->nonce
was stored previously in allBootstrapStorage
andExocoreGatewayStorage
. This change moves that mapping into the parentGatewayStorage
contract, as well as its associated validation functionality.The PR removes the TSS-related nonce that is no longer used.
Summary by CodeRabbit
Bug Fixes
Documentation