Skip to content

Commit

Permalink
two steps to exit game (#667)
Browse files Browse the repository at this point in the history
* two steps to exit game
  • Loading branch information
Ino Murko authored Aug 3, 2020
1 parent 04f3f45 commit 3e5887b
Show file tree
Hide file tree
Showing 26 changed files with 351 additions and 166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ contract PaymentInFlightExitRouterMock is FailFastReentrancyGuard, PaymentInFlig
PaymentInFlightExitRouterArgs.ChallengeInputSpentArgs private challengeInputSpentArgs;
PaymentInFlightExitRouterArgs.ChallengeOutputSpent private challengeOutputSpentArgs;

constructor(PaymentExitGameArgs.Args memory args)
function bootInternal(PaymentExitGameArgs.Args memory paymentExitGameArgs)
public
PaymentInFlightExitRouter(args)
{
framework = args.framework;
framework = paymentExitGameArgs.framework;
PaymentInFlightExitRouter.boot(paymentExitGameArgs);
}

/** override and calls processInFlightExit for test */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ contract PaymentStandardExitRouterMock is PaymentStandardExitRouter {
PaymentStandardExitRouterArgs.StartStandardExitArgs private startStandardExitArgs;
PaymentStandardExitRouterArgs.ChallengeStandardExitArgs private challengeStandardExitArgs;

constructor(PaymentExitGameArgs.Args memory args)
function bootInternal(PaymentExitGameArgs.Args memory paymentExitGameArgs)
public
PaymentStandardExitRouter(args)
{
framework = args.framework;
PaymentStandardExitRouter.boot(paymentExitGameArgs);
framework = paymentExitGameArgs.framework;
}

/** override and calls processStandardExit for test */
Expand Down
19 changes: 13 additions & 6 deletions plasma_framework/contracts/src/exits/payment/PaymentExitGame.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,35 @@ import "../../utils/OnlyFromAddress.sol";
* @notice The exit game contract implementation for Payment Transaction
*/
contract PaymentExitGame is IExitProcessor, OnlyFromAddress, PaymentStandardExitRouter, PaymentInFlightExitRouter {
PlasmaFramework private plasmaFramework;
PaymentExitGameArgs.Args private paymentExitGameArgs;
bool private initDone = false;

/**
* @dev use struct PaymentExitGameArgs to avoid stack too deep compilation error.
*/
constructor(PaymentExitGameArgs.Args memory args)
public
PaymentStandardExitRouter(args)
PaymentInFlightExitRouter(args)
PaymentStandardExitRouter()
PaymentInFlightExitRouter()
{
plasmaFramework = args.framework;

paymentExitGameArgs = args;
// makes sure that the spending condition has already renounced ownership
require(args.spendingConditionRegistry.owner() == address(0), "Spending condition registry ownership needs to be renounced");
}

function init() public onlyFrom(paymentExitGameArgs.framework.getMaintainer()) {
require(!initDone, "Exit game was already initialized");
initDone = true;
PaymentStandardExitRouter.boot(paymentExitGameArgs);
PaymentInFlightExitRouter.boot(paymentExitGameArgs);
}

/**
* @notice Callback processes exit function for the PlasmaFramework to call
* @param exitId The exit ID
* @param token Token (ERC20 address or address(0) for ETH) of the exiting output
*/
function processExit(uint168 exitId, uint256, address token) external onlyFrom(address(plasmaFramework)) {
function processExit(uint168 exitId, uint256, address token) external onlyFrom(address(paymentExitGameArgs.framework)) {
if (ExitId.isStandardExit(exitId)) {
PaymentStandardExitRouter.processStandardExit(exitId, token);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ contract PaymentInFlightExitRouter is
BondSize.Params internal piggybackBond;

PlasmaFramework private framework;
bool private bootDone = false;

event IFEBondUpdated(uint128 bondSize);
event PiggybackBondUpdated(uint128 bondSize);
Expand Down Expand Up @@ -127,59 +128,59 @@ contract PaymentInFlightExitRouter is
uint168 indexed exitId
);

constructor(PaymentExitGameArgs.Args memory args)
public
function boot(PaymentExitGameArgs.Args memory paymentExitGameArgs)
internal
{
framework = args.framework;

EthVault ethVault = EthVault(args.framework.vaults(args.ethVaultId));
require(msg.sender == paymentExitGameArgs.framework.getMaintainer(), "Only Maintainer can perform this action");
require(!bootDone, "Exit game was already initialized");
EthVault ethVault = EthVault(paymentExitGameArgs.framework.vaults(paymentExitGameArgs.ethVaultId));
require(address(ethVault) != address(0), "Invalid ETH vault");

Erc20Vault erc20Vault = Erc20Vault(args.framework.vaults(args.erc20VaultId));
Erc20Vault erc20Vault = Erc20Vault(paymentExitGameArgs.framework.vaults(paymentExitGameArgs.erc20VaultId));
require(address(erc20Vault) != address(0), "Invalid ERC20 vault");

framework = paymentExitGameArgs.framework;
bootDone = true;
startInFlightExitController = PaymentStartInFlightExit.buildController(
args.framework,
args.spendingConditionRegistry,
args.stateTransitionVerifier,
args.supportTxType
paymentExitGameArgs.framework,
paymentExitGameArgs.spendingConditionRegistry,
paymentExitGameArgs.stateTransitionVerifier,
paymentExitGameArgs.supportTxType
);

piggybackInFlightExitController = PaymentPiggybackInFlightExit.buildController(
args.framework,
paymentExitGameArgs.framework,
this,
args.ethVaultId,
args.erc20VaultId
paymentExitGameArgs.ethVaultId,
paymentExitGameArgs.erc20VaultId
);

challengeCanonicityController = PaymentChallengeIFENotCanonical.buildController(
args.framework,
args.spendingConditionRegistry,
args.supportTxType
paymentExitGameArgs.framework,
paymentExitGameArgs.spendingConditionRegistry,
paymentExitGameArgs.supportTxType
);

challengeInputSpentController = PaymentChallengeIFEInputSpent.buildController(
args.framework,
args.spendingConditionRegistry,
args.safeGasStipend
paymentExitGameArgs.framework,
paymentExitGameArgs.spendingConditionRegistry,
paymentExitGameArgs.safeGasStipend
);

challengeOutputSpentController = PaymentChallengeIFEOutputSpent.Controller(
args.framework,
args.spendingConditionRegistry,
args.safeGasStipend
paymentExitGameArgs.framework,
paymentExitGameArgs.spendingConditionRegistry,
paymentExitGameArgs.safeGasStipend
);

deleteNonPiggybackIFEController = PaymentDeleteInFlightExit.Controller({
minExitPeriod: args.framework.minExitPeriod(),
safeGasStipend: args.safeGasStipend
minExitPeriod: paymentExitGameArgs.framework.minExitPeriod(),
safeGasStipend: paymentExitGameArgs.safeGasStipend
});

processInflightExitController = PaymentProcessInFlightExit.Controller({
framework: args.framework,
framework: paymentExitGameArgs.framework,
ethVault: ethVault,
erc20Vault: erc20Vault,
safeGasStipend: args.safeGasStipend
safeGasStipend: paymentExitGameArgs.safeGasStipend
});
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ contract PaymentStandardExitRouter is
BondSize.Params internal startStandardExitBond;

PlasmaFramework private framework;
bool private bootDone = false;

event StandardExitBondUpdated(uint128 bondSize);

Expand All @@ -67,33 +68,33 @@ contract PaymentStandardExitRouter is
uint256 amount
);

constructor(PaymentExitGameArgs.Args memory args)
public
function boot(PaymentExitGameArgs.Args memory paymentExitGameArgs)
internal
{
framework = args.framework;

EthVault ethVault = EthVault(args.framework.vaults(args.ethVaultId));
require(msg.sender == paymentExitGameArgs.framework.getMaintainer(), "Only Maintainer can perform this action");
require(!bootDone, "Exit game was already initialized");
EthVault ethVault = EthVault(paymentExitGameArgs.framework.vaults(paymentExitGameArgs.ethVaultId));
require(address(ethVault) != address(0), "Invalid ETH vault");

Erc20Vault erc20Vault = Erc20Vault(args.framework.vaults(args.erc20VaultId));
require(address(erc20Vault) != address(0), "Invalid ERC20 vault");

Erc20Vault erc20Vault = Erc20Vault(paymentExitGameArgs.framework.vaults(paymentExitGameArgs.erc20VaultId));
require(address(erc20Vault) != address(0), "Invalid ERC20 vault");
framework = paymentExitGameArgs.framework;
bootDone = true;
startStandardExitController = PaymentStartStandardExit.buildController(
this,
args.framework,
args.ethVaultId,
args.erc20VaultId,
args.supportTxType
paymentExitGameArgs.framework,
paymentExitGameArgs.ethVaultId,
paymentExitGameArgs.erc20VaultId,
paymentExitGameArgs.supportTxType
);

challengeStandardExitController = PaymentChallengeStandardExit.buildController(
args.framework,
args.spendingConditionRegistry,
args.safeGasStipend
paymentExitGameArgs.framework,
paymentExitGameArgs.spendingConditionRegistry,
paymentExitGameArgs.safeGasStipend
);

processStandardExitController = PaymentProcessStandardExit.Controller(
args.framework, ethVault, erc20Vault, args.safeGasStipend
paymentExitGameArgs.framework, ethVault, erc20Vault, paymentExitGameArgs.safeGasStipend
);

startStandardExitBond = BondSize.buildParams(INITIAL_BOND_SIZE, BOND_LOWER_BOUND_DIVISOR, BOND_UPPER_BOUND_MULTIPLIER);
Expand Down
5 changes: 3 additions & 2 deletions plasma_framework/migrations/140_payment_exit_game.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ module.exports = async (
PAYMENT_TX_TYPE,
config.frameworks.safeGasStipend.v1,
];
const paymentExitGame = await deployer.deploy(PaymentExitGame, paymentExitGameArgs);

await deployer.deploy(PaymentExitGame, paymentExitGameArgs);
const paymentExitGame = await PaymentExitGame.deployed();
await paymentExitGame.init({ from: maintainerAddress });
// register the exit game to framework
await plasmaFramework.registerExitGame(
PAYMENT_TX_TYPE,
Expand Down
62 changes: 58 additions & 4 deletions plasma_framework/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion plasma_framework/package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
{
"name": "plasma_framework",
"version": "1.0.5",
"version": "2.0.0",
"description": "Plasma Framework",
"directories": {
"test": "test"
},
"dependencies": {
"@truffle/hdwallet-provider": "^1.0.37",
"dotenv": "^8.0.0",
"elliptic": ">=6.5.3",
"lodash.clonedeep": "^4.5.0",
"openzeppelin-solidity": "2.3.0",
"solidoc": "^1.0.5"
},
"devDependencies": {
"elliptic": ">=6.5.3",
"@codechecks/client": "^0.1.10",
"chai": "^4.2.0",
"coveralls": "^3.0.6",
Expand Down
Loading

0 comments on commit 3e5887b

Please sign in to comment.