Skip to content

Commit 2136f9b

Browse files
committed
[ETCM-19] EIP-1344: ChainID opcode
1 parent 1259ef7 commit 2136f9b

File tree

7 files changed

+28
-7
lines changed

7 files changed

+28
-7
lines changed

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

+2-1
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+
chainId = 0x3d.toByte //TODO include chainId in protobuf
192193
)
193194
}
194195
}

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

+4-2
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+
chainId: Byte
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+
chainId = chainId
4244
)
4345
}
4446

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

+11-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import akka.util.ByteString
44
import io.iohk.ethereum.domain.UInt256
55
import io.iohk.ethereum.utils.BlockchainConfig
66
import EvmConfig._
7+
import io.iohk.ethereum
78
import io.iohk.ethereum.vm
89

910
// scalastyle:off number.of.methods
@@ -36,7 +37,8 @@ object EvmConfig {
3637
blockchainConfig.byzantiumBlockNumber -> ByzantiumConfigBuilder,
3738
blockchainConfig.constantinopleBlockNumber -> ConstantinopleConfigBuilder,
3839
blockchainConfig.atlantisBlockNumber -> AtlantisConfigBuilder,
39-
blockchainConfig.aghartaBlockNumber -> AghartaConfigBuilder
40+
blockchainConfig.aghartaBlockNumber -> AghartaConfigBuilder,
41+
blockchainConfig.phoenixBlockNumber -> PhoenixConfigBuilder
4042
)
4143

4244
// highest transition block that is less/equal to `blockNumber`
@@ -53,6 +55,7 @@ object EvmConfig {
5355
val AtlantisOpCodes = ByzantiumOpCodes
5456
val ConstantinopleOpCodes = OpCodeList(OpCodes.ConstantinopleOpCodes)
5557
val AghartaOpCodes = ConstantinopleOpCodes
58+
val PhoenixOpCodes = OpCodeList(OpCodes.PhoenixOpCodes)
5659

5760
val FrontierConfigBuilder: EvmConfigBuilder = config => EvmConfig(
5861
blockchainConfig = config,
@@ -105,6 +108,11 @@ object EvmConfig {
105108
opCodeList = AghartaOpCodes
106109
)
107110

111+
val PhoenixConfigBuilder: EvmConfigBuilder = config => AghartaConfigBuilder(config).copy(
112+
feeSchedule = new ethereum.vm.FeeSchedule.PhoenixFeeSchedule,
113+
opCodeList = PhoenixOpCodes
114+
)
115+
108116
case class OpCodeList(opCodes: List[OpCode]) {
109117
val byteToOpCode: Map[Byte, OpCode] =
110118
opCodes.map(op => op.code -> op).toMap
@@ -253,6 +261,8 @@ object FeeSchedule {
253261

254262
class AghartaFeeSchedule extends ByzantiumFeeSchedule
255263

264+
class PhoenixFeeSchedule extends AghartaFeeSchedule
265+
256266
}
257267

258268
trait FeeSchedule {

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

+5
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ object OpCodes {
166166

167167
val ConstantinopleOpCodes: List[OpCode] =
168168
List(EXTCODEHASH, CREATE2, SHL, SHR, SAR) ++ ByzantiumOpCodes
169+
170+
val PhoenixOpCodes: List[OpCode] =
171+
List(CHAINID) ++ ConstantinopleOpCodes
169172
}
170173

171174
object OpCode {
@@ -1149,3 +1152,5 @@ case object SELFDESTRUCT extends OpCode(0xff, 1, 0, _.G_selfdestruct) {
11491152

11501153
override protected def availableInContext[W <: WorldStateProxy[W, S], S <: Storage[S]]: ProgramState[W, S] => Boolean = !_.staticCtx
11511154
}
1155+
1156+
case object CHAINID extends ConstOp(0x46)(state => UInt256(state.env.evmConfig.blockchainConfig.chainId))

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

+2-1
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+
chainId = 0x3d.toByte
181182
)
182183
val evmConfig = EvmConfig.FrontierConfigBuilder(blockchainConfigForEvm)
183184

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ object Fixtures {
1717
accountStartNonce = 0,
1818
atlantisBlockNumber = 0,
1919
aghartaBlockNumber = 0,
20-
phoenixBlockNumber = 0
20+
phoenixBlockNumber = 0,
21+
chainId = 0x3d.toByte
2122
)
2223

2324
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ class VMSpec extends WordSpec with PropertyChecks with Matchers {
157157
accountStartNonce = 0,
158158
atlantisBlockNumber = Long.MaxValue,
159159
aghartaBlockNumber = Long.MaxValue,
160-
phoenixBlockNumber = Long.MaxValue
160+
phoenixBlockNumber = Long.MaxValue,
161+
chainId = 0x3d.toByte
161162
)
162163

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

0 commit comments

Comments
 (0)