From 1ebce1d89b47ae692144e672f4d932cef659716d Mon Sep 17 00:00:00 2001 From: Michal Mrozek Date: Tue, 1 Sep 2020 10:09:01 +0200 Subject: [PATCH] [ETCM-41] Add Istanbul fork configuration --- .../ets/blockchain/BlockchainTestConfig.scala | 1 + .../io/iohk/ethereum/txExecTest/ECIP1017Test.scala | 1 + .../scala/io/iohk/ethereum/txExecTest/ForksTest.scala | 1 + src/main/resources/chains/base.conf | 4 ++++ src/main/resources/chains/eth.conf | 4 ++++ src/main/scala/io/iohk/ethereum/extvm/VMServer.scala | 1 + .../scala/io/iohk/ethereum/jsonrpc/TestService.scala | 1 + src/main/scala/io/iohk/ethereum/utils/Config.scala | 2 ++ .../io/iohk/ethereum/vm/BlockchainConfigForEvm.scala | 11 ++++++++--- src/main/scala/io/iohk/ethereum/vm/EvmConfig.scala | 3 +++ .../iohk/ethereum/consensus/BlockGeneratorSpec.scala | 2 ++ .../validators/BlockHeaderValidatorSpec.scala | 3 ++- .../scala/io/iohk/ethereum/extvm/VMClientSpec.scala | 1 + .../io/iohk/ethereum/jsonrpc/EthServiceSpec.scala | 1 + .../iohk/ethereum/jsonrpc/PersonalServiceSpec.scala | 1 + .../io/iohk/ethereum/ledger/LedgerTestSetup.scala | 1 + .../scala/io/iohk/ethereum/ledger/StxLedgerSpec.scala | 1 + .../network/handshaker/EtcHandshakerSpec.scala | 1 + src/test/scala/io/iohk/ethereum/vm/Fixtures.scala | 2 ++ src/test/scala/io/iohk/ethereum/vm/VMSpec.scala | 1 + 20 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/ets/scala/io/iohk/ethereum/ets/blockchain/BlockchainTestConfig.scala b/src/ets/scala/io/iohk/ethereum/ets/blockchain/BlockchainTestConfig.scala index c7a3955929..10bfc00063 100644 --- a/src/ets/scala/io/iohk/ethereum/ets/blockchain/BlockchainTestConfig.scala +++ b/src/ets/scala/io/iohk/ethereum/ets/blockchain/BlockchainTestConfig.scala @@ -19,6 +19,7 @@ trait BlockchainTestConfig extends BlockchainConfig { val eip161BlockNumber: BigInt = Long.MaxValue val byzantiumBlockNumber: BigInt = Long.MaxValue val constantinopleBlockNumber: BigInt = Long.MaxValue + val istanbulBlockNumber: BigInt = Long.MaxValue // unused override val maxCodeSize: Option[BigInt] = None override val difficultyBombPauseBlockNumber: BigInt = 3000000 diff --git a/src/it/scala/io/iohk/ethereum/txExecTest/ECIP1017Test.scala b/src/it/scala/io/iohk/ethereum/txExecTest/ECIP1017Test.scala index 70b3be6dfb..62f033b116 100644 --- a/src/it/scala/io/iohk/ethereum/txExecTest/ECIP1017Test.scala +++ b/src/it/scala/io/iohk/ethereum/txExecTest/ECIP1017Test.scala @@ -32,6 +32,7 @@ class ECIP1017Test extends FlatSpec with Matchers { override val eip161BlockNumber: BigInt = Long.MaxValue override val byzantiumBlockNumber: BigInt = Long.MaxValue override val constantinopleBlockNumber: BigInt = Long.MaxValue + override val istanbulBlockNumber: BigInt = Long.MaxValue override val customGenesisFileOpt: Option[String] = None override val daoForkConfig: Option[DaoForkConfig] = None override val difficultyBombPauseBlockNumber: BigInt = Long.MaxValue diff --git a/src/it/scala/io/iohk/ethereum/txExecTest/ForksTest.scala b/src/it/scala/io/iohk/ethereum/txExecTest/ForksTest.scala index f6a967fcf8..c2350fcaec 100644 --- a/src/it/scala/io/iohk/ethereum/txExecTest/ForksTest.scala +++ b/src/it/scala/io/iohk/ethereum/txExecTest/ForksTest.scala @@ -35,6 +35,7 @@ class ForksTest extends FlatSpec with Matchers { override val difficultyBombRemovalBlockNumber: BigInt = Long.MaxValue override val byzantiumBlockNumber: BigInt = Long.MaxValue override val constantinopleBlockNumber: BigInt = Long.MaxValue + override val istanbulBlockNumber: BigInt = Long.MaxValue override val accountStartNonce: UInt256 = UInt256.Zero override val daoForkConfig: Option[DaoForkConfig] = None override val gasTieBreaker: Boolean = false diff --git a/src/main/resources/chains/base.conf b/src/main/resources/chains/base.conf index 102007253d..49208bca91 100644 --- a/src/main/resources/chains/base.conf +++ b/src/main/resources/chains/base.conf @@ -74,6 +74,10 @@ # https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1716.md petersburg-block-number = "1000000000000000000" + # Istanbul fork block number (ETH only) + # https://eips.ethereum.org/EIPS/eip-1679 + istanbul-block-number = "1000000000000000000" + # DAO fork configuration (Ethereum HF/Classic split) # https://blog.ethereum.org/2016/07/20/hard-fork-completed/ dao { diff --git a/src/main/resources/chains/eth.conf b/src/main/resources/chains/eth.conf index 90e27a2906..24261ff489 100644 --- a/src/main/resources/chains/eth.conf +++ b/src/main/resources/chains/eth.conf @@ -41,6 +41,10 @@ # https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1716.md petersburg-block-number = "7280000" + # Istanbul fork block number (ETH only) + # https://eips.ethereum.org/EIPS/eip-1679 + istanbul-block-number = "9069000" + monetary-policy { # Setting era-duration for eth and ropsten chain to big number is necessery to ensure diff --git a/src/main/scala/io/iohk/ethereum/extvm/VMServer.scala b/src/main/scala/io/iohk/ethereum/extvm/VMServer.scala index b0d53ace22..fe1b3f5934 100644 --- a/src/main/scala/io/iohk/ethereum/extvm/VMServer.scala +++ b/src/main/scala/io/iohk/ethereum/extvm/VMServer.scala @@ -184,6 +184,7 @@ class VMServer(messageHandler: MessageHandler) eip161BlockNumber = conf.eip161BlockNumber, byzantiumBlockNumber = BigInt(4370000), //TODO include byzantium block number in protobuf constantinopleBlockNumber = BigInt(10000000), //TODO include constantinople block number in protobuf + istanbulBlockNumber = BigInt(10000000), //TODO include istanbul block number in protobuf maxCodeSize = if (conf.maxCodeSize.isEmpty) None else Some(bigintFromGByteString(conf.maxCodeSize)), accountStartNonce = conf.accountStartNonce, atlantisBlockNumber = BigInt(8772000), //TODO include atlantis block number in protobuf diff --git a/src/main/scala/io/iohk/ethereum/jsonrpc/TestService.scala b/src/main/scala/io/iohk/ethereum/jsonrpc/TestService.scala index 1f436fb282..24cb0f76bd 100644 --- a/src/main/scala/io/iohk/ethereum/jsonrpc/TestService.scala +++ b/src/main/scala/io/iohk/ethereum/jsonrpc/TestService.scala @@ -73,6 +73,7 @@ class TestService( override val eip161BlockNumber: BigInt = testLedgerWrapper.blockchainConfig.eip161BlockNumber override val byzantiumBlockNumber: BigInt = testLedgerWrapper.blockchainConfig.byzantiumBlockNumber override val constantinopleBlockNumber: BigInt = testLedgerWrapper.blockchainConfig.constantinopleBlockNumber + override val istanbulBlockNumber: BigInt = testLedgerWrapper.blockchainConfig.istanbulBlockNumber override val maxCodeSize: Option[BigInt] = testLedgerWrapper.blockchainConfig.maxCodeSize override val difficultyBombPauseBlockNumber: BigInt = testLedgerWrapper.blockchainConfig.difficultyBombPauseBlockNumber override val difficultyBombContinueBlockNumber: BigInt = testLedgerWrapper.blockchainConfig.difficultyBombContinueBlockNumber diff --git a/src/main/scala/io/iohk/ethereum/utils/Config.scala b/src/main/scala/io/iohk/ethereum/utils/Config.scala index 69eed9cacd..fab08f808f 100644 --- a/src/main/scala/io/iohk/ethereum/utils/Config.scala +++ b/src/main/scala/io/iohk/ethereum/utils/Config.scala @@ -348,6 +348,7 @@ trait BlockchainConfig { val eip161BlockNumber: BigInt val byzantiumBlockNumber: BigInt val constantinopleBlockNumber: BigInt + val istanbulBlockNumber: BigInt val maxCodeSize: Option[BigInt] val difficultyBombPauseBlockNumber: BigInt val difficultyBombContinueBlockNumber: BigInt @@ -389,6 +390,7 @@ object BlockchainConfig { override val eip161BlockNumber: BigInt = BigInt(blockchainConfig.getString("eip161-block-number")) override val byzantiumBlockNumber: BigInt = BigInt(blockchainConfig.getString("byzantium-block-number")) override val constantinopleBlockNumber: BigInt = BigInt(blockchainConfig.getString("constantinople-block-number")) + override val istanbulBlockNumber: BigInt = BigInt(blockchainConfig.getString("istanbul-block-number")) override val maxCodeSize: Option[BigInt] = Try(BigInt(blockchainConfig.getString("max-code-size"))).toOption override val difficultyBombPauseBlockNumber: BigInt = BigInt(blockchainConfig.getString("difficulty-bomb-pause-block-number")) override val difficultyBombContinueBlockNumber: BigInt = BigInt(blockchainConfig.getString("difficulty-bomb-continue-block-number")) diff --git a/src/main/scala/io/iohk/ethereum/vm/BlockchainConfigForEvm.scala b/src/main/scala/io/iohk/ethereum/vm/BlockchainConfigForEvm.scala index 80664f978e..7a45b988a2 100644 --- a/src/main/scala/io/iohk/ethereum/vm/BlockchainConfigForEvm.scala +++ b/src/main/scala/io/iohk/ethereum/vm/BlockchainConfigForEvm.scala @@ -3,14 +3,16 @@ package io.iohk.ethereum.vm import io.iohk.ethereum.domain.UInt256 import io.iohk.ethereum.utils.BlockchainConfig import io.iohk.ethereum.vm.BlockchainConfigForEvm.EtcForks.{Agharta, Atlantis, BeforeAtlantis, EtcFork, Phoenix} -import io.iohk.ethereum.vm.BlockchainConfigForEvm.EthForks.{BeforeByzantium, Byzantium, Constantinople, Petersburg} +import io.iohk.ethereum.vm.BlockchainConfigForEvm.EthForks.{BeforeByzantium, Byzantium, Constantinople, Istanbul, Petersburg} /** * A subset of [[io.iohk.ethereum.utils.BlockchainConfig]] that is required for instantiating an [[EvmConfig]] * Note that `accountStartNonce` is required for a [[WorldStateProxy]] implementation that is used * by a given VM */ +// FIXME manage etc/eth forks in a more sophisticated way case class BlockchainConfigForEvm( + // ETH forks frontierBlockNumber: BigInt, homesteadBlockNumber: BigInt, eip150BlockNumber: BigInt, @@ -18,8 +20,10 @@ case class BlockchainConfigForEvm( eip161BlockNumber: BigInt, byzantiumBlockNumber: BigInt, constantinopleBlockNumber: BigInt, + istanbulBlockNumber: BigInt, maxCodeSize: Option[BigInt], accountStartNonce: UInt256, + // ETC forks atlantisBlockNumber: BigInt, aghartaBlockNumber: BigInt, petersburgBlockNumber: BigInt, @@ -37,8 +41,8 @@ case class BlockchainConfigForEvm( case _ if blockNumber < byzantiumBlockNumber => BeforeByzantium case _ if blockNumber < constantinopleBlockNumber => Byzantium case _ if blockNumber < petersburgBlockNumber => Constantinople - case _ if blockNumber >= petersburgBlockNumber => Petersburg - // TODO add Istanbul + case _ if blockNumber < istanbulBlockNumber => Petersburg + case _ if blockNumber >= istanbulBlockNumber => Istanbul } } @@ -65,6 +69,7 @@ object BlockchainConfigForEvm { eip161BlockNumber = eip161BlockNumber, byzantiumBlockNumber = byzantiumBlockNumber, constantinopleBlockNumber = constantinopleBlockNumber, + istanbulBlockNumber = istanbulBlockNumber, maxCodeSize = maxCodeSize, accountStartNonce = accountStartNonce, atlantisBlockNumber = atlantisBlockNumber, diff --git a/src/main/scala/io/iohk/ethereum/vm/EvmConfig.scala b/src/main/scala/io/iohk/ethereum/vm/EvmConfig.scala index ced7ea330f..7ed1751c84 100644 --- a/src/main/scala/io/iohk/ethereum/vm/EvmConfig.scala +++ b/src/main/scala/io/iohk/ethereum/vm/EvmConfig.scala @@ -36,6 +36,7 @@ object EvmConfig { blockchainConfig.eip161BlockNumber -> PostEIP161ConfigBuilder, blockchainConfig.byzantiumBlockNumber -> ByzantiumConfigBuilder, blockchainConfig.constantinopleBlockNumber -> ConstantinopleConfigBuilder, + blockchainConfig.istanbulBlockNumber -> IstanbulConfigBuilder, blockchainConfig.atlantisBlockNumber -> AtlantisConfigBuilder, blockchainConfig.aghartaBlockNumber -> AghartaConfigBuilder, blockchainConfig.petersburgBlockNumber -> PetersburgConfigBuilder, @@ -99,6 +100,8 @@ object EvmConfig { val PetersburgConfigBuilder: EvmConfigBuilder = config => ConstantinopleConfigBuilder(config) + val IstanbulConfigBuilder: EvmConfigBuilder = config => PhoenixConfigBuilder(config) + // Ethereum classic forks only val AtlantisConfigBuilder: EvmConfigBuilder = config => PostEIP160ConfigBuilder(config).copy( feeSchedule = new FeeSchedule.AtlantisFeeSchedule, diff --git a/src/test/scala/io/iohk/ethereum/consensus/BlockGeneratorSpec.scala b/src/test/scala/io/iohk/ethereum/consensus/BlockGeneratorSpec.scala index a65c4b47e6..ef34564ef3 100644 --- a/src/test/scala/io/iohk/ethereum/consensus/BlockGeneratorSpec.scala +++ b/src/test/scala/io/iohk/ethereum/consensus/BlockGeneratorSpec.scala @@ -150,6 +150,7 @@ class BlockGeneratorSpec extends FlatSpec with Matchers with PropertyChecks with override val eip106BlockNumber: BigInt = Long.MaxValue override val byzantiumBlockNumber: BigInt = Long.MaxValue override val constantinopleBlockNumber: BigInt = Long.MaxValue + override val istanbulBlockNumber: BigInt = Long.MaxValue override val chainId: Byte = 0x3d.toByte override val networkId: Int = 1 override val customGenesisFileOpt: Option[String] = Some("test-genesis.json") @@ -321,6 +322,7 @@ class BlockGeneratorSpec extends FlatSpec with Matchers with PropertyChecks with override val eip106BlockNumber: BigInt = Long.MaxValue override val byzantiumBlockNumber: BigInt = Long.MaxValue override val constantinopleBlockNumber: BigInt = Long.MaxValue + override val istanbulBlockNumber: BigInt = Long.MaxValue override val chainId: Byte = 0x3d.toByte override val customGenesisFileOpt: Option[String] = Some("test-genesis.json") override val monetaryPolicyConfig: MonetaryPolicyConfig = diff --git a/src/test/scala/io/iohk/ethereum/consensus/validators/BlockHeaderValidatorSpec.scala b/src/test/scala/io/iohk/ethereum/consensus/validators/BlockHeaderValidatorSpec.scala index 00b044f726..e6d686e7c6 100644 --- a/src/test/scala/io/iohk/ethereum/consensus/validators/BlockHeaderValidatorSpec.scala +++ b/src/test/scala/io/iohk/ethereum/consensus/validators/BlockHeaderValidatorSpec.scala @@ -358,7 +358,8 @@ class BlockHeaderValidatorSpec override val difficultyBombContinueBlockNumber: BigInt = 5000000 override val difficultyBombRemovalBlockNumber: BigInt = 5900000 override val byzantiumBlockNumber: BigInt = 4370000 - override val constantinopleBlockNumber: BigInt = 10000000 //todo + override val constantinopleBlockNumber: BigInt = 7280000 + override val istanbulBlockNumber: BigInt = 9069000 override val daoForkConfig: Option[DaoForkConfig] = Some(new DaoForkConfig { override val blockExtraData: Option[ByteString] = if(supportsDaoFork) Some(ProDaoForkBlock.header.extraData) else None diff --git a/src/test/scala/io/iohk/ethereum/extvm/VMClientSpec.scala b/src/test/scala/io/iohk/ethereum/extvm/VMClientSpec.scala index 1a5edb09d2..2de0ce6b4b 100644 --- a/src/test/scala/io/iohk/ethereum/extvm/VMClientSpec.scala +++ b/src/test/scala/io/iohk/ethereum/extvm/VMClientSpec.scala @@ -173,6 +173,7 @@ class VMClientSpec extends FlatSpec with Matchers with MockFactory { eip161BlockNumber = 0, byzantiumBlockNumber = 0, constantinopleBlockNumber = 0, + istanbulBlockNumber = 0, maxCodeSize = None, accountStartNonce = 0, atlantisBlockNumber = 0, diff --git a/src/test/scala/io/iohk/ethereum/jsonrpc/EthServiceSpec.scala b/src/test/scala/io/iohk/ethereum/jsonrpc/EthServiceSpec.scala index dc10d45a0f..971d154169 100644 --- a/src/test/scala/io/iohk/ethereum/jsonrpc/EthServiceSpec.scala +++ b/src/test/scala/io/iohk/ethereum/jsonrpc/EthServiceSpec.scala @@ -884,6 +884,7 @@ class EthServiceSpec extends FlatSpec with Matchers with ScalaFutures with MockF override val eip106BlockNumber: BigInt = 0 override val byzantiumBlockNumber: BigInt = 0 override val constantinopleBlockNumber: BigInt = 0 + override val istanbulBlockNumber: BigInt = 0 override val difficultyBombPauseBlockNumber: BigInt = 0 override val difficultyBombContinueBlockNumber: BigInt = 0 override val difficultyBombRemovalBlockNumber: BigInt = 0 diff --git a/src/test/scala/io/iohk/ethereum/jsonrpc/PersonalServiceSpec.scala b/src/test/scala/io/iohk/ethereum/jsonrpc/PersonalServiceSpec.scala index 0483724171..b4f32c5708 100644 --- a/src/test/scala/io/iohk/ethereum/jsonrpc/PersonalServiceSpec.scala +++ b/src/test/scala/io/iohk/ethereum/jsonrpc/PersonalServiceSpec.scala @@ -431,6 +431,7 @@ class PersonalServiceSpec extends FlatSpec with Matchers with MockFactory with S override val eip106BlockNumber: BigInt = 0 override val byzantiumBlockNumber: BigInt = 0 override val constantinopleBlockNumber: BigInt = 0 + override val istanbulBlockNumber: BigInt = 0 override val difficultyBombPauseBlockNumber: BigInt = 0 override val difficultyBombContinueBlockNumber: BigInt = 0 override val difficultyBombRemovalBlockNumber: BigInt = Long.MaxValue diff --git a/src/test/scala/io/iohk/ethereum/ledger/LedgerTestSetup.scala b/src/test/scala/io/iohk/ethereum/ledger/LedgerTestSetup.scala index 5dc4515df4..13be3b6a02 100644 --- a/src/test/scala/io/iohk/ethereum/ledger/LedgerTestSetup.scala +++ b/src/test/scala/io/iohk/ethereum/ledger/LedgerTestSetup.scala @@ -201,6 +201,7 @@ trait DaoForkTestSetup extends TestSetup with MockFactory { override val eip150BlockNumber: BigInt = blockchainConfig.eip150BlockNumber override val byzantiumBlockNumber: BigInt = blockchainConfig.byzantiumBlockNumber override val constantinopleBlockNumber: BigInt = blockchainConfig.constantinopleBlockNumber + override val istanbulBlockNumber: BigInt = blockchainConfig.istanbulBlockNumber override val chainId: Byte = 0x01.toByte override val networkId: Int = 1 override val difficultyBombContinueBlockNumber: BigInt = blockchainConfig.difficultyBombContinueBlockNumber diff --git a/src/test/scala/io/iohk/ethereum/ledger/StxLedgerSpec.scala b/src/test/scala/io/iohk/ethereum/ledger/StxLedgerSpec.scala index 63f50fd538..7d473bce20 100644 --- a/src/test/scala/io/iohk/ethereum/ledger/StxLedgerSpec.scala +++ b/src/test/scala/io/iohk/ethereum/ledger/StxLedgerSpec.scala @@ -114,6 +114,7 @@ trait ScenarioSetup extends EphemBlockchainTestSetup { override val eip106BlockNumber: BigInt = 0 override val byzantiumBlockNumber: BigInt = 0 override val constantinopleBlockNumber: BigInt = 0 + override val istanbulBlockNumber: BigInt = 0 override val difficultyBombPauseBlockNumber: BigInt = 0 override val difficultyBombContinueBlockNumber: BigInt = 0 override val difficultyBombRemovalBlockNumber: BigInt = Long.MaxValue diff --git a/src/test/scala/io/iohk/ethereum/network/handshaker/EtcHandshakerSpec.scala b/src/test/scala/io/iohk/ethereum/network/handshaker/EtcHandshakerSpec.scala index 061348e5b3..2d14512d7f 100644 --- a/src/test/scala/io/iohk/ethereum/network/handshaker/EtcHandshakerSpec.scala +++ b/src/test/scala/io/iohk/ethereum/network/handshaker/EtcHandshakerSpec.scala @@ -184,6 +184,7 @@ class EtcHandshakerSpec extends FlatSpec with Matchers { override val eip106BlockNumber: BigInt = 0 override val byzantiumBlockNumber: BigInt = 0 override val constantinopleBlockNumber: BigInt = 0 + override val istanbulBlockNumber: BigInt = 0 override val difficultyBombPauseBlockNumber: BigInt = 0 override val difficultyBombContinueBlockNumber: BigInt = 0 override val difficultyBombRemovalBlockNumber: BigInt = Long.MaxValue diff --git a/src/test/scala/io/iohk/ethereum/vm/Fixtures.scala b/src/test/scala/io/iohk/ethereum/vm/Fixtures.scala index e20a57d8e3..78260e8773 100644 --- a/src/test/scala/io/iohk/ethereum/vm/Fixtures.scala +++ b/src/test/scala/io/iohk/ethereum/vm/Fixtures.scala @@ -5,6 +5,7 @@ object Fixtures { val ConstantinopleBlockNumber = 200 val PetersburgBlockNumber = 400 val PhoenixBlockNumber = 600 + val IstanbulBlockNumber = 600 val blockchainConfig = BlockchainConfigForEvm( // block numbers are irrelevant @@ -15,6 +16,7 @@ object Fixtures { eip161BlockNumber = 0, byzantiumBlockNumber = 0, constantinopleBlockNumber = ConstantinopleBlockNumber, + istanbulBlockNumber = IstanbulBlockNumber, maxCodeSize = None, accountStartNonce = 0, atlantisBlockNumber = 0, diff --git a/src/test/scala/io/iohk/ethereum/vm/VMSpec.scala b/src/test/scala/io/iohk/ethereum/vm/VMSpec.scala index f4d600b64a..d38fa134ad 100644 --- a/src/test/scala/io/iohk/ethereum/vm/VMSpec.scala +++ b/src/test/scala/io/iohk/ethereum/vm/VMSpec.scala @@ -153,6 +153,7 @@ class VMSpec extends WordSpec with PropertyChecks with Matchers { eip161BlockNumber = Long.MaxValue, byzantiumBlockNumber = Long.MaxValue, constantinopleBlockNumber = Long.MaxValue, + istanbulBlockNumber = Long.MaxValue, maxCodeSize = Some(16), accountStartNonce = 0, atlantisBlockNumber = Long.MaxValue,