diff --git a/packages/protocol/contracts/L1/libs/LibProposing.sol b/packages/protocol/contracts/L1/libs/LibProposing.sol index b234b81ea42..4af52c7b236 100644 --- a/packages/protocol/contracts/L1/libs/LibProposing.sol +++ b/packages/protocol/contracts/L1/libs/LibProposing.sol @@ -28,6 +28,11 @@ library LibProposing { // field element has 32 bytes. uint256 public constant MAX_BYTES_PER_BLOB = 4096 * 32; + // Max gas paying the prover. This should be large enough to prevent the + // worst cases, usually block proposer shall be aware the risks and only + // choose provers that cannot consume too much gas when receiving Ether. + uint256 public constant MAX_GAS_PAYING_PROVER = 200_000; + // Warning: Any events defined here must also be defined in TaikoEvents.sol. event BlockProposed( uint256 indexed blockId, @@ -354,12 +359,13 @@ library LibProposing { uint256 tip; if (assignment.feeToken == address(0)) { if (msg.value < proverFee) revert L1_ASSIGNMENT_INSUFFICIENT_FEE(); + unchecked { tip = msg.value - proverFee; } // Paying Ether - assignment.prover.sendEther(proverFee); + assignment.prover.sendEther(proverFee, MAX_GAS_PAYING_PROVER); } else { tip = msg.value; diff --git a/packages/protocol/contracts/libs/LibAddress.sol b/packages/protocol/contracts/libs/LibAddress.sol index d52201f03bd..0402013a0b5 100644 --- a/packages/protocol/contracts/libs/LibAddress.sol +++ b/packages/protocol/contracts/libs/LibAddress.sol @@ -22,13 +22,11 @@ library LibAddress { error ETH_TRANSFER_FAILED(); - /// @dev Sends Ether to the specified address. It is recommended to avoid - /// using `.transfer()` due to potential reentrancy issues. - /// Reference: - /// https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now + /// @dev Sends Ether to the specified address. /// @param to The recipient address. /// @param amount The amount of Ether to send in wei. - function sendEther(address to, uint256 amount) internal { + /// @param gasLimit The max amount gas to pay for this transaction. + function sendEther(address to, uint256 amount, uint256 gasLimit) internal { // Check for zero-value or zero-address transactions if (to == address(0)) revert ETH_TRANSFER_FAILED(); @@ -36,12 +34,19 @@ library LibAddress { // WARNING: call() functions do not have an upper gas cost limit, so // it's important to note that it may not reliably execute as expected // when invoked with untrusted addresses. - (bool success,) = payable(to).call{ value: amount }(""); + (bool success,) = payable(to).call{ value: amount, gas: gasLimit }(""); // Ensure the transfer was successful if (!success) revert ETH_TRANSFER_FAILED(); } + /// @dev Sends Ether to the specified address. + /// @param to The recipient address. + /// @param amount The amount of Ether to send in wei. + function sendEther(address to, uint256 amount) internal { + sendEther(to, amount, gasleft()); + } + function supportsInterface( address addr, bytes4 interfaceId