integrate evmc 'getStorage'

This commit is contained in:
andri lim 2020-01-16 21:56:59 +07:00 committed by zah
parent a4a1148a45
commit fdbc888840
3 changed files with 11 additions and 6 deletions

View File

@ -80,6 +80,12 @@ template accountExists*(c: Computation, address: EthAddress): bool =
else:
c.vmState.readOnlyStateDB.accountExists(address)
template getStorage*(c: Computation, slot: Uint256): Uint256 =
when evmc_enabled:
c.host.getStorage(c.msg.contractAddress, slot)
else:
c.vmState.readOnlyStateDB.getStorage(c.msg.contractAddress, slot)[0]
proc newComputation*(vmState: BaseVMState, message: Message): Computation =
new result
result.vmState = vmState

View File

@ -48,6 +48,7 @@ proc getStorage*(ctx: HostContext, address: EthAddress, key: Uint256): Uint256 =
var
address = toEvmc(address)
key = toEvmc(key)
{.gcsafe.}:
Uint256.fromEvmc ctx.host.get_storage(ctx.context, address.addr, key.addr)
proc setStorage*(ctx: HostContext, address: EthAddress,

View File

@ -426,15 +426,13 @@ op mstore8, inline = true, memStartPos, value:
op sload, inline = true, slot:
## 0x54, Load word from storage.
let (value, _) = c.vmState.readOnlyStateDB.getStorage(c.msg.contractAddress, slot)
push(value)
push: c.getStorage(slot)
op sstore, inline = false, slot, value:
## 0x55, Save word to storage.
checkInStaticContext(c)
let (currentValue, existing) = c.vmState.readOnlyStateDB.getStorage(c.msg.contractAddress, slot)
let currentValue = c.getStorage(slot)
let
gasParam = GasParams(kind: Op.Sstore, s_isStorageEmpty: currentValue.isZero)
@ -930,7 +928,7 @@ op sstoreEIP2200, inline = false, slot, value:
raise newException(OutOfGas, "Gas not enough to perform EIP2200 SSTORE")
let stateDB = c.vmState.readOnlyStateDB
let (currentValue, existing) = stateDB.getStorage(c.msg.contractAddress, slot)
let currentValue = c.getStorage(slot)
let
gasParam = GasParams(kind: Op.Sstore,