Commit 39bbc583 authored by Mark Tyneway's avatar Mark Tyneway Committed by GitHub

Merge pull request #5757 from ethereum-optimism/fix/bond-manager-gas

contracts-bedrock: seize and split gas management
parents aef72764 4440ecbf
...@@ -13,7 +13,9 @@ import { IDisputeGameFactory } from "./IDisputeGameFactory.sol"; ...@@ -13,7 +13,9 @@ import { IDisputeGameFactory } from "./IDisputeGameFactory.sol";
* @notice The Bond Manager serves as an escrow for permissionless output proposal bonds. * @notice The Bond Manager serves as an escrow for permissionless output proposal bonds.
*/ */
contract BondManager { contract BondManager {
// The Bond Type /**
* @notice The Bond Type
*/
struct Bond { struct Bond {
address owner; address owner;
uint256 expiration; uint256 expiration;
...@@ -58,6 +60,13 @@ contract BondManager { ...@@ -58,6 +60,13 @@ contract BondManager {
*/ */
IDisputeGameFactory public immutable DISPUTE_GAME_FACTORY; IDisputeGameFactory public immutable DISPUTE_GAME_FACTORY;
/**
* @notice Amount of gas used to transfer ether when splitting the bond.
* This is a reasonable amount of gas for a transfer, even to a smart contract.
* The number of participants is bound of by the block gas limit.
*/
uint256 private constant TRANSFER_GAS = 30_000;
/** /**
* @notice Instantiates the bond maanger with the registered dispute game factory. * @notice Instantiates the bond maanger with the registered dispute game factory.
* @param _disputeGameFactory is the dispute game factory. * @param _disputeGameFactory is the dispute game factory.
...@@ -147,13 +156,14 @@ contract BondManager { ...@@ -147,13 +156,14 @@ contract BondManager {
uint256 len = _claimRecipients.length; uint256 len = _claimRecipients.length;
uint256 proportionalAmount = b.amount / len; uint256 proportionalAmount = b.amount / len;
for (uint256 i = 0; i < len; i++) { // Send the proportional amount to each recipient. Do not revert if a send fails as that
bool success = SafeCall.send( // will prevent other recipients from receiving their share.
payable(_claimRecipients[i]), for (uint256 i; i < len; i++) {
gasleft() / len, SafeCall.send({
proportionalAmount _target: payable(_claimRecipients[i]),
); _gas: TRANSFER_GAS,
require(success, "BondManager: Failed to send Ether."); _value: proportionalAmount
});
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment