Skip to content

Commit

Permalink
feat: make bounty updatable
Browse files Browse the repository at this point in the history
  • Loading branch information
souradeep-das committed Aug 20, 2020
1 parent 4f0adfe commit 9ad8d07
Show file tree
Hide file tree
Showing 24 changed files with 209 additions and 191 deletions.
16 changes: 8 additions & 8 deletions plasma_framework/contracts/mocks/utils/ExitBountyWrapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ pragma solidity 0.5.11;

import "../../src/exits/utils/ExitBounty.sol";

contract ExitBountyWrapper {
// contract ExitBountyWrapper {

function processStandardExitBountySize(uint256 gasPriceStartExit) public view returns (uint256) {
return ExitBounty.processStandardExitBountySize(gasPriceStartExit);
}
// function processStandardExitBountySize(uint256 gasPriceStartExit) public view returns (uint256) {
// return ExitBounty.processStandardExitBountySize(gasPriceStartExit);
// }

function processInFlightExitBountySize(uint256 gasPricePiggyback) public view returns (uint256) {
return ExitBounty.processInFlightExitBountySize(gasPricePiggyback);
}
// function processInFlightExitBountySize(uint256 gasPricePiggyback) public view returns (uint256) {
// return ExitBounty.processInFlightExitBountySize(gasPricePiggyback);
// }

}
// }
4 changes: 3 additions & 1 deletion plasma_framework/contracts/poc/fast_exits/Liquidity.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ import "../../src/exits/utils/ExitBounty.sol";
import "openzeppelin-solidity/contracts/token/ERC721/ERC721Full.sol";
import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";
import "openzeppelin-solidity/contracts/token/ERC20/SafeERC20.sol";
import "openzeppelin-solidity/contracts/math/SafeMath.sol";

/**
* @title Liquidity Contract
* Implementation Doc - https://github.com/omisego/research/blob/master/plasma/simple_fast_withdrawals.md
*/
contract Liquidity is ERC721Full {
using SafeERC20 for IERC20;
using SafeMath for uint256;

PaymentExitGame public paymentExitGame;

Expand Down Expand Up @@ -167,7 +169,7 @@ contract Liquidity is ERC721Full {
FungibleTokenOutputModel.Output memory outputFromSecondTransaction
= decodedSecondTx.outputs[0];
exitData[exitId] = ExitData(
msg.value - ExitBounty.processStandardExitBountySize(tx.gasprice),
msg.value.sub(paymentExitGame.processStandardExitBountySize()),
msg.sender,
outputFromSecondTransaction.amount,
outputFromSecondTransaction.token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import "../PaymentInFlightExitModelUtils.sol";
import "../routers/PaymentInFlightExitRouterArgs.sol";
import "../../utils/ExitableTimestamp.sol";
import "../../utils/ExitId.sol";
import "../../utils/ExitBounty.sol";
import "../../../framework/PlasmaFramework.sol";
import "../../../framework/interfaces/IExitProcessor.sol";
import "../../../transactions/PaymentTransactionModel.sol";
Expand Down Expand Up @@ -75,7 +74,8 @@ library PaymentPiggybackInFlightExit {
function piggybackInput(
Controller memory self,
PaymentExitDataModel.InFlightExitMap storage inFlightExitMap,
PaymentInFlightExitRouterArgs.PiggybackInFlightExitOnInputArgs memory args
PaymentInFlightExitRouterArgs.PiggybackInFlightExitOnInputArgs memory args,
uint128 processInFlightExitBountySize
)
public
{
Expand All @@ -91,7 +91,7 @@ library PaymentPiggybackInFlightExit {
PaymentExitDataModel.WithdrawData storage withdrawData = exit.inputs[args.inputIndex];

require(withdrawData.exitTarget == msg.sender, "Can be called only by the exit target");
withdrawData.bountySize = ExitBounty.processInFlightExitBountySize(tx.gasprice);
withdrawData.bountySize = processInFlightExitBountySize;
withdrawData.piggybackBondSize = msg.value.sub(withdrawData.bountySize);

if (isFirstPiggybackOfTheToken(exit, withdrawData.token)) {
Expand All @@ -113,7 +113,8 @@ library PaymentPiggybackInFlightExit {
function piggybackOutput(
Controller memory self,
PaymentExitDataModel.InFlightExitMap storage inFlightExitMap,
PaymentInFlightExitRouterArgs.PiggybackInFlightExitOnOutputArgs memory args
PaymentInFlightExitRouterArgs.PiggybackInFlightExitOnOutputArgs memory args,
uint128 processInFlightExitBountySize
)
public
{
Expand All @@ -129,7 +130,7 @@ library PaymentPiggybackInFlightExit {
PaymentExitDataModel.WithdrawData storage withdrawData = exit.outputs[args.outputIndex];

require(withdrawData.exitTarget == msg.sender, "Can be called only by the exit target");
withdrawData.bountySize = ExitBounty.processInFlightExitBountySize(tx.gasprice);
withdrawData.bountySize = processInFlightExitBountySize;
withdrawData.piggybackBondSize = msg.value.sub(withdrawData.bountySize);

if (isFirstPiggybackOfTheToken(exit, withdrawData.token)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import "../../utils/ExitableTimestamp.sol";
import "../../utils/ExitId.sol";
import "../../utils/OutputId.sol";
import "../../utils/MoreVpFinalization.sol";
import "../../utils/ExitBounty.sol";
import "../../../transactions/PaymentTransactionModel.sol";
import "../../../utils/PosLib.sol";
import "../../../framework/PlasmaFramework.sol";
Expand Down Expand Up @@ -84,13 +83,14 @@ library PaymentStartStandardExit {
function run(
Controller memory self,
PaymentExitDataModel.StandardExitMap storage exitMap,
PaymentStandardExitRouterArgs.StartStandardExitArgs memory args
PaymentStandardExitRouterArgs.StartStandardExitArgs memory args,
uint128 processStandardExitBountySize
)
public
{
StartStandardExitData memory data = setupStartStandardExitData(self, args);
verifyStartStandardExitData(self, data, exitMap);
saveStandardExitData(data, exitMap);
saveStandardExitData(data, exitMap, processStandardExitBountySize);
enqueueStandardExit(data);

emit ExitStarted(msg.sender, data.exitId);
Expand Down Expand Up @@ -163,7 +163,8 @@ library PaymentStartStandardExit {

function saveStandardExitData(
StartStandardExitData memory data,
PaymentExitDataModel.StandardExitMap storage exitMap
PaymentExitDataModel.StandardExitMap storage exitMap,
uint128 processStandardExitBountySize
)
private
{
Expand All @@ -173,8 +174,8 @@ library PaymentStartStandardExit {
outputId: data.outputId,
exitTarget: msg.sender,
amount: data.output.amount,
bondSize: msg.value.sub(ExitBounty.processStandardExitBountySize(tx.gasprice)),
bountySize: ExitBounty.processStandardExitBountySize(tx.gasprice)
bondSize: msg.value.sub(processStandardExitBountySize),
bountySize: processStandardExitBountySize
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import "../controllers/PaymentProcessInFlightExit.sol";
import "../../registries/SpendingConditionRegistry.sol";
import "../../interfaces/IStateTransitionVerifier.sol";
import "../../utils/BondSize.sol";
import "../../utils/ExitBounty.sol";
import "../../../utils/FailFastReentrancyGuard.sol";
import "../../../utils/OnlyFromAddress.sol";
import "../../../utils/OnlyWithValue.sol";
Expand All @@ -35,6 +36,7 @@ contract PaymentInFlightExitRouter is
using PaymentDeleteInFlightExit for PaymentDeleteInFlightExit.Controller;
using PaymentProcessInFlightExit for PaymentProcessInFlightExit.Controller;
using BondSize for BondSize.Params;
using ExitBounty for ExitBounty.Params;

// Initial IFE bond size = 185000 (gas cost of challenge) * 20 gwei (current fast gas price) * 10 (safety margin)
uint128 public constant INITIAL_IFE_BOND_SIZE = 37000000000000000 wei;
Expand All @@ -46,6 +48,13 @@ contract PaymentInFlightExitRouter is
uint16 public constant BOND_LOWER_BOUND_DIVISOR = 2;
uint16 public constant BOND_UPPER_BOUND_MULTIPLIER = 2;

// Initial exit bounty size = 500000 (approx gas usage for processExit) * 80 gwei (current fast gas price)
uint128 public constant INITIAL_IFE_EXIT_BOUNTY_SIZE = 40000000000000000 wei;

// Each bounty size upgrade can either at most increase to 200% or decrease to 50% of current size
uint16 public constant EXIT_BOUNTY_LOWER_BOUND_DIVISOR = 2;
uint16 public constant EXIT_BOUNTY_UPPER_BOUND_MULTIPLIER = 2;

PaymentExitDataModel.InFlightExitMap internal inFlightExitMap;
PaymentStartInFlightExit.Controller internal startInFlightExitController;
PaymentPiggybackInFlightExit.Controller internal piggybackInFlightExitController;
Expand All @@ -56,12 +65,14 @@ contract PaymentInFlightExitRouter is
PaymentProcessInFlightExit.Controller internal processInflightExitController;
BondSize.Params internal startIFEBond;
BondSize.Params internal piggybackBond;
ExitBounty.Params internal processIFEBounty;

PlasmaFramework private framework;
bool private bootDone = false;

event IFEBondUpdated(uint128 bondSize);
event PiggybackBondUpdated(uint128 bondSize);
event ProcessInFlightExitBountyUpdated(uint128 exitBountySize);

event InFlightExitStarted(
address indexed initiator,
Expand Down Expand Up @@ -184,6 +195,7 @@ contract PaymentInFlightExitRouter is
});
startIFEBond = BondSize.buildParams(INITIAL_IFE_BOND_SIZE, BOND_LOWER_BOUND_DIVISOR, BOND_UPPER_BOUND_MULTIPLIER);
piggybackBond = BondSize.buildParams(INITIAL_PB_BOND_SIZE, BOND_LOWER_BOUND_DIVISOR, BOND_UPPER_BOUND_MULTIPLIER);
processIFEBounty = ExitBounty.buildParams(INITIAL_IFE_EXIT_BOUNTY_SIZE, EXIT_BOUNTY_LOWER_BOUND_DIVISOR, EXIT_BOUNTY_UPPER_BOUND_MULTIPLIER);
}

/**
Expand Down Expand Up @@ -222,9 +234,10 @@ contract PaymentInFlightExitRouter is
public
payable
nonReentrant(framework)
onlyWithValue(piggybackBondSize() + processInFlightExitBountySize(tx.gasprice))
onlyWithValue(piggybackBondSize() + processInFlightExitBountySize())
{
piggybackInFlightExitController.piggybackInput(inFlightExitMap, args);
uint128 bountySize = processInFlightExitBountySize();
piggybackInFlightExitController.piggybackInput(inFlightExitMap, args, bountySize);
}

/**
Expand All @@ -237,9 +250,10 @@ contract PaymentInFlightExitRouter is
public
payable
nonReentrant(framework)
onlyWithValue(piggybackBondSize() + processInFlightExitBountySize(tx.gasprice))
onlyWithValue(piggybackBondSize() + processInFlightExitBountySize())
{
piggybackInFlightExitController.piggybackOutput(inFlightExitMap, args);
uint128 bountySize = processInFlightExitBountySize();
piggybackInFlightExitController.piggybackOutput(inFlightExitMap, args, bountySize);
}

/**
Expand Down Expand Up @@ -348,7 +362,16 @@ contract PaymentInFlightExitRouter is
/**
* @notice Retrieves the process IFE bounty size
*/
function processInFlightExitBountySize(uint256 gasPricePiggyback) public view returns (uint256) {
return ExitBounty.processInFlightExitBountySize(gasPricePiggyback);
function processInFlightExitBountySize() public view returns (uint128) {
return processIFEBounty.exitBountySize();
}

/**
* @notice Updates the process in-flight exit bounty size, taking two days to become effective
* @param newExitBountySize The new exit bounty size
*/
function updateProcessInFlightExitBountySize(uint128 newExitBountySize) public onlyFrom(framework.getMaintainer()) {
processIFEBounty.updateExitBountySize(newExitBountySize);
emit ProcessInFlightExitBountyUpdated(newExitBountySize);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import "../controllers/PaymentProcessStandardExit.sol";
import "../controllers/PaymentChallengeStandardExit.sol";
import "../../registries/SpendingConditionRegistry.sol";
import "../../utils/BondSize.sol";
import "../../utils/ExitBounty.sol";
import "../../../vaults/EthVault.sol";
import "../../../vaults/Erc20Vault.sol";
import "../../../framework/PlasmaFramework.sol";
Expand All @@ -27,6 +28,7 @@ contract PaymentStandardExitRouter is
using PaymentChallengeStandardExit for PaymentChallengeStandardExit.Controller;
using PaymentProcessStandardExit for PaymentProcessStandardExit.Controller;
using BondSize for BondSize.Params;
using ExitBounty for ExitBounty.Params;

// Initial bond size = 70000 (gas cost of challenge) * 20 gwei (current fast gas price) * 10 (safety margin)
uint128 public constant INITIAL_BOND_SIZE = 14000000000000000 wei;
Expand All @@ -35,16 +37,25 @@ contract PaymentStandardExitRouter is
uint16 public constant BOND_LOWER_BOUND_DIVISOR = 2;
uint16 public constant BOND_UPPER_BOUND_MULTIPLIER = 2;

// Initial exit bounty size = 107000 (approx gas usage for processExit) * 80 gwei (current fast gas price)
uint128 public constant INITIAL_EXIT_BOUNTY_SIZE = 8560000000000000 wei;

// Each bounty size upgrade can either at most increase to 200% or decrease to 50% of current size
uint16 public constant EXIT_BOUNTY_LOWER_BOUND_DIVISOR = 2;
uint16 public constant EXIT_BOUNTY_UPPER_BOUND_MULTIPLIER = 2;

PaymentExitDataModel.StandardExitMap internal standardExitMap;
PaymentStartStandardExit.Controller internal startStandardExitController;
PaymentProcessStandardExit.Controller internal processStandardExitController;
PaymentChallengeStandardExit.Controller internal challengeStandardExitController;
BondSize.Params internal startStandardExitBond;
ExitBounty.Params internal processStandardExitBounty;

PlasmaFramework private framework;
bool private bootDone = false;

event StandardExitBondUpdated(uint128 bondSize);
event ProcessStandardExitBountyUpdated(uint128 exitBountySize);

event ExitStarted(
address indexed owner,
Expand Down Expand Up @@ -98,6 +109,7 @@ contract PaymentStandardExitRouter is
);

startStandardExitBond = BondSize.buildParams(INITIAL_BOND_SIZE, BOND_LOWER_BOUND_DIVISOR, BOND_UPPER_BOUND_MULTIPLIER);
processStandardExitBounty = ExitBounty.buildParams(INITIAL_EXIT_BOUNTY_SIZE, EXIT_BOUNTY_LOWER_BOUND_DIVISOR, EXIT_BOUNTY_UPPER_BOUND_MULTIPLIER);
}

/**
Expand Down Expand Up @@ -132,8 +144,17 @@ contract PaymentStandardExitRouter is
/**
* @notice Retrieves the process standard exit bounty size
*/
function processStandardExitBountySize(uint256 gasPriceStartExit) public view returns (uint256) {
return ExitBounty.processStandardExitBountySize(gasPriceStartExit);
function processStandardExitBountySize() public view returns (uint128) {
return processStandardExitBounty.exitBountySize();
}

/**
* @notice Updates the process standard exit bounty size, taking two days to become effective
* @param newExitBountySize The new exit bounty size
*/
function updateProcessStandardExitBountySize(uint128 newExitBountySize) public onlyFrom(framework.getMaintainer()) {
processStandardExitBounty.updateExitBountySize(newExitBountySize);
emit ProcessStandardExitBountyUpdated(newExitBountySize);
}

/**
Expand All @@ -145,9 +166,10 @@ contract PaymentStandardExitRouter is
public
payable
nonReentrant(framework)
onlyWithValue(startStandardExitBondSize() + processStandardExitBountySize(tx.gasprice))
onlyWithValue(startStandardExitBondSize() + processStandardExitBountySize())
{
startStandardExitController.run(standardExitMap, args);
uint128 bountySize = processStandardExitBountySize();
startStandardExitController.run(standardExitMap, args, bountySize);
}

/**
Expand Down
Loading

0 comments on commit 9ad8d07

Please sign in to comment.