Skip to content
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

fix(BridgeReward): add addition gas stipend config to ensure sufficient gas after London hardfork #39

Merged
merged 4 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/extensions/RONTransferHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ abstract contract RONTransferHelper {
* @dev Same purpose with {_unsafeSendRONLimitGas(address,uin256)} but containing gas limit stipend forwarded in the call.
*/
function _unsafeSendRONLimitGas(address payable recipient, uint256 amount, uint256 gas) internal returns (bool success) {
// When msg.value = 0, the forwarding gas will not be auto-added 2300.
// We add an extra 2300 to make sure all calls will have the same amount of gas.
if (amount == 0) {
gas += 2300;
}

(success,) = recipient.call{ value: amount, gas: gas }("");
}
}
5 changes: 5 additions & 0 deletions src/interfaces/bridge/IBridgeReward.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ pragma solidity ^0.8.9;
import { IBridgeRewardEvents } from "./events/IBridgeRewardEvents.sol";

interface IBridgeReward is IBridgeRewardEvents {
/**
* @dev Configuration of gas stipend to ensure sufficient gas after London Hardfork.
*/
function DEFAULT_ADDITION_GAS() external view returns (uint256);

/**
* @dev This function allows bridge operators to manually synchronize the reward for a given period length.
* @param periodCount The length of the reward period for which synchronization is requested.
Expand Down
4 changes: 3 additions & 1 deletion src/ronin/gateway/BridgeReward.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { TUint256Slot } from "../../types/Types.sol";
import { ErrSyncTooFarPeriod, ErrInvalidArguments, ErrLengthMismatch, ErrUnauthorizedCall } from "../../utils/CommonErrors.sol";

contract BridgeReward is IBridgeReward, BridgeTrackingHelper, HasContracts, RONTransferHelper, Initializable {
/// @inheritdoc IBridgeReward
uint256 public constant DEFAULT_ADDITION_GAS = 6200;
/// @dev value is equal to keccak256("@ronin.dpos.gateway.BridgeReward.rewardInfo.slot") - 1
bytes32 private constant $_REWARD_INFO = 0x518cfd198acbffe95e740cfce1af28a3f7de51f0d784893d3d72c5cc59d7062a;
/// @dev value is equal to keccak256("@ronin.dpos.gateway.BridgeReward.rewardPerPeriod.slot") - 1
Expand Down Expand Up @@ -316,7 +318,7 @@ contract BridgeReward is IBridgeReward, BridgeTrackingHelper, HasContracts, RONT
return false;
}

if (_unsafeSendRONLimitGas({ recipient: payable(operator), amount: reward, gas: 0 })) {
if (_unsafeSendRONLimitGas({ recipient: payable(operator), amount: reward, gas: DEFAULT_ADDITION_GAS })) {
_iRewardInfo.claimed += reward;
emit BridgeRewardScattered(period, operator, reward);
return true;
Expand Down
Loading