Skip to content

Commit 9b1bb44

Browse files
committed
[ETCM-28] Petersburg fork
1 parent 2560382 commit 9b1bb44

File tree

19 files changed

+55
-14
lines changed

19 files changed

+55
-14
lines changed

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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ 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-
phoenixBlockNumber = BigInt(10500839) //TODO include phoenix block number in protobuf
191+
phoenixBlockNumber = BigInt(10500839), //TODO include phoenix block number in protobuf
192+
petersburgBlockNumber = BigInt(10000000) //TODO include petersburg block number in protobuf
192193
)
193194
}
194195
}

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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ case class BlockchainConfigForEvm(
2020
accountStartNonce: UInt256,
2121
atlantisBlockNumber: BigInt,
2222
aghartaBlockNumber: BigInt,
23-
phoenixBlockNumber: BigInt
23+
phoenixBlockNumber: BigInt,
24+
petersburgBlockNumber: BigInt
2425
)
2526

2627
object BlockchainConfigForEvm {
@@ -38,7 +39,8 @@ object BlockchainConfigForEvm {
3839
accountStartNonce = accountStartNonce,
3940
atlantisBlockNumber = atlantisBlockNumber,
4041
aghartaBlockNumber = aghartaBlockNumber,
41-
phoenixBlockNumber = phoenixBlockNumber
42+
phoenixBlockNumber = phoenixBlockNumber,
43+
petersburgBlockNumber = petersburgBlockNumber
4244
)
4345
}
4446

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ object EvmConfig {
3636
blockchainConfig.byzantiumBlockNumber -> ByzantiumConfigBuilder,
3737
blockchainConfig.constantinopleBlockNumber -> ConstantinopleConfigBuilder,
3838
blockchainConfig.atlantisBlockNumber -> AtlantisConfigBuilder,
39-
blockchainConfig.aghartaBlockNumber -> AghartaConfigBuilder
39+
blockchainConfig.aghartaBlockNumber -> AghartaConfigBuilder,
40+
blockchainConfig.petersburgBlockNumber -> PetersburgConfigBuilder
4041
)
4142

4243
// highest transition block that is less/equal to `blockNumber`
@@ -93,6 +94,8 @@ object EvmConfig {
9394
opCodeList = ConstantinopleOpCodes
9495
)
9596

97+
val PetersburgConfigBuilder: EvmConfigBuilder = config => ConstantinopleConfigBuilder(config)
98+
9699
// Ethereum classic forks only
97100
val AtlantisConfigBuilder: EvmConfigBuilder = config => PostEIP160ConfigBuilder(config).copy(
98101
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
@@ -591,7 +591,7 @@ case object SSTORE extends OpCode(0x55, 2, 0, _.G_zero) {
591591
protected def exec[W <: WorldStateProxy[W, S], S <: Storage[S]](state: ProgramState[W, S]): ProgramState[W, S] = {
592592
val (Seq(offset, newValue), stack1) = state.stack.pop(2)
593593
val currentValue = state.storage.load(offset)
594-
val refund: BigInt = if (isAfterConstantinopleFork(state)) {
594+
val refund: BigInt = if (isEip1283Enabled(state)) {
595595
val originalValue = state.originalWorld.getStorage(state.ownAddress).load(offset)
596596
if (currentValue != newValue.toBigInt) {
597597
if (originalValue == currentValue) { // fresh slot
@@ -633,7 +633,7 @@ case object SSTORE extends OpCode(0x55, 2, 0, _.G_zero) {
633633
protected def varGas[W <: WorldStateProxy[W, S], S <: Storage[S]](state: ProgramState[W, S]): BigInt = {
634634
val (Seq(offset, newValue), _) = state.stack.pop(2)
635635
val currentValue = state.storage.load(offset)
636-
if (isAfterConstantinopleFork(state)) {
636+
if (isEip1283Enabled(state)) {
637637
// https://eips.ethereum.org/EIPS/eip-1283
638638
if (currentValue == newValue.toBigInt) { // no-op
639639
state.config.feeSchedule.G_sload
@@ -659,8 +659,10 @@ case object SSTORE extends OpCode(0x55, 2, 0, _.G_zero) {
659659

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

662-
private def isAfterConstantinopleFork[W <: WorldStateProxy[W, S], S <: Storage[S]](state: ProgramState[W, S]): Boolean =
663-
state.env.blockHeader.number >= state.config.blockchainConfig.constantinopleBlockNumber
662+
private def isEip1283Enabled[W <: WorldStateProxy[W, S], S <: Storage[S]](state: ProgramState[W, S]): Boolean = {
663+
val blockNumber = state.env.blockHeader.number
664+
blockNumber >= state.config.blockchainConfig.constantinopleBlockNumber && blockNumber < state.config.blockchainConfig.petersburgBlockNumber
665+
}
664666
}
665667

666668
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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ class VMClientSpec extends FlatSpec with Matchers with MockFactory {
177177
accountStartNonce = 0,
178178
atlantisBlockNumber = 0,
179179
aghartaBlockNumber = 0,
180-
phoenixBlockNumber = 0
180+
phoenixBlockNumber = 0,
181+
petersburgBlockNumber = 0
181182
)
182183
val evmConfig = EvmConfig.FrontierConfigBuilder(blockchainConfigForEvm)
183184

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: 3 additions & 1 deletion
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,7 +18,8 @@ object Fixtures {
1718
accountStartNonce = 0,
1819
atlantisBlockNumber = 0,
1920
aghartaBlockNumber = 0,
20-
phoenixBlockNumber = 0
21+
phoenixBlockNumber = 0,
22+
petersburgBlockNumber = PetersburgBlockNumber
2123
)
2224

2325
}

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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ class VMSpec extends WordSpec with PropertyChecks with Matchers {
150150
accountStartNonce = 0,
151151
atlantisBlockNumber = Long.MaxValue,
152152
aghartaBlockNumber = Long.MaxValue,
153-
phoenixBlockNumber = Long.MaxValue
153+
phoenixBlockNumber = Long.MaxValue,
154+
petersburgBlockNumber = Long.MaxValue
154155
)
155156

156157
val homesteadConfig = EvmConfig.forBlock(0, evmBlockchainConfig.copy(homesteadBlockNumber = 0))

0 commit comments

Comments
 (0)