Merge pull request #82 from status-im/ImplementSelfDestructOp

Implemented selfDestruct op
This commit is contained in:
Yuriy Glukhov 2018-07-25 13:41:14 +03:00 committed by GitHub
commit 8713939bfe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 6 deletions

View File

@ -602,7 +602,7 @@ OK: 0/18 Fail: 0/18 Skip: 18/18
+ push30.json OK
+ push31.json OK
+ push32.json OK
- push32AndSuicide.json Fail
+ push32AndSuicide.json OK
+ push32FillUpInputWithZerosAtTheEnd.json OK
+ push32Undefined.json OK
+ push32Undefined2.json OK
@ -633,7 +633,7 @@ OK: 0/18 Fail: 0/18 Skip: 18/18
+ swap9.json OK
+ swapjump1.json OK
```
OK: 73/74 Fail: 1/74 Skip: 0/74
OK: 74/74 Fail: 0/74 Skip: 0/74
## vmRandomTest
```diff
201503102037PYTHON.json Skip
@ -722,6 +722,6 @@ OK: 0/36 Fail: 0/36 Skip: 36/36
- arith.json Fail
- boolean.json Fail
- mktx.json Fail
- suicide.json Fail
+ suicide.json OK
```
OK: 0/4 Fail: 4/4 Skip: 0/4
OK: 1/4 Fail: 3/4 Skip: 0/4

View File

@ -775,8 +775,29 @@ op revert, inline = false, startPos, size:
op selfDestruct, inline = false:
## 0xff Halt execution and register account for later deletion.
# TODO: This is the basic implementation of the self destruct op,
# Other forks have some extra functionality around this call.
# In particular, EIP150 and EIP161 have extra requirements.
let beneficiary = computation.stack.popAddress()
## TODO
computation.vmState.mutateStateDB:
let
local_balance = db.get_balance(computation.msg.storage_address)
beneficiary_balance = db.get_balance(beneficiary)
# Transfer to beneficiary
db.setBalance(beneficiary, local_balance + beneficiary_balance)
# Zero the balance of the address being deleted.
# This must come after sending to beneficiary in case the
# contract named itself as the beneficiary.
db.set_balance(computation.msg.storage_address, 0.u256)
# Register the account to be deleted
computation.registerAccountForDeletion(beneficiary)
computation.vm_state.logger.debug(
"SELFDESTRUCT: %s (%s) -> %s" &
computation.msg.storage_address.toHex &
local_balance.toString &
beneficiary.toHex)