From 268e6d3475a108d0dd822fe14a431b50da06483f Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 19 Oct 2023 20:35:44 -0700 Subject: [PATCH 1/5] removed the is-refund-worth-the-cost check to remove the unaligned incentive for searchers to overpay as little as possible thereby increasing odds of failure --- .../FastLaneAuctionHandler.sol | 32 +++++++------------ lib/openzeppelin-contracts | 2 +- lib/openzeppelin-contracts-upgradeable | 2 +- 3 files changed, 13 insertions(+), 23 deletions(-) diff --git a/contracts/auction-handler/FastLaneAuctionHandler.sol b/contracts/auction-handler/FastLaneAuctionHandler.sol index 88b74cb..cee8a7f 100644 --- a/contracts/auction-handler/FastLaneAuctionHandler.sol +++ b/contracts/auction-handler/FastLaneAuctionHandler.sol @@ -92,7 +92,6 @@ contract FastLaneAuctionHandler is FastLaneAuctionHandlerEvents { uint32 internal constant BLOCK_TIMELOCK = 6 days; uint256 internal constant MIN_GAS_SPENT_PGA = 100_000; - uint256 internal constant REFUND_GAS_SPENT = 2_500; // TODO: This is wrong - add in call cost & verify. /// @notice The scale for validator refund share uint256 internal constant VALIDATOR_REFUND_SCALE = 10_000; // 1 = 0.01% @@ -232,7 +231,6 @@ contract FastLaneAuctionHandler is FastLaneAuctionHandlerEvents { ) returns (uint256 bidAmount) { emit RelayFastBid(msg.sender, block.coinbase, true, bidAmount, searcherToAddress); } catch { - // TODO: Catch specific errors - remove custom errors first before coding. emit RelayFastBid(msg.sender, block.coinbase, false, 0, searcherToAddress); } } @@ -366,27 +364,19 @@ contract FastLaneAuctionHandler is FastLaneAuctionHandlerEvents { uint256 surplus = (address(this).balance - balanceBefore) - _bidAmount; if (surplus > 0) { - // Only refund the searcher if the refund value exceeds its gas cost - if (surplus > REFUND_GAS_SPENT * tx.gasprice) { - - // If value came from the EOA, refund to EOA - if (msg.value > _bidAmount) { - SafeTransferLib.safeTransferETH( - tx.origin, - surplus - ); - - // Otherwise refund the searcher contract - } else { - SafeTransferLib.safeTransferETH( - _searcherToAddress, - surplus - ); - } + // If value came from the EOA, refund to EOA + if (msg.value > _bidAmount) { + SafeTransferLib.safeTransferETH( + tx.origin, + surplus + ); - // If refunding is too expensive, add it to _bidAmount + // Otherwise refund the searcher contract } else { - _bidAmount += surplus; + SafeTransferLib.safeTransferETH( + _searcherToAddress, + surplus + ); } } diff --git a/lib/openzeppelin-contracts b/lib/openzeppelin-contracts index 0a25c19..3bd9ed3 160000 --- a/lib/openzeppelin-contracts +++ b/lib/openzeppelin-contracts @@ -1 +1 @@ -Subproject commit 0a25c1940ca220686588c4af3ec526f725fe2582 +Subproject commit 3bd9ed377e738a1cc66cca180a2a26426c63b8dc diff --git a/lib/openzeppelin-contracts-upgradeable b/lib/openzeppelin-contracts-upgradeable index 58fa0f8..b6becf8 160000 --- a/lib/openzeppelin-contracts-upgradeable +++ b/lib/openzeppelin-contracts-upgradeable @@ -1 +1 @@ -Subproject commit 58fa0f81c4036f1a3b616fdffad2fd27e5d5ce21 +Subproject commit b6becf82d734bc66fec9cf25a48d598356f3bf11 From 43175ac8852ad4f08dfd03e97dfd6d566209237d Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 28 Dec 2023 04:19:03 -0800 Subject: [PATCH 2/5] added a msg value refund when catching execution revert --- contracts/auction-handler/FastLaneAuctionHandler.sol | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/contracts/auction-handler/FastLaneAuctionHandler.sol b/contracts/auction-handler/FastLaneAuctionHandler.sol index cee8a7f..6ad0122 100644 --- a/contracts/auction-handler/FastLaneAuctionHandler.sol +++ b/contracts/auction-handler/FastLaneAuctionHandler.sol @@ -231,6 +231,12 @@ contract FastLaneAuctionHandler is FastLaneAuctionHandlerEvents { ) returns (uint256 bidAmount) { emit RelayFastBid(msg.sender, block.coinbase, true, bidAmount, searcherToAddress); } catch { + if (msg.value > 0) { + SafeTransferLib.safeTransferETH( + msg.sender, + msg.value + ); + } emit RelayFastBid(msg.sender, block.coinbase, false, 0, searcherToAddress); } } @@ -494,7 +500,7 @@ contract FastLaneAuctionHandler is FastLaneAuctionHandlerEvents { limitedReentrant(paymentProcessor) validPayee { - if (paymentProcessor == address(0)) revert RelayProcessorCannotBeZero(); + if (paymentProcessor == address(0) || paymentProcessor == address(this)) revert RelayProcessorCannotBeZero(); address validator = getValidator(); uint256 validatorBalance = validatorsBalanceMap[validator] - 1; From 848b8b6bd38082717b9c0aa4ab8abef3c6ab705c Mon Sep 17 00:00:00 2001 From: jj1980a Date: Thu, 4 Jan 2024 10:22:12 +0800 Subject: [PATCH 3/5] bump solc to 0.8.20 --- contracts/FastLaneFactory.sol | 2 +- contracts/legacy/FastLaneLegacyAuction.sol | 2 +- foundry.toml | 2 +- script/legacy-script/UUPSDeploy.s.sol | 2 +- test/legacy-test/PFLDeploy.t.sol | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/contracts/FastLaneFactory.sol b/contracts/FastLaneFactory.sol index 0cc2705..410bc8d 100644 --- a/contracts/FastLaneFactory.sol +++ b/contracts/FastLaneFactory.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: Unlicensed -pragma solidity 0.8.16; +pragma solidity ^0.8.16; import {FastLaneLegacyAuction} from "./legacy/FastLaneLegacyAuction.sol"; diff --git a/contracts/legacy/FastLaneLegacyAuction.sol b/contracts/legacy/FastLaneLegacyAuction.sol index f3f181d..fe33d57 100644 --- a/contracts/legacy/FastLaneLegacyAuction.sol +++ b/contracts/legacy/FastLaneLegacyAuction.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: Unlicensed -pragma solidity 0.8.16; +pragma solidity ^0.8.16; import "openzeppelin-contracts/contracts/utils/Address.sol"; import { SafeTransferLib, ERC20 } from "solmate/utils/SafeTransferLib.sol"; diff --git a/foundry.toml b/foundry.toml index 65c47be..60d8ed7 100644 --- a/foundry.toml +++ b/foundry.toml @@ -15,5 +15,5 @@ bytecode_hash = "none" names = true sizes = true gas_price = 60000000000 -solc_version = '0.8.16' +solc_version = '0.8.20' # See more config options https://github.com/foundry-rs/foundry/tree/master/config \ No newline at end of file diff --git a/script/legacy-script/UUPSDeploy.s.sol b/script/legacy-script/UUPSDeploy.s.sol index c4a113a..90fb7a2 100644 --- a/script/legacy-script/UUPSDeploy.s.sol +++ b/script/legacy-script/UUPSDeploy.s.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: AGPL-3.0-only -pragma solidity 0.8.16; +pragma solidity ^0.8.16; import "forge-std/Test.sol"; import "forge-std/Script.sol"; diff --git a/test/legacy-test/PFLDeploy.t.sol b/test/legacy-test/PFLDeploy.t.sol index d6e0276..6c92f68 100644 --- a/test/legacy-test/PFLDeploy.t.sol +++ b/test/legacy-test/PFLDeploy.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: UNLICENSED -pragma solidity 0.8.16; +pragma solidity ^0.8.16; import "contracts/legacy/FastLaneLegacyAuction.sol"; From caf03c2a5f80fc8ad4b087e4b2d49f6991f96fe0 Mon Sep 17 00:00:00 2001 From: jj1980a Date: Thu, 4 Jan 2024 10:24:24 +0800 Subject: [PATCH 4/5] comment deprecated function in legacy contract --- contracts/legacy/FastLaneLegacyAuction.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/legacy/FastLaneLegacyAuction.sol b/contracts/legacy/FastLaneLegacyAuction.sol index fe33d57..0eb1e42 100644 --- a/contracts/legacy/FastLaneLegacyAuction.sol +++ b/contracts/legacy/FastLaneLegacyAuction.sol @@ -174,7 +174,7 @@ contract FastLaneLegacyAuction is Initializable, OwnableUpgradeable , UUPSUpgrad } function initialize(address _newOwner) public initializer { - __Ownable_init(); + // __Ownable_init(); __UUPSUpgradeable_init(); _transferOwnership(_newOwner); } From 413c2bfd59d085525fb7706c3ed3170f216bc5cf Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Thu, 4 Jan 2024 14:31:02 +0200 Subject: [PATCH 5/5] Target Paris as EVM version, if Solc > 0.8.19 --- foundry.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/foundry.toml b/foundry.toml index 60d8ed7..989a0bc 100644 --- a/foundry.toml +++ b/foundry.toml @@ -16,4 +16,5 @@ names = true sizes = true gas_price = 60000000000 solc_version = '0.8.20' +evm_version = 'paris' # See more config options https://github.com/foundry-rs/foundry/tree/master/config \ No newline at end of file