2018-04-06 14:52:10 +00:00
|
|
|
# Nimbus
|
|
|
|
# Copyright (c) 2018 Status Research & Development GmbH
|
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
2018-01-29 17:40:22 +00:00
|
|
|
import
|
2018-05-28 10:22:28 +00:00
|
|
|
../constants, ../utils_numeric, .. / utils / [keccak, bytes], .. / vm / [stack, memory, gas_meter], ../computation, ../vm_types, helpers, stint
|
2018-01-29 17:40:22 +00:00
|
|
|
|
|
|
|
proc sha3op*(computation: var BaseComputation) =
|
|
|
|
let (startPosition, size) = computation.stack.popInt(2)
|
2018-05-25 10:25:19 +00:00
|
|
|
let (pos, len) = (startPosition.toInt, size.toInt)
|
|
|
|
computation.extendMemory(pos, len)
|
|
|
|
let sha3Bytes = computation.memory.read(pos, len)
|
|
|
|
let wordCount = sha3Bytes.len.ceil32 div 32 # TODO, can't we just shr instead of rounding + div
|
2018-01-29 17:40:22 +00:00
|
|
|
let gasCost = constants.GAS_SHA3_WORD * wordCount
|
|
|
|
computation.gasMeter.consumeGas(gasCost, reason="SHA3: word gas cost")
|
2018-01-31 12:57:05 +00:00
|
|
|
var res = keccak("")
|
2018-01-29 17:40:22 +00:00
|
|
|
pushRes()
|