Commit 4440ecbf authored by Mark Tyneway's avatar Mark Tyneway

contracts-bedrock: seize and split gas management

Ensure that a constant amount of gas is passed to each account
when splitting up the seized bond. We can assume that the recipients
will be able to receive ether with 30,000 gas. It is the end user's
fault if they do funny business in a fallback function and cannot
receive the ether. We also cannot revert if the transfer fails
because a malicious entity could prevent all other entities from
receiving their funds. Previously, the amount of gas sent to each
recipient was different and also based on the amount of gasleft
in the execution. The problem with using gasleft here is that
gas estimation will result in enough gas being used for the most
gas guzzling call to be used for each of the calls.
parent 7dea0cf0
...@@ -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