From a0b548e838bf3ed91d27c9af2d1aa011b2ce0116 Mon Sep 17 00:00:00 2001 From: Nick Johnson Date: Wed, 2 May 2018 14:22:15 -0400 Subject: [PATCH 1/2] Create eip-x-codehash.md --- EIPS/eip-x-codehash.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 EIPS/eip-x-codehash.md diff --git a/EIPS/eip-x-codehash.md b/EIPS/eip-x-codehash.md new file mode 100644 index 00000000000000..ecf0a36571154c --- /dev/null +++ b/EIPS/eip-x-codehash.md @@ -0,0 +1,36 @@ +--- +eip: +title: CODEHASH opcode +author: Nick Johnson +discussions-to: +status: Draft +type: Standards Track +category: Core +created: 2018-05-02 +--- + +## Abstract +This EIP specifies a new opcode, which returns the keccak256 hash of a contract's code. + +## Motivation +Many contracts need to perform checks on a contract's bytecode, but do not necessarily need the bytecode itself. For instance, a contract may want to check if another contract's bytecode is one of a set of permitted implementations, or it may perform analyses on code and whitelist any contract with matching bytecode if the analysis passes. + +Contracts can presently do this using the `CODECOPY` opcode, but this is expensive, especially for large contracts, in cases where only the hash is required. As a result, we propose a new opcode, `CODEHASH`, which returns the keccak256 hash of a contract's bytecode. + +## Specification +A new opcode, `CODEHASH`, is introduced, with number 0x3D. `CODEHASH` takes one argument from the stack, and pushes the keccak256 hash of the code at that address to the stack. + +## Rationale +As described in the motivation section, this opcode is widely useful, and saves on wasted gas in many cases. + +## Backwards Compatibility +There are no backwards compatibility concerns. + +## Test Cases +TBD + +## Implementation +TBD + +## Copyright +Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/). From 5d88c56d1aa10713b64eee47f8b3cd48a222ac8b Mon Sep 17 00:00:00 2001 From: Nick Johnson Date: Wed, 2 May 2018 14:25:08 -0400 Subject: [PATCH 2/2] Update and rename eip-x-codehash.md to eip-1052.md --- EIPS/{eip-x-codehash.md => eip-1052.md} | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) rename EIPS/{eip-x-codehash.md => eip-1052.md} (62%) diff --git a/EIPS/eip-x-codehash.md b/EIPS/eip-1052.md similarity index 62% rename from EIPS/eip-x-codehash.md rename to EIPS/eip-1052.md index ecf0a36571154c..112a9f7348c2cd 100644 --- a/EIPS/eip-x-codehash.md +++ b/EIPS/eip-1052.md @@ -1,8 +1,8 @@ --- -eip: -title: CODEHASH opcode +eip: 1052 +title: EXTCODEHASH opcode author: Nick Johnson -discussions-to: +discussions-to: https://ethereum-magicians.org/t/extcodehash-opcode/262 status: Draft type: Standards Track category: Core @@ -15,10 +15,10 @@ This EIP specifies a new opcode, which returns the keccak256 hash of a contract' ## Motivation Many contracts need to perform checks on a contract's bytecode, but do not necessarily need the bytecode itself. For instance, a contract may want to check if another contract's bytecode is one of a set of permitted implementations, or it may perform analyses on code and whitelist any contract with matching bytecode if the analysis passes. -Contracts can presently do this using the `CODECOPY` opcode, but this is expensive, especially for large contracts, in cases where only the hash is required. As a result, we propose a new opcode, `CODEHASH`, which returns the keccak256 hash of a contract's bytecode. +Contracts can presently do this using the `EXTCODECOPY` opcode, but this is expensive, especially for large contracts, in cases where only the hash is required. As a result, we propose a new opcode, `EXTCODEHASH`, which returns the keccak256 hash of a contract's bytecode. ## Specification -A new opcode, `CODEHASH`, is introduced, with number 0x3D. `CODEHASH` takes one argument from the stack, and pushes the keccak256 hash of the code at that address to the stack. +A new opcode, `EXTCODEHASH`, is introduced, with number 0x3D. `EXTCODEHASH` takes one argument from the stack, and pushes the keccak256 hash of the code at that address to the stack. ## Rationale As described in the motivation section, this opcode is widely useful, and saves on wasted gas in many cases.