From 90d88261d1f0822e28a6b2a30c7580364728e318 Mon Sep 17 00:00:00 2001 From: boolafish Date: Wed, 2 Oct 2019 17:00:49 +0900 Subject: [PATCH] chore: make compiler happy when optimizer is off Somehow if we adding 'require' inside 'buildParams' in BondSize and use that in our Routers during their constructor, the compile would fail with the exception of "Assembly exception for bytecode". However, this would be fine if the optimizer is turned on. After a few tries, by making it being called in a non-constructor solves the compile issue. Thus, this commit changes the constructor for Routers to become a 'init' function instead. This was found because solidity coverage would force turning off the optimizer, see: https://github.com/sc-forks/solidity-coverage/issues/417 --- .../payment/routers/PaymentInFlightExitRouterMock.sol | 10 +++++----- .../payment/routers/PaymentStandardExitRouterMock.sol | 6 +++--- plasma_framework/contracts/mocks/utils/BitsWrapper.sol | 2 +- .../contracts/src/exits/payment/PaymentExitGame.sol | 10 +++++----- .../payment/routers/PaymentInFlightExitRouter.sol | 3 ++- .../payment/routers/PaymentStandardExitRouter.sol | 2 +- .../contracts/src/exits/utils/BondSize.sol | 9 +++++---- 7 files changed, 22 insertions(+), 20 deletions(-) diff --git a/plasma_framework/contracts/mocks/exits/payment/routers/PaymentInFlightExitRouterMock.sol b/plasma_framework/contracts/mocks/exits/payment/routers/PaymentInFlightExitRouterMock.sol index c2c4d59b4..2ac37b0ba 100644 --- a/plasma_framework/contracts/mocks/exits/payment/routers/PaymentInFlightExitRouterMock.sol +++ b/plasma_framework/contracts/mocks/exits/payment/routers/PaymentInFlightExitRouterMock.sol @@ -21,10 +21,11 @@ contract PaymentInFlightExitRouterMock is PaymentInFlightExitRouter { SpendingConditionRegistry spendingConditionRegistry, IStateTransitionVerifier stateTransitionVerifier, ITxFinalizationVerifier txFinalizationVerifier, - uint256 supportedTxType + uint256 supportTxType ) public - PaymentInFlightExitRouter( + { + PaymentInFlightExitRouter.init( plasmaFramework, ethVault, erc20Vault, @@ -32,9 +33,8 @@ contract PaymentInFlightExitRouterMock is PaymentInFlightExitRouter { spendingConditionRegistry, stateTransitionVerifier, txFinalizationVerifier, - supportedTxType - ) - { + supportTxType + ); framework = plasmaFramework; } diff --git a/plasma_framework/contracts/mocks/exits/payment/routers/PaymentStandardExitRouterMock.sol b/plasma_framework/contracts/mocks/exits/payment/routers/PaymentStandardExitRouterMock.sol index 2a4d1207f..b9ed00ff5 100644 --- a/plasma_framework/contracts/mocks/exits/payment/routers/PaymentStandardExitRouterMock.sol +++ b/plasma_framework/contracts/mocks/exits/payment/routers/PaymentStandardExitRouterMock.sol @@ -18,15 +18,15 @@ contract PaymentStandardExitRouterMock is PaymentStandardExitRouter { ITxFinalizationVerifier txFinalizationVerifier ) public - PaymentStandardExitRouter( + { + PaymentStandardExitRouter.init( plasmaFramework, ethVault, erc20Vault, outputGuardHandlerRegistry, spendingConditionRegistry, txFinalizationVerifier - ) - { + ); framework = plasmaFramework; } diff --git a/plasma_framework/contracts/mocks/utils/BitsWrapper.sol b/plasma_framework/contracts/mocks/utils/BitsWrapper.sol index 4b2c56cbf..8c74e636d 100644 --- a/plasma_framework/contracts/mocks/utils/BitsWrapper.sol +++ b/plasma_framework/contracts/mocks/utils/BitsWrapper.sol @@ -20,4 +20,4 @@ contract BitsWrapper { { return Bits.bitSet(_self, _index); } -} \ No newline at end of file +} diff --git a/plasma_framework/contracts/src/exits/payment/PaymentExitGame.sol b/plasma_framework/contracts/src/exits/payment/PaymentExitGame.sol index 87b0cde2e..ab9e5b0aa 100644 --- a/plasma_framework/contracts/src/exits/payment/PaymentExitGame.sol +++ b/plasma_framework/contracts/src/exits/payment/PaymentExitGame.sol @@ -30,15 +30,16 @@ contract PaymentExitGame is IExitProcessor, PaymentStandardExitRouter, PaymentIn uint256 supportTxType ) public - PaymentStandardExitRouter( + { + PaymentStandardExitRouter.init( framework, ethVault, erc20Vault, outputGuardHandlerRegistry, spendingConditionRegistry, txFinalizationVerifier - ) - PaymentInFlightExitRouter( + ); + PaymentInFlightExitRouter.init( framework, ethVault, erc20Vault, @@ -47,8 +48,7 @@ contract PaymentExitGame is IExitProcessor, PaymentStandardExitRouter, PaymentIn stateTransitionVerifier, txFinalizationVerifier, supportTxType - ) - { + ); plasmaFramework = framework; } diff --git a/plasma_framework/contracts/src/exits/payment/routers/PaymentInFlightExitRouter.sol b/plasma_framework/contracts/src/exits/payment/routers/PaymentInFlightExitRouter.sol index 61c8afed4..a02d6acf1 100644 --- a/plasma_framework/contracts/src/exits/payment/routers/PaymentInFlightExitRouter.sol +++ b/plasma_framework/contracts/src/exits/payment/routers/PaymentInFlightExitRouter.sol @@ -51,7 +51,7 @@ contract PaymentInFlightExitRouter is IExitProcessor, Operated, OnlyWithValue { event IFEBondUpdated(uint128 bondSize); event PiggybackBondUpdated(uint128 bondSize); - constructor( + function init( PlasmaFramework framework, EthVault ethVault, Erc20Vault erc20Vault, @@ -105,6 +105,7 @@ contract PaymentInFlightExitRouter is IExitProcessor, Operated, OnlyWithValue { ethVault: ethVault, erc20Vault: erc20Vault }); + 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); } diff --git a/plasma_framework/contracts/src/exits/payment/routers/PaymentStandardExitRouter.sol b/plasma_framework/contracts/src/exits/payment/routers/PaymentStandardExitRouter.sol index 2e7534ef9..61b972ad1 100644 --- a/plasma_framework/contracts/src/exits/payment/routers/PaymentStandardExitRouter.sol +++ b/plasma_framework/contracts/src/exits/payment/routers/PaymentStandardExitRouter.sol @@ -42,7 +42,7 @@ contract PaymentStandardExitRouter is event StandardExitBondUpdated(uint128 bondSize); - constructor( + function init( PlasmaFramework framework, EthVault ethVault, Erc20Vault erc20Vault, diff --git a/plasma_framework/contracts/src/exits/utils/BondSize.sol b/plasma_framework/contracts/src/exits/utils/BondSize.sol index 9b7e14c62..bd52c4767 100644 --- a/plasma_framework/contracts/src/exits/utils/BondSize.sol +++ b/plasma_framework/contracts/src/exits/utils/BondSize.sol @@ -31,12 +31,13 @@ library BondSize { pure returns (Params memory) { - require(initialBondSize > 0, "initialBondSize cannot be 0"); - require(lowerBoundDivisor > 0, "lowerBoundDivisor cannot be 0"); - require(upperBoundMultiplier > 0, "upperBoundMultiplier cannot be 0"); - // Set the initial value to far in the future uint128 initialEffectiveUpdateTime = 2 ** 63; + + require(initialBondSize != 0, "initialBondSize cannot be 0"); + require(lowerBoundDivisor != 0, "lowerBoundDivisor cannot be 0"); + require(upperBoundMultiplier != 0, "upperBoundMultiplier cannot be 0"); + return Params({ previousBondSize: initialBondSize, updatedBondSize: 0,