Skip to content

Commit

Permalink
Pass accessList in extenal EVM calls
Browse files Browse the repository at this point in the history
  • Loading branch information
dzajkowski committed Sep 28, 2021
1 parent a0bdfe5 commit 9e5189e
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/main/scala/io/iohk/ethereum/extvm/VMServer.scala
@@ -1,7 +1,6 @@
package io.iohk.ethereum.extvm

import java.nio.ByteOrder

import akka.NotUsed
import akka.actor.ActorSystem
import akka.stream.OverflowStrategy
Expand All @@ -17,13 +16,12 @@ import scala.annotation.tailrec
import scala.util.Failure
import scala.util.Success
import scala.util.Try

import com.google.protobuf.{ByteString => GByteString}
import com.typesafe.config.ConfigFactory

import io.iohk.ethereum.domain.Address
import io.iohk.ethereum.domain.BlockHeader
import io.iohk.ethereum.extvm.Implicits._
import io.iohk.ethereum.extvm.msg.{AccessListData, StorageEntry}
import io.iohk.ethereum.utils._
import io.iohk.ethereum.vm.BlockchainConfigForEvm
import io.iohk.ethereum.vm.EvmConfig
Expand Down Expand Up @@ -106,6 +104,7 @@ class VMServer(messageHandler: MessageHandler) extends Logger {
messageHandler.close()
}

// scalastyle:off method.length
private def constructContextFromMsg(contextMsg: msg.CallContext): ProgramContext[World, Storage] = {
import ByteString.{empty => irrelevant} // used for irrelevant BlockHeader fields

Expand Down Expand Up @@ -136,6 +135,10 @@ class VMServer(messageHandler: MessageHandler) extends Logger {
val recipientAddr: Option[Address] =
Option(contextMsg.recipientAddr).filterNot(_.isEmpty).map(bytes => Address(bytes: ByteString))

val (warmAddresses: Set[Address], warmStorage: Set[(Address, BigInt)]) = contextMsg.extraData.accessList
.map(extractWarmAccessList)
.getOrElse((Set.empty[Address], Set.empty[(Address, BigInt)]))

ProgramContext(
callerAddr = contextMsg.callerAddr,
originAddr = contextMsg.callerAddr,
Expand All @@ -152,11 +155,19 @@ class VMServer(messageHandler: MessageHandler) extends Logger {
initialAddressesToDelete = Set(),
evmConfig = vmConfig,
originalWorld = world,
// TODO ETCM-1202 use access list from CallContext
warmAddresses = Set.empty,
warmStorage = Set.empty
warmAddresses = warmAddresses,
warmStorage = warmStorage
)
}
// scalastyle:on method.length

private def extractWarmAccessList(ald: AccessListData): (Set[Address], Set[(Address, BigInt)]) = {
val warmAddresses: Set[Address] = ald.addresses.toSet.map((bs: GByteString) => Address(bs: ByteString))
val warmStorage: Set[(Address, BigInt)] = ald.storageLocations.toSet.map { (se: StorageEntry) =>
(Address(se.address: ByteString), se.storageLocation: BigInt)
}
(warmAddresses, warmStorage)
}

private def buildResultMsg(result: ProgramResult[World, Storage]): msg.CallResult = {

Expand Down

0 comments on commit 9e5189e

Please sign in to comment.