Skip to content

Commit c153333

Browse files
author
Michał Mrożek
authored
Merge pull request #644 from input-output-hk/etcm-28-petersbug-changes
[ETCM-28] petersburg changes
2 parents 1fd0a07 + 379ff3d commit c153333

File tree

22 files changed

+52
-8
lines changed

22 files changed

+52
-8
lines changed

src/ets/scala/io/iohk/ethereum/ets/blockchain/BlockchainTestConfig.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ trait BlockchainTestConfig extends BlockchainConfig {
3939
override val atlantisBlockNumber: BigInt = Long.MaxValue
4040
override val aghartaBlockNumber: BigInt = Long.MaxValue
4141
override val phoenixBlockNumber: BigInt = Long.MaxValue
42+
override val petersburgBlockNumber: BigInt = Long.MaxValue
4243
}
4344

4445
object FrontierConfig extends BlockchainTestConfig {

src/it/scala/io/iohk/ethereum/txExecTest/ECIP1017Test.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class ECIP1017Test extends FlatSpec with Matchers {
4545
override val atlantisBlockNumber: BigInt = Long.MaxValue
4646
override val aghartaBlockNumber: BigInt = Long.MaxValue
4747
override val phoenixBlockNumber: BigInt = Long.MaxValue
48+
override val petersburgBlockNumber: BigInt = Long.MaxValue
4849
}
4950
val ec = ExecutionContext.fromExecutor(Executors.newFixedThreadPool(4))
5051

src/it/scala/io/iohk/ethereum/txExecTest/ForksTest.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class ForksTest extends FlatSpec with Matchers {
4242
override val atlantisBlockNumber: BigInt = Long.MaxValue
4343
override val aghartaBlockNumber: BigInt = Long.MaxValue
4444
override val phoenixBlockNumber: BigInt = Long.MaxValue
45+
override val petersburgBlockNumber: BigInt = Long.MaxValue
4546
}
4647

4748
val noErrors = a[Right[_, Seq[Receipt]]]

src/main/resources/chains/base.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@
7070
# https://github.com/ethereum/pm/issues/53
7171
constantinople-block-number = "1000000000000000000"
7272

73+
# Petersburg fork block number (ETH only)
74+
# https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1716.md
75+
petersburg-block-number = "1000000000000000000"
76+
7377
# DAO fork configuration (Ethereum HF/Classic split)
7478
# https://blog.ethereum.org/2016/07/20/hard-fork-completed/
7579
dao {

src/main/resources/chains/eth.conf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
# Constantinople fork block number (ETH only)
1414
# https://github.com/ethereum/pm/issues/53
15-
constantinople-block-number = "7080000"
15+
constantinople-block-number = "7280000"
1616

1717
# EIP-170 max code size (Enabled from eip161-block-number)
1818
max-code-size = "24576"
@@ -37,6 +37,10 @@
3737
# https://ecips.ethereumclassic.org/ECIPs/ecip-1088
3838
phoenix-block-number = "1000000000000000000"
3939

40+
# Petersburg fork block number (ETH only)
41+
# https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1716.md
42+
petersburg-block-number = "7280000"
43+
4044
monetary-policy {
4145

4246
# Setting era-duration for eth and ropsten chain to big number is necessery to ensure

src/main/scala/io/iohk/ethereum/extvm/VMServer.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ class VMServer(messageHandler: MessageHandler)
188188
accountStartNonce = conf.accountStartNonce,
189189
atlantisBlockNumber = BigInt(8772000), //TODO include atlantis block number in protobuf
190190
aghartaBlockNumber = BigInt(9573000), //TODO include agharta block number in protobuf
191+
petersburgBlockNumber = BigInt(10000000), //TODO include petersburg block number in protobuf
191192
phoenixBlockNumber = BigInt(10500839), //TODO include phoenix block number in protobuf
192193
chainId = 0x3d.toByte //TODO include chainId in protobuf
193194
)

src/main/scala/io/iohk/ethereum/jsonrpc/TestService.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class TestService(
6161

6262
private var etherbase: Address = consensusConfig.coinbase
6363

64+
// scalastyle:off method.length
6465
def setChainParams(request: SetChainParamsRequest): ServiceResponse[SetChainParamsResponse] = {
6566
val newBlockchainConfig = new BlockchainConfig {
6667
override val frontierBlockNumber: BigInt = testLedgerWrapper.blockchainConfig.frontierBlockNumber
@@ -88,7 +89,9 @@ class TestService(
8889
override val atlantisBlockNumber: BigInt = testLedgerWrapper.blockchainConfig.atlantisBlockNumber
8990
override val aghartaBlockNumber: BigInt = testLedgerWrapper.blockchainConfig.aghartaBlockNumber
9091
override val phoenixBlockNumber: BigInt = testLedgerWrapper.blockchainConfig.phoenixBlockNumber
92+
override val petersburgBlockNumber: BigInt = testLedgerWrapper.blockchainConfig.petersburgBlockNumber
9193
}
94+
// scalastyle:on method.length
9295

9396
val genesisData = GenesisData(
9497
nonce = ByteString(Hex.decode("00")),

src/main/scala/io/iohk/ethereum/utils/Config.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ trait BlockchainConfig {
373373
val atlantisBlockNumber: BigInt
374374
val aghartaBlockNumber: BigInt
375375
val phoenixBlockNumber: BigInt
376+
val petersburgBlockNumber: BigInt
376377
}
377378

378379
object BlockchainConfig {
@@ -419,6 +420,8 @@ object BlockchainConfig {
419420
override val aghartaBlockNumber: BigInt = BigInt(blockchainConfig.getString("agharta-block-number"))
420421

421422
override val phoenixBlockNumber: BigInt = BigInt(blockchainConfig.getString("phoenix-block-number"))
423+
424+
override val petersburgBlockNumber: BigInt = BigInt(blockchainConfig.getString("petersburg-block-number"))
422425
}
423426
}
424427
}

src/main/scala/io/iohk/ethereum/vm/BlockchainConfigForEvm.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ case class BlockchainConfigForEvm(
2020
accountStartNonce: UInt256,
2121
atlantisBlockNumber: BigInt,
2222
aghartaBlockNumber: BigInt,
23+
petersburgBlockNumber: BigInt,
2324
phoenixBlockNumber: BigInt,
2425
chainId: Byte
2526
)
@@ -39,6 +40,7 @@ object BlockchainConfigForEvm {
3940
accountStartNonce = accountStartNonce,
4041
atlantisBlockNumber = atlantisBlockNumber,
4142
aghartaBlockNumber = aghartaBlockNumber,
43+
petersburgBlockNumber = petersburgBlockNumber,
4244
phoenixBlockNumber = phoenixBlockNumber,
4345
chainId = chainId
4446
)

src/main/scala/io/iohk/ethereum/vm/EvmConfig.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ object EvmConfig {
3838
blockchainConfig.constantinopleBlockNumber -> ConstantinopleConfigBuilder,
3939
blockchainConfig.atlantisBlockNumber -> AtlantisConfigBuilder,
4040
blockchainConfig.aghartaBlockNumber -> AghartaConfigBuilder,
41+
blockchainConfig.petersburgBlockNumber -> PetersburgConfigBuilder,
4142
blockchainConfig.phoenixBlockNumber -> PhoenixConfigBuilder
4243
)
4344

@@ -96,6 +97,8 @@ object EvmConfig {
9697
opCodeList = ConstantinopleOpCodes
9798
)
9899

100+
val PetersburgConfigBuilder: EvmConfigBuilder = config => ConstantinopleConfigBuilder(config)
101+
99102
// Ethereum classic forks only
100103
val AtlantisConfigBuilder: EvmConfigBuilder = config => PostEIP160ConfigBuilder(config).copy(
101104
feeSchedule = new FeeSchedule.AtlantisFeeSchedule,

src/main/scala/io/iohk/ethereum/vm/OpCode.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ case object SSTORE extends OpCode(0x55, 2, 0, _.G_zero) {
594594
protected def exec[W <: WorldStateProxy[W, S], S <: Storage[S]](state: ProgramState[W, S]): ProgramState[W, S] = {
595595
val (Seq(offset, newValue), stack1) = state.stack.pop(2)
596596
val currentValue = state.storage.load(offset)
597-
val refund: BigInt = if (isAfterConstantinopleFork(state)) {
597+
val refund: BigInt = if (isEip1283Enabled(state)) {
598598
val originalValue = state.originalWorld.getStorage(state.ownAddress).load(offset)
599599
if (currentValue != newValue.toBigInt) {
600600
if (originalValue == currentValue) { // fresh slot
@@ -636,7 +636,7 @@ case object SSTORE extends OpCode(0x55, 2, 0, _.G_zero) {
636636
protected def varGas[W <: WorldStateProxy[W, S], S <: Storage[S]](state: ProgramState[W, S]): BigInt = {
637637
val (Seq(offset, newValue), _) = state.stack.pop(2)
638638
val currentValue = state.storage.load(offset)
639-
if (isAfterConstantinopleFork(state)) {
639+
if (isEip1283Enabled(state)) {
640640
// https://eips.ethereum.org/EIPS/eip-1283
641641
if (currentValue == newValue.toBigInt) { // no-op
642642
state.config.feeSchedule.G_sload
@@ -662,8 +662,10 @@ case object SSTORE extends OpCode(0x55, 2, 0, _.G_zero) {
662662

663663
override protected def availableInContext[W <: WorldStateProxy[W, S], S <: Storage[S]]: ProgramState[W, S] => Boolean = !_.staticCtx
664664

665-
private def isAfterConstantinopleFork[W <: WorldStateProxy[W, S], S <: Storage[S]](state: ProgramState[W, S]): Boolean =
666-
state.env.blockHeader.number >= state.config.blockchainConfig.constantinopleBlockNumber
665+
private def isEip1283Enabled[W <: WorldStateProxy[W, S], S <: Storage[S]](state: ProgramState[W, S]): Boolean = {
666+
val blockNumber = state.env.blockHeader.number
667+
blockNumber >= state.config.blockchainConfig.constantinopleBlockNumber && blockNumber < state.config.blockchainConfig.petersburgBlockNumber
668+
}
667669
}
668670

669671
case object JUMP extends OpCode(0x56, 1, 0, _.G_mid) with ConstGas {

src/test/scala/io/iohk/ethereum/consensus/BlockGeneratorSpec.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ class BlockGeneratorSpec extends FlatSpec with Matchers with PropertyChecks with
169169
override val atlantisBlockNumber: BigInt = Long.MaxValue
170170
override val aghartaBlockNumber: BigInt = Long.MaxValue
171171
override val phoenixBlockNumber: BigInt = Long.MaxValue
172+
override val petersburgBlockNumber: BigInt = Long.MaxValue
172173
}
173174

174175
override lazy val blockExecution = new BlockExecution(blockchain, blockchainConfig, consensus.blockPreparator, blockValidation)
@@ -339,6 +340,8 @@ class BlockGeneratorSpec extends FlatSpec with Matchers with PropertyChecks with
339340
override val atlantisBlockNumber: BigInt = Long.MaxValue
340341
override val aghartaBlockNumber: BigInt = Long.MaxValue
341342
override val phoenixBlockNumber: BigInt = Long.MaxValue
343+
override val petersburgBlockNumber: BigInt = Long.MaxValue
344+
342345
}
343346

344347
val genesisDataLoader = new GenesisDataLoader(blockchain, blockchainConfig)

src/test/scala/io/iohk/ethereum/consensus/validators/BlockHeaderValidatorSpec.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ class BlockHeaderValidatorSpec
387387
override val atlantisBlockNumber: BigInt = Long.MaxValue
388388
override val aghartaBlockNumber: BigInt = Long.MaxValue
389389
override val phoenixBlockNumber: BigInt = Long.MaxValue
390+
override val petersburgBlockNumber: BigInt = Long.MaxValue
390391
}
391392

392393
val ProDaoBlock1920008Header = BlockHeader(

src/test/scala/io/iohk/ethereum/extvm/VMClientSpec.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ class VMClientSpec extends FlatSpec with Matchers with MockFactory {
177177
accountStartNonce = 0,
178178
atlantisBlockNumber = 0,
179179
aghartaBlockNumber = 0,
180+
petersburgBlockNumber = 0,
180181
phoenixBlockNumber = 0,
181182
chainId = 0x3d.toByte
182183
)

src/test/scala/io/iohk/ethereum/jsonrpc/EthServiceSpec.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,7 @@ class EthServiceSpec extends FlatSpec with Matchers with ScalaFutures with MockF
896896
override val atlantisBlockNumber: BigInt = 0
897897
override val aghartaBlockNumber: BigInt = 0
898898
override val phoenixBlockNumber: BigInt = 0
899+
override val petersburgBlockNumber: BigInt = 0
899900
}
900901

901902
override lazy val consensus: TestConsensus = buildTestConsensus().withBlockGenerator(blockGenerator)

src/test/scala/io/iohk/ethereum/jsonrpc/PersonalServiceSpec.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ class PersonalServiceSpec extends FlatSpec with Matchers with MockFactory with S
444444
override val atlantisBlockNumber: BigInt = 0
445445
override val aghartaBlockNumber: BigInt = 0
446446
override val phoenixBlockNumber: BigInt = 0
447+
override val petersburgBlockNumber: BigInt = 0
447448
}
448449

449450
val wallet = Wallet(address, prvKey)

src/test/scala/io/iohk/ethereum/ledger/LedgerTestSetup.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ trait DaoForkTestSetup extends TestSetup with MockFactory {
214214
override val atlantisBlockNumber: BigInt = Long.MaxValue
215215
override val aghartaBlockNumber: BigInt = Long.MaxValue
216216
override val phoenixBlockNumber: BigInt = Long.MaxValue
217+
override val petersburgBlockNumber: BigInt = Long.MaxValue
217218
}
218219

219220
(testBlockchain.getBlockHeaderByHash _).expects(proDaoBlock.header.parentHash).returning(Some(Fixtures.Blocks.DaoParentBlock.header))

src/test/scala/io/iohk/ethereum/ledger/StxLedgerSpec.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ trait ScenarioSetup extends EphemBlockchainTestSetup {
127127
override val atlantisBlockNumber: BigInt = 0
128128
override val aghartaBlockNumber: BigInt = 0
129129
override val phoenixBlockNumber: BigInt = 0
130+
override val petersburgBlockNumber: BigInt = 0
130131
}
131132

132133
override lazy val stxLedger = new StxLedger(blockchain, blockchainConfig, consensus.blockPreparator)

src/test/scala/io/iohk/ethereum/network/handshaker/EtcHandshakerSpec.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ class EtcHandshakerSpec extends FlatSpec with Matchers {
206206
override val atlantisBlockNumber: BigInt = 0
207207
override val aghartaBlockNumber: BigInt = 0
208208
override val phoenixBlockNumber: BigInt = 0
209+
override val petersburgBlockNumber: BigInt = 0
209210
}
210211

211212
val etcHandshakerConfigurationWithResolver = new MockEtcHandshakerConfiguration {

src/test/scala/io/iohk/ethereum/vm/Fixtures.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package io.iohk.ethereum.vm
33
object Fixtures {
44

55
val ConstantinopleBlockNumber = 200
6+
val PetersburgBlockNumber = 400
67

78
val blockchainConfig = BlockchainConfigForEvm(
89
// block numbers are irrelevant
@@ -17,6 +18,7 @@ object Fixtures {
1718
accountStartNonce = 0,
1819
atlantisBlockNumber = 0,
1920
aghartaBlockNumber = 0,
21+
petersburgBlockNumber = PetersburgBlockNumber,
2022
phoenixBlockNumber = 0,
2123
chainId = 0x3d.toByte
2224
)

src/test/scala/io/iohk/ethereum/vm/OpCodeGasSpec.scala

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import io.iohk.ethereum.vm.Generators._
66
import org.scalatest.prop.PropertyChecks
77
import org.scalatest.{FunSuite, Matchers}
88
import Fixtures.blockchainConfig
9+
import org.scalacheck.Gen
910

1011
class OpCodeGasSpec extends FunSuite with OpCodeTesting with Matchers with PropertyChecks {
1112

@@ -421,15 +422,20 @@ class OpCodeGasSpec extends FunSuite with OpCodeTesting with Matchers with Prope
421422

422423
forAll(table) { (offset, value, expectedGas, _) =>
423424
val stackIn = Stack.empty().push(value).push(offset)
424-
val stateIn = getProgramStateGen(blockNumberGen = getUInt256Gen(0, Fixtures.ConstantinopleBlockNumber - 1))
425-
.sample.get.withStack(stackIn).withStorage(storage).copy(gas = expectedGas)
425+
val stateIn = getProgramStateGen(blockNumberGen = Gen.frequency(
426+
(1, getUInt256Gen(0, Fixtures.ConstantinopleBlockNumber - 1)),
427+
(1, getUInt256Gen(Fixtures.PetersburgBlockNumber + 1, UInt256.MaxValue))
428+
)).sample.get.withStack(stackIn).withStorage(storage).copy(gas = expectedGas)
426429
val stateOut = op.execute(stateIn)
427430
verifyGas(expectedGas, stateIn, stateOut, allowOOG = false)
428431
}
429432

430433
val maxGasUsage = G_sset + G_sreset
431434
val stateGen = getProgramStateGen(
432-
blockNumberGen = getUInt256Gen(0, Fixtures.ConstantinopleBlockNumber - 1),
435+
blockNumberGen = Gen.frequency(
436+
(1, getUInt256Gen(0, Fixtures.ConstantinopleBlockNumber - 1)),
437+
(1, getUInt256Gen(Fixtures.PetersburgBlockNumber + 1, UInt256.MaxValue))
438+
),
433439
stackGen = getStackGen(elems = 2, maxUInt = Two),
434440
gasGen = getBigIntGen(max = maxGasUsage),
435441
storageGen = getStorageGen(3, getUInt256Gen(max = One))

src/test/scala/io/iohk/ethereum/vm/VMSpec.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ class VMSpec extends WordSpec with PropertyChecks with Matchers {
157157
accountStartNonce = 0,
158158
atlantisBlockNumber = Long.MaxValue,
159159
aghartaBlockNumber = Long.MaxValue,
160+
petersburgBlockNumber = Long.MaxValue,
160161
phoenixBlockNumber = Long.MaxValue,
161162
chainId = 0x3d.toByte
162163
)

0 commit comments

Comments
 (0)