From b22dda1ee32bcb5684bf1154db3f273bdcc61d3f Mon Sep 17 00:00:00 2001 From: parodime Date: Fri, 25 Oct 2024 12:29:53 -0400 Subject: [PATCH 1/6] default exclusivityEndtime to zero when offset is zero --- packages/contracts-rfq/contracts/FastBridgeV2.sol | 6 ++++-- .../test/FastBridgeV2.GasBench.Src.t.sol | 12 ++++++------ .../test/FastBridgeV2.Src.Exclusivity.Negative.t.sol | 6 ++---- packages/contracts-rfq/test/FastBridgeV2.t.sol | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/contracts-rfq/contracts/FastBridgeV2.sol b/packages/contracts-rfq/contracts/FastBridgeV2.sol index 9f54c87f42..42eff2db75 100644 --- a/packages/contracts-rfq/contracts/FastBridgeV2.sol +++ b/packages/contracts-rfq/contracts/FastBridgeV2.sol @@ -177,7 +177,9 @@ contract FastBridgeV2 is Admin, IFastBridgeV2, IFastBridgeV2Errors { /// @inheritdoc IFastBridgeV2 function bridge(BridgeParams memory params, BridgeParamsV2 memory paramsV2) public payable { - int256 exclusivityEndTime = int256(block.timestamp) + paramsV2.quoteExclusivitySeconds; + int256 exclusivityEndTime = paramsV2.quoteExclusivitySeconds != 0 + ? int256(block.timestamp) + paramsV2.quoteExclusivitySeconds + : int256(0); _validateBridgeParams(params, paramsV2, exclusivityEndTime); // transfer tokens to bridge contract @@ -444,7 +446,7 @@ contract FastBridgeV2 is Admin, IFastBridgeV2, IFastBridgeV2Errors { revert NativeTokenCallValueNotSupported(); } // exclusivityEndTime must be in range (0 .. params.deadline] - if (exclusivityEndTime <= 0 || exclusivityEndTime > int256(params.deadline)) { + if (exclusivityEndTime < 0 || exclusivityEndTime > int256(params.deadline)) { revert ExclusivityParamsIncorrect(); } } diff --git a/packages/contracts-rfq/test/FastBridgeV2.GasBench.Src.t.sol b/packages/contracts-rfq/test/FastBridgeV2.GasBench.Src.t.sol index 940eae3aa1..2d6f93c42e 100644 --- a/packages/contracts-rfq/test/FastBridgeV2.GasBench.Src.t.sol +++ b/packages/contracts-rfq/test/FastBridgeV2.GasBench.Src.t.sol @@ -50,13 +50,13 @@ contract FastBridgeV2GasBenchmarkSrcTest is FastBridgeV2SrcBaseTest { function createFixturesV2() public virtual override { super.createFixturesV2(); - bridgedTokenTx.exclusivityEndTime = block.timestamp; - provenTokenTx.exclusivityEndTime = block.timestamp; - bridgedEthTx.exclusivityEndTime = block.timestamp; - provenEthTx.exclusivityEndTime = block.timestamp; + bridgedTokenTx.exclusivityEndTime = 0; + provenTokenTx.exclusivityEndTime = 0; + bridgedEthTx.exclusivityEndTime = 0; + provenEthTx.exclusivityEndTime = 0; // Actual tx will be submitted one block later - tokenTx.exclusivityEndTime = block.timestamp + BLOCK_TIME; - ethTx.exclusivityEndTime = block.timestamp + BLOCK_TIME; + tokenTx.exclusivityEndTime = 0; + ethTx.exclusivityEndTime = 0; } function mintTokens() public virtual override { diff --git a/packages/contracts-rfq/test/FastBridgeV2.Src.Exclusivity.Negative.t.sol b/packages/contracts-rfq/test/FastBridgeV2.Src.Exclusivity.Negative.t.sol index 4eeacb2f88..05db1713e3 100644 --- a/packages/contracts-rfq/test/FastBridgeV2.Src.Exclusivity.Negative.t.sol +++ b/packages/contracts-rfq/test/FastBridgeV2.Src.Exclusivity.Negative.t.sol @@ -23,9 +23,8 @@ contract FastBridgeV2SrcExclusivityNegativeTest is FastBridgeV2SrcTest { bridge(caller, msgValue, params, paramsV2); } - function test_bridge_revert_exclusivityEndTimeZero() public { + function test_bridge_exclusivityEndTimeZero() public { tokenParamsV2.quoteExclusivitySeconds = -int256(block.timestamp); - vm.expectRevert(ExclusivityParamsIncorrect.selector); bridge({caller: userA, msgValue: 0, params: tokenParams, paramsV2: tokenParamsV2}); } @@ -35,9 +34,8 @@ contract FastBridgeV2SrcExclusivityNegativeTest is FastBridgeV2SrcTest { bridge({caller: userA, msgValue: 0, params: tokenParams, paramsV2: tokenParamsV2}); } - function test_bridge_eth_revert_exclusivityEndTimeZero() public { + function test_bridge_eth_exclusivityEndTimeZero() public { ethParamsV2.quoteExclusivitySeconds = -int256(block.timestamp); - vm.expectRevert(ExclusivityParamsIncorrect.selector); bridge({caller: userA, msgValue: ethParams.originAmount, params: ethParams, paramsV2: ethParamsV2}); } diff --git a/packages/contracts-rfq/test/FastBridgeV2.t.sol b/packages/contracts-rfq/test/FastBridgeV2.t.sol index 7c3581e6ee..99a73655ce 100644 --- a/packages/contracts-rfq/test/FastBridgeV2.t.sol +++ b/packages/contracts-rfq/test/FastBridgeV2.t.sol @@ -173,9 +173,9 @@ abstract contract FastBridgeV2Test is Test, IFastBridgeV2Errors { }); tokenTx.exclusivityRelayer = address(0); - tokenTx.exclusivityEndTime = block.timestamp; + tokenTx.exclusivityEndTime = 0; ethTx.exclusivityRelayer = address(0); - ethTx.exclusivityEndTime = block.timestamp; + ethTx.exclusivityEndTime = 0; } function setStorageBridgeTxV2( From 10b94b03936ab369c0150bd821e608c8f21a926d Mon Sep 17 00:00:00 2001 From: parodime Date: Fri, 25 Oct 2024 12:34:51 -0400 Subject: [PATCH 2/6] set excl endtime via quoteRelayer 0, not offset. --- 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 42eff2db75..0188501228 100644 --- a/packages/contracts-rfq/contracts/FastBridgeV2.sol +++ b/packages/contracts-rfq/contracts/FastBridgeV2.sol @@ -177,7 +177,7 @@ contract FastBridgeV2 is Admin, IFastBridgeV2, IFastBridgeV2Errors { /// @inheritdoc IFastBridgeV2 function bridge(BridgeParams memory params, BridgeParamsV2 memory paramsV2) public payable { - int256 exclusivityEndTime = paramsV2.quoteExclusivitySeconds != 0 + int256 exclusivityEndTime = paramsV2.quoteRelayer != address(0) ? int256(block.timestamp) + paramsV2.quoteExclusivitySeconds : int256(0); _validateBridgeParams(params, paramsV2, exclusivityEndTime); From 48954d9f4a6cacf7ac9187e078433440777d8f09 Mon Sep 17 00:00:00 2001 From: parodime Date: Fri, 25 Oct 2024 12:37:03 -0400 Subject: [PATCH 3/6] lint impv --- packages/contracts-rfq/contracts/FastBridgeV2.sol | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/contracts-rfq/contracts/FastBridgeV2.sol b/packages/contracts-rfq/contracts/FastBridgeV2.sol index 0188501228..060ad2d26d 100644 --- a/packages/contracts-rfq/contracts/FastBridgeV2.sol +++ b/packages/contracts-rfq/contracts/FastBridgeV2.sol @@ -178,6 +178,7 @@ contract FastBridgeV2 is Admin, IFastBridgeV2, IFastBridgeV2Errors { /// @inheritdoc IFastBridgeV2 function bridge(BridgeParams memory params, BridgeParamsV2 memory paramsV2) public payable { int256 exclusivityEndTime = paramsV2.quoteRelayer != address(0) + // prettier-ignore ? int256(block.timestamp) + paramsV2.quoteExclusivitySeconds : int256(0); _validateBridgeParams(params, paramsV2, exclusivityEndTime); From 4808690e183da037365ca99169b22bd9a7494363 Mon Sep 17 00:00:00 2001 From: parodime Date: Sun, 27 Oct 2024 05:28:37 -0400 Subject: [PATCH 4/6] excl end time logic refactor. comment & test tweaks. --- packages/contracts-rfq/contracts/FastBridgeV2.sol | 10 ++++++---- .../test/FastBridgeV2.GasBench.Src.t.sol | 11 ----------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/packages/contracts-rfq/contracts/FastBridgeV2.sol b/packages/contracts-rfq/contracts/FastBridgeV2.sol index 060ad2d26d..495fce0d54 100644 --- a/packages/contracts-rfq/contracts/FastBridgeV2.sol +++ b/packages/contracts-rfq/contracts/FastBridgeV2.sol @@ -177,10 +177,12 @@ contract FastBridgeV2 is Admin, IFastBridgeV2, IFastBridgeV2Errors { /// @inheritdoc IFastBridgeV2 function bridge(BridgeParams memory params, BridgeParamsV2 memory paramsV2) public payable { - int256 exclusivityEndTime = paramsV2.quoteRelayer != address(0) - // prettier-ignore - ? int256(block.timestamp) + paramsV2.quoteExclusivitySeconds - : int256(0); + int256 exclusivityEndTime = 0; + // if relayer exclusivity is not intended for this bridge, set exclusivityEndTime to static zero + // otherwise, set exclusivity to expire at the current block ts offset by quoteExclusivitySeconds + if (paramsV2.quoteRelayer != address(0)) { + exclusivityEndTime = int256(block.timestamp) + paramsV2.quoteExclusivitySeconds; + } _validateBridgeParams(params, paramsV2, exclusivityEndTime); // transfer tokens to bridge contract diff --git a/packages/contracts-rfq/test/FastBridgeV2.GasBench.Src.t.sol b/packages/contracts-rfq/test/FastBridgeV2.GasBench.Src.t.sol index 2d6f93c42e..0ffa7d8d5e 100644 --- a/packages/contracts-rfq/test/FastBridgeV2.GasBench.Src.t.sol +++ b/packages/contracts-rfq/test/FastBridgeV2.GasBench.Src.t.sol @@ -48,17 +48,6 @@ contract FastBridgeV2GasBenchmarkSrcTest is FastBridgeV2SrcBaseTest { ethTx.nonce = 5; } - function createFixturesV2() public virtual override { - super.createFixturesV2(); - bridgedTokenTx.exclusivityEndTime = 0; - provenTokenTx.exclusivityEndTime = 0; - bridgedEthTx.exclusivityEndTime = 0; - provenEthTx.exclusivityEndTime = 0; - // Actual tx will be submitted one block later - tokenTx.exclusivityEndTime = 0; - ethTx.exclusivityEndTime = 0; - } - function mintTokens() public virtual override { super.mintTokens(); srcToken.mint(relayerA, INITIAL_RELAYER_BALANCE); From 4316e46b29b20c5033b37e0103744f07d065f1dc Mon Sep 17 00:00:00 2001 From: parodime Date: Mon, 28 Oct 2024 09:16:54 -0400 Subject: [PATCH 5/6] comment typo --- packages/contracts-rfq/contracts/FastBridgeV2.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/contracts-rfq/contracts/FastBridgeV2.sol b/packages/contracts-rfq/contracts/FastBridgeV2.sol index 495fce0d54..113398f4b6 100644 --- a/packages/contracts-rfq/contracts/FastBridgeV2.sol +++ b/packages/contracts-rfq/contracts/FastBridgeV2.sol @@ -211,7 +211,7 @@ contract FastBridgeV2 is Admin, IFastBridgeV2, IFastBridgeV2Errors { deadline: params.deadline, nonce: senderNonces[params.sender]++, // increment nonce on every bridge exclusivityRelayer: paramsV2.quoteRelayer, - // We checked exclusivityEndTime to be in range (0 .. params.deadline] above, so can safely cast + // We checked exclusivityEndTime to be in range (0 .. params.deadline) above, so can safely cast exclusivityEndTime: uint256(exclusivityEndTime), callValue: paramsV2.callValue, callParams: paramsV2.callParams @@ -448,7 +448,7 @@ contract FastBridgeV2 is Admin, IFastBridgeV2, IFastBridgeV2Errors { if (paramsV2.callValue != 0 && params.destToken == UniversalTokenLib.ETH_ADDRESS) { revert NativeTokenCallValueNotSupported(); } - // exclusivityEndTime must be in range (0 .. params.deadline] + // exclusivityEndTime must be in range (0 .. params.deadline) if (exclusivityEndTime < 0 || exclusivityEndTime > int256(params.deadline)) { revert ExclusivityParamsIncorrect(); } From 4d77ec2f865fd6e266ae898c0740c645eb56fe0a Mon Sep 17 00:00:00 2001 From: ChiTimesChi <88190723+ChiTimesChi@users.noreply.github.com> Date: Mon, 28 Oct 2024 15:04:45 +0000 Subject: [PATCH 6/6] docs: use `[]` for inclusive ranges --- packages/contracts-rfq/contracts/FastBridgeV2.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/contracts-rfq/contracts/FastBridgeV2.sol b/packages/contracts-rfq/contracts/FastBridgeV2.sol index 113398f4b6..9666ba35a3 100644 --- a/packages/contracts-rfq/contracts/FastBridgeV2.sol +++ b/packages/contracts-rfq/contracts/FastBridgeV2.sol @@ -211,7 +211,7 @@ contract FastBridgeV2 is Admin, IFastBridgeV2, IFastBridgeV2Errors { deadline: params.deadline, nonce: senderNonces[params.sender]++, // increment nonce on every bridge exclusivityRelayer: paramsV2.quoteRelayer, - // We checked exclusivityEndTime to be in range (0 .. params.deadline) above, so can safely cast + // We checked exclusivityEndTime to be in range [0 .. params.deadline] above, so can safely cast exclusivityEndTime: uint256(exclusivityEndTime), callValue: paramsV2.callValue, callParams: paramsV2.callParams @@ -448,7 +448,7 @@ contract FastBridgeV2 is Admin, IFastBridgeV2, IFastBridgeV2Errors { if (paramsV2.callValue != 0 && params.destToken == UniversalTokenLib.ETH_ADDRESS) { revert NativeTokenCallValueNotSupported(); } - // exclusivityEndTime must be in range (0 .. params.deadline) + // exclusivityEndTime must be in range [0 .. params.deadline] if (exclusivityEndTime < 0 || exclusivityEndTime > int256(params.deadline)) { revert ExclusivityParamsIncorrect(); }