Skip to content

[ETCM-19] chainId opcode #645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main/scala/io/iohk/ethereum/extvm/VMServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ class VMServer(messageHandler: MessageHandler)
accountStartNonce = conf.accountStartNonce,
atlantisBlockNumber = BigInt(8772000), //TODO include atlantis block number in protobuf
aghartaBlockNumber = BigInt(9573000), //TODO include agharta block number in protobuf
phoenixBlockNumber = BigInt(10500839) //TODO include phoenix block number in protobuf
phoenixBlockNumber = BigInt(10500839), //TODO include phoenix block number in protobuf
chainId = 0x3d.toByte //TODO include chainId in protobuf
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ case class BlockchainConfigForEvm(
accountStartNonce: UInt256,
atlantisBlockNumber: BigInt,
aghartaBlockNumber: BigInt,
phoenixBlockNumber: BigInt
phoenixBlockNumber: BigInt,
chainId: Byte
)

object BlockchainConfigForEvm {
Expand All @@ -38,7 +39,8 @@ object BlockchainConfigForEvm {
accountStartNonce = accountStartNonce,
atlantisBlockNumber = atlantisBlockNumber,
aghartaBlockNumber = aghartaBlockNumber,
phoenixBlockNumber = phoenixBlockNumber
phoenixBlockNumber = phoenixBlockNumber,
chainId = chainId
)
}

Expand Down
12 changes: 11 additions & 1 deletion src/main/scala/io/iohk/ethereum/vm/EvmConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import akka.util.ByteString
import io.iohk.ethereum.domain.UInt256
import io.iohk.ethereum.utils.BlockchainConfig
import EvmConfig._
import io.iohk.ethereum
import io.iohk.ethereum.vm

// scalastyle:off number.of.methods
Expand Down Expand Up @@ -36,7 +37,8 @@ object EvmConfig {
blockchainConfig.byzantiumBlockNumber -> ByzantiumConfigBuilder,
blockchainConfig.constantinopleBlockNumber -> ConstantinopleConfigBuilder,
blockchainConfig.atlantisBlockNumber -> AtlantisConfigBuilder,
blockchainConfig.aghartaBlockNumber -> AghartaConfigBuilder
blockchainConfig.aghartaBlockNumber -> AghartaConfigBuilder,
blockchainConfig.phoenixBlockNumber -> PhoenixConfigBuilder
)

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

val FrontierConfigBuilder: EvmConfigBuilder = config => EvmConfig(
blockchainConfig = config,
Expand Down Expand Up @@ -105,6 +108,11 @@ object EvmConfig {
opCodeList = AghartaOpCodes
)

val PhoenixConfigBuilder: EvmConfigBuilder = config => AghartaConfigBuilder(config).copy(
feeSchedule = new ethereum.vm.FeeSchedule.PhoenixFeeSchedule,
opCodeList = PhoenixOpCodes
)

case class OpCodeList(opCodes: List[OpCode]) {
val byteToOpCode: Map[Byte, OpCode] =
opCodes.map(op => op.code -> op).toMap
Expand Down Expand Up @@ -253,6 +261,8 @@ object FeeSchedule {

class AghartaFeeSchedule extends ByzantiumFeeSchedule

class PhoenixFeeSchedule extends AghartaFeeSchedule

}

trait FeeSchedule {
Expand Down
5 changes: 5 additions & 0 deletions src/main/scala/io/iohk/ethereum/vm/OpCode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ object OpCodes {

val ConstantinopleOpCodes: List[OpCode] =
List(EXTCODEHASH, CREATE2, SHL, SHR, SAR) ++ ByzantiumOpCodes

val PhoenixOpCodes: List[OpCode] =
List(CHAINID) ++ ConstantinopleOpCodes
}

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

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

case object CHAINID extends ConstOp(0x46)(state => UInt256(state.env.evmConfig.blockchainConfig.chainId))
3 changes: 2 additions & 1 deletion src/test/scala/io/iohk/ethereum/extvm/VMClientSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ class VMClientSpec extends FlatSpec with Matchers with MockFactory {
accountStartNonce = 0,
atlantisBlockNumber = 0,
aghartaBlockNumber = 0,
phoenixBlockNumber = 0
phoenixBlockNumber = 0,
chainId = 0x3d.toByte
)
val evmConfig = EvmConfig.FrontierConfigBuilder(blockchainConfigForEvm)

Expand Down
3 changes: 2 additions & 1 deletion src/test/scala/io/iohk/ethereum/vm/Fixtures.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ object Fixtures {
accountStartNonce = 0,
atlantisBlockNumber = 0,
aghartaBlockNumber = 0,
phoenixBlockNumber = 0
phoenixBlockNumber = 0,
chainId = 0x3d.toByte
)

}
4 changes: 2 additions & 2 deletions src/test/scala/io/iohk/ethereum/vm/OpCodeFunSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class OpCodeFunSpec extends FunSuite with OpCodeTesting with Matchers with Prope

import MockWorldState.PS

override val config = EvmConfig.ByzantiumConfigBuilder(blockchainConfig)
override val config = EvmConfig.PhoenixConfigBuilder(blockchainConfig)

def executeOp(op: OpCode, stateIn: PS): PS = {
// gas is not tested in this spec
Expand Down Expand Up @@ -819,7 +819,7 @@ class OpCodeFunSpec extends FunSuite with OpCodeTesting with Matchers with Prope
}
}

verifyAllOpCodesRegistered(except = CREATE, CREATE2, CALL, CALLCODE, DELEGATECALL, STATICCALL)
verifyAllOpCodesRegistered(except = CREATE, CREATE2, CALL, CALLCODE, DELEGATECALL, STATICCALL, SHL, SHR, SAR)

test("sliceBytes helper") {
def zeroes(i: Int): ByteString =
Expand Down
3 changes: 2 additions & 1 deletion src/test/scala/io/iohk/ethereum/vm/VMSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ class VMSpec extends WordSpec with PropertyChecks with Matchers {
accountStartNonce = 0,
atlantisBlockNumber = Long.MaxValue,
aghartaBlockNumber = Long.MaxValue,
phoenixBlockNumber = Long.MaxValue
phoenixBlockNumber = Long.MaxValue,
chainId = 0x3d.toByte
)

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