From 256d913c381644cb9c186b4a342e561ca654f43a 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 f22bad5c5..d7ff1fdf7 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 5947dd2df..6ff2d12d8 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 db68774ee..dccd34665 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 3bb7f83a0..10ac2d19b 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 15f2c7881..99777dafe 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 1f19ac8c4..70e608791 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 5b6fc1a1e..e74b9dd59 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,