Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EIP-6190: Functional SELFDESTRUCT #6190

Merged
merged 11 commits into from
Jan 10, 2023
56 changes: 56 additions & 0 deletions EIPS/eip-6190.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
eip: 6190
title: Functional SELFDESTRUCT
description: Changes SELFDESTRUCT to only cause a finite number of state changes
author: Pandapip1 (@Pandapip1), Alex Beregszaszi (@axic)
discussions-to: https://ethereum-magicians.org/t/eip-6190-functional-selfdestruct/12232
status: Draft
type: Standards Track
category: Core
created: 2022-12-20
requires: 2929, 6189
---

## Abstract

Changes `SELFDESTRUCT` to only cause a finite number of state changes.

## Motivation

The `SELFDESTRUCT` instruction has a fixed price, but is unbounded in storage/account changes (it needs to delete all keys). This has been an outstanding concern for some time.

Furthermore, with *Verkle trees* accounts will be organised differently. Account properties, including storage, would have individual keys. It would not be possible to traverse and find all used keys. This makes `SELFDESTRUCT` very challenging to support in Verkle trees. This EIP is a step towards supporting `SELFDESTRUCT` in Verkle trees.

## Specification

The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC 2119 and RFC 8174.

### `SELFDESTRUCT` Behaviour

Instead of destroying the contract at the end of the transaction, instead, the following will occur at the end of the transaction in which it is invoked:

1. The contract's code is set to `0x1`, and its nonce is set to `2^64-1`.
2. Starting at the contract's address plus one, while either that address's code or nonce are not equal to zero, increment it. The contract's `0`th storage slot is set to that address.
3. If the contract was self-destructed after the call being forwarded by one or more alias contracts, the alias contract's `0`th storage slot is set to the address calculated in step 2.
4. The contract's balance is transferred, in its entirety, to the address on the top of the stack.
5. The top of the stack is popped.

### Gas Cost of `SELFDESTRUCT`

The base gas cost of `SELFDESTRUCT` is set to `5000`. The gas cost of `SELFDESTRUCT` is increased by `5000` for each alias contract that forwarded to the contract being self-destructed. Finally, the [EIP-2929](./eip-2929.md) gas cost increase is applied.

## Rationale

This EIP is a step towards supporting `SELFDESTRUCT` in Verkle trees. It is a minimal change to the current behaviour.
Pandapip1 marked this conversation as resolved.
Show resolved Hide resolved

## Backwards Compatibility

This EIP requires a protocol upgrade, since it modifies consensus rules.

## Security Considerations

None.
Pandapip1 marked this conversation as resolved.
Show resolved Hide resolved

## Copyright

Copyright and related rights waived via [CC0](../LICENSE.md).