implement constantinople bitwise opcode
This commit is contained in:
parent
2f08a6bc0e
commit
4a7f58c7dc
|
@ -198,9 +198,7 @@ proc isEmptyAccount*(db: AccountStateDB, address: EthAddress): bool =
|
|||
account.balance.isZero and
|
||||
account.nonce == 0
|
||||
|
||||
proc isDeadAccount*(db: AccountStateDB, address: EthAddress, dust: static[bool]): bool =
|
||||
## dust == true: deadAccount == accountExists or emptyAccount
|
||||
## dust == false: deadAccount == accountExists and emptyAccount(used in EIP158)
|
||||
proc isDeadAccount*(db: AccountStateDB, address: EthAddress): bool =
|
||||
let recordFound = db.trie.get(createRangeFromAddress address)
|
||||
if recordFound.len > 0:
|
||||
let account = rlp.decode(recordFound, Account)
|
||||
|
@ -208,10 +206,7 @@ proc isDeadAccount*(db: AccountStateDB, address: EthAddress, dust: static[bool])
|
|||
account.balance.isZero and
|
||||
account.nonce == 0
|
||||
else:
|
||||
result = dust
|
||||
|
||||
template isDeadAccount*(db: AccountStateDB, address: EthAddress): bool =
|
||||
isDeadAccount(db, address, true)
|
||||
result = true
|
||||
|
||||
proc rootHash*(db: ReadOnlyStateDB): KeccakHash {.borrow.}
|
||||
proc getAccount*(db: ReadOnlyStateDB, address: EthAddress): Account {.borrow.}
|
||||
|
@ -223,6 +218,5 @@ proc getNonce*(db: ReadOnlyStateDB, address: EthAddress): AccountNonce {.borrow.
|
|||
proc getCode*(db: ReadOnlyStateDB, address: EthAddress): ByteRange {.borrow.}
|
||||
proc hasCodeOrNonce*(db: ReadOnlyStateDB, address: EthAddress): bool {.borrow.}
|
||||
proc accountExists*(db: ReadOnlyStateDB, address: EthAddress): bool {.borrow.}
|
||||
|
||||
template isDeadAccount*(db: ReadOnlyStateDB, address: EthAddress): bool =
|
||||
isDeadAccount(AccountStateDB(db), address, true)
|
||||
proc isDeadAccount*(db: ReadOnlyStateDB, address: EthAddress): bool {.borrow.}
|
||||
proc isEmptyAccount*(db: ReadOnlyStateDB, address: EthAddress): bool {.borrow.}
|
||||
|
|
|
@ -878,21 +878,37 @@ op selfDestructEip161, inline = false:
|
|||
selfDestructImpl(computation, beneficiary)
|
||||
|
||||
# Constantinople's new opcodes
|
||||
op shlOp, inline = true, num, shift:
|
||||
# TODO: implementation
|
||||
discard
|
||||
op shlOp, inline = true, shift, num:
|
||||
let shiftLen = shift.safeInt
|
||||
if shiftLen >= 256:
|
||||
push: 0
|
||||
else:
|
||||
push: num shl shiftLen
|
||||
|
||||
op shrOp, inline = true, num, shift:
|
||||
# TODO: implementation
|
||||
discard
|
||||
op shrOp, inline = true, shift, num:
|
||||
let shiftLen = shift.safeInt
|
||||
if shiftLen >= 256:
|
||||
push: 0
|
||||
else:
|
||||
push: num shr shiftLen
|
||||
|
||||
op sarOp, inline = true, num, shift:
|
||||
# TODO: implementation
|
||||
discard
|
||||
op sarOp, inline = true:
|
||||
let shiftLen = computation.stack.popInt().safeInt
|
||||
let num = cast[Int256](computation.stack.popInt())
|
||||
if shiftLen >= 256:
|
||||
if num.isNegative:
|
||||
push: cast[Uint256]((-1).i256)
|
||||
else:
|
||||
push: 0
|
||||
else:
|
||||
push: cast[Uint256](ashr(num, shiftLen))
|
||||
|
||||
op extCodeHash, inline = true, address:
|
||||
# TODO: implementation
|
||||
discard
|
||||
op extCodeHash, inline = true:
|
||||
let address = computation.stack.popAddress()
|
||||
if computation.vmState.readOnlyStateDB.isEmptyAccount(address):
|
||||
push: 0
|
||||
else:
|
||||
push: computation.vmState.readOnlyStateDB.getCodeHash(address)
|
||||
|
||||
op create2, inline = false:
|
||||
# TODO: implementation
|
||||
|
|
Loading…
Reference in New Issue