From d35ecbc675849faeb70bc06d6d80abb64507b9f4 Mon Sep 17 00:00:00 2001 From: parodime Date: Tue, 1 Oct 2024 15:38:50 -0400 Subject: [PATCH 1/2] senderNonce [SLT-183] --- packages/contracts-rfq/contracts/FastBridgeV2.sol | 13 +++++++++---- packages/contracts-rfq/test/FastBridgeV2.Src.t.sol | 5 ++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/contracts-rfq/contracts/FastBridgeV2.sol b/packages/contracts-rfq/contracts/FastBridgeV2.sol index b6d49ac9dd..d931baa348 100644 --- a/packages/contracts-rfq/contracts/FastBridgeV2.sol +++ b/packages/contracts-rfq/contracts/FastBridgeV2.sol @@ -28,9 +28,8 @@ contract FastBridgeV2 is Admin, IFastBridgeV2, IFastBridgeV2Errors { 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 => uint96) public senderNonces; // @dev the block the contract was deployed at uint256 public immutable deployBlock; @@ -71,7 +70,7 @@ contract FastBridgeV2 is Admin, IFastBridgeV2, IFastBridgeV2Errors { originFeeAmount: originFeeAmount, sendChainGas: params.sendChainGas, deadline: params.deadline, - nonce: nonce++ // increment nonce on every bridge + nonce: senderNonces[params.sender]++ // increment nonce on every bridge }) ); bytes32 transactionId = keccak256(request); @@ -156,6 +155,12 @@ contract FastBridgeV2 is Admin, IFastBridgeV2, IFastBridgeV2Errors { 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 IFastBridgeV2 function relay(bytes memory request, address relayer) public payable { if (relayer == address(0)) revert ZeroAddress(); diff --git a/packages/contracts-rfq/test/FastBridgeV2.Src.t.sol b/packages/contracts-rfq/test/FastBridgeV2.Src.t.sol index e0eb6d6ca3..5632fb7fe3 100644 --- a/packages/contracts-rfq/test/FastBridgeV2.Src.t.sol +++ b/packages/contracts-rfq/test/FastBridgeV2.Src.t.sol @@ -137,8 +137,9 @@ contract FastBridgeV2SrcTest is FastBridgeV2SrcBaseTest { } function test_bridge_userSpecificNonce() public { - vm.skip(true); // TODO: unskip when implemented bridge({caller: userA, msgValue: 0, params: tokenParams}); + assertEq(fastBridge.senderNonces(userA), 1); + assertEq(fastBridge.senderNonces(userB), 0); // UserB nonce is 0 ethTx.nonce = 0; ethParams.sender = userB; @@ -146,6 +147,8 @@ contract FastBridgeV2SrcTest is FastBridgeV2SrcBaseTest { bytes32 txId = getTxId(ethTx); expectBridgeRequested(ethTx, txId); bridge({caller: userB, msgValue: ethParams.originAmount, params: ethParams}); + assertEq(fastBridge.senderNonces(userA), 1); + assertEq(fastBridge.senderNonces(userB), 1); assertEq(fastBridge.bridgeStatuses(txId), IFastBridgeV2.BridgeStatus.REQUESTED); checkEthBalancesAfterBridge(userB); } From 66c3611dced9db1bf3d3a0abfa87b3bab78c7c79 Mon Sep 17 00:00:00 2001 From: parodime Date: Tue, 1 Oct 2024 15:43:04 -0400 Subject: [PATCH 2/2] uint96 -> uint256 --- packages/contracts-rfq/contracts/FastBridgeV2.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/contracts-rfq/contracts/FastBridgeV2.sol b/packages/contracts-rfq/contracts/FastBridgeV2.sol index d931baa348..7ddc807761 100644 --- a/packages/contracts-rfq/contracts/FastBridgeV2.sol +++ b/packages/contracts-rfq/contracts/FastBridgeV2.sol @@ -29,7 +29,7 @@ contract FastBridgeV2 is Admin, IFastBridgeV2, IFastBridgeV2Errors { /// @notice Relay details on destination chain mapping(bytes32 => BridgeRelay) public bridgeRelayDetails; /// @notice Unique bridge nonces tracked per originSender - mapping(address => uint96) public senderNonces; + mapping(address => uint256) public senderNonces; // @dev the block the contract was deployed at uint256 public immutable deployBlock;