-
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
FbV2 sender nonces [SLT-183] #3214
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -28,9 +28,8 @@ | |||||
mapping(bytes32 => BridgeTxDetails) public bridgeTxDetails; | ||||||
/// @notice Relay details on destination chain | ||||||
mapping(bytes32 => BridgeRelay) public bridgeRelayDetails; | ||||||
|
||||||
/// @dev to prevent replays | ||||||
uint256 public nonce; | ||||||
/// @notice Unique bridge nonces tracked per originSender | ||||||
mapping(address => uint256) public senderNonces; | ||||||
|
||||||
// @dev the block the contract was deployed at | ||||||
uint256 public immutable deployBlock; | ||||||
|
@@ -113,6 +112,12 @@ | |||||
return _timeSince(bridgeTxDetails[transactionId].proofBlockTimestamp) > DISPUTE_PERIOD; | ||||||
} | ||||||
|
||||||
/// @notice This function is deprecated and should not be used. | ||||||
/// @dev Replaced by senderNonces | ||||||
function nonce() external pure returns (uint256) { | ||||||
return 0; | ||||||
} | ||||||
|
||||||
/// @inheritdoc IFastBridge | ||||||
function getBridgeTransaction(bytes memory request) external pure returns (BridgeTransaction memory) { | ||||||
// Note: when passing V2 request, this will decode the V1 fields correctly since the new fields were | ||||||
|
@@ -158,7 +163,7 @@ | |||||
originFeeAmount: originFeeAmount, | ||||||
sendChainGas: params.sendChainGas, | ||||||
deadline: params.deadline, | ||||||
nonce: nonce++, // increment nonce on every bridge | ||||||
nonce: senderNonces[params.sender]++, // increment nonce on every bridge | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential off-by-one error due to postfix increment operator The use of the postfix increment operator Suggested change: - nonce: senderNonces[params.sender]++, // increment nonce on every bridge
+ nonce: ++senderNonces[params.sender], // increment nonce on every bridge 📝 Committable suggestion
Suggested change
|
||||||
exclusivityRelayer: paramsV2.quoteRelayer, | ||||||
// We checked exclusivityEndTime to be in range (0 .. params.deadline] above, so can safely cast | ||||||
exclusivityEndTime: uint256(exclusivityEndTime) | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,6 +95,11 @@ abstract contract FastBridgeV2SrcBaseTest is FastBridgeV2Test { | |
fastBridge.refund(abi.encode(bridgeTx)); | ||
} | ||
|
||
function test_nonce() public view { | ||
// deprecated. should always return zero in FbV2. | ||
assertEq(fastBridge.nonce(), 0); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Update the The
🔗 Analysis chainClarify the purpose of the The newly added
Consider the following actions:
To better understand the context, let's check for other nonce-related implementations: This will help us verify if the nonce implementation has been updated elsewhere in the contract. 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Search for nonce-related implementations in the FastBridgeV2 contract
rg --type solidity -i "nonce" packages/contracts-rfq/src/FastBridgeV2.sol
Length of output: 106 Script: #!/bin/bash
# Search for nonce-related implementations in the FastBridgeV2 contract without specifying file type
rg -i "nonce" packages/contracts-rfq/src/FastBridgeV2.sol
Length of output: 141 Script: #!/bin/bash
# Search for FastBridgeV2.sol in the entire repository
fd "FastBridgeV2\.sol" . -t f
Length of output: 147 Script: #!/bin/bash
# Search for nonce-related implementations in FastBridgeV2.sol
rg -i "nonce" packages/contracts-rfq/contracts/FastBridgeV2.sol
Length of output: 360 |
||
|
||
function assertEq(FastBridgeV2.BridgeStatus a, FastBridgeV2.BridgeStatus b) public pure { | ||
assertEq(uint8(a), uint8(b)); | ||
} | ||
|
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.
Consider modifying or removing the deprecated
nonce()
functionThe
nonce()
function is deprecated and currently returns0
, which might lead to confusion or unintended behavior if external callers rely on its previous functionality. Consider either removing the function or updating it to revert with a clear deprecation message to prevent misuse.Suggested change:
📝 Committable suggestion